diff --git a/handwritten/datastore/src/index.ts b/handwritten/datastore/src/index.ts index 8cdf0bfce658..939ec3c07cd3 100644 --- a/handwritten/datastore/src/index.ts +++ b/handwritten/datastore/src/index.ts @@ -113,16 +113,20 @@ export interface LongRunningCallback { export type LongRunningResponse = [Operation, google.longrunning.IOperation]; export type Fallback = boolean | 'rest' | 'proto'; -export interface ExportEntitiesConfig - extends Omit { +export interface ExportEntitiesConfig extends Omit< + google.datastore.admin.v1.IExportEntitiesRequest, + 'projectId' +> { bucket?: string | {name: string}; kinds?: string[]; namespaces?: string[]; gaxOptions?: CallOptions; } -export interface ImportEntitiesConfig - extends Omit { +export interface ImportEntitiesConfig extends Omit< + google.datastore.admin.v1.IImportEntitiesRequest, + 'projectId' +> { file?: string | {bucket: {name: string}; name: string}; kinds?: string[]; namespaces?: string[]; @@ -486,7 +490,7 @@ class Datastore extends DatastoreRequest { auth: GoogleAuth; constructor(options?: DatastoreOptions) { super(); - options = options || {}; + options = {...options}; this.clients_ = new Map(); this.datastore = this; diff --git a/handwritten/datastore/test/index.ts b/handwritten/datastore/test/index.ts index 03fedde213ce..730ad832caf7 100644 --- a/handwritten/datastore/test/index.ts +++ b/handwritten/datastore/test/index.ts @@ -294,6 +294,7 @@ async.each( const datastore = new Datastore(options); assert.notStrictEqual(datastore.options, options); + assert.deepStrictEqual(options, {a: 'b', c: 'd'}); assert.deepStrictEqual( datastore.options, @@ -311,6 +312,16 @@ async.each( ); }); + it('should not mutate the passed options object', () => { + process.env.DATASTORE_PROJECT_ID = 'env-project-id'; + const options = Object.freeze({namespace: 'ns'}) as DatastoreOptions; + + const datastore = new Datastore(options); + + assert.deepStrictEqual(options, {namespace: 'ns'}); + assert.strictEqual(datastore.options.projectId, 'env-project-id'); + }); + it('should set port if detected', () => { const determineBaseUrl_ = Datastore.prototype.determineBaseUrl_; const port = 99;