From b0b131f214547f342d54e1169a592b34d3da7cc5 Mon Sep 17 00:00:00 2001 From: jelveh Date: Wed, 2 Jul 2025 22:54:55 -0700 Subject: [PATCH] add `expire` mthod to `puter.kv` --- src/puter-js/src/modules/KV.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/puter-js/src/modules/KV.js b/src/puter-js/src/modules/KV.js index a2c2c2f00..4c7383a70 100644 --- a/src/puter-js/src/modules/KV.js +++ b/src/puter-js/src/modules/KV.js @@ -180,6 +180,19 @@ class KV{ return utils.make_driver_method(['key'], 'puter-kvstore', undefined, 'decr').call(this, options); } + expire = async(...args) => { + let options = {}; + options.key = args[0]; + options.seconds = args[1]; + + // key size cannot be larger than MAX_KEY_SIZE + if(options.key.length > this.MAX_KEY_SIZE){ + throw ({message: 'Key size cannot be larger than ' + this.MAX_KEY_SIZE, code: 'key_too_large'}); + } + + return utils.make_driver_method(['key'], 'puter-kvstore', undefined, 'expire').call(this, options); + } + // resolves to 'true' on success, or rejects with an error on failure // will still resolve to 'true' if the key does not exist del = utils.make_driver_method(['key'], 'puter-kvstore', undefined, 'del', {