@google-cloud/spanner 6.5.0 → 6.6.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 CHANGED
@@ -4,6 +4,19 @@
4
4
 
5
5
  [1]: https://www.npmjs.com/package/nodejs-spanner?activeTab=versions
6
6
 
7
+ ## [6.6.0](https://github.com/googleapis/nodejs-spanner/compare/v6.5.0...v6.6.0) (2022-12-16)
8
+
9
+
10
+ ### Features
11
+
12
+ * Export data types in index.ts ([#1726](https://github.com/googleapis/nodejs-spanner/issues/1726)) ([844f57f](https://github.com/googleapis/nodejs-spanner/commit/844f57fa5e79e5e5a5ede80df5e117004427f201)), closes [#1720](https://github.com/googleapis/nodejs-spanner/issues/1720)
13
+ * Fgac support and samples ([#1751](https://github.com/googleapis/nodejs-spanner/issues/1751)) ([0a394df](https://github.com/googleapis/nodejs-spanner/commit/0a394df9bfa193d79edc4c3a3d26238f361c0d45))
14
+
15
+
16
+ ### Bug Fixes
17
+
18
+ * Add sleep after admin request intensive tests ([#1758](https://github.com/googleapis/nodejs-spanner/issues/1758)) ([7643ceb](https://github.com/googleapis/nodejs-spanner/commit/7643ceb7cde9f420539877b86fdb0d38b254348d))
19
+
7
20
  ## [6.5.0](https://github.com/googleapis/nodejs-spanner/compare/v6.4.0...v6.5.0) (2022-11-30)
8
21
 
9
22
 
package/README.md CHANGED
@@ -89,6 +89,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/nodejs-spanner/tre
89
89
 
90
90
  | Sample | Source Code | Try it |
91
91
  | --------------------------- | --------------------------------- | ------ |
92
+ | Add and drop new database role | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/add-and-drop-new-database-role.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/add-and-drop-new-database-role.js,samples/README.md) |
92
93
  | Backups-cancel | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/backups-cancel.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/backups-cancel.js,samples/README.md) |
93
94
  | Copies a source backup | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/backups-copy.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/backups-copy.js,samples/README.md) |
94
95
  | Backups-create-with-encryption-key | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/backups-create-with-encryption-key.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/backups-create-with-encryption-key.js,samples/README.md) |
@@ -111,7 +112,9 @@ Samples are in the [`samples/`](https://github.com/googleapis/nodejs-spanner/tre
111
112
  | Updates the default leader of an existing database | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/database-update-default-leader.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/database-update-default-leader.js,samples/README.md) |
112
113
  | Datatypes | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/datatypes.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/datatypes.js,samples/README.md) |
113
114
  | DML | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/dml.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/dml.js,samples/README.md) |
115
+ | Enable fine grained access control | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/enable-fine-grained-access.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/enable-fine-grained-access.js,samples/README.md) |
114
116
  | Get-commit-stats | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/get-commit-stats.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/get-commit-stats.js,samples/README.md) |
117
+ | List database roles | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/get-database-roles.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/get-database-roles.js,samples/README.md) |
115
118
  | Gets the instance config metadata for the configuration nam6 | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/get-instance-config.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/get-instance-config.js,samples/README.md) |
116
119
  | Creates a new value-storing index | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/index-create-storing.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/index-create-storing.js,samples/README.md) |
117
120
  | Creates a new index | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/index-create.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/index-create.js,samples/README.md) |
@@ -153,6 +156,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/nodejs-spanner/tre
153
156
  | Query the information schema metadata in a Spanner PostgreSQL database. | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/pg-schema-information.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/pg-schema-information.js,samples/README.md) |
154
157
  | Queryoptions | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/queryoptions.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/queryoptions.js,samples/README.md) |
155
158
  | Quickstart | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/quickstart.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/quickstart.js,samples/README.md) |
159
+ | Read data with database role | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/read-data-with-database-role.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/read-data-with-database-role.js,samples/README.md) |
156
160
  | Sets a request tag for a single query | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/request-tag.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/request-tag.js,samples/README.md) |
157
161
  | Run Batch update with RPC priority | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/rpc-priority-batch-dml.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/rpc-priority-batch-dml.js,samples/README.md) |
158
162
  | Run partitioned update with RPC priority | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/rpc-priority-partitioned-dml.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/rpc-priority-partitioned-dml.js,samples/README.md) |
@@ -31,6 +31,12 @@ import { AsyncRunTransactionCallback, RunTransactionCallback, RunTransactionOpti
31
31
  import { IOperation, LongRunningCallback, NormalCallback, PagedOptionsWithFilter, PagedResponse, RequestCallback, ResourceCallback, Schema } from './common';
32
32
  import { Duplex, Readable } from 'stream';
33
33
  import { EnumKey, RequestConfig, TranslateEnumKeys } from '.';
34
+ import IPolicy = google.iam.v1.IPolicy;
35
+ import Policy = google.iam.v1.Policy;
36
+ import FieldMask = google.protobuf.FieldMask;
37
+ export type GetDatabaseRolesCallback = RequestCallback<IDatabaseRole, databaseAdmin.spanner.admin.database.v1.IListDatabaseRolesResponse>;
38
+ export type GetDatabaseRolesResponse = PagedResponse<IDatabaseRole, databaseAdmin.spanner.admin.database.v1.IListDatabaseRolesResponse>;
39
+ type IDatabaseRole = databaseAdmin.spanner.admin.database.v1.IDatabaseRole;
34
40
  type CreateBatchTransactionCallback = ResourceCallback<BatchTransaction, google.spanner.v1.ITransaction | google.spanner.v1.ISession>;
35
41
  type CreateBatchTransactionResponse = [
36
42
  BatchTransaction,
@@ -43,6 +49,10 @@ type GetTransactionCallback = NormalCallback<Transaction>;
43
49
  export interface SessionPoolConstructor {
44
50
  new (database: Database, options?: SessionPoolOptions | null): SessionPoolInterface;
45
51
  }
52
+ export interface SetIamPolicyRequest {
53
+ policy: Policy | null;
54
+ updateMask?: FieldMask | null;
55
+ }
46
56
  export type UpdateSchemaCallback = ResourceCallback<GaxOperation, databaseAdmin.longrunning.IOperation>;
47
57
  export type UpdateSchemaResponse = [
48
58
  GaxOperation,
@@ -50,6 +60,7 @@ export type UpdateSchemaResponse = [
50
60
  ];
51
61
  type PoolRequestCallback = RequestCallback<Session>;
52
62
  export type GetSessionsOptions = PagedOptionsWithFilter;
63
+ export type GetDatabaseRolesOptions = PagedOptionsWithFilter;
53
64
  /**
54
65
  * IDatabase structure with database state enum translated to string form.
55
66
  */
@@ -67,6 +78,10 @@ type GetSchemaResponse = [
67
78
  string[],
68
79
  databaseAdmin.spanner.admin.database.v1.IGetDatabaseDdlResponse
69
80
  ];
81
+ type GetIamPolicyResponse = IPolicy;
82
+ type GetIamPolicyCallback = RequestCallback<IPolicy>;
83
+ type SetIamPolicyResponse = IPolicy;
84
+ type SetIamPolicyCallback = RequestCallback<IPolicy>;
70
85
  type GetSessionsCallback = RequestCallback<Session, google.spanner.v1.IListSessionsResponse>;
71
86
  type GetSessionsResponse = PagedResponse<Session, google.spanner.v1.IListSessionsResponse>;
72
87
  export type GetDatabaseConfig = GetConfig & databaseAdmin.spanner.admin.database.v1.IGetDatabaseRequest & {
@@ -81,6 +96,11 @@ export interface CreateSessionOptions {
81
96
  labels?: {
82
97
  [k: string]: string;
83
98
  } | null;
99
+ databaseRole?: string | null;
100
+ gaxOptions?: CallOptions;
101
+ }
102
+ export interface GetIamPolicyOptions {
103
+ requestedPolicyVersion?: number | null;
84
104
  gaxOptions?: CallOptions;
85
105
  }
86
106
  export type CreateSessionCallback = ResourceCallback<Session, spannerClient.spanner.v1.ISession>;
@@ -142,6 +162,7 @@ declare class Database extends common.GrpcServiceObject {
142
162
  [k: string]: string;
143
163
  };
144
164
  request: DatabaseRequest;
165
+ databaseRole?: string | null;
145
166
  constructor(instance: Instance, name: string, poolOptions?: SessionPoolConstructor | SessionPoolOptions, queryOptions?: spannerClient.spanner.v1.ExecuteSqlRequest.IQueryOptions);
146
167
  static getEnvironmentQueryOptions(): databaseAdmin.spanner.v1.ExecuteSqlRequest.IQueryOptions;
147
168
  /**
@@ -772,6 +793,53 @@ declare class Database extends common.GrpcServiceObject {
772
793
  getSchema(options?: CallOptions): Promise<GetSchemaResponse>;
773
794
  getSchema(callback: GetSchemaCallback): void;
774
795
  getSchema(options: CallOptions, callback: GetSchemaCallback): void;
796
+ /**
797
+ * Options object for requested policy version.
798
+ *
799
+ * @typedef {object} GetIamPolicyOptions
800
+ * @property {number|null} [requestedPolicyVersion] policy version requested, possible values are 0, 1 and 3,
801
+ * See {@link https://cloud.google.com/iam/docs/policies#versions} for more details
802
+ * @property {object} [gaxOptions] Request configuration options,
803
+ * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
804
+ * for more details.
805
+ */
806
+ /**
807
+ * @callback GetIamPolicyCallback
808
+ * @param {?Error} err Request error, if any.
809
+ * @param {google.iam.v1.Policy| undefined} policy Returns policy for the give database
810
+ */
811
+ /**
812
+ * Retrieves the policy of the database.
813
+ *
814
+ * A Policy is a collection of bindings. A binding binds one or more members, or principals,
815
+ * to a single role. Principals can be user accounts, service accounts, Google groups, and
816
+ * domains (such as G Suite). A role is a named list of permissions; each role can be an IAM
817
+ * predefined role or a user-created custom role.
818
+ *
819
+ * @see {@link #getIamPolicy}
820
+ *
821
+ * @method Database#getIamPolicy
822
+ * @param {object} [options] requestedPolicyVersion and gax options(configuration options)
823
+ * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html}
824
+ * for more details on gax options.
825
+ * @param {GetIamPolicyCallback} [callback] Callback function.
826
+ * @returns {Promise<Policy | undefined>}
827
+ * When resolved, contains the current policy of the database.
828
+ *
829
+ * @example
830
+ * ```
831
+ * const {Spanner} = require('@google-cloud/spanner');
832
+ * const spanner = new Spanner();
833
+ * const instance = spanner.instance('my-instance');
834
+ * const database = instance.database('my-database');
835
+ * const policy = await database.getIamPolicy();
836
+ * console.log(policy.bindings, policy.version, policy.etag, policy.auditConfigs)
837
+ * const policyWithVersion specified = await database.getIamPolicy({requestedPolicyVersion: 3});
838
+ * ```
839
+ */
840
+ getIamPolicy(options?: GetIamPolicyOptions): Promise<GetIamPolicyResponse>;
841
+ getIamPolicy(callback: GetIamPolicyCallback): void;
842
+ getIamPolicy(options: GetIamPolicyOptions, callback: GetIamPolicyCallback): void;
775
843
  /**
776
844
  * Options object for listing sessions.
777
845
  *
@@ -1068,6 +1136,67 @@ declare class Database extends common.GrpcServiceObject {
1068
1136
  getOperations(options?: GetDatabaseOperationsOptions): Promise<GetDatabaseOperationsResponse>;
1069
1137
  getOperations(callback: GetDatabaseOperationsCallback): void;
1070
1138
  getOperations(options: GetDatabaseOperationsOptions, callback: GetDatabaseOperationsCallback): void;
1139
+ /**
1140
+ * @typedef {array} GetDatabaseRolesResponse
1141
+ * @property {IDatabaseRolees[]} 0 Array of list of database roles.
1142
+ * @property {object} 1 A query object to receive more results.
1143
+ * @property {object} 2 The full API response.
1144
+ */
1145
+ /**
1146
+ * @callback GetDatabaseRolesCallback
1147
+ * @param {?Error} err Request error, if any.
1148
+ * @param {object} apiResponse The full API response.
1149
+ */
1150
+ /**
1151
+ * Gets a list of database roles
1152
+ *
1153
+ * @see {@link v1.DatabaseAdminClient#getDatabaseRoles}
1154
+ * @see [GetDatabaseRoles API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.admin.database.v1#google.spanner.admin.database.v1.DatabaseAdmin.GetDatabaseRoles)
1155
+ *
1156
+ * @param {object} [gaxOptions] Request configuration options,
1157
+ * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
1158
+ * for more details.
1159
+ * @param {GetDatabaseRolesCallback} [callback] Callback function.
1160
+ * @returns {Promise<GetDatabaseRolesResponse>}
1161
+ *
1162
+ * @example
1163
+ * ```
1164
+ * const {Spanner} = require('@google-cloud/spanner');
1165
+ * const spanner = new Spanner();
1166
+ *
1167
+ * const instance = spanner.instance('my-instance');
1168
+ * const database = instance.database('my-database');
1169
+ *
1170
+ * database.getDatabaseRoles(function(err, roles) {
1171
+ * // `roles` is an array of `DatabaseRoles` objects.
1172
+ * });
1173
+ *
1174
+ * //-
1175
+ * // To control how many API requests are made and page through the results
1176
+ * // manually, set `autoPaginate` to `false`.
1177
+ * //-
1178
+ * function callback(err, roles, nextQuery, apiResponse) {
1179
+ * if (nextQuery) {
1180
+ * // More results exist.
1181
+ * database.getDatabaseRoles(nextQuery, callback);
1182
+ * }
1183
+ * }
1184
+ *
1185
+ * database.getInstances({
1186
+ * gaxOptions: {autoPaginate: false}
1187
+ * }, callback);
1188
+ *
1189
+ * //-
1190
+ * // If the callback is omitted, we'll return a Promise.
1191
+ * //-
1192
+ * database.getInstances().then(function(data) {
1193
+ * const roles = data[0];
1194
+ * });
1195
+ * ```
1196
+ */
1197
+ getDatabaseRoles(gaxOptions?: CallOptions): Promise<GetDatabaseRolesResponse>;
1198
+ getDatabaseRoles(callback: GetDatabaseRolesCallback): void;
1199
+ getDatabaseRoles(gaxOptions: CallOptions, callback: GetDatabaseRolesCallback): void;
1071
1200
  /**
1072
1201
  * Make an API request, first assuring an active session is used.
1073
1202
  *
@@ -1583,6 +1712,57 @@ declare class Database extends common.GrpcServiceObject {
1583
1712
  * const table = database.table('Singers');
1584
1713
  * ```
1585
1714
  */
1715
+ /**
1716
+ * @callback SetIamPolicyCallback
1717
+ * @param {?Error} err Request error, if any.
1718
+ * @param {google.iam.v1.Policy| undefined} policy Returns policy for the give database
1719
+ */
1720
+ /**
1721
+ * Sets the policy for the database.
1722
+ *
1723
+ * A Policy is a collection of bindings. A binding binds one or more members, or principals,
1724
+ * to a single role. Principals can be user accounts, service accounts, Google groups, and
1725
+ * domains (such as G Suite). A role is a named list of permissions; each role can be an IAM
1726
+ * predefined role or a user-created custom role.
1727
+ *
1728
+ * @see {@link #setIamPolicy}
1729
+ *
1730
+ * @method Database#setIamPolicy
1731
+ * @param {object} [policy] requestedPolicyVersion and gax options(configuration options)
1732
+ * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html}
1733
+ * for more details on gax options.
1734
+ * @param {object} [options] Requested configuration options,
1735
+ * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html}
1736
+ * for more details on Call Options.
1737
+ * @param {SetIamPolicyCallback} [callback] Callback function.
1738
+ * @returns {Promise<Policy | undefined>}
1739
+ * When resolved, contains the current policy of the database.
1740
+ *
1741
+ * @example
1742
+ * ```
1743
+ * const {Spanner} = require('@google-cloud/spanner');
1744
+ * const spanner = new Spanner();
1745
+ * const instance = spanner.instance('my-instance');
1746
+ * const database = instance.database('my-database');
1747
+ * const binding = {
1748
+ * role: 'roles/spanner.fineGrainedAccessUser',
1749
+ * members: ['user:asthamohta@google.com'],
1750
+ * condition: {
1751
+ * title: 'new condition',
1752
+ * expression: 'resource.name.endsWith("/databaseRoles/parent")',
1753
+ * },
1754
+ * };
1755
+ * const policy = {
1756
+ * bindings: [newBinding],
1757
+ * version: 3,
1758
+ *};
1759
+ * const policy = await database.setIamPolicy({policy: policy});
1760
+ * ```
1761
+ */
1762
+ setIamPolicy(policy: SetIamPolicyRequest): Promise<SetIamPolicyResponse>;
1763
+ setIamPolicy(policy: SetIamPolicyRequest, options?: CallOptions): Promise<SetIamPolicyResponse>;
1764
+ setIamPolicy(policy: SetIamPolicyRequest, callback: SetIamPolicyCallback): void;
1765
+ setIamPolicy(policy: SetIamPolicyRequest, options: CallOptions, callback: SetIamPolicyCallback): void;
1586
1766
  table(name: string): Table;
1587
1767
  /**
1588
1768
  * Update the schema of the database by creating/altering/dropping tables,
@@ -141,6 +141,9 @@ class Database extends common.GrpcServiceObject {
141
141
  typeof poolOptions === 'function'
142
142
  ? new poolOptions(this, null)
143
143
  : new session_pool_1.SessionPool(this, poolOptions);
144
+ if (typeof poolOptions === 'object') {
145
+ this.databaseRole = poolOptions.databaseRole || null;
146
+ }
144
147
  this.formattedName_ = formattedName_;
145
148
  this.instance = instance;
146
149
  this.resourceHeader_ = {
@@ -170,9 +173,10 @@ class Database extends common.GrpcServiceObject {
170
173
  }
171
174
  const count = options.count;
172
175
  const labels = options.labels || {};
176
+ const databaseRole = options.databaseRole || this.databaseRole || null;
173
177
  const reqOpts = {
174
178
  database: this.formattedName_,
175
- sessionTemplate: { labels },
179
+ sessionTemplate: { labels: labels, creatorRole: databaseRole },
176
180
  sessionCount: count,
177
181
  };
178
182
  this.request({
@@ -265,9 +269,12 @@ class Database extends common.GrpcServiceObject {
265
269
  const reqOpts = {
266
270
  database: this.formattedName_,
267
271
  };
272
+ reqOpts.session = {};
268
273
  if (options.labels) {
269
- reqOpts.session = { labels: options.labels };
274
+ reqOpts.session.labels = options.labels;
270
275
  }
276
+ reqOpts.session.creatorRole =
277
+ options.databaseRole || this.databaseRole || null;
271
278
  this.request({
272
279
  client: 'SpannerClient',
273
280
  method: 'createSession',
@@ -425,6 +432,25 @@ class Database extends common.GrpcServiceObject {
425
432
  callback(err, statements ? statements.statements : null, ...args);
426
433
  });
427
434
  }
435
+ getIamPolicy(optionsOrCallback, cb) {
436
+ const options = typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
437
+ const callback = typeof optionsOrCallback === 'function' ? optionsOrCallback : cb;
438
+ const reqOpts = {
439
+ resource: this.formattedName_,
440
+ options: {
441
+ requestedPolicyVersion: options.requestedPolicyVersion || null,
442
+ },
443
+ };
444
+ this.request({
445
+ client: 'DatabaseAdminClient',
446
+ method: 'getIamPolicy',
447
+ reqOpts,
448
+ gaxOpts: options.gaxOptions,
449
+ headers: this.resourceHeader_,
450
+ }, (err, resp) => {
451
+ callback(err, resp);
452
+ });
453
+ }
428
454
  getSessions(optionsOrCallback, cb) {
429
455
  // eslint-disable-next-line @typescript-eslint/no-this-alias
430
456
  const self = this;
@@ -586,6 +612,35 @@ class Database extends common.GrpcServiceObject {
586
612
  };
587
613
  return this.instance.getDatabaseOperations(dbSpecificQuery);
588
614
  }
615
+ getDatabaseRoles(optionsOrCallback, cb) {
616
+ const gaxOpts = typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
617
+ const callback = typeof optionsOrCallback === 'function' ? optionsOrCallback : cb;
618
+ let reqOpts = {
619
+ parent: this.formattedName_,
620
+ };
621
+ // Copy over pageSize and pageToken values from gaxOptions.
622
+ // However, values set on options take precedence.
623
+ if (gaxOpts) {
624
+ reqOpts = extend({}, {
625
+ pageSize: gaxOpts.pageSize,
626
+ pageToken: gaxOpts.pageToken,
627
+ }, reqOpts);
628
+ delete gaxOpts.pageSize;
629
+ delete gaxOpts.pageToken;
630
+ }
631
+ this.request({
632
+ client: 'DatabaseAdminClient',
633
+ method: 'listDatabaseRoles',
634
+ reqOpts,
635
+ gaxOpts,
636
+ headers: this.resourceHeader_,
637
+ }, (err, roles, nextPageRequest, ...args) => {
638
+ const nextQuery = nextPageRequest
639
+ ? extend({}, gaxOpts, nextPageRequest)
640
+ : null;
641
+ callback(err, roles, nextQuery, ...args);
642
+ });
643
+ }
589
644
  makePooledRequest_(config, callback) {
590
645
  const pool = this.pool_;
591
646
  pool.getSession((err, session) => {
@@ -1045,25 +1100,27 @@ class Database extends common.GrpcServiceObject {
1045
1100
  session(name) {
1046
1101
  return new session_1.Session(this, name);
1047
1102
  }
1048
- /**
1049
- * Get a reference to a Table object.
1050
- *
1051
- * @throws {GoogleError} If a name is not provided.
1052
- *
1053
- * @param {string} name The name of the table.
1054
- * @return {Table} A Table object.
1055
- *
1056
- * @example
1057
- * ```
1058
- * const {Spanner} = require('@google-cloud/spanner');
1059
- * const spanner = new Spanner();
1060
- *
1061
- * const instance = spanner.instance('my-instance');
1062
- * const database = instance.database('my-database');
1063
- *
1064
- * const table = database.table('Singers');
1065
- * ```
1066
- */
1103
+ setIamPolicy(policy, optionsOrCallback, cb) {
1104
+ const options = typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
1105
+ const callback = typeof optionsOrCallback === 'function'
1106
+ ? optionsOrCallback
1107
+ : cb;
1108
+ const gaxOpts = options;
1109
+ const reqOpts = {
1110
+ resource: this.formattedName_,
1111
+ policy: policy.policy,
1112
+ updateMask: policy.updateMask || null,
1113
+ };
1114
+ this.request({
1115
+ client: 'DatabaseAdminClient',
1116
+ method: 'setIamPolicy',
1117
+ reqOpts,
1118
+ gaxOpts: gaxOpts,
1119
+ headers: this.resourceHeader_,
1120
+ }, (err, resp) => {
1121
+ callback(err, resp);
1122
+ });
1123
+ }
1067
1124
  table(name) {
1068
1125
  if (!name) {
1069
1126
  throw new google_gax_1.GoogleError('A name is required to access a Table object.');
@@ -1155,6 +1212,7 @@ exports.Database = Database;
1155
1212
  'getSessions',
1156
1213
  'getSnapshot',
1157
1214
  'getTransaction',
1215
+ 'getIamPolicy',
1158
1216
  'restore',
1159
1217
  'run',
1160
1218
  'runPartitionedUpdate',
@@ -18,7 +18,7 @@ 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, PGNumeric, PGJsonb, Struct } from './codec';
21
+ import { Float, Int, Numeric, PGNumeric, PGJsonb, SpannerDate, Struct } from './codec';
22
22
  import { Backup } from './backup';
23
23
  import { Database } from './database';
24
24
  import { Instance, CreateInstanceCallback, CreateInstanceResponse } from './instance';
@@ -1070,3 +1070,4 @@ declare const _default: {
1070
1070
  Spanner: typeof Spanner;
1071
1071
  };
1072
1072
  export default _default;
1073
+ export { Float, Int, Struct, Numeric, PGNumeric, SpannerDate };
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.protos = exports.v1 = exports.Transaction = exports.Snapshot = exports.PartitionedDml = exports.Table = exports.SessionPool = exports.Session = exports.Backup = exports.Database = exports.InstanceConfig = exports.Instance = exports.Spanner = void 0;
18
+ exports.SpannerDate = exports.PGNumeric = exports.Numeric = exports.Struct = exports.Int = exports.Float = exports.protos = exports.v1 = exports.Transaction = exports.Snapshot = exports.PartitionedDml = exports.Table = exports.SessionPool = exports.Session = exports.Backup = exports.Database = exports.InstanceConfig = exports.Instance = exports.Spanner = void 0;
19
19
  const service_1 = require("./common-grpc/service");
20
20
  const precise_date_1 = require("@google-cloud/precise-date");
21
21
  const projectify_1 = require("@google-cloud/projectify");
@@ -26,6 +26,12 @@ const path = require("path");
26
26
  const streamEvents = require("stream-events");
27
27
  const through = require("through2");
28
28
  const codec_1 = require("./codec");
29
+ Object.defineProperty(exports, "Float", { enumerable: true, get: function () { return codec_1.Float; } });
30
+ Object.defineProperty(exports, "Int", { enumerable: true, get: function () { return codec_1.Int; } });
31
+ Object.defineProperty(exports, "Numeric", { enumerable: true, get: function () { return codec_1.Numeric; } });
32
+ Object.defineProperty(exports, "PGNumeric", { enumerable: true, get: function () { return codec_1.PGNumeric; } });
33
+ Object.defineProperty(exports, "SpannerDate", { enumerable: true, get: function () { return codec_1.SpannerDate; } });
34
+ Object.defineProperty(exports, "Struct", { enumerable: true, get: function () { return codec_1.Struct; } });
29
35
  const backup_1 = require("./backup");
30
36
  Object.defineProperty(exports, "Backup", { enumerable: true, get: function () { return backup_1.Backup; } });
31
37
  const database_1 = require("./database");
@@ -149,6 +149,7 @@ export interface SessionPoolOptions {
149
149
  */
150
150
  writes?: number;
151
151
  incStep?: number;
152
+ databaseRole?: string | null;
152
153
  }
153
154
  /**
154
155
  * Error to be thrown when attempting to release unknown resources.
@@ -32,6 +32,7 @@ const DEFAULTS = {
32
32
  maxIdle: 1,
33
33
  min: 25,
34
34
  incStep: 25,
35
+ databaseRole: null,
35
36
  };
36
37
  /**
37
38
  * Error to be thrown when attempting to release unknown resources.
@@ -245,6 +246,9 @@ class SessionPool extends events_1.EventEmitter {
245
246
  this.database = database;
246
247
  this.options = Object.assign({}, DEFAULTS, options);
247
248
  this.options.min = Math.min(this.options.min, this.options.max);
249
+ this.options.databaseRole = this.options.databaseRole
250
+ ? this.options.databaseRole
251
+ : database.databaseRole;
248
252
  this._inventory = {
249
253
  sessions: [],
250
254
  borrowed: new Set(),
@@ -458,6 +462,7 @@ class SessionPool extends events_1.EventEmitter {
458
462
  */
459
463
  async _createSessions(amount) {
460
464
  const labels = this.options.labels;
465
+ const databaseRole = this.options.databaseRole;
461
466
  if (amount <= 0) {
462
467
  return;
463
468
  }
@@ -469,7 +474,8 @@ class SessionPool extends events_1.EventEmitter {
469
474
  try {
470
475
  [sessions] = await this.database.batchCreateSessions({
471
476
  count: amount,
472
- labels,
477
+ labels: labels,
478
+ databaseRole: databaseRole,
473
479
  });
474
480
  amount -= sessions.length;
475
481
  }
@@ -32,8 +32,16 @@ export declare const enum types {
32
32
  ReadOnly = "readonly",
33
33
  ReadWrite = "readwrite"
34
34
  }
35
- export type GetSessionMetadataCallback = NormalCallback<google.spanner.v1.ISession>;
36
- export type GetSessionMetadataResponse = [google.spanner.v1.ISession];
35
+ export interface GetSessionMetadataResponse {
36
+ name?: string | null;
37
+ labels?: {
38
+ [k: string]: string;
39
+ } | null;
40
+ createTime?: google.protobuf.ITimestamp | null;
41
+ approximateLastUseTime?: google.protobuf.ITimestamp | null;
42
+ databaseRole?: string | null;
43
+ }
44
+ export type GetSessionMetadataCallback = NormalCallback<GetSessionMetadataResponse>;
37
45
  export type KeepAliveCallback = NormalCallback<google.spanner.v1.IResultSet>;
38
46
  export type KeepAliveResponse = [google.spanner.v1.IResultSet];
39
47
  export type DeleteSessionResponse = [google.protobuf.IEmpty];
@@ -185,6 +185,9 @@ class Session extends common.GrpcServiceObject {
185
185
  typeof optionsOrCallback === 'function'
186
186
  ? optionsOrCallback
187
187
  : callback;
188
+ this.labels = options.labels || null;
189
+ this.databaseRole =
190
+ options.databaseRole || database.databaseRole || null;
188
191
  return database.createSession(options, (err, session, apiResponse) => {
189
192
  if (err) {
190
193
  callback(err, null, apiResponse);
@@ -232,6 +235,8 @@ class Session extends common.GrpcServiceObject {
232
235
  headers: this.resourceHeader_,
233
236
  }, (err, resp) => {
234
237
  if (resp) {
238
+ resp.databaseRole = resp.creatorRole;
239
+ delete resp.creatorRole;
235
240
  this.metadata = resp;
236
241
  }
237
242
  callback(err, resp);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@google-cloud/spanner",
3
3
  "description": "Cloud Spanner Client Library for Node.js",
4
- "version": "6.5.0",
4
+ "version": "6.6.0",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Google Inc.",
7
7
  "engines": {
@@ -91,7 +91,7 @@
91
91
  "@types/request": "^2.48.3",
92
92
  "@types/sinon": "^10.0.0",
93
93
  "@types/through2": "^2.0.34",
94
- "@types/uuid": "^8.0.0",
94
+ "@types/uuid": "^9.0.0",
95
95
  "binary-search-bounds": "^2.0.4",
96
96
  "c8": "^7.0.0",
97
97
  "codecov": "^3.0.2",