Something like this ```typescript const defaultPayload = { hits: 1, expiration: new Date(new Dat
Something like this
const defaultPayload = {
hits: 1,
expiration: new Date(new Date().getTime() + 60_000),
}
const record = await env.NAMESPACE.get('key', { type: 'json' })
const payload = {
...defaultPayload,
...(record ?? {}), // if record is nullish, spread an empty object in its place
}
await env.NAMESPACE.put('key', payload, { expiration: payload.expiration })WorkerKV with hono which uses expiration or expirationTtl?
WorkerKV is giving me some troubleresetTime if there's already an expiration field?expiration when we update the value, if you not it's not gonna expire.get('key') it returns an object with the expiration field, right? So if it already has that field, you can re-write it back without altering it.expiration which is fixed in time, and keep adding to it each time the request happens. is that what you want? for the expiration to be moved forward?limit. so not very many.put(); you fire and foget them until the next request where you list() and count.expiration prop. But at the end of the day it will be too expensive to use this solution for rate limiting.
WorkerKV and use DurableObjectsKV is not really a good idea here due to itโs eventually consistent nature. You can however make a rate-limit from Durable Objects 272, which some others have already made from too.
npx wrangler pages deploy is erroring for me, Cloudflare having API issues?
wrangler secret put INNGEST_SIGNING_KEY doesn't make it available in the "environment variables", inngest sync fails and to put it in environment variables, I need to add it to wrangler.toml as "plain text" and deploy.honoexpirationTtlresetTimeget('key')limitput()DurableObjectsnpx wrangler pages deploy โ [ERROR] Received a malformed response from the API
upstream connect error or disconnect/reset before headers. retried and the latest reset reason: conn... (length = 114)
GET /accounts/***/pages/projects/example -> 503 Service Unavailableโ [ERROR] More than one account available but unable to select one in non-interactive mode.
Please set the appropriate `account_id` in your `wrangler.toml` file.
Available accounts are (`<name>`: `<account_id>`):wrangler secret put INNGEST_SIGNING_KEYPS D:\others\durable-objects-template> wrangler dev
โ
๏ธ wrangler 3.63.1
-------------------
Your worker has access to the following bindings:
- Durable Objects:
- COUNTER: Counter
โ Starting local server...
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ [b] open a browser, [d] open Devtools, [l] turn off local mode, [c] clear console, [x] to exit
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
C:\Users\user\AppData\Roaming\npm\node_modules\wrangler\wrangler-dist\cli.js:29765
throw a;
^
MiniflareCoreError [ERR_RUNTIME_FAILURE]: The Workers runtime failed to start. There is likely additional logging output above.
at #assembleAndUpdateConfig (C:\Users\user\AppData\Roaming\npm\node_modules\wrangler\node_modules\miniflare\dist\src\index.js:9178:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Mutex.runWith (C:\Users\user\AppData\Roaming\npm\node_modules\wrangler\node_modules\miniflare\dist\src\index.js:3521:16) {
code: 'ERR_RUNTIME_FAILURE',
cause: undefined
}
Node.js v20.14.0async increment(key: string): Promise<ClientRateLimitInfo> {
const keyWithPrefix = this.prefixKey(key);
const defaultPayload = {
totalHits: 1,
resetTime: new Date(Date.now() + this.windowMs),
}
// @ts-ignore
const record: Required<ClientRateLimitInfo> | null = await this.namespace.get<Required<ClientRateLimitInfo>>(
keyWithPrefix,
"json",
);
const payload = { ...defaultPayload, ...(record ? { totalHits: record.totalHits + 1, resetTime: new Date(record.resetTime) } : {}) }
console.log("Payload - ", payload, " Expire - ", payload.resetTime.toLocaleString(), " Current - ", new Date().toLocaleString())
await this.namespace.put(keyWithPrefix, JSON.stringify(payload), {
expirationTtl: !record ? payload.resetTime.getTime() / 1000 : undefined,
});
return payload;
}