Skip to content

Apparently wrong type of CopyOptions.metadata #2389

@anantakrishna

Description

@anantakrishna

It seems that the type of CopyOptions.metadata is wrong.

Prior to #2234 (landed in f48dcd2), CopyOptions.metadata was of type Metadata=any: https://github.com/googleapis/nodejs-storage/pull/2234/files#diff-bc9705d0f7a567399044dfc66ccc82d4d9aa1cff116842a0094d54e463c9ecbcL313, https://github.com/googleapis/nodejs-storage/pull/2234/files#diff-dd08f09f3839e8051415914bfa81750cc0f28ae2d9b1d6b95eb87bb0efff2577L48. This fact indicates that this property refers to the custom metadata. Moreover, cacheControl, contentType and other known metadata properties are declared directly on the CopyOptions interface.

After that PR was merged, CopyOptions.metadata got type FileMetadata, which itself contains cacheControl, contentType, as well as nested metadata, which is essentially a Record<string, string> and means “custom metadata”.

It seems to me that CopyOptions.metadata should be of type Record<string, string> directly. This is confirmed by the code below.

Steps to reproduce

file.copy(to,
  {
    contentType: 'outer', // A property from CopyOptions
    metadata: { // Typed as FileMetadata
      contentType: 'internal',
      custom1: 'outer', // Not a part of FileMetadata, but allowed by TypeScript
      metadata: { // Intended to hold custom metadata, but ignored
        custom2: 'internal'
      }
    },
  }
);

The copied file gets the following metadata:

  • Content-Type: outer
  • Custom metadata:
    • contentType: inner - note how a property of FileMetadata.contentType it became a custom metadata.
    • custom1: outer

Whereas custom2 is ignored.

image


Environment details

  • OS: any
  • Node.js version: any
  • npm version: any
  • @google-cloud/storage version: 7.7.0

Metadata

Metadata

Labels

api: storageIssues related to the googleapis/nodejs-storage API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions