Skip to content

Commit 404a5f4

Browse files
authored
Merge pull request #287 from lutovich/1.5-result-docs
Improve JSDoc around Result and ResultSummary
2 parents 7925c65 + 4c6b130 commit 404a5f4

File tree

2 files changed

+76
-12
lines changed

2 files changed

+76
-12
lines changed

src/v1/result-summary.js

+64-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* limitations under the License.
1818
*/
1919

20-
import {int, isInt} from './integer';
20+
import {isInt} from './integer';
2121

2222
/**
2323
* A ResultSummary instance contains structured metadata for a {Result}.
@@ -31,19 +31,79 @@ class ResultSummary {
3131
* @param {Object} metadata - Statement metadata
3232
*/
3333
constructor(statement, parameters, metadata) {
34+
/**
35+
* The statement and parameters this summary is for.
36+
* @type {{text: string, parameters: Object}}
37+
* @public
38+
*/
3439
this.statement = {text: statement, parameters};
40+
41+
/**
42+
* The type of statement executed. Can be "r" for read-only statement, "rw" for read-write statement,
43+
* "w" for write-only statement and "s" for schema-write statement.
44+
* String constants are available in {@link statementType} object.
45+
* @type {string}
46+
* @public
47+
*/
3548
this.statementType = metadata.type;
36-
let counters = new StatementStatistics(metadata.stats || {});
37-
this.counters = counters;
49+
50+
/**
51+
* Counters for operations the statement triggered.
52+
* @type {StatementStatistics}
53+
* @public
54+
*/
55+
this.counters = new StatementStatistics(metadata.stats || {});
3856
//for backwards compatibility, remove in future version
39-
this.updateStatistics = counters;
57+
this.updateStatistics = this.counters;
58+
59+
/**
60+
* This describes how the database will execute the statement.
61+
* Statement plan for the executed statement if available, otherwise undefined.
62+
* Will only be populated for queries that start with "EXPLAIN".
63+
* @type {Plan}
64+
*/
4065
this.plan = metadata.plan || metadata.profile ? new Plan(metadata.plan || metadata.profile) : false;
66+
67+
/**
68+
* This describes how the database did execute your statement. This will contain detailed information about what
69+
* each step of the plan did. Profiled statement plan for the executed statement if available, otherwise undefined.
70+
* Will only be populated for queries that start with "PROFILE".
71+
* @type {ProfiledPlan}
72+
* @public
73+
*/
4174
this.profile = metadata.profile ? new ProfiledPlan(metadata.profile) : false;
75+
76+
/**
77+
* An array of notifications that might arise when executing the statement. Notifications can be warnings about
78+
* problematic statements or other valuable information that can be presented in a client. Unlike failures
79+
* or errors, notifications do not affect the execution of a statement.
80+
* @type {Array<Notification>}
81+
* @public
82+
*/
4283
this.notifications = this._buildNotifications(metadata.notifications);
84+
85+
/**
86+
* The basic information of the server where the result is obtained from.
87+
* @type {ServerInfo}
88+
* @public
89+
*/
4390
this.server = new ServerInfo(metadata.server);
91+
92+
/**
93+
* The time it took the server to consume the result.
94+
* @type {number}
95+
* @public
96+
*/
4497
this.resultConsumedAfter = metadata.result_consumed_after;
98+
99+
/**
100+
* The time it took the server to make the result available for consumption in milliseconds.
101+
* @type {number}
102+
* @public
103+
*/
45104
this.resultAvailableAfter = metadata.result_available_after;
46105
}
106+
47107
_buildNotifications(notifications) {
48108
if(!notifications) {
49109
return [];

src/v1/result.js

+12-8
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@ const DEFAULT_ON_COMPLETED = summary => {
2727
};
2828

2929
/**
30-
* A stream of {@link Record} representing the result of a statement.
31-
* @access public
32-
*/
30+
* A stream of {@link Record} representing the result of a statement.
31+
* Can be consumed eagerly as {@link Promise} resolved with {@link Array<Record>} records and {@link ResultSummary}
32+
* summary, or rejected with error that contains {@link string} code and {@link string} message.
33+
* Alternatively can be consumed lazily using {@link Result.subscribe()}.
34+
* @access public
35+
*/
3336
class Result {
3437
/**
3538
* Inject the observer to be used.
@@ -77,8 +80,9 @@ class Result {
7780
* Waits for all results and calls the passed in function with the results.
7881
* Cannot be combined with the {@link #subscribe} function.
7982
*
80-
* @param {function(result: {records:Array<Record>})} onFulfilled - Function to be called when finished.
81-
* @param {function(error: {message:string, code:string})} onRejected - Function to be called upon errors.
83+
* @param {function(result: {records:Array<Record>, summary: ResultSummary})} onFulfilled - function to be called
84+
* when finished.
85+
* @param {function(error: {message:string, code:string})} onRejected - function to be called upon errors.
8286
* @return {Promise} promise.
8387
*/
8488
then(onFulfilled, onRejected) {
@@ -102,9 +106,9 @@ class Result {
102106
* of handling the results, and allows you to handle arbitrarily large results.
103107
*
104108
* @param {Object} observer - Observer object
105-
* @param {function(record: Record)} observer.onNext - Handle records, one by one.
106-
* @param {function(metadata: Object)} observer.onCompleted - Handle stream tail, the metadata.
107-
* @param {function(error: {message:string, code:string})} observer.onError - Handle errors.
109+
* @param {function(record: Record)} observer.onNext - handle records, one by one.
110+
* @param {function(summary: ResultSummary)} observer.onCompleted - handle stream tail, the result summary.
111+
* @param {function(error: {message:string, code:string})} observer.onError - handle errors.
108112
* @return
109113
*/
110114
subscribe(observer) {

0 commit comments

Comments
 (0)