nodejs-storage
nodejs-storage copied to clipboard
Stronger typing for LifecycleRule conditions
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.
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.
Released with 7.0.