@google-cloud/spanner 5.17.0 → 6.1.0
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 +53 -0
- package/README.md +16 -0
- package/build/protos/google/spanner/admin/database/v1/backup.proto +174 -9
- package/build/protos/google/spanner/admin/database/v1/common.proto +1 -2
- package/build/protos/google/spanner/admin/database/v1/spanner_database_admin.proto +27 -2
- package/build/protos/google/spanner/admin/instance/v1/spanner_instance_admin.proto +22 -10
- package/build/protos/google/spanner/v1/commit_response.proto +1 -3
- package/build/protos/google/spanner/v1/keys.proto +1 -2
- package/build/protos/google/spanner/v1/mutation.proto +1 -2
- package/build/protos/google/spanner/v1/query_plan.proto +1 -2
- package/build/protos/google/spanner/v1/result_set.proto +1 -3
- package/build/protos/google/spanner/v1/spanner.proto +4 -1
- package/build/protos/google/spanner/v1/transaction.proto +73 -22
- package/build/protos/google/spanner/v1/type.proto +1 -2
- package/build/protos/protos.d.ts +883 -282
- package/build/protos/protos.js +2447 -880
- package/build/protos/protos.json +297 -87
- package/build/src/backup.d.ts +27 -5
- package/build/src/backup.js +62 -31
- package/build/src/batch-transaction.js +1 -1
- package/build/src/codec.d.ts +12 -1
- package/build/src/codec.js +44 -13
- package/build/src/common-grpc/service-object.js +1 -1
- package/build/src/common-grpc/service.js +2 -2
- package/build/src/database.d.ts +26 -6
- package/build/src/database.js +8 -8
- package/build/src/index.d.ts +18 -3
- package/build/src/index.js +26 -7
- package/build/src/instance.d.ts +41 -1
- package/build/src/instance.js +56 -2
- package/build/src/session-pool.d.ts +1 -0
- package/build/src/session-pool.js +46 -46
- package/build/src/session.js +1 -1
- package/build/src/table.d.ts +5 -1
- package/build/src/table.js +1 -1
- package/build/src/transaction-runner.js +3 -3
- package/build/src/transaction.d.ts +10 -2
- package/build/src/transaction.js +12 -12
- package/build/src/v1/database_admin_client.d.ts +267 -30
- package/build/src/v1/database_admin_client.js +148 -13
- package/build/src/v1/database_admin_client_config.json +5 -0
- package/build/src/v1/index.js +1 -0
- package/build/src/v1/instance_admin_client.d.ts +63 -18
- package/build/src/v1/instance_admin_client.js +42 -9
- package/build/src/v1/spanner_client.d.ts +70 -19
- package/build/src/v1/spanner_client.js +7 -8
- package/package.json +12 -12
package/build/src/codec.d.ts
CHANGED
|
@@ -46,7 +46,7 @@ export declare class SpannerDate extends Date {
|
|
|
46
46
|
constructor(year: number, month: number, date: number);
|
|
47
47
|
/**
|
|
48
48
|
* Returns the date in ISO date format.
|
|
49
|
-
* `YYYY-
|
|
49
|
+
* `YYYY-MM-DD`
|
|
50
50
|
*
|
|
51
51
|
* @returns {string}
|
|
52
52
|
*/
|
|
@@ -120,6 +120,16 @@ export declare class Numeric {
|
|
|
120
120
|
valueOf(): Big;
|
|
121
121
|
toJSON(): string;
|
|
122
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* @typedef PGNumeric
|
|
125
|
+
* @see Spanner.pgNumeric
|
|
126
|
+
*/
|
|
127
|
+
export declare class PGNumeric {
|
|
128
|
+
value: string;
|
|
129
|
+
constructor(pgValue: string | number);
|
|
130
|
+
valueOf(): Big;
|
|
131
|
+
toJSON(): string;
|
|
132
|
+
}
|
|
123
133
|
/**
|
|
124
134
|
* @typedef JSONOptions
|
|
125
135
|
* @property {boolean} [wrapNumbers=false] Indicates if the numbers should be
|
|
@@ -257,6 +267,7 @@ export declare const codec: {
|
|
|
257
267
|
Float: typeof Float;
|
|
258
268
|
Int: typeof Int;
|
|
259
269
|
Numeric: typeof Numeric;
|
|
270
|
+
PGNumeric: typeof PGNumeric;
|
|
260
271
|
convertFieldsToJson: typeof convertFieldsToJson;
|
|
261
272
|
decode: typeof decode;
|
|
262
273
|
encode: typeof encode;
|
package/build/src/codec.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.codec = exports.Numeric = exports.Struct = exports.Int = exports.Float = exports.SpannerDate = void 0;
|
|
3
|
+
exports.codec = exports.PGNumeric = exports.Numeric = exports.Struct = exports.Int = exports.Float = exports.SpannerDate = void 0;
|
|
4
4
|
/*!
|
|
5
5
|
* Copyright 2017 Google Inc. All Rights Reserved.
|
|
6
6
|
*
|
|
@@ -67,21 +67,15 @@ class SpannerDate extends Date {
|
|
|
67
67
|
}
|
|
68
68
|
/**
|
|
69
69
|
* Returns the date in ISO date format.
|
|
70
|
-
* `YYYY-
|
|
70
|
+
* `YYYY-MM-DD`
|
|
71
71
|
*
|
|
72
72
|
* @returns {string}
|
|
73
73
|
*/
|
|
74
74
|
toJSON() {
|
|
75
|
-
const year = this.getFullYear();
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
month = `0${month}`;
|
|
80
|
-
}
|
|
81
|
-
if (date.length === 1) {
|
|
82
|
-
date = `0${date}`;
|
|
83
|
-
}
|
|
84
|
-
return `${year}-${month}-${date}`;
|
|
75
|
+
const year = this.getFullYear().toString();
|
|
76
|
+
const month = (this.getMonth() + 1).toString();
|
|
77
|
+
const date = this.getDate().toString();
|
|
78
|
+
return `${year.padStart(4, '0')}-${month.padStart(2, '0')}-${date.padStart(2, '0')}`;
|
|
85
79
|
}
|
|
86
80
|
}
|
|
87
81
|
exports.SpannerDate = SpannerDate;
|
|
@@ -182,6 +176,25 @@ class Numeric {
|
|
|
182
176
|
}
|
|
183
177
|
}
|
|
184
178
|
exports.Numeric = Numeric;
|
|
179
|
+
/**
|
|
180
|
+
* @typedef PGNumeric
|
|
181
|
+
* @see Spanner.pgNumeric
|
|
182
|
+
*/
|
|
183
|
+
class PGNumeric {
|
|
184
|
+
constructor(pgValue) {
|
|
185
|
+
this.value = pgValue.toString();
|
|
186
|
+
}
|
|
187
|
+
valueOf() {
|
|
188
|
+
if (this.value.toLowerCase() === 'nan') {
|
|
189
|
+
throw new Error(`${this.value} cannot be converted to a numeric value`);
|
|
190
|
+
}
|
|
191
|
+
return new big_js_1.Big(this.value);
|
|
192
|
+
}
|
|
193
|
+
toJSON() {
|
|
194
|
+
return this.valueOf().toJSON();
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
exports.PGNumeric = PGNumeric;
|
|
185
198
|
/**
|
|
186
199
|
* @typedef JSONOptions
|
|
187
200
|
* @property {boolean} [wrapNumbers=false] Indicates if the numbers should be
|
|
@@ -287,6 +300,12 @@ function decode(value, type) {
|
|
|
287
300
|
break;
|
|
288
301
|
case protos_1.google.spanner.v1.TypeCode.NUMERIC:
|
|
289
302
|
case 'NUMERIC':
|
|
303
|
+
if (type.typeAnnotation ===
|
|
304
|
+
protos_1.google.spanner.v1.TypeAnnotationCode.PG_NUMERIC ||
|
|
305
|
+
type.typeAnnotation === 'PG_NUMERIC') {
|
|
306
|
+
decoded = new PGNumeric(decoded);
|
|
307
|
+
break;
|
|
308
|
+
}
|
|
290
309
|
decoded = new Numeric(decoded);
|
|
291
310
|
break;
|
|
292
311
|
case protos_1.google.spanner.v1.TypeCode.TIMESTAMP:
|
|
@@ -354,6 +373,9 @@ function encodeValue(value) {
|
|
|
354
373
|
if (value instanceof Numeric) {
|
|
355
374
|
return value.value;
|
|
356
375
|
}
|
|
376
|
+
if (value instanceof PGNumeric) {
|
|
377
|
+
return value.value;
|
|
378
|
+
}
|
|
357
379
|
if (Buffer.isBuffer(value)) {
|
|
358
380
|
return value.toString('base64');
|
|
359
381
|
}
|
|
@@ -380,6 +402,7 @@ const TypeCode = {
|
|
|
380
402
|
int64: 'INT64',
|
|
381
403
|
float64: 'FLOAT64',
|
|
382
404
|
numeric: 'NUMERIC',
|
|
405
|
+
pgNumeric: 'NUMERIC',
|
|
383
406
|
timestamp: 'TIMESTAMP',
|
|
384
407
|
date: 'DATE',
|
|
385
408
|
string: 'STRING',
|
|
@@ -436,6 +459,9 @@ function getType(value) {
|
|
|
436
459
|
if (value instanceof Numeric) {
|
|
437
460
|
return { type: 'numeric' };
|
|
438
461
|
}
|
|
462
|
+
if (value instanceof PGNumeric) {
|
|
463
|
+
return { type: 'pgNumeric' };
|
|
464
|
+
}
|
|
439
465
|
if (is.boolean(value)) {
|
|
440
466
|
return { type: 'bool' };
|
|
441
467
|
}
|
|
@@ -528,7 +554,7 @@ function createTypeObject(friendlyType) {
|
|
|
528
554
|
if (!friendlyType) {
|
|
529
555
|
friendlyType = 'unspecified';
|
|
530
556
|
}
|
|
531
|
-
if (
|
|
557
|
+
if (typeof friendlyType === 'string') {
|
|
532
558
|
friendlyType = { type: friendlyType };
|
|
533
559
|
}
|
|
534
560
|
const config = friendlyType;
|
|
@@ -546,6 +572,10 @@ function createTypeObject(friendlyType) {
|
|
|
546
572
|
}),
|
|
547
573
|
};
|
|
548
574
|
}
|
|
575
|
+
if (friendlyType.type === 'pgNumeric') {
|
|
576
|
+
type.typeAnnotation =
|
|
577
|
+
protos_1.google.spanner.v1.TypeAnnotationCode.PG_NUMERIC;
|
|
578
|
+
}
|
|
549
579
|
return type;
|
|
550
580
|
}
|
|
551
581
|
exports.codec = {
|
|
@@ -557,6 +587,7 @@ exports.codec = {
|
|
|
557
587
|
Float,
|
|
558
588
|
Int,
|
|
559
589
|
Numeric,
|
|
590
|
+
PGNumeric,
|
|
560
591
|
convertFieldsToJson,
|
|
561
592
|
decode,
|
|
562
593
|
encode,
|
|
@@ -97,5 +97,5 @@ exports.GrpcServiceObject = GrpcServiceObject;
|
|
|
97
97
|
* All async methods (except for streams) will return a Promise in the event
|
|
98
98
|
* that a callback is omitted.
|
|
99
99
|
*/
|
|
100
|
-
promisify_1.promisifyAll(GrpcServiceObject);
|
|
100
|
+
(0, promisify_1.promisifyAll)(GrpcServiceObject);
|
|
101
101
|
//# sourceMappingURL=service-object.js.map
|
|
@@ -747,7 +747,7 @@ class GrpcService extends common_1.Service {
|
|
|
747
747
|
delete reqOpts.autoPaginate;
|
|
748
748
|
delete reqOpts.autoPaginateVal;
|
|
749
749
|
delete reqOpts.objectMode;
|
|
750
|
-
return projectify_1.replaceProjectIdToken(reqOpts, this.projectId);
|
|
750
|
+
return (0, projectify_1.replaceProjectIdToken)(reqOpts, this.projectId);
|
|
751
751
|
}
|
|
752
752
|
/**
|
|
753
753
|
* To authorize requests through gRPC, we must get the raw google-auth-library
|
|
@@ -780,7 +780,7 @@ class GrpcService extends common_1.Service {
|
|
|
780
780
|
loadProtoFile(protoPath, config) {
|
|
781
781
|
const protoObjectCacheKey = [config.protosDir, protoPath].join('$');
|
|
782
782
|
if (!GrpcService.protoObjectCache[protoObjectCacheKey]) {
|
|
783
|
-
const services = proto_loader_1.loadSync(protoPath, {
|
|
783
|
+
const services = (0, proto_loader_1.loadSync)(protoPath, {
|
|
784
784
|
keepCase: false,
|
|
785
785
|
defaults: true,
|
|
786
786
|
bytes: String,
|
package/build/src/database.d.ts
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
/// <reference types="node" />
|
|
17
|
+
/// <reference types="node" />
|
|
17
18
|
import { ExistsCallback, GetConfig } from '@google-cloud/common';
|
|
18
19
|
declare const common: any;
|
|
19
20
|
import * as r from 'teeny-request';
|
|
@@ -31,7 +32,10 @@ import { IOperation, LongRunningCallback, NormalCallback, PagedOptionsWithFilter
|
|
|
31
32
|
import { Duplex, Readable } from 'stream';
|
|
32
33
|
import { EnumKey, RequestConfig, TranslateEnumKeys } from '.';
|
|
33
34
|
declare type CreateBatchTransactionCallback = ResourceCallback<BatchTransaction, google.spanner.v1.ITransaction | google.spanner.v1.ISession>;
|
|
34
|
-
declare type CreateBatchTransactionResponse = [
|
|
35
|
+
declare type CreateBatchTransactionResponse = [
|
|
36
|
+
BatchTransaction,
|
|
37
|
+
google.spanner.v1.ITransaction | google.spanner.v1.ISession
|
|
38
|
+
];
|
|
35
39
|
declare type DatabaseResponse = [Database, r.Response];
|
|
36
40
|
declare type DatabaseCallback = ResourceCallback<Database, r.Response>;
|
|
37
41
|
declare type GetSnapshotCallback = NormalCallback<Snapshot>;
|
|
@@ -40,7 +44,10 @@ export interface SessionPoolConstructor {
|
|
|
40
44
|
new (database: Database, options?: SessionPoolOptions | null): SessionPoolInterface;
|
|
41
45
|
}
|
|
42
46
|
export declare type UpdateSchemaCallback = ResourceCallback<GaxOperation, databaseAdmin.longrunning.IOperation>;
|
|
43
|
-
export declare type UpdateSchemaResponse = [
|
|
47
|
+
export declare type UpdateSchemaResponse = [
|
|
48
|
+
GaxOperation,
|
|
49
|
+
databaseAdmin.longrunning.IOperation
|
|
50
|
+
];
|
|
44
51
|
declare type PoolRequestCallback = RequestCallback<Session>;
|
|
45
52
|
export declare type GetSessionsOptions = PagedOptionsWithFilter;
|
|
46
53
|
/**
|
|
@@ -56,14 +63,20 @@ declare type IRestoreInfoTranslatedEnum = TranslateEnumKeys<databaseAdmin.spanne
|
|
|
56
63
|
declare type GetDatabaseMetadataResponse = [IDatabaseTranslatedEnum];
|
|
57
64
|
declare type GetDatabaseMetadataCallback = RequestCallback<IDatabaseTranslatedEnum>;
|
|
58
65
|
declare type GetSchemaCallback = RequestCallback<string, databaseAdmin.spanner.admin.database.v1.IGetDatabaseDdlResponse>;
|
|
59
|
-
declare type GetSchemaResponse = [
|
|
66
|
+
declare type GetSchemaResponse = [
|
|
67
|
+
string[],
|
|
68
|
+
databaseAdmin.spanner.admin.database.v1.IGetDatabaseDdlResponse
|
|
69
|
+
];
|
|
60
70
|
declare type GetSessionsCallback = RequestCallback<Session, google.spanner.v1.IListSessionsResponse>;
|
|
61
71
|
declare type GetSessionsResponse = PagedResponse<Session, google.spanner.v1.IListSessionsResponse>;
|
|
62
72
|
export declare type GetDatabaseConfig = GetConfig & databaseAdmin.spanner.admin.database.v1.IGetDatabaseRequest & {
|
|
63
73
|
gaxOptions?: CallOptions;
|
|
64
74
|
};
|
|
65
75
|
declare type DatabaseCloseResponse = [google.protobuf.IEmpty];
|
|
66
|
-
export declare type CreateSessionResponse = [
|
|
76
|
+
export declare type CreateSessionResponse = [
|
|
77
|
+
Session,
|
|
78
|
+
spannerClient.spanner.v1.ISession
|
|
79
|
+
];
|
|
67
80
|
export interface CreateSessionOptions {
|
|
68
81
|
labels?: {
|
|
69
82
|
[k: string]: string;
|
|
@@ -74,7 +87,10 @@ export declare type CreateSessionCallback = ResourceCallback<Session, spannerCli
|
|
|
74
87
|
export interface BatchCreateSessionsOptions extends CreateSessionOptions {
|
|
75
88
|
count: number;
|
|
76
89
|
}
|
|
77
|
-
export declare type BatchCreateSessionsResponse = [
|
|
90
|
+
export declare type BatchCreateSessionsResponse = [
|
|
91
|
+
Session[],
|
|
92
|
+
spannerClient.spanner.v1.IBatchCreateSessionsResponse
|
|
93
|
+
];
|
|
78
94
|
export declare type BatchCreateSessionsCallback = ResourceCallback<Session[], spannerClient.spanner.v1.IBatchCreateSessionsResponse>;
|
|
79
95
|
export declare type DatabaseDeleteResponse = [databaseAdmin.protobuf.IEmpty];
|
|
80
96
|
export declare type DatabaseDeleteCallback = NormalCallback<databaseAdmin.protobuf.IEmpty>;
|
|
@@ -82,7 +98,11 @@ export interface CancelableDuplex extends Duplex {
|
|
|
82
98
|
cancel(): void;
|
|
83
99
|
}
|
|
84
100
|
export declare type RestoreDatabaseCallback = LongRunningCallback<Database>;
|
|
85
|
-
export declare type RestoreDatabaseResponse = [
|
|
101
|
+
export declare type RestoreDatabaseResponse = [
|
|
102
|
+
Database,
|
|
103
|
+
GaxOperation,
|
|
104
|
+
databaseAdmin.longrunning.IOperation
|
|
105
|
+
];
|
|
86
106
|
export declare type GetRestoreInfoCallback = NormalCallback<IRestoreInfoTranslatedEnum>;
|
|
87
107
|
export declare type GetStateCallback = NormalCallback<EnumKey<typeof databaseAdmin.spanner.admin.database.v1.Database.State>>;
|
|
88
108
|
interface DatabaseRequest {
|
package/build/src/database.js
CHANGED
|
@@ -547,7 +547,7 @@ class Database extends common.GrpcServiceObject {
|
|
|
547
547
|
const snapshot = session.snapshot(options, this.queryOptions_);
|
|
548
548
|
snapshot.begin(err => {
|
|
549
549
|
if (err) {
|
|
550
|
-
if (session_pool_1.isSessionNotFoundError(err)) {
|
|
550
|
+
if ((0, session_pool_1.isSessionNotFoundError)(err)) {
|
|
551
551
|
session.lastError = err;
|
|
552
552
|
this.pool_.release(session);
|
|
553
553
|
this.getSnapshot(options, callback);
|
|
@@ -880,7 +880,7 @@ class Database extends common.GrpcServiceObject {
|
|
|
880
880
|
.once('data', () => (dataReceived = true))
|
|
881
881
|
.once('error', err => {
|
|
882
882
|
if (!dataReceived &&
|
|
883
|
-
session_pool_1.isSessionNotFoundError(err)) {
|
|
883
|
+
(0, session_pool_1.isSessionNotFoundError)(err)) {
|
|
884
884
|
// If it is a 'Session not found' error and we have not yet received
|
|
885
885
|
// any data, we can safely retry the query on a new session.
|
|
886
886
|
// Register the error on the session so the pool can discard it.
|
|
@@ -916,7 +916,7 @@ class Database extends common.GrpcServiceObject {
|
|
|
916
916
|
? optionsOrRunFn
|
|
917
917
|
: {};
|
|
918
918
|
this.pool_.getWriteSession((err, session, transaction) => {
|
|
919
|
-
if (err && session_pool_1.isSessionNotFoundError(err)) {
|
|
919
|
+
if (err && (0, session_pool_1.isSessionNotFoundError)(err)) {
|
|
920
920
|
this.runTransaction(options, runFn);
|
|
921
921
|
return;
|
|
922
922
|
}
|
|
@@ -927,7 +927,7 @@ class Database extends common.GrpcServiceObject {
|
|
|
927
927
|
const release = this.pool_.release.bind(this.pool_, session);
|
|
928
928
|
const runner = new transaction_runner_1.TransactionRunner(session, transaction, runFn, options);
|
|
929
929
|
runner.run().then(release, err => {
|
|
930
|
-
if (session_pool_1.isSessionNotFoundError(err)) {
|
|
930
|
+
if ((0, session_pool_1.isSessionNotFoundError)(err)) {
|
|
931
931
|
release();
|
|
932
932
|
this.runTransaction(options, runFn);
|
|
933
933
|
}
|
|
@@ -1010,7 +1010,7 @@ class Database extends common.GrpcServiceObject {
|
|
|
1010
1010
|
// eslint-disable-next-line no-constant-condition
|
|
1011
1011
|
while (true) {
|
|
1012
1012
|
try {
|
|
1013
|
-
const [session, transaction] = await promisify_1.promisify(getWriteSession)();
|
|
1013
|
+
const [session, transaction] = await (0, promisify_1.promisify)(getWriteSession)();
|
|
1014
1014
|
transaction.requestOptions = Object.assign(transaction.requestOptions || {}, options.requestOptions);
|
|
1015
1015
|
const runner = new transaction_runner_1.AsyncTransactionRunner(session, transaction, runFn, options);
|
|
1016
1016
|
try {
|
|
@@ -1021,7 +1021,7 @@ class Database extends common.GrpcServiceObject {
|
|
|
1021
1021
|
}
|
|
1022
1022
|
}
|
|
1023
1023
|
catch (e) {
|
|
1024
|
-
if (!session_pool_1.isSessionNotFoundError(e)) {
|
|
1024
|
+
if (!(0, session_pool_1.isSessionNotFoundError)(e)) {
|
|
1025
1025
|
throw e;
|
|
1026
1026
|
}
|
|
1027
1027
|
}
|
|
@@ -1121,7 +1121,7 @@ exports.Database = Database;
|
|
|
1121
1121
|
* All async methods (except for streams) will return a Promise in the event
|
|
1122
1122
|
* that a callback is omitted.
|
|
1123
1123
|
*/
|
|
1124
|
-
promisify_1.promisifyAll(Database, {
|
|
1124
|
+
(0, promisify_1.promisifyAll)(Database, {
|
|
1125
1125
|
exclude: [
|
|
1126
1126
|
'batchTransaction',
|
|
1127
1127
|
'getRestoreInfo',
|
|
@@ -1138,7 +1138,7 @@ promisify_1.promisifyAll(Database, {
|
|
|
1138
1138
|
* All async methods (except for streams) will return a Promise in the event
|
|
1139
1139
|
* that a callback is omitted.
|
|
1140
1140
|
*/
|
|
1141
|
-
promisify_1.callbackifyAll(Database, {
|
|
1141
|
+
(0, promisify_1.callbackifyAll)(Database, {
|
|
1142
1142
|
exclude: [
|
|
1143
1143
|
'create',
|
|
1144
1144
|
'batchCreateSessions',
|
package/build/src/index.d.ts
CHANGED
|
@@ -18,12 +18,12 @@ import { GrpcService } from './common-grpc/service';
|
|
|
18
18
|
import { PreciseDate } from '@google-cloud/precise-date';
|
|
19
19
|
import { GoogleAuth, GoogleAuthOptions } from 'google-auth-library';
|
|
20
20
|
import { common as p } from 'protobufjs';
|
|
21
|
-
import { Float, Int, Numeric, Struct } from './codec';
|
|
21
|
+
import { Float, Int, Numeric, PGNumeric, Struct } from './codec';
|
|
22
22
|
import { Backup } from './backup';
|
|
23
23
|
import { Database } from './database';
|
|
24
24
|
import { Instance, CreateInstanceCallback, CreateInstanceResponse } from './instance';
|
|
25
25
|
import { grpc, GrpcClientOptions, CallOptions } from 'google-gax';
|
|
26
|
-
import { google as instanceAdmin } from '../protos/protos';
|
|
26
|
+
import { google, google as instanceAdmin } from '../protos/protos';
|
|
27
27
|
import { PagedOptions, PagedResponse, PagedCallback, PagedOptionsWithFilter, NormalCallback } from './common';
|
|
28
28
|
import { Session } from './session';
|
|
29
29
|
import { SessionPool } from './session-pool';
|
|
@@ -146,6 +146,8 @@ declare class Spanner extends GrpcService {
|
|
|
146
146
|
* @type {string}
|
|
147
147
|
*/
|
|
148
148
|
static COMMIT_TIMESTAMP: string;
|
|
149
|
+
static POSTGRESQL: google.spanner.admin.database.v1.DatabaseDialect;
|
|
150
|
+
static GOOGLE_STANDARD_SQL: google.spanner.admin.database.v1.DatabaseDialect;
|
|
149
151
|
/**
|
|
150
152
|
* Gets the configured Spanner emulator host from an environment variable.
|
|
151
153
|
*/
|
|
@@ -197,7 +199,7 @@ declare class Spanner extends GrpcService {
|
|
|
197
199
|
* Wrapper around {@link v1.InstanceAdminClient#createInstance}.
|
|
198
200
|
*
|
|
199
201
|
* @see {@link v1.InstanceAdminClient#createInstance}
|
|
200
|
-
* @see [
|
|
202
|
+
* @see [CreateInstance API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.admin.instance.v1#google.spanner.admin.instance.v1.InstanceAdmin.CreateInstance)
|
|
201
203
|
*
|
|
202
204
|
* @throws {GoogleError} If a name is not provided.
|
|
203
205
|
* @throws {GoogleError} If a configuration object is not provided.
|
|
@@ -684,6 +686,19 @@ declare class Spanner extends GrpcService {
|
|
|
684
686
|
* ```
|
|
685
687
|
*/
|
|
686
688
|
static numeric(value: any): Numeric;
|
|
689
|
+
/**
|
|
690
|
+
* Helper function to get a Cloud Spanner pgNumeric object.
|
|
691
|
+
*
|
|
692
|
+
* @param {string} value The pgNumeric value as a string.
|
|
693
|
+
* @returns {PGNumeric}
|
|
694
|
+
*
|
|
695
|
+
* @example
|
|
696
|
+
* ```
|
|
697
|
+
* const {Spanner} = require('@google-cloud/spanner');
|
|
698
|
+
* const pgNumeric = Spanner.pgNumeric("3.141592653");
|
|
699
|
+
* ```
|
|
700
|
+
*/
|
|
701
|
+
static pgNumeric(value: any): PGNumeric;
|
|
687
702
|
/**
|
|
688
703
|
* Helper function to get a Cloud Spanner Struct object.
|
|
689
704
|
*
|
package/build/src/index.js
CHANGED
|
@@ -33,6 +33,7 @@ Object.defineProperty(exports, "Database", { enumerable: true, get: function ()
|
|
|
33
33
|
const instance_1 = require("./instance");
|
|
34
34
|
Object.defineProperty(exports, "Instance", { enumerable: true, get: function () { return instance_1.Instance; } });
|
|
35
35
|
const google_gax_1 = require("google-gax");
|
|
36
|
+
const protos_1 = require("../protos/protos");
|
|
36
37
|
const common_1 = require("./common");
|
|
37
38
|
const session_1 = require("./session");
|
|
38
39
|
Object.defineProperty(exports, "Session", { enumerable: true, get: function () { return session_1.Session; } });
|
|
@@ -493,23 +494,23 @@ class Spanner extends service_1.GrpcService {
|
|
|
493
494
|
}
|
|
494
495
|
const gaxClient = this.clients_.get(clientName);
|
|
495
496
|
let reqOpts = extend(true, {}, config.reqOpts);
|
|
496
|
-
reqOpts = projectify_1.replaceProjectIdToken(reqOpts, projectId);
|
|
497
|
+
reqOpts = (0, projectify_1.replaceProjectIdToken)(reqOpts, projectId);
|
|
497
498
|
// It would have been preferable to replace the projectId already in the
|
|
498
499
|
// constructor of Spanner, but that is not possible as auth.getProjectId
|
|
499
500
|
// is an async method. This is therefore the first place where we have
|
|
500
501
|
// access to the value that should be used instead of the placeholder.
|
|
501
502
|
if (!this.projectIdReplaced_) {
|
|
502
|
-
this.projectId = projectify_1.replaceProjectIdToken(this.projectId, projectId);
|
|
503
|
-
this.projectFormattedName_ = projectify_1.replaceProjectIdToken(this.projectFormattedName_, projectId);
|
|
503
|
+
this.projectId = (0, projectify_1.replaceProjectIdToken)(this.projectId, projectId);
|
|
504
|
+
this.projectFormattedName_ = (0, projectify_1.replaceProjectIdToken)(this.projectFormattedName_, projectId);
|
|
504
505
|
this.instances_.forEach(instance => {
|
|
505
|
-
instance.formattedName_ = projectify_1.replaceProjectIdToken(instance.formattedName_, projectId);
|
|
506
|
+
instance.formattedName_ = (0, projectify_1.replaceProjectIdToken)(instance.formattedName_, projectId);
|
|
506
507
|
instance.databases_.forEach(database => {
|
|
507
|
-
database.formattedName_ = projectify_1.replaceProjectIdToken(database.formattedName_, projectId);
|
|
508
|
+
database.formattedName_ = (0, projectify_1.replaceProjectIdToken)(database.formattedName_, projectId);
|
|
508
509
|
});
|
|
509
510
|
});
|
|
510
511
|
this.projectIdReplaced_ = true;
|
|
511
512
|
}
|
|
512
|
-
config.headers[common_1.CLOUD_RESOURCE_HEADER] = projectify_1.replaceProjectIdToken(config.headers[common_1.CLOUD_RESOURCE_HEADER], projectId);
|
|
513
|
+
config.headers[common_1.CLOUD_RESOURCE_HEADER] = (0, projectify_1.replaceProjectIdToken)(config.headers[common_1.CLOUD_RESOURCE_HEADER], projectId);
|
|
513
514
|
const requestFn = gaxClient[config.method].bind(gaxClient, reqOpts,
|
|
514
515
|
// Add headers to `gaxOpts`
|
|
515
516
|
extend(true, {}, config.gaxOpts, {
|
|
@@ -705,6 +706,21 @@ class Spanner extends service_1.GrpcService {
|
|
|
705
706
|
static numeric(value) {
|
|
706
707
|
return new codec_1.codec.Numeric(value);
|
|
707
708
|
}
|
|
709
|
+
/**
|
|
710
|
+
* Helper function to get a Cloud Spanner pgNumeric object.
|
|
711
|
+
*
|
|
712
|
+
* @param {string} value The pgNumeric value as a string.
|
|
713
|
+
* @returns {PGNumeric}
|
|
714
|
+
*
|
|
715
|
+
* @example
|
|
716
|
+
* ```
|
|
717
|
+
* const {Spanner} = require('@google-cloud/spanner');
|
|
718
|
+
* const pgNumeric = Spanner.pgNumeric("3.141592653");
|
|
719
|
+
* ```
|
|
720
|
+
*/
|
|
721
|
+
static pgNumeric(value) {
|
|
722
|
+
return new codec_1.codec.PGNumeric(value);
|
|
723
|
+
}
|
|
708
724
|
/**
|
|
709
725
|
* Helper function to get a Cloud Spanner Struct object.
|
|
710
726
|
*
|
|
@@ -736,18 +752,21 @@ exports.Spanner = Spanner;
|
|
|
736
752
|
* @type {string}
|
|
737
753
|
*/
|
|
738
754
|
Spanner.COMMIT_TIMESTAMP = 'spanner.commit_timestamp()';
|
|
755
|
+
Spanner.POSTGRESQL = protos_1.google.spanner.admin.database.v1.DatabaseDialect.POSTGRESQL;
|
|
756
|
+
Spanner.GOOGLE_STANDARD_SQL = protos_1.google.spanner.admin.database.v1.DatabaseDialect.GOOGLE_STANDARD_SQL;
|
|
739
757
|
/*! Developer Documentation
|
|
740
758
|
*
|
|
741
759
|
* All async methods (except for streams) will return a Promise in the event
|
|
742
760
|
* that a callback is omitted.
|
|
743
761
|
*/
|
|
744
|
-
promisify_1.promisifyAll(Spanner, {
|
|
762
|
+
(0, promisify_1.promisifyAll)(Spanner, {
|
|
745
763
|
exclude: [
|
|
746
764
|
'date',
|
|
747
765
|
'float',
|
|
748
766
|
'instance',
|
|
749
767
|
'int',
|
|
750
768
|
'numeric',
|
|
769
|
+
'pgNumeric',
|
|
751
770
|
'operation',
|
|
752
771
|
'timestamp',
|
|
753
772
|
],
|
package/build/src/instance.d.ts
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
/// <reference types="node" />
|
|
17
|
+
/// <reference types="node" />
|
|
17
18
|
import { GetConfig } from '@google-cloud/common';
|
|
18
19
|
declare const common: any;
|
|
19
20
|
import { Database, SessionPoolConstructor } from './database';
|
|
@@ -22,7 +23,7 @@ import { RequestCallback, PagedOptions, PagedResponse, LongRunningCallback, Norm
|
|
|
22
23
|
import { Duplex } from 'stream';
|
|
23
24
|
import { SessionPoolOptions, SessionPool } from './session-pool';
|
|
24
25
|
import { Operation as GaxOperation, CallOptions } from 'google-gax';
|
|
25
|
-
import { Backup } from './backup';
|
|
26
|
+
import { Backup, CopyBackupCallback, CopyBackupResponse, CopyBackupOptions } from './backup';
|
|
26
27
|
import { google as instanceAdmin } from '../protos/protos';
|
|
27
28
|
import { google as databaseAdmin } from '../protos/protos';
|
|
28
29
|
import { google as spannerClient } from '../protos/protos';
|
|
@@ -119,6 +120,45 @@ declare class Instance extends common.GrpcServiceObject {
|
|
|
119
120
|
* ```
|
|
120
121
|
*/
|
|
121
122
|
backup(backupId: string): Backup;
|
|
123
|
+
/**
|
|
124
|
+
* Get a reference to a Backup object.
|
|
125
|
+
*
|
|
126
|
+
* @throws {GoogleError} If any parameter is not provided.
|
|
127
|
+
*
|
|
128
|
+
* @typedef {object} CopyBackupOptions
|
|
129
|
+
* * @property {string|null}
|
|
130
|
+
* * sourceBackup The full path of the backup to be copied
|
|
131
|
+
* * @property {string|number|google.protobuf.Timestamp|external:PreciseDate}
|
|
132
|
+
* * expireTime The expire time of the backup.
|
|
133
|
+
* * @property {google.spanner.admin.database.v1.ICopyBackupEncryptionConfig}
|
|
134
|
+
* * encryptionConfig An encryption configuration describing the
|
|
135
|
+
* * encryption type and key resources in Cloud KMS to be used to encrypt
|
|
136
|
+
* * the copy backup.
|
|
137
|
+
* * @property {object} [gaxOptions] The request configuration options,
|
|
138
|
+
* * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
|
|
139
|
+
* * for more details.
|
|
140
|
+
* */
|
|
141
|
+
/**
|
|
142
|
+
* @callback CopyBackupCallback
|
|
143
|
+
* @param {string} sourceBackupId Full path of the source backup to be copied.
|
|
144
|
+
* @param {string} backupId The name of the backup.
|
|
145
|
+
* @param {CopyBackupOptions}
|
|
146
|
+
* @return {Backup} A Backup object.
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```
|
|
150
|
+
* const {Spanner} = require('@google-cloud/spanner');
|
|
151
|
+
* const spanner = new Spanner();
|
|
152
|
+
* const instance = spanner.instance('my-instance');
|
|
153
|
+
* const backup = instance.copyBackup('my-source-backup','my-backup',{
|
|
154
|
+
* expireTime: expireTime,
|
|
155
|
+
* encryptionConfig: {
|
|
156
|
+
* encryptionType: 'CUSTOMER_MANAGED_ENCRYPTION',
|
|
157
|
+
* kmsKeyName: 'projects/my-project-id/my-region/keyRings/my-key-ring/cryptoKeys/my-key',
|
|
158
|
+
* },);
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
copyBackup(sourceBackupId: string, backupId: string, options: CopyBackupOptions, callback?: CopyBackupCallback): Promise<CopyBackupResponse> | void;
|
|
122
162
|
/**
|
|
123
163
|
* Query object for listing backups.
|
|
124
164
|
*
|
package/build/src/instance.js
CHANGED
|
@@ -26,6 +26,7 @@ const database_1 = require("./database");
|
|
|
26
26
|
const common_1 = require("./common");
|
|
27
27
|
const google_gax_1 = require("google-gax");
|
|
28
28
|
const backup_1 = require("./backup");
|
|
29
|
+
const protos_1 = require("../protos/protos");
|
|
29
30
|
/**
|
|
30
31
|
* The {@link Instance} class represents a [Cloud Spanner
|
|
31
32
|
* instance](https://cloud.google.com/spanner/docs/instances).
|
|
@@ -139,6 +140,54 @@ class Instance extends common.GrpcServiceObject {
|
|
|
139
140
|
}
|
|
140
141
|
return new backup_1.Backup(this, backupId);
|
|
141
142
|
}
|
|
143
|
+
/**
|
|
144
|
+
* Get a reference to a Backup object.
|
|
145
|
+
*
|
|
146
|
+
* @throws {GoogleError} If any parameter is not provided.
|
|
147
|
+
*
|
|
148
|
+
* @typedef {object} CopyBackupOptions
|
|
149
|
+
* * @property {string|null}
|
|
150
|
+
* * sourceBackup The full path of the backup to be copied
|
|
151
|
+
* * @property {string|number|google.protobuf.Timestamp|external:PreciseDate}
|
|
152
|
+
* * expireTime The expire time of the backup.
|
|
153
|
+
* * @property {google.spanner.admin.database.v1.ICopyBackupEncryptionConfig}
|
|
154
|
+
* * encryptionConfig An encryption configuration describing the
|
|
155
|
+
* * encryption type and key resources in Cloud KMS to be used to encrypt
|
|
156
|
+
* * the copy backup.
|
|
157
|
+
* * @property {object} [gaxOptions] The request configuration options,
|
|
158
|
+
* * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
|
|
159
|
+
* * for more details.
|
|
160
|
+
* */
|
|
161
|
+
/**
|
|
162
|
+
* @callback CopyBackupCallback
|
|
163
|
+
* @param {string} sourceBackupId Full path of the source backup to be copied.
|
|
164
|
+
* @param {string} backupId The name of the backup.
|
|
165
|
+
* @param {CopyBackupOptions}
|
|
166
|
+
* @return {Backup} A Backup object.
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```
|
|
170
|
+
* const {Spanner} = require('@google-cloud/spanner');
|
|
171
|
+
* const spanner = new Spanner();
|
|
172
|
+
* const instance = spanner.instance('my-instance');
|
|
173
|
+
* const backup = instance.copyBackup('my-source-backup','my-backup',{
|
|
174
|
+
* expireTime: expireTime,
|
|
175
|
+
* encryptionConfig: {
|
|
176
|
+
* encryptionType: 'CUSTOMER_MANAGED_ENCRYPTION',
|
|
177
|
+
* kmsKeyName: 'projects/my-project-id/my-region/keyRings/my-key-ring/cryptoKeys/my-key',
|
|
178
|
+
* },);
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
181
|
+
copyBackup(sourceBackupId, backupId, options, callback) {
|
|
182
|
+
if (!backupId || !sourceBackupId) {
|
|
183
|
+
throw new google_gax_1.GoogleError('A backup ID and source backup ID is required to create a copy of the source backup.');
|
|
184
|
+
}
|
|
185
|
+
const copyOfBackup = new backup_1.Backup(this, backupId, sourceBackupId);
|
|
186
|
+
if (callback) {
|
|
187
|
+
return copyOfBackup.create(options, callback);
|
|
188
|
+
}
|
|
189
|
+
return copyOfBackup.create(options);
|
|
190
|
+
}
|
|
142
191
|
getBackups(optionsOrCallback, cb) {
|
|
143
192
|
const callback = typeof optionsOrCallback === 'function' ? optionsOrCallback : cb;
|
|
144
193
|
const options = typeof optionsOrCallback === 'object'
|
|
@@ -394,9 +443,14 @@ class Instance extends common.GrpcServiceObject {
|
|
|
394
443
|
: {};
|
|
395
444
|
const poolOptions = options.poolOptions;
|
|
396
445
|
const poolCtor = options.poolCtor;
|
|
446
|
+
let createStatement = 'CREATE DATABASE `' + name.split('/').pop() + '`';
|
|
447
|
+
if (protos_1.google.spanner.admin.database.v1.DatabaseDialect.POSTGRESQL ===
|
|
448
|
+
options.databaseDialect) {
|
|
449
|
+
createStatement = 'CREATE DATABASE "' + name.split('/').pop() + '"';
|
|
450
|
+
}
|
|
397
451
|
const reqOpts = extend({
|
|
398
452
|
parent: this.formattedName_,
|
|
399
|
-
createStatement:
|
|
453
|
+
createStatement: createStatement,
|
|
400
454
|
}, options);
|
|
401
455
|
delete reqOpts.poolOptions;
|
|
402
456
|
delete reqOpts.poolCtor;
|
|
@@ -717,7 +771,7 @@ exports.Instance = Instance;
|
|
|
717
771
|
* All async methods (except for streams) will return a Promise in the event
|
|
718
772
|
* that a callback is omitted.
|
|
719
773
|
*/
|
|
720
|
-
promisify_1.promisifyAll(Instance, {
|
|
774
|
+
(0, promisify_1.promisifyAll)(Instance, {
|
|
721
775
|
exclude: ['database', 'backup'],
|
|
722
776
|
});
|
|
723
777
|
//# sourceMappingURL=instance.js.map
|