Skip to content
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
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,22 @@
"prettier": "repo-tools exec -- prettier --write src/*.js src/*/*.js samples/*.js samples/*/*.js test/*.js test/*/*.js system-test/*.js system-test/*/*.js"
},
"dependencies": {
"@google-cloud/common": "^0.13.0",
"@google-cloud/common-grpc": "^0.4.0",

This comment was marked as spam.

This comment was marked as spam.

"@google-cloud/common": "^0.14.0",
"arrify": "^1.0.0",
"concat-stream": "^1.5.0",
"create-error-class": "^3.0.2",
"extend": "^3.0.0",
"google-auto-auth": "^0.7.2",
"google-gax": "^0.14.2",
"google-proto-files": "^0.13.1",
"is": "^3.0.1",
"lodash.flatten": "^4.2.0",
"modelo": "^4.2.0",
"prop-assign": "^1.0.0",
"propprop": "^0.3.0",
"split-array-stream": "^1.0.0"
"safe-buffer": "^5.1.1",
"split-array-stream": "^1.0.0",
"stream-events": "^1.0.2",
"through2": "^2.0.3"
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "^2.1.1",
Expand All @@ -78,10 +80,9 @@
"eslint-plugin-prettier": "^2.3.1",
"ink-docstrap": "^1.3.0",
"jsdoc": "^3.5.5",
"mocha": "^3.0.1",
"mocha": "^4.0.1",
"prettier": "^1.7.4",
"proxyquire": "^1.7.10",
"sinon": "^1.17.6",
"through2": "^2.0.0"
"sinon": "^4.1.1"
}
}
11 changes: 6 additions & 5 deletions src/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
'use strict';

var arrify = require('arrify');
var Buffer = require('safe-buffer').Buffer;
var createErrorClass = require('create-error-class');
var extend = require('extend');
var is = require('is');
Expand Down Expand Up @@ -215,7 +216,7 @@ entity.isDsKey = isDsKey;
* // <Buffer 68 65 6c 6c 6f>
*/
function decodeValueProto(valueProto) {
var valueType = valueProto.value_type;
var valueType = valueProto.valueType;
var value = valueProto[valueType];

switch (valueType) {
Expand Down Expand Up @@ -378,7 +379,7 @@ entity.encodeValue = encodeValue;
* map: {
* name: {
* value: {
* value_type: 'stringValue',
* valueType: 'stringValue',
* stringValue: 'Stephen'
* }
* }
Expand Down Expand Up @@ -482,7 +483,7 @@ function entityToEntityProto(entityObject) {
var delimiter = firstPathPartIsArray ? '[]' : '.';
var splitPath = path.split(delimiter);
var firstPathPart = splitPath.shift();
var remainderPath = splitPath.join(delimiter).replace(/^(\.|[])/, '');
var remainderPath = splitPath.join(delimiter).replace(/^(\.|\[\])/, '');

if (!entity.properties[firstPathPart]) {
return;
Expand Down Expand Up @@ -581,9 +582,9 @@ function keyFromKeyProto(keyProto) {
keyProto.path.forEach(function(path, index) {
keyOptions.path.push(path.kind);

var id = path[path.id_type];
var id = path[path.idType];

if (path.id_type === 'id') {
if (path.idType === 'id') {
id = new entity.Int(id);
}

Expand Down
64 changes: 39 additions & 25 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@

var arrify = require('arrify');
var common = require('@google-cloud/common');
var commonGrpc = require('@google-cloud/common-grpc');
var extend = require('extend');
var grpc = require('google-gax').grpc;
var googleAuth = require('google-auto-auth');
var is = require('is');
var modelo = require('modelo');
var path = require('path');
var util = require('util');

/**
* @type {module:datastore/request}
Expand All @@ -51,6 +52,11 @@ var Query = require('./query.js');
*/
var Transaction = require('./transaction.js');

// Import the clients for each version supported by this package.
const gapic = Object.freeze({
v1: require('./v1'),
});

/**
* @constructor
* @alias module:datastore
Expand Down Expand Up @@ -301,34 +307,36 @@ function Datastore(options) {
return new Datastore(options);
}

options = options || {};

this.clients_ = new Map();
this.datastore = this;
this.namespace = options.namespace;
this.projectId =
process.env.DATASTORE_PROJECT_ID || options.projectId || '{{projectId}}';

this.defaultBaseUrl_ = 'datastore.googleapis.com';
this.determineBaseUrl_(options.apiEndpoint);

this.namespace = options.namespace;
this.projectId = process.env.DATASTORE_PROJECT_ID || options.projectId;

var config = {
projectIdRequired: false,
baseUrl: this.baseUrl_,
customEndpoint: this.customEndpoint_,
protosDir: path.resolve(__dirname, '../protos'),
protoServices: {
Datastore: {
path: 'google/datastore/v1/datastore.proto',
service: 'datastore.v1',
},
this.options = extend(
{
libName: 'gccl',
libVersion: require('../package.json').version,
scopes: gapic.v1.DatastoreClient.scopes,
servicePath: this.baseUrl_,
port: is.number(this.port_) ? this.port_ : 443,
},
scopes: ['https://www.googleapis.com/auth/datastore'],
packageJson: require('../package.json'),
grpcMetadata: {
'google-cloud-resource-prefix': 'projects/' + this.projectId,
},
};
options
);

if (this.customEndpoint_) {
this.options.sslCreds = grpc.credentials.createInsecure();
}

commonGrpc.Service.call(this, config, options);
this.auth = googleAuth(this.options);
}

modelo.inherits(Datastore, DatastoreRequest, commonGrpc.Service);
util.inherits(Datastore, DatastoreRequest);

/**
* Helper function to get a Datastore Double object.
Expand Down Expand Up @@ -595,6 +603,7 @@ Datastore.prototype.determineBaseUrl_ = function(customApiEndpoint) {
var baseUrl = this.defaultBaseUrl_;
var leadingProtocol = new RegExp('^https*://');
var trailingSlashes = new RegExp('/*$');
var port = new RegExp(':(\\d+)');

if (customApiEndpoint) {
baseUrl = customApiEndpoint;
Expand All @@ -604,8 +613,13 @@ Datastore.prototype.determineBaseUrl_ = function(customApiEndpoint) {
this.customEndpoint_ = true;
}

if (port.test(baseUrl)) {
this.port_ = baseUrl.match(port)[1];
}

this.baseUrl_ = baseUrl
.replace(leadingProtocol, '')
.replace(port, '')
.replace(trailingSlashes, '');
};

Expand All @@ -614,4 +628,4 @@ Datastore.Query = Query;
Datastore.Transaction = Transaction;

module.exports = Datastore;
module.exports.v1 = require('./v1');
module.exports.v1 = gapic.v1;
Loading