rqlite-js 2.5.2 → 2.5.5
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/.eslintrc +1 -1
- package/.travis.yml +2 -2
- package/es6/api/client/index.js +9 -3
- package/es6/api/data/index.js +35 -7
- package/es6/api/results/data-result-error.js +6 -0
- package/es6/api/results/data-result.js +6 -5
- package/es6/api/results/data-results.js +8 -6
- package/es6/api/status/index.js +1 -1
- package/es6/http-request/content-types.js +1 -1
- package/es6/http-request/index.js +41 -33
- package/lib/api/backup/index.js +1 -1
- package/lib/api/backup/index.js.map +1 -1
- package/lib/api/client/index.js +18 -12
- package/lib/api/client/index.js.map +1 -1
- package/lib/api/data/index.js +43 -15
- package/lib/api/data/index.js.map +1 -1
- package/lib/api/results/data-result-error.js +6 -0
- package/lib/api/results/data-result-error.js.map +1 -1
- package/lib/api/results/data-result.js +7 -6
- package/lib/api/results/data-result.js.map +1 -1
- package/lib/api/results/data-results.js +13 -11
- package/lib/api/results/data-results.js.map +1 -1
- package/lib/api/results/index.js.map +1 -1
- package/lib/api/status/index.js +2 -2
- package/lib/api/status/index.js.map +1 -1
- package/lib/http-request/content-types.js +2 -2
- package/lib/http-request/content-types.js.map +1 -1
- package/lib/http-request/errors.js.map +1 -1
- package/lib/http-request/http-methods.js.map +1 -1
- package/lib/http-request/index.js +62 -54
- package/lib/http-request/index.js.map +1 -1
- package/lib/http-request/retryable.js +1 -1
- package/lib/http-request/retryable.js.map +1 -1
- package/lib/index.js.map +1 -1
- package/package.json +18 -18
- package/CHANGELOG.md +0 -306
package/.eslintrc
CHANGED
package/.travis.yml
CHANGED
|
@@ -13,8 +13,8 @@ cache:
|
|
|
13
13
|
- "node_modules"
|
|
14
14
|
|
|
15
15
|
before_install:
|
|
16
|
-
- docker pull rqlite/rqlite:5.
|
|
17
|
-
- docker run -d -p 4001:4001 -p 4002:4002 --name=rqlite-js rqlite/rqlite:5.
|
|
16
|
+
- docker pull rqlite/rqlite:5.12.1
|
|
17
|
+
- docker run -d -p 4001:4001 -p 4002:4002 --name=rqlite-js rqlite/rqlite:5.12.1
|
|
18
18
|
|
|
19
19
|
script:
|
|
20
20
|
- npm run build-all
|
package/es6/api/client/index.js
CHANGED
|
@@ -5,6 +5,11 @@
|
|
|
5
5
|
import HttpRequest from '../../http-request'
|
|
6
6
|
import { HTTP_METHOD_GET, HTTP_METHOD_POST } from '../../http-request/http-methods'
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* @typedef HttpRequestOptions
|
|
10
|
+
* @type {import('../../http-request').HttpRequestOptions}
|
|
11
|
+
*/
|
|
12
|
+
|
|
8
13
|
/**
|
|
9
14
|
* Create the base HTTP query options from RQLite API options
|
|
10
15
|
* @param {Object} [options={}] The RQLite API options
|
|
@@ -40,7 +45,8 @@ export default class ApiClient extends HttpRequest {
|
|
|
40
45
|
/**
|
|
41
46
|
* Perform a RQLite data API get request
|
|
42
47
|
* @param {String} path The path for the request i.e. /db/query
|
|
43
|
-
* @param {
|
|
48
|
+
* @param {String} sql The SQL query
|
|
49
|
+
* @param {HttpRequestOptions} [options={}] RQLite API options
|
|
44
50
|
*/
|
|
45
51
|
async get (path, sql, options = {}) {
|
|
46
52
|
const { useLeader } = options
|
|
@@ -58,8 +64,8 @@ export default class ApiClient extends HttpRequest {
|
|
|
58
64
|
/**
|
|
59
65
|
* Perform a RQLite data API post request
|
|
60
66
|
* @param {String} path The path for the request i.e. /db/query
|
|
61
|
-
* @param {String
|
|
62
|
-
* @param {
|
|
67
|
+
* @param {String} sql The SQL query
|
|
68
|
+
* @param {HttpRequestOptions} [options={}] RQLite API options
|
|
63
69
|
*/
|
|
64
70
|
async post (path, sql, options = {}) {
|
|
65
71
|
const { useLeader } = options
|
package/es6/api/data/index.js
CHANGED
|
@@ -34,12 +34,42 @@ export const CONSISTENCY_LEVEL_STRONG = 'strong'
|
|
|
34
34
|
*/
|
|
35
35
|
export const CONSISTENCY_LEVEL_WEAK = 'weak'
|
|
36
36
|
|
|
37
|
+
/**
|
|
38
|
+
* @typedef HttpRequestOptions
|
|
39
|
+
* @type {import('../../http-request').HttpRequestOptions}
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Data request base options
|
|
44
|
+
* @typedef DataRequestBaseOptions
|
|
45
|
+
* @type {Object}
|
|
46
|
+
* @property {Boolean} [raw] If true return the raw http response from
|
|
47
|
+
* RQLite response
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Data query request base options
|
|
52
|
+
* @typedef QueryRequestBaseOptions
|
|
53
|
+
* @type {Object}
|
|
54
|
+
* @property {String} level The api consistency level
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Data query request options
|
|
59
|
+
* @typedef QueryRequestOptions
|
|
60
|
+
* @type {HttpRequestOptions & DataRequestBaseOptions & QueryRequestBaseOptions}
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Data execute request options
|
|
65
|
+
* @typedef ExecuteRequestOptions
|
|
66
|
+
* @type {HttpRequestOptions & DataRequestBaseOptions}
|
|
67
|
+
*/
|
|
68
|
+
|
|
37
69
|
/**
|
|
38
70
|
* Send an RQLite query API request to the RQLite server
|
|
39
71
|
* @param {String} sql The SQL string to excute on the server
|
|
40
|
-
* @param {
|
|
41
|
-
* @param {Object} [options.raw] If true return the raw http resposne from
|
|
42
|
-
* RQLite response
|
|
72
|
+
* @param {DataRequestBaseOptions} [options={}] RQLite api options
|
|
43
73
|
*/
|
|
44
74
|
function handleResponse (response, options = {}) {
|
|
45
75
|
const { raw } = options
|
|
@@ -57,9 +87,7 @@ export default class DataApiClient extends ApiClient {
|
|
|
57
87
|
/**
|
|
58
88
|
* Send an RQLite query API request to the RQLite server
|
|
59
89
|
* @param {String} sql The SQL string to excute on the server
|
|
60
|
-
* @param {
|
|
61
|
-
* @param {Object} [options.raw] If true return the raw http resposne from
|
|
62
|
-
* RQLite response
|
|
90
|
+
* @param {QueryRequestOptions} [options={}] RQLite api options
|
|
63
91
|
*/
|
|
64
92
|
async query (sql, options = {}) {
|
|
65
93
|
const { level } = options
|
|
@@ -86,7 +114,7 @@ export default class DataApiClient extends ApiClient {
|
|
|
86
114
|
/**
|
|
87
115
|
* Send an RQLite execute API request to the RQLite server
|
|
88
116
|
* @param {String} sql The SQL string to excute on the server
|
|
89
|
-
* @param {
|
|
117
|
+
* @param {ExecuteRequestOptions} [options={}] RQLite execute api options
|
|
90
118
|
*/
|
|
91
119
|
async execute (sql, options = {}) {
|
|
92
120
|
const response = await super.post(PATH_EXECUTE, sql, options)
|
|
@@ -8,6 +8,12 @@
|
|
|
8
8
|
* API call
|
|
9
9
|
*/
|
|
10
10
|
export default class DataResultError extends Error {
|
|
11
|
+
constructor (...args) {
|
|
12
|
+
super(...args)
|
|
13
|
+
this.name = this.constructor.name
|
|
14
|
+
this.code = this.constructor.name
|
|
15
|
+
}
|
|
16
|
+
|
|
11
17
|
/**
|
|
12
18
|
* Get the result data error as plain object
|
|
13
19
|
* @returns {Object} The data as an object
|
|
@@ -10,8 +10,9 @@
|
|
|
10
10
|
export default class DataResult {
|
|
11
11
|
/**
|
|
12
12
|
* The time the results query took to complete
|
|
13
|
+
* @type {Number}
|
|
13
14
|
*/
|
|
14
|
-
time = 0
|
|
15
|
+
time = 0.0
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* The last insert id
|
|
@@ -23,7 +24,7 @@ export default class DataResult {
|
|
|
23
24
|
* The rows affected
|
|
24
25
|
* @type {Number}
|
|
25
26
|
*/
|
|
26
|
-
rowsAffected
|
|
27
|
+
rowsAffected = 0
|
|
27
28
|
|
|
28
29
|
/**
|
|
29
30
|
* An array of DataResult and/or DataResultError instances
|
|
@@ -49,8 +50,8 @@ export default class DataResult {
|
|
|
49
50
|
if (typeof valuesIndex !== 'undefined' && !Number.isFinite(valuesIndex)) {
|
|
50
51
|
throw new Error('The valuesIndex argument is required to be a finite number when provided')
|
|
51
52
|
}
|
|
52
|
-
this.time = result.time
|
|
53
|
-
this.rowsAffected = result.rows_affected
|
|
53
|
+
this.time = parseFloat(result.time || 0.0)
|
|
54
|
+
this.rowsAffected = parseInt(result.rows_affected || 0, 10)
|
|
54
55
|
this.lastInsertId = result.last_insert_id
|
|
55
56
|
// Map the values array to an object where columns are the properties
|
|
56
57
|
if (Number.isFinite(valuesIndex)) {
|
|
@@ -76,7 +77,7 @@ export default class DataResult {
|
|
|
76
77
|
|
|
77
78
|
/**
|
|
78
79
|
* Get the time the result took
|
|
79
|
-
* @returns {Number}
|
|
80
|
+
* @returns {Number} The time the query took
|
|
80
81
|
*/
|
|
81
82
|
getTime () {
|
|
82
83
|
return this.time
|
|
@@ -12,8 +12,9 @@ export default class DataResults {
|
|
|
12
12
|
/**
|
|
13
13
|
* The time the results took to return from the
|
|
14
14
|
* RQLite api
|
|
15
|
+
* @type {Number}
|
|
15
16
|
*/
|
|
16
|
-
time = 0
|
|
17
|
+
time = 0.0
|
|
17
18
|
|
|
18
19
|
/**
|
|
19
20
|
* The results which is an empty arry to start
|
|
@@ -23,8 +24,9 @@ export default class DataResults {
|
|
|
23
24
|
|
|
24
25
|
/**
|
|
25
26
|
* The data result list constructor
|
|
26
|
-
* @param {
|
|
27
|
-
* @param {Number} time The time the API response took to complete
|
|
27
|
+
* @param {Object} data The data object sent from a RQLite API response
|
|
28
|
+
* @param {Number} data.time The time the API response took to complete
|
|
29
|
+
* @param {Object[{error:String,values:Object}]} data.results The results array
|
|
28
30
|
*/
|
|
29
31
|
constructor (data) {
|
|
30
32
|
this.setApiData(data)
|
|
@@ -41,7 +43,7 @@ export default class DataResults {
|
|
|
41
43
|
if (!data.results) {
|
|
42
44
|
throw new Error('The data object is required to have a results property')
|
|
43
45
|
}
|
|
44
|
-
this.time = data.time || 0
|
|
46
|
+
this.time = parseFloat(data.time || 0.0)
|
|
45
47
|
const { results = [] } = data
|
|
46
48
|
this.results = results.reduce((acc, result) => {
|
|
47
49
|
// If there is an error property this is an error
|
|
@@ -77,7 +79,7 @@ export default class DataResults {
|
|
|
77
79
|
|
|
78
80
|
/**
|
|
79
81
|
* Get the time the results took
|
|
80
|
-
* @
|
|
82
|
+
* @returns {Number} The time the query took
|
|
81
83
|
*/
|
|
82
84
|
getTime () {
|
|
83
85
|
return this.time
|
|
@@ -113,7 +115,7 @@ export default class DataResults {
|
|
|
113
115
|
* @returns {String} A JSON string
|
|
114
116
|
*/
|
|
115
117
|
toString () {
|
|
116
|
-
const list = this.results.map((result) => result.
|
|
118
|
+
const list = this.results.map((result) => result.toObject())
|
|
117
119
|
return JSON.stringify(list)
|
|
118
120
|
}
|
|
119
121
|
}
|
package/es6/api/status/index.js
CHANGED
|
@@ -38,7 +38,7 @@ export default class StatusApiClient extends ApiClient {
|
|
|
38
38
|
* Get the RQLite server status for all hosts as an array of object with
|
|
39
39
|
* the host and their status
|
|
40
40
|
* @param {Object} [options={}] RQLite api options
|
|
41
|
-
* @param {Object} [options.raw] If true return the raw http
|
|
41
|
+
* @param {Object} [options.raw] If true return the raw http response from
|
|
42
42
|
* RQLite response
|
|
43
43
|
* @returns {StatusAllHostsResponse[]} An array of http response for the provide hosts
|
|
44
44
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export const CONTENT_TYPE_TEXT_PLAIN = 'text/plain'
|
|
2
|
-
export const CONTENT_TYPE_APPLICATION_JSON = 'application/json
|
|
2
|
+
export const CONTENT_TYPE_APPLICATION_JSON = 'application/json'
|
|
3
3
|
export const CONTENT_TYPE_APPLICATION_X_WWW_FORM_URLENCODED = 'application/x-www-form-urlencoded'
|
|
4
4
|
export const CONTENT_TYPE_APPLICATION_OCTET_STREAM = 'application/octet-stream'
|
|
@@ -20,6 +20,41 @@ import {
|
|
|
20
20
|
RETRYABLE_STATUS_CODES,
|
|
21
21
|
} from './retryable'
|
|
22
22
|
|
|
23
|
+
/**
|
|
24
|
+
* RQliteJS HTTP Request options
|
|
25
|
+
* @typedef HttpRequestOptions
|
|
26
|
+
* @type {Object}
|
|
27
|
+
* @property {Object} [auth] A object for user authentication
|
|
28
|
+
* @property {String} [auth.username] The username for authentication
|
|
29
|
+
* @property {String} [auth.password] The username for authentication
|
|
30
|
+
* @property {Object} [body] The body of the HTTP request
|
|
31
|
+
* @property {Object} [headers={}] HTTP headers to send with the request
|
|
32
|
+
* @property {String} [httpMethod=HTTP_METHOD_GET] The HTTP method for the request
|
|
33
|
+
* i.e. GET or POST
|
|
34
|
+
* @property {Object} [query] An object with the query to send with the HTTP request
|
|
35
|
+
* @property {Boolean} [stream=false] When true the returned value is a request object with
|
|
36
|
+
* stream support instead of a request-promise result
|
|
37
|
+
* @property {Number} [timeout=DEAULT_TIMEOUT] Optional timeout to override default
|
|
38
|
+
* @property {String} uri The uri for the request which can be a relative path to use
|
|
39
|
+
* the currently active host or a full i.e. http://localhost:4001/db/query which is used
|
|
40
|
+
* literally
|
|
41
|
+
* @property {Boolean} [useLeader=false] When true the request will use the master host, the
|
|
42
|
+
* first host in this.hosts, this is ideal for write operations to skip the redirect
|
|
43
|
+
* @property {Number} [retries] The number of retries, defaults to the number of
|
|
44
|
+
* hosts times 3
|
|
45
|
+
* @property {Number} [maxRedirects=10] The maximum number of HTTP redirects to follow before
|
|
46
|
+
* throwing an error
|
|
47
|
+
* @property {Number} [attempt=0] The current attempt count when retrying or redirecting
|
|
48
|
+
* @property {Number} [retryAttempt=0] The current attempt based on retry logic
|
|
49
|
+
* @property {Number} [redirectAttempt=0] The current attempt based on redirect logic
|
|
50
|
+
* @property {Number} [attemptHostIndex] When in a retry state the host index of the last
|
|
51
|
+
* attempt which is used to get the next host index
|
|
52
|
+
* @property {import('http').Agent} [httpAgent] An option http agent, useful for
|
|
53
|
+
* keepalive pools using plain HTTP
|
|
54
|
+
* @property {import('https').Agent} [httpsAgent] An option http agent, useful
|
|
55
|
+
* for keepalive pools using SSL
|
|
56
|
+
*/
|
|
57
|
+
|
|
23
58
|
/**
|
|
24
59
|
* The default timeout value
|
|
25
60
|
*/
|
|
@@ -536,36 +571,7 @@ export default class HttpRequest {
|
|
|
536
571
|
|
|
537
572
|
/**
|
|
538
573
|
* Perform an HTTP request using the provided options
|
|
539
|
-
* @param {
|
|
540
|
-
* @param {Object} [options.auth] A object for user authentication
|
|
541
|
-
* @param {String} [options.auth.username] The username for authentication
|
|
542
|
-
* @param {String} [options.auth.password] The username for authentication
|
|
543
|
-
* @param {Object} [options.body] The body of the HTTP request
|
|
544
|
-
* @param {Object} [options.headers={}] HTTP headers to send with the request
|
|
545
|
-
* @param {String} [options.httpMethod=HTTP_METHOD_GET] The HTTP method for the request
|
|
546
|
-
* i.e. GET or POST
|
|
547
|
-
* @param {Object} [options.query] An object with the query to send with the HTTP request
|
|
548
|
-
* @param {Boolean} [options.stream=false] When true the returned value is a request object with
|
|
549
|
-
* stream support instead of a request-promise result
|
|
550
|
-
* @param {Number} [options.timeout=DEAULT_TIMEOUT] Optional timeout to override default
|
|
551
|
-
* @param {String} options.uri The uri for the request which can be a relative path to use
|
|
552
|
-
* the currently active host or a full i.e. http://localhost:4001/db/query which is used
|
|
553
|
-
* literally
|
|
554
|
-
* @param {Boolean} [options.useLeader=false] When true the request will use the master host, the
|
|
555
|
-
* first host in this.hosts, this is ideal for write operations to skip the redirect
|
|
556
|
-
* @param {Number} [options.retries] The number of retries, defaults to the number of
|
|
557
|
-
* hosts times 3
|
|
558
|
-
* @param {Number} [options.maxRedirects=10] The maximum number of HTTP redirects to follow before
|
|
559
|
-
* throwing an error
|
|
560
|
-
* @param {Number} [options.attempt=0] The current attempt count when retrying or redirecting
|
|
561
|
-
* @param {Number} [options.retryAttempt=0] The current attempt based on retry logic
|
|
562
|
-
* @param {Number} [options.redirectAttempt=0] The current attempt based on redirect logic
|
|
563
|
-
* @param {Number} [options.attemptHostIndex] When in a retry state the host index of the last
|
|
564
|
-
* attempt which is used to get the next host index
|
|
565
|
-
* @param {import('http').Agent} [options.httpAgent] An option http agent, useful for
|
|
566
|
-
* keepalive pools using plain HTTP
|
|
567
|
-
* @param {import('https').Agent} [options.httpsAgent] An option http agent, useful
|
|
568
|
-
* for keepalive pools using SSL
|
|
574
|
+
* @param {HttpRequestOptions} [options={}] Options for the HTTP client
|
|
569
575
|
* @returns {Promise<{status: Number, body: Object|String}>} An object with a status and body
|
|
570
576
|
* property when stream is false and a stream when the stream option is true
|
|
571
577
|
* @throws {ERROR_HTTP_REQUEST_MAX_REDIRECTS} When the maximum number of redirect has been reached
|
|
@@ -670,7 +676,9 @@ export default class HttpRequest {
|
|
|
670
676
|
}
|
|
671
677
|
if (retryable && retryAttempt < retries) {
|
|
672
678
|
const waitTime = getWaitTimeExponential(retryAttempt, exponentailBackoffBase)
|
|
673
|
-
const delayPromise = new Promise((resolve) =>
|
|
679
|
+
const delayPromise = new Promise((resolve) => {
|
|
680
|
+
setTimeout(resolve, waitTime)
|
|
681
|
+
})
|
|
674
682
|
await delayPromise
|
|
675
683
|
return this.fetch({
|
|
676
684
|
...options,
|
|
@@ -685,7 +693,7 @@ export default class HttpRequest {
|
|
|
685
693
|
|
|
686
694
|
/**
|
|
687
695
|
* Perform an HTTP GET request
|
|
688
|
-
* @param {
|
|
696
|
+
* @param {HttpRequestOptions} [options={}] The options
|
|
689
697
|
* @see this.fetch() for options
|
|
690
698
|
*/
|
|
691
699
|
async get (options = {}) {
|
|
@@ -694,7 +702,7 @@ export default class HttpRequest {
|
|
|
694
702
|
|
|
695
703
|
/**
|
|
696
704
|
* Perform an HTTP POST request
|
|
697
|
-
* @param {
|
|
705
|
+
* @param {HttpRequestOptions} [options={}] The options
|
|
698
706
|
* @see this.fetch() for options
|
|
699
707
|
*/
|
|
700
708
|
async post (options = {}) {
|
package/lib/api/backup/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports, "__esModule", { value: true });exports.default = exports.
|
|
1
|
+
"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports, "__esModule", { value: true });exports.default = exports.PATH_LOAD = exports.PATH_BACKUP = exports.BACKUP_DATA_FORMAT_SQL = exports.BACKUP_DATA_FORMAT_DUMP = void 0;var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","names":["PATH_LOAD","PATH_BACKUP","BACKUP_DATA_FORMAT_SQL","BACKUP_DATA_FORMAT_DUMP","BackupApiClient","HttpRequest","backup","format","stream","headers","Accept","CONTENT_TYPE_APPLICATION_OCTET_STREAM","query","fmt","undefined","json","uri","useLeader","load","data","body","CONTENT_TYPE_TEXT_PLAIN"],"sources":["../../../es6/api/backup/index.js"],"sourcesContent":["/**\n * Backup api client to perform RQLite back and load operations\n * @module api/backup\n */\nimport HttpRequest from '../../http-request'\nimport { CONTENT_TYPE_APPLICATION_OCTET_STREAM, CONTENT_TYPE_TEXT_PLAIN } from '../../http-request/content-types'\n\n/**\n * The RQLite load api path\n */\nexport const PATH_LOAD = '/db/load'\n\n/**\n * The RQLite backup api path\n */\nexport const PATH_BACKUP = '/db/backup'\n\n/**\n * Use plain SQL dump as the back up format\n */\nexport const BACKUP_DATA_FORMAT_SQL = 'sql'\n\n/**\n * Use sqlite3 dump as the back up format\n */\nexport const BACKUP_DATA_FORMAT_DUMP = 'dump'\n\n/**\n * Backup api client to perform RQLite back up and load operations\n */\nexport default class BackupApiClient extends HttpRequest {\n /**\n * Perform a SQL dump backup from the RQLite server\n * @param {String} [format=BACKUP_DATA_FORMAT_DUMP] The backup data format\n * @returns {Stream} The response stream\n */\n async backup (format = BACKUP_DATA_FORMAT_DUMP) {\n const stream = super.get({\n headers: {\n // Always sends application/octet-stream from the server in RQLite v4.x\n Accept: CONTENT_TYPE_APPLICATION_OCTET_STREAM,\n },\n query: { fmt: format === BACKUP_DATA_FORMAT_SQL ? format : undefined },\n json: false,\n stream: true,\n uri: PATH_BACKUP,\n useLeader: true,\n })\n return stream\n }\n\n /**\n * Perform a SQL restore by sending data the RQLite server\n * @param {Buffer|String} data The data to be loaded\n * @param {String} [format=BACKUP_DATA_FORMAT_SQL] The backup data format\n * @returns {Stream} The response stream\n */\n async load (data, format = BACKUP_DATA_FORMAT_SQL) {\n return super.post({\n body: data,\n headers: {\n // eslint-disable-next-line max-len\n 'Content-Type': format === BACKUP_DATA_FORMAT_SQL ? CONTENT_TYPE_TEXT_PLAIN : CONTENT_TYPE_APPLICATION_OCTET_STREAM,\n },\n json: false,\n stream: true,\n uri: PATH_LOAD,\n useLeader: true,\n })\n }\n}\n"],"mappings":";;;;AAIA;AACA,gE,CALA;AACA;AACA;AACA,G,CAIA;AACA;AACA,GACO,MAAMA,SAAS,GAAG,UAAlB;;AAEP;AACA;AACA,G;AACO,MAAMC,WAAW,GAAG,YAApB;;AAEP;AACA;AACA,G;AACO,MAAMC,sBAAsB,GAAG,KAA/B;;AAEP;AACA;AACA,G;AACO,MAAMC,uBAAuB,GAAG,MAAhC;;AAEP;AACA;AACA,G;AACe,MAAMC,eAAN,SAA8BC,oBAA9B,CAA0C;EACvD;AACF;AACA;AACA;AACA;EACQC,MAAM,CAAEC,MAAM,GAAGJ,uBAAX,EAAoC;MAC9C,MAAMK,MAAM,GAAG,gCAAU;QACvBC,OAAO,EAAE;UACP;UACAC,MAAM,EAAEC,mDAFD,EADc;;QAKvBC,KAAK,EAAE,EAAEC,GAAG,EAAEN,MAAM,KAAKL,sBAAX,GAAoCK,MAApC,GAA6CO,SAApD,EALgB;QAMvBC,IAAI,EAAE,KANiB;QAOvBP,MAAM,EAAE,IAPe;QAQvBQ,GAAG,EAAEf,WARkB;QASvBgB,SAAS,EAAE,IATY,EAAV,CAAf;;MAWA,OAAOT,MAAP,CAZ8C;EAa/C;;EAED;AACF;AACA;AACA;AACA;AACA;EACQU,IAAI,CAAEC,IAAF,EAAQZ,MAAM,GAAGL,sBAAjB,EAAyC;MACjD,OAAO,kCAAW;QAChBkB,IAAI,EAAED,IADU;QAEhBV,OAAO,EAAE;UACP;UACA,gBAAgBF,MAAM,KAAKL,sBAAX,GAAoCmB,qCAApC,GAA8DV,mDAFvE,EAFO;;QAMhBI,IAAI,EAAE,KANU;QAOhBP,MAAM,EAAE,IAPQ;QAQhBQ,GAAG,EAAEhB,SARW;QAShBiB,SAAS,EAAE,IATK,EAAX,CAAP,CADiD;;EAYlD,CAvCsD,C"}
|
package/lib/api/client/index.js
CHANGED
|
@@ -3,7 +3,12 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
var _httpRequest = _interopRequireDefault(require("../../http-request"));
|
|
6
|
-
var _httpMethods = require("../../http-request/http-methods");function ownKeys(object, enumerableOnly) {var keys = Object.keys(object);if (Object.getOwnPropertySymbols) {var symbols = Object.getOwnPropertySymbols(object);
|
|
6
|
+
var _httpMethods = require("../../http-request/http-methods");function ownKeys(object, enumerableOnly) {var keys = Object.keys(object);if (Object.getOwnPropertySymbols) {var symbols = Object.getOwnPropertySymbols(object);enumerableOnly && (symbols = symbols.filter(function (sym) {return Object.getOwnPropertyDescriptor(object, sym).enumerable;})), keys.push.apply(keys, symbols);}return keys;}function _objectSpread(target) {for (var i = 1; i < arguments.length; i++) {var source = null != arguments[i] ? arguments[i] : {};i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {(0, _defineProperty2.default)(target, key, source[key]);}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));});}return target;}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @typedef HttpRequestOptions
|
|
10
|
+
* @type {import('../../http-request').HttpRequestOptions}
|
|
11
|
+
*/
|
|
7
12
|
|
|
8
13
|
/**
|
|
9
14
|
* Create the base HTTP query options from RQLite API options
|
|
@@ -17,13 +22,13 @@ var _httpMethods = require("../../http-request/http-methods");function ownKeys(o
|
|
|
17
22
|
* for RQLite v4 and lower
|
|
18
23
|
* @returns {Object} The HTTP query
|
|
19
24
|
*/
|
|
20
|
-
function createQuery(options = {}) {
|
|
21
|
-
level = options.level,pretty = options.pretty,timings = options.timings,atomic = options.atomic,transaction = options.transaction;
|
|
25
|
+
function createQuery(options = {}) {
|
|
26
|
+
const level = options.level,pretty = options.pretty,timings = options.timings,atomic = options.atomic,transaction = options.transaction;
|
|
22
27
|
|
|
23
28
|
// Remove all undefined values
|
|
24
29
|
const query = { level, pretty, timings, atomic, transaction };
|
|
25
|
-
return Object.entries(query).reduce((acc, entry) => {
|
|
26
|
-
entry, 2),key = _entry[0],val = _entry[1];
|
|
30
|
+
return Object.entries(query).reduce((acc, entry) => {
|
|
31
|
+
const _entry = (0, _slicedToArray2.default)(entry, 2),key = _entry[0],val = _entry[1];
|
|
27
32
|
// Only take defined values
|
|
28
33
|
if (typeof val !== 'undefined') {
|
|
29
34
|
acc[key] = val;
|
|
@@ -40,10 +45,11 @@ class ApiClient extends _httpRequest.default {
|
|
|
40
45
|
/**
|
|
41
46
|
* Perform a RQLite data API get request
|
|
42
47
|
* @param {String} path The path for the request i.e. /db/query
|
|
43
|
-
* @param {
|
|
48
|
+
* @param {String} sql The SQL query
|
|
49
|
+
* @param {HttpRequestOptions} [options={}] RQLite API options
|
|
44
50
|
*/
|
|
45
|
-
get(path, sql, options = {}) {var _superprop_getGet = () => super.get,_this = this;return (0, _asyncToGenerator2.default)(function* () {
|
|
46
|
-
useLeader = options.useLeader;
|
|
51
|
+
get(path, sql, options = {}) {var _superprop_getGet = () => super.get,_this = this;return (0, _asyncToGenerator2.default)(function* () {
|
|
52
|
+
const useLeader = options.useLeader;
|
|
47
53
|
if (!path) {
|
|
48
54
|
throw new Error('The path argument is required');
|
|
49
55
|
}
|
|
@@ -58,11 +64,11 @@ class ApiClient extends _httpRequest.default {
|
|
|
58
64
|
/**
|
|
59
65
|
* Perform a RQLite data API post request
|
|
60
66
|
* @param {String} path The path for the request i.e. /db/query
|
|
61
|
-
* @param {String
|
|
62
|
-
* @param {
|
|
67
|
+
* @param {String} sql The SQL query
|
|
68
|
+
* @param {HttpRequestOptions} [options={}] RQLite API options
|
|
63
69
|
*/
|
|
64
|
-
post(path, sql, options = {}) {var _superprop_getPost = () => super.post,_this2 = this;return (0, _asyncToGenerator2.default)(function* () {
|
|
65
|
-
useLeader = options.useLeader;
|
|
70
|
+
post(path, sql, options = {}) {var _superprop_getPost = () => super.post,_this2 = this;return (0, _asyncToGenerator2.default)(function* () {
|
|
71
|
+
const useLeader = options.useLeader;
|
|
66
72
|
if (!path) {
|
|
67
73
|
throw new Error('The path argument is required');
|
|
68
74
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","names":["createQuery","options","level","pretty","timings","atomic","transaction","query","Object","entries","reduce","acc","entry","key","val","ApiClient","HttpRequest","get","path","sql","useLeader","Error","uri","httpMethod","HTTP_METHOD_GET","q","post","HTTP_METHOD_POST","body","Array","isArray"],"sources":["../../../es6/api/client/index.js"],"sourcesContent":["/**\n * Base API client for RQLite which abstracts the HTTP calls\n * @module api/client\n */\nimport HttpRequest from '../../http-request'\nimport { HTTP_METHOD_GET, HTTP_METHOD_POST } from '../../http-request/http-methods'\n\n/**\n * @typedef HttpRequestOptions\n * @type {import('../../http-request').HttpRequestOptions}\n */\n\n/**\n * Create the base HTTP query options from RQLite API options\n * @param {Object} [options={}] The RQLite API options\n * @param {String} [options.level] The consistency level\n * @param {String} [options.pretty] Pretty print the response body\n * @param {String} [options.timings] Provide query timings\n * @param {String} [options.atomic] Treat all commands in the request as a single transaction\n * for RQLite v5 and higher\n * @param {String} [options.transaction] Treat all commands in the request as a single transaction\n * for RQLite v4 and lower\n * @returns {Object} The HTTP query\n */\nexport function createQuery (options = {}) {\n const { level, pretty, timings, atomic, transaction } = options\n\n // Remove all undefined values\n const query = { level, pretty, timings, atomic, transaction }\n return Object.entries(query).reduce((acc, entry) => {\n const [key, val] = entry\n // Only take defined values\n if (typeof val !== 'undefined') {\n acc[key] = val\n }\n return acc\n }, {})\n}\n\n/**\n * Base API client for RQLite which abstracts the HTTP calls\n * from the user\n */\nexport default class ApiClient extends HttpRequest {\n /**\n * Perform a RQLite data API get request\n * @param {String} path The path for the request i.e. /db/query\n * @param {String} sql The SQL query\n * @param {HttpRequestOptions} [options={}] RQLite API options\n */\n async get (path, sql, options = {}) {\n const { useLeader } = options\n if (!path) {\n throw new Error('The path argument is required')\n }\n return super.get({\n useLeader,\n uri: path,\n httpMethod: HTTP_METHOD_GET,\n query: { ...createQuery(options), q: sql },\n })\n }\n\n /**\n * Perform a RQLite data API post request\n * @param {String} path The path for the request i.e. /db/query\n * @param {String} sql The SQL query\n * @param {HttpRequestOptions} [options={}] RQLite API options\n */\n async post (path, sql, options = {}) {\n const { useLeader } = options\n if (!path) {\n throw new Error('The path argument is required')\n }\n return super.post({\n useLeader,\n uri: path,\n httpMethod: HTTP_METHOD_POST,\n query: createQuery(options),\n body: Array.isArray(sql) ? sql : [sql],\n })\n }\n}\n"],"mappings":";;;;AAIA;AACA,8D;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,WAAT,CAAsBC,OAAO,GAAG,EAAhC,EAAoC;EACzC,MAAQC,KAAR,GAAwDD,OAAxD,CAAQC,KAAR,CAAeC,MAAf,GAAwDF,OAAxD,CAAeE,MAAf,CAAuBC,OAAvB,GAAwDH,OAAxD,CAAuBG,OAAvB,CAAgCC,MAAhC,GAAwDJ,OAAxD,CAAgCI,MAAhC,CAAwCC,WAAxC,GAAwDL,OAAxD,CAAwCK,WAAxC;;EAEA;EACA,MAAMC,KAAK,GAAG,EAAEL,KAAF,EAASC,MAAT,EAAiBC,OAAjB,EAA0BC,MAA1B,EAAkCC,WAAlC,EAAd;EACA,OAAOE,MAAM,CAACC,OAAP,CAAeF,KAAf,EAAsBG,MAAtB,CAA6B,CAACC,GAAD,EAAMC,KAAN,KAAgB;IAClD,4CAAmBA,KAAnB,KAAOC,GAAP,aAAYC,GAAZ;IACA;IACA,IAAI,OAAOA,GAAP,KAAe,WAAnB,EAAgC;MAC9BH,GAAG,CAACE,GAAD,CAAH,GAAWC,GAAX;IACD;IACD,OAAOH,GAAP;EACD,CAPM,EAOJ,EAPI,CAAP;AAQD;;AAED;AACA;AACA;AACA;AACe,MAAMI,SAAN,SAAwBC,oBAAxB,CAAoC;EACjD;AACF;AACA;AACA;AACA;AACA;EACQC,GAAG,CAAEC,IAAF,EAAQC,GAAR,EAAalB,OAAO,GAAG,EAAvB,EAA2B;MAClC,MAAQmB,SAAR,GAAsBnB,OAAtB,CAAQmB,SAAR;MACA,IAAI,CAACF,IAAL,EAAW;QACT,MAAM,IAAIG,KAAJ,CAAU,+BAAV,CAAN;MACD;MACD,OAAO,gCAAU;QACfD,SADe;QAEfE,GAAG,EAAEJ,IAFU;QAGfK,UAAU,EAAEC,4BAHG;QAIfjB,KAAK,kCAAOP,WAAW,CAACC,OAAD,CAAlB,SAA6BwB,CAAC,EAAEN,GAAhC,GAJU,EAAV,CAAP,CALkC;;EAWnC;;EAED;AACF;AACA;AACA;AACA;AACA;EACQO,IAAI,CAAER,IAAF,EAAQC,GAAR,EAAalB,OAAO,GAAG,EAAvB,EAA2B;MACnC,MAAQmB,SAAR,GAAsBnB,OAAtB,CAAQmB,SAAR;MACA,IAAI,CAACF,IAAL,EAAW;QACT,MAAM,IAAIG,KAAJ,CAAU,+BAAV,CAAN;MACD;MACD,OAAO,kCAAW;QAChBD,SADgB;QAEhBE,GAAG,EAAEJ,IAFW;QAGhBK,UAAU,EAAEI,6BAHI;QAIhBpB,KAAK,EAAEP,WAAW,CAACC,OAAD,CAJF;QAKhB2B,IAAI,EAAEC,KAAK,CAACC,OAAN,CAAcX,GAAd,IAAqBA,GAArB,GAA2B,CAACA,GAAD,CALjB,EAAX,CAAP,CALmC;;EAYpC,CAtCgD,C"}
|
package/lib/api/data/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports, "__esModule", { value: true });exports.default = exports.
|
|
1
|
+
"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports, "__esModule", { value: true });exports.default = exports.PATH_QUERY = exports.PATH_EXECUTE = exports.CONSISTENCY_LEVEL_WEAK = exports.CONSISTENCY_LEVEL_STRONG = exports.CONSISTENCY_LEVEL_NONE = void 0;var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
var _client = _interopRequireDefault(require("../client"));
|
|
7
|
-
var _results = require("../results");function ownKeys(object, enumerableOnly) {var keys = Object.keys(object);if (Object.getOwnPropertySymbols) {var symbols = Object.getOwnPropertySymbols(object);
|
|
7
|
+
var _results = require("../results");function ownKeys(object, enumerableOnly) {var keys = Object.keys(object);if (Object.getOwnPropertySymbols) {var symbols = Object.getOwnPropertySymbols(object);enumerableOnly && (symbols = symbols.filter(function (sym) {return Object.getOwnPropertyDescriptor(object, sym).enumerable;})), keys.push.apply(keys, symbols);}return keys;}function _objectSpread(target) {for (var i = 1; i < arguments.length; i++) {var source = null != arguments[i] ? arguments[i] : {};i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {(0, _defineProperty2.default)(target, key, source[key]);}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));});}return target;}
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* The RQLite query api path
|
|
@@ -34,16 +34,46 @@ const CONSISTENCY_LEVEL_STRONG = 'strong';
|
|
|
34
34
|
*/exports.CONSISTENCY_LEVEL_STRONG = CONSISTENCY_LEVEL_STRONG;
|
|
35
35
|
const CONSISTENCY_LEVEL_WEAK = 'weak';
|
|
36
36
|
|
|
37
|
+
/**
|
|
38
|
+
* @typedef HttpRequestOptions
|
|
39
|
+
* @type {import('../../http-request').HttpRequestOptions}
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Data request base options
|
|
44
|
+
* @typedef DataRequestBaseOptions
|
|
45
|
+
* @type {Object}
|
|
46
|
+
* @property {Boolean} [raw] If true return the raw http response from
|
|
47
|
+
* RQLite response
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Data query request base options
|
|
52
|
+
* @typedef QueryRequestBaseOptions
|
|
53
|
+
* @type {Object}
|
|
54
|
+
* @property {String} level The api consistency level
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Data query request options
|
|
59
|
+
* @typedef QueryRequestOptions
|
|
60
|
+
* @type {HttpRequestOptions & DataRequestBaseOptions & QueryRequestBaseOptions}
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Data execute request options
|
|
65
|
+
* @typedef ExecuteRequestOptions
|
|
66
|
+
* @type {HttpRequestOptions & DataRequestBaseOptions}
|
|
67
|
+
*/
|
|
68
|
+
|
|
37
69
|
/**
|
|
38
70
|
* Send an RQLite query API request to the RQLite server
|
|
39
71
|
* @param {String} sql The SQL string to excute on the server
|
|
40
|
-
* @param {
|
|
41
|
-
* @param {Object} [options.raw] If true return the raw http resposne from
|
|
42
|
-
* RQLite response
|
|
72
|
+
* @param {DataRequestBaseOptions} [options={}] RQLite api options
|
|
43
73
|
*/exports.CONSISTENCY_LEVEL_WEAK = CONSISTENCY_LEVEL_WEAK;
|
|
44
|
-
function handleResponse(response, options = {}) {
|
|
45
|
-
raw = options.raw;
|
|
46
|
-
body = response.body;
|
|
74
|
+
function handleResponse(response, options = {}) {
|
|
75
|
+
const raw = options.raw;
|
|
76
|
+
const body = response.body;
|
|
47
77
|
if (raw) {
|
|
48
78
|
return response;
|
|
49
79
|
}
|
|
@@ -57,13 +87,11 @@ class DataApiClient extends _client.default {
|
|
|
57
87
|
/**
|
|
58
88
|
* Send an RQLite query API request to the RQLite server
|
|
59
89
|
* @param {String} sql The SQL string to excute on the server
|
|
60
|
-
* @param {
|
|
61
|
-
* @param {Object} [options.raw] If true return the raw http resposne from
|
|
62
|
-
* RQLite response
|
|
90
|
+
* @param {QueryRequestOptions} [options={}] RQLite api options
|
|
63
91
|
*/
|
|
64
|
-
query(sql, options = {}) {var _superprop_getPost = () => super.post,_superprop_getGet = () => super.get,_this = this;return (0, _asyncToGenerator2.default)(function* () {
|
|
65
|
-
level = options.level;
|
|
66
|
-
useLeader = options.useLeader;
|
|
92
|
+
query(sql, options = {}) {var _superprop_getPost = () => super.post,_superprop_getGet = () => super.get,_this = this;return (0, _asyncToGenerator2.default)(function* () {
|
|
93
|
+
const level = options.level;
|
|
94
|
+
let useLeader = options.useLeader;
|
|
67
95
|
// Weak and strong consistency will be redirect to the master anyway
|
|
68
96
|
// so skip the redirect HTTP response and got right to the master
|
|
69
97
|
if (level !== CONSISTENCY_LEVEL_NONE) {
|
|
@@ -86,7 +114,7 @@ class DataApiClient extends _client.default {
|
|
|
86
114
|
/**
|
|
87
115
|
* Send an RQLite execute API request to the RQLite server
|
|
88
116
|
* @param {String} sql The SQL string to excute on the server
|
|
89
|
-
* @param {
|
|
117
|
+
* @param {ExecuteRequestOptions} [options={}] RQLite execute api options
|
|
90
118
|
*/
|
|
91
119
|
execute(sql, options = {}) {var _superprop_getPost2 = () => super.post,_this2 = this;return (0, _asyncToGenerator2.default)(function* () {
|
|
92
120
|
const response = yield _superprop_getPost2().call(_this2, PATH_EXECUTE, sql, options);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","names":["PATH_QUERY","PATH_EXECUTE","CONSISTENCY_LEVEL_NONE","CONSISTENCY_LEVEL_STRONG","CONSISTENCY_LEVEL_WEAK","handleResponse","response","options","raw","body","DataResults","DataApiClient","ApiClient","query","sql","level","useLeader","Array","isArray","setNextActiveHostIndex","execute"],"sources":["../../../es6/api/data/index.js"],"sourcesContent":["/**\n * Data api client to perform RQLite data operations such\n * as query and execute\n * @module api/data\n */\nimport ApiClient from '../client'\nimport { DataResults } from '../results'\n\n/**\n * The RQLite query api path\n */\nexport const PATH_QUERY = '/db/query'\n\n/**\n * The RQLite execute api path\n */\nexport const PATH_EXECUTE = '/db/execute'\n\n/**\n * Read query consistency level none which means\n * any node can respond\n */\nexport const CONSISTENCY_LEVEL_NONE = 'none'\n\n/**\n * Read query consistency strong which must come from\n * the master node\n */\nexport const CONSISTENCY_LEVEL_STRONG = 'strong'\n\n/**\n * Read query consistency weak which must come from\n * the master node\n */\nexport const CONSISTENCY_LEVEL_WEAK = 'weak'\n\n/**\n * @typedef HttpRequestOptions\n * @type {import('../../http-request').HttpRequestOptions}\n */\n\n/**\n * Data request base options\n * @typedef DataRequestBaseOptions\n * @type {Object}\n * @property {Boolean} [raw] If true return the raw http response from\n * RQLite response\n */\n\n/**\n * Data query request base options\n * @typedef QueryRequestBaseOptions\n * @type {Object}\n * @property {String} level The api consistency level\n */\n\n/**\n * Data query request options\n * @typedef QueryRequestOptions\n * @type {HttpRequestOptions & DataRequestBaseOptions & QueryRequestBaseOptions}\n */\n\n/**\n * Data execute request options\n * @typedef ExecuteRequestOptions\n * @type {HttpRequestOptions & DataRequestBaseOptions}\n */\n\n/**\n * Send an RQLite query API request to the RQLite server\n * @param {String} sql The SQL string to excute on the server\n * @param {DataRequestBaseOptions} [options={}] RQLite api options\n */\nfunction handleResponse (response, options = {}) {\n const { raw } = options\n const { body } = response\n if (raw) {\n return response\n }\n return new DataResults(body)\n}\n\n/**\n * Data api client to perform RQLite queries\n */\nexport default class DataApiClient extends ApiClient {\n /**\n * Send an RQLite query API request to the RQLite server\n * @param {String} sql The SQL string to excute on the server\n * @param {QueryRequestOptions} [options={}] RQLite api options\n */\n async query (sql, options = {}) {\n const { level } = options\n let { useLeader } = options\n // Weak and strong consistency will be redirect to the master anyway\n // so skip the redirect HTTP response and got right to the master\n if (level !== CONSISTENCY_LEVEL_NONE) {\n useLeader = true\n }\n let response\n if (Array.isArray(sql)) {\n response = await super.post(PATH_QUERY, sql, { ...options, useLeader })\n } else {\n response = await super.get(PATH_QUERY, sql, { ...options, useLeader })\n }\n // If round robin is true try and balance selects across hosts when\n // the master node is not queried directly\n if (!useLeader) {\n this.setNextActiveHostIndex()\n }\n return handleResponse(response, options)\n }\n\n /**\n * Send an RQLite execute API request to the RQLite server\n * @param {String} sql The SQL string to excute on the server\n * @param {ExecuteRequestOptions} [options={}] RQLite execute api options\n */\n async execute (sql, options = {}) {\n const response = await super.post(PATH_EXECUTE, sql, options)\n return handleResponse(response, options)\n }\n}\n"],"mappings":";;;;;AAKA;AACA,qC;;AAEA;AACA;AACA;AACO,MAAMA,UAAU,GAAG,WAAnB;;AAEP;AACA;AACA,G;AACO,MAAMC,YAAY,GAAG,aAArB;;AAEP;AACA;AACA;AACA,G;AACO,MAAMC,sBAAsB,GAAG,MAA/B;;AAEP;AACA;AACA;AACA,G;AACO,MAAMC,wBAAwB,GAAG,QAAjC;;AAEP;AACA;AACA;AACA,G;AACO,MAAMC,sBAAsB,GAAG,MAA/B;;AAEP;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,G;AACA,SAASC,cAAT,CAAyBC,QAAzB,EAAmCC,OAAO,GAAG,EAA7C,EAAiD;EAC/C,MAAQC,GAAR,GAAgBD,OAAhB,CAAQC,GAAR;EACA,MAAQC,IAAR,GAAiBH,QAAjB,CAAQG,IAAR;EACA,IAAID,GAAJ,EAAS;IACP,OAAOF,QAAP;EACD;EACD,OAAO,IAAII,oBAAJ,CAAgBD,IAAhB,CAAP;AACD;;AAED;AACA;AACA;AACe,MAAME,aAAN,SAA4BC,eAA5B,CAAsC;EACnD;AACF;AACA;AACA;AACA;EACQC,KAAK,CAAEC,GAAF,EAAOP,OAAO,GAAG,EAAjB,EAAqB;MAC9B,MAAQQ,KAAR,GAAkBR,OAAlB,CAAQQ,KAAR;MACA,IAAMC,SAAN,GAAoBT,OAApB,CAAMS,SAAN;MACA;MACA;MACA,IAAID,KAAK,KAAKb,sBAAd,EAAsC;QACpCc,SAAS,GAAG,IAAZ;MACD;MACD,IAAIV,QAAJ;MACA,IAAIW,KAAK,CAACC,OAAN,CAAcJ,GAAd,CAAJ,EAAwB;QACtBR,QAAQ,SAAS,iCAAWN,UAAX,EAAuBc,GAAvB,kCAAiCP,OAAjC,SAA0CS,SAA1C,IAAjB;MACD,CAFD,MAEO;QACLV,QAAQ,SAAS,gCAAUN,UAAV,EAAsBc,GAAtB,kCAAgCP,OAAhC,SAAyCS,SAAzC,IAAjB;MACD;MACD;MACA;MACA,IAAI,CAACA,SAAL,EAAgB;QACd,KAAI,CAACG,sBAAL;MACD;MACD,OAAOd,cAAc,CAACC,QAAD,EAAWC,OAAX,CAArB,CAnB8B;EAoB/B;;EAED;AACF;AACA;AACA;AACA;EACQa,OAAO,CAAEN,GAAF,EAAOP,OAAO,GAAG,EAAjB,EAAqB;MAChC,MAAMD,QAAQ,SAAS,mCAAWL,YAAX,EAAyBa,GAAzB,EAA8BP,OAA9B,CAAvB;MACA,OAAOF,cAAc,CAACC,QAAD,EAAWC,OAAX,CAArB,CAFgC;EAGjC,CApCkD,C"}
|
|
@@ -8,6 +8,12 @@
|
|
|
8
8
|
* API call
|
|
9
9
|
*/
|
|
10
10
|
class DataResultError extends Error {
|
|
11
|
+
constructor(...args) {
|
|
12
|
+
super(...args);
|
|
13
|
+
this.name = this.constructor.name;
|
|
14
|
+
this.code = this.constructor.name;
|
|
15
|
+
}
|
|
16
|
+
|
|
11
17
|
/**
|
|
12
18
|
* Get the result data error as plain object
|
|
13
19
|
* @returns {Object} The data as an object
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"data-result-error.js","names":["DataResultError","Error","constructor","args","name","code","toObject","error","message","toString","JSON","stringify"],"sources":["../../../es6/api/results/data-result-error.js"],"sourcesContent":["/**\n * Class for handling RQLite data api result error\n * @module api/results/data-results\n */\n\n/**\n * A class that represents one data error result from an RQLite query or execute\n * API call\n */\nexport default class DataResultError extends Error {\n constructor (...args) {\n super(...args)\n this.name = this.constructor.name\n this.code = this.constructor.name\n }\n\n /**\n * Get the result data error as plain object\n * @returns {Object} The data as an object\n */\n toObject () {\n return { error: this.message }\n }\n\n /**\n * Convert the result data error to a JSON string\n * @returns {String} The JSON string for the data object\n */\n toString () {\n return JSON.stringify(this.toObject())\n }\n}\n"],"mappings":"qGAAA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACe,MAAMA,eAAN,SAA8BC,KAA9B,CAAoC;EACjDC,WAAW,CAAE,GAAGC,IAAL,EAAW;IACpB,MAAM,GAAGA,IAAT;IACA,KAAKC,IAAL,GAAY,KAAKF,WAAL,CAAiBE,IAA7B;IACA,KAAKC,IAAL,GAAY,KAAKH,WAAL,CAAiBE,IAA7B;EACD;;EAED;AACF;AACA;AACA;EACEE,QAAQ,GAAI;IACV,OAAO,EAAEC,KAAK,EAAE,KAAKC,OAAd,EAAP;EACD;;EAED;AACF;AACA;AACA;EACEC,QAAQ,GAAI;IACV,OAAOC,IAAI,CAACC,SAAL,CAAe,KAAKL,QAAL,EAAf,CAAP;EACD,CArBgD,C"}
|