nodejs-storage icon indicating copy to clipboard operation
nodejs-storage copied to clipboard

Stronger typing for LifecycleRule conditions

Open bryfox opened this issue 2 years ago • 1 comments

Is your feature request related to a problem? Please describe.

It's easy to write an incorrect lifecycle condition resulting in unwanted results, particularly for a delete action. For example, the following rule uses a string for matchesPrefix when an array of strings is expected.

addLifecycleRule({ action: { type: "Delete" }, condition: { isLive: true, matchesPrefix: "tmp/", age: 1 }})

This rule will be added, but without the prefix condition, so that it (as far as I can tell) applies to all objects in the bucket:

// bucket.metadata.lifecycle.rule
[ { action: { type: 'Delete' }, condition: { age: 1, isLive: true } } ]

Describe the solution you'd like

Stronger typing on the LifecycleRule would help TS users write rules correctly.

(c.f. the go SDK: https://github.com/googleapis/google-cloud-go/blob/5a9102369b64e06a1564b9d769da7bd044035b7e/storage/bucket.go#L649)

Describe alternatives you've considered

The client SDK could throw an error if unexpected types are passed, to protect me from myself. However, gsutil appears to have the same behavior of creating rules while discarding conditions with unexpected types in the JSON.

bryfox avatar Sep 08 '22 15:09 bryfox

Thanks for calling this out! I can see how this leads to a confusing user experience. We will take another look at this as we plan our next major release, as this would be a breaking change.

shaffeeullah avatar Sep 08 '22 17:09 shaffeeullah

Released with 7.0.

ddelgrosso1 avatar Aug 03 '23 19:08 ddelgrosso1