Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: various jsdoc fixes #352

Merged
merged 3 commits into from
Oct 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/batch-transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class BatchTransaction extends Transaction {
* @private
*
* @param {object} config The request config.
* @param {function} Callback function.
* @param {function} callback Callback function.
*/
createPartitions_(config, callback) {
const self = this;
Expand Down Expand Up @@ -218,7 +218,7 @@ class BatchTransaction extends Transaction {
* @param {ReadPartition|QueryParition} partition The partition object.
* @param {object} [partition.gaxOptions] Request configuration options,
* outlined here: https://googleapis.github.io/gax-nodejs/CallSettings.html.
* @param {TransactionRequestReadCallback|RunCallback} callback Callback
* @param {TransactionRequestReadCallback|RunCallback} [callback] Callback
* function.
* @returns {Promise<RunResponse>|Promise<TransactionRequestReadResponse>}
*
Expand Down
14 changes: 13 additions & 1 deletion src/codec.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ codec.TYPE = TYPE;
* struct characteristics.
*
* @private
*
* @returns {array}
*/
function Struct() {
const struct = [];
Expand Down Expand Up @@ -161,6 +163,9 @@ module.exports.Struct = Struct;
/**
* Wherever a row object is returned, it is assigned a "toJSON" function. This
* function will create that function in a consistent format.
*
* @param {array} row The row to generate JSON for.
* @returns {function}
*/
function generateToJSONFromRow(row) {
return function(options) {
Expand Down Expand Up @@ -205,6 +210,10 @@ codec.generateToJSONFromRow = generateToJSONFromRow;
* Re-decode after the generic gRPC decoding step.
*
* @private
*
* @param {*} value Value to decode
* @param {object[]} field Struct fields
* @returns {*}
*/
function decode(value, field) {
function decodeValue_(decoded, type) {
Expand Down Expand Up @@ -265,6 +274,9 @@ codec.decode = decode;
* Encode a value in the format the API expects.
*
* @private
*
* @param {*} value The value to be encoded
* @returns {*}
*/
function encode(value) {
function preEncode(value) {
Expand Down Expand Up @@ -314,7 +326,7 @@ codec.encode = encode;
* @private
*
* @param {*} field - The field value.
* @return {string}
* @returns {string}
*
* @example
* Database.getType_(NaN);
Expand Down
25 changes: 15 additions & 10 deletions src/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -916,8 +916,8 @@ class Database extends ServiceObject {
*
* @private
*
* @param {object} config
* @param {function} callback
* @param {object} config Request config
* @param {function} callback Callback function
*/
makePooledRequest_(config, callback) {
const self = this;
Expand All @@ -940,7 +940,7 @@ class Database extends ServiceObject {
*
* @private
*
* @param {object} config
* @param {object} config Request config
* @returns {Stream}
*/
makePooledStreamingRequest_(config) {
Expand Down Expand Up @@ -1412,28 +1412,29 @@ class Database extends ServiceObject {
* region_tag:spanner_read_write_transaction
* Read-write transaction:
*/
runTransaction(options, runFn) {
runTransaction(options, callback) {
if (is.fn(options)) {
runFn = options;
callback = options;
options = null;
}
options = extend({}, options);
this.getTransaction(options, function(err, transaction) {
if (err) {
runFn(err);
callback(err);
return;
}
transaction.beginTime_ = Date.now();
transaction.runFn_ = runFn;
transaction.runFn_ = callback;
if (options && options.timeout) {
transaction.timeout_ = options.timeout;
delete options.timeout;
}
runFn(null, transaction);
callback(null, transaction);
});
}
/**
* A function to execute in the context of a transaction.
* @callback RunTransactionAsyncCallback
* @param {Transaction} transaction The transaction object. The transaction has
* already been created, and is ready to be queried and committed against.
*/
Expand Down Expand Up @@ -1464,6 +1465,9 @@ class Database extends ServiceObject {
* @see [Transactions](https://cloud.google.com/spanner/docs/transactions)
* @see [Timestamp Bounds](https://cloud.google.com/spanner/docs/timestamp-bounds)
*
* @param {RunTransactionAsyncCallback} callback A function to execute in the
* context of a transaction.
* @returns {Promise}
*
* @example
* const {Spanner} = require('@google-cloud/spanner');
Expand All @@ -1482,12 +1486,12 @@ class Database extends ServiceObject {
* // ...
* });
*/
runTransactionAsync(runFn) {
runTransactionAsync(callback) {
return retry(() =>
this.getTransaction()
.then(r => {
const transaction = r[0];
return runFn(transaction);
return callback(transaction);
})
.catch(e => {
if (e.code === Transaction.ABORTED) throw e;
Expand Down Expand Up @@ -1635,6 +1639,7 @@ class Database extends ServiceObject {
*
* @param {string} instanceName The formatted instance name.
* @param {string} name The table name.
* @returns {string}
*
* @example
* Database.formatName_(
Expand Down
5 changes: 5 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,9 @@ class Spanner extends Service {
* {{projectId}} placeholders, if necessary.
*
* @private
*
* @param {object} config Request config
* @param {function} callback Callback function
*/
prepareGapicRequest_(config, callback) {
const self = this;
Expand Down Expand Up @@ -647,6 +650,7 @@ class Spanner extends Service {
* @param {function} config.method The gax method to call.
* @param {object} config.reqOpts Request options.
* @param {function} [callback] Callback function.
* @returns {Promise}
*/
request(config, callback) {
const self = this;
Expand Down Expand Up @@ -680,6 +684,7 @@ class Spanner extends Service {
* @param {function} config.method The gax method to call.
* @param {object} config.reqOpts Request options.
* @param {function} [callback] Callback function.
* @returns {Stream}
*/
requestStream(config) {
const self = this;
Expand Down
3 changes: 2 additions & 1 deletion src/instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ class Instance extends common.ServiceObject {
* @see {@link v1.InstanceAdminClient#updateInstance}
* @see [UpdateInstance API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.admin.instance.v1#google.spanner.admin.instance.v1.InstanceAdmin.UpdateInstance)
*
* @param {object<string, *>} metadata The metadata you wish to set.
* @param {object} metadata The metadata you wish to set.
* @param {LongRunningOperationCallback} [callback] Callback function.
* @returns {Promise<LongRunningOperationResponse>}
*
Expand Down Expand Up @@ -650,6 +650,7 @@ class Instance extends common.ServiceObject {
*
* @param {string} projectId The project ID.
* @param {string} name The instance name.
* @returns {string}
*
* @example
* Instance.formatName_('grape-spaceship-123', 'my-instance');
Expand Down
3 changes: 2 additions & 1 deletion src/partial-result-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ const RowBuilder = require('./row-builder');
* @private
*
* @class
* @param {function} requestFn - The function that makes an API request. It will
* @param {function} requestFn The function that makes an API request. It will
* receive one argument, `resumeToken`, which should be used however is
* necessary to send to the API for additional requests.
* @param {object} options Request options
*/
function partialResultStream(requestFn, options) {
let lastResumeToken;
Expand Down
21 changes: 21 additions & 0 deletions src/row-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,16 @@ class RowBuilder {
}
/**
* Add a PartialResultSet response object to the pending rows.
*
* @param {array} row Row values
*/
addRow(row) {
this.chunks = this.chunks.concat(row);
}
/**
* Appends element to row.
*
* @param {*} value Row value
*/
append(value) {
if (this.currentRow.length === this.fields.length) {
Expand Down Expand Up @@ -81,6 +85,8 @@ class RowBuilder {
}
/**
* Flush already complete rows.
*
* @returns {array}
*/
flush() {
const rowsToReturn = this.rows;
Expand All @@ -97,6 +103,9 @@ class RowBuilder {
}
/**
* Transforms values into JSON format.
*
* @param {array[]} rows Rows to convert to JSON.
* @returns {object[]}
*/
toJSON(rows) {
return rows.map(values => {
Expand All @@ -116,6 +125,9 @@ class RowBuilder {
}
/**
* Extracts value from chunk.
*
* @param {object} obj Row value object.
* @returns {*}
*/
static getValue(obj) {
let value = obj;
Expand All @@ -130,6 +142,10 @@ class RowBuilder {
/**
* Format a value into the expected structure, e.g. turn struct values into an
* object.
*
* @param {object} field Field object
* @param {*} value Field value
* @returns {*}
*/
static formatValue(field, value) {
if (value === 'NULL_VALUE') {
Expand All @@ -150,6 +166,11 @@ class RowBuilder {
}
/**
* Merge chunk values.
*
* @param {object} type Field type
* @param {object} head Field value
* @param {object} tail Field value
* @return {array}
*/
static merge(type, head, tail) {
const code = type.code;
Expand Down
1 change: 1 addition & 0 deletions src/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ class Session extends ServiceObject {
*
* @param {string} databaseName The parent database's name.
* @param {string} name The instance name.
* @returns {string}
*
* @example
* Session.formatName_('my-database', 'my-session');
Expand Down
6 changes: 2 additions & 4 deletions src/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ class Table extends TransactionRequest {
* @see [StreamingRead API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.Spanner.StreamingRead)
* @see [ReadRequest API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.ReadRequest)
*
* @param {string} table The table to read from.
* @param {ReadStreamRequestOptions} query Configuration object. See
* [`ReadRequest`](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.ReadRequest).
* @param {TransactionOptions} [options] [Transaction options](https://cloud.google.com/spanner/docs/timestamp-bounds).
Expand Down Expand Up @@ -387,7 +386,6 @@ class Table extends TransactionRequest {
*/
/**
* @typedef {array} TableReadResponse
* @property {Table} 0 The new {@link Table}.
* @property {array[]} 1 Rows are returned as an array of object arrays. Each

This comment was marked as spam.

* object has a `name` and `value` property. To get a serialized object,
* call `toJSON()`. Optionally, provide an options object to `toJSON()`
Expand Down Expand Up @@ -515,13 +513,13 @@ class Table extends TransactionRequest {
* region_tag:spanner_read_data_with_storing_index
* Reading data using a storing index:
*/
read(keyVals, options, callback) {
read(query, options, callback) {
const rows = [];
if (is.fn(options)) {
callback = options;
options = null;
}
this.createReadStream(keyVals, options)
this.createReadStream(query, options)
.on('error', callback)
.on('data', function(row) {
rows.push(row);
Expand Down
Loading