@fedify/fedify 1.6.1-pr.242.858 → 1.6.1-pr.242.860

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -19,12 +19,16 @@ var WorkersKvStore = class {
19
19
  }
20
20
  async get(key) {
21
21
  const encodedKey = this.#encodeKey(key);
22
- const value = await this.#namespace.get(encodedKey);
23
- return value == null ? void 0 : JSON.parse(value);
22
+ const { value, metadata } = await this.#namespace.getWithMetadata(encodedKey, "json");
23
+ return metadata == null || metadata.expires < Date.now() ? void 0 : value;
24
24
  }
25
25
  async set(key, value, options) {
26
26
  const encodedKey = this.#encodeKey(key);
27
- await this.#namespace.put(encodedKey, JSON.stringify(value), options?.ttl == null ? {} : { expirationTtl: Math.max(options.ttl.total("seconds"), 60) });
27
+ const metadata = options?.ttl == null ? {} : { expires: Date.now() + options.ttl.total("milliseconds") };
28
+ await this.#namespace.put(encodedKey, JSON.stringify(value), options?.ttl == null ? { metadata } : {
29
+ expirationTtl: Math.max(options.ttl.total("seconds"), 60),
30
+ metadata
31
+ });
28
32
  }
29
33
  delete(key) {
30
34
  return this.#namespace.delete(this.#encodeKey(key));
@@ -0,0 +1,2 @@
1
+ import { Temporal } from "@js-temporal/polyfill";
2
+ import { URLPattern } from "urlpattern-polyfill";
@@ -0,0 +1,36 @@
1
+
2
+ import { Temporal } from "@js-temporal/polyfill";
3
+ import { URLPattern } from "urlpattern-polyfill";
4
+
5
+ import { assertEquals } from "../node_modules/.pnpm/@jsr_std__assert@0.226.0/node_modules/@jsr/std__assert/assert_equals.js";
6
+ import { test } from "../testing/mod.js";
7
+ import { WorkersKvStore } from "./cfworkers.js";
8
+
9
+ //#region x/cfworkers.test.ts
10
+ test({
11
+ name: "WorkersKvStore",
12
+ ignore: !("navigator" in globalThis && navigator.userAgent === "Cloudflare-Workers"),
13
+ async fn(t) {
14
+ const { env } = t;
15
+ const store = new WorkersKvStore(env.KV1);
16
+ await t.step("set() & get()", async () => {
17
+ await store.set(["foo", "bar"], {
18
+ foo: 1,
19
+ bar: 2
20
+ });
21
+ assertEquals(await store.get(["foo", "bar"]), {
22
+ foo: 1,
23
+ bar: 2
24
+ });
25
+ assertEquals(await store.get(["foo"]), void 0);
26
+ await store.set(["foo", "baz"], "baz", { ttl: Temporal.Duration.from({ seconds: 0 }) });
27
+ assertEquals(await store.get(["foo", "baz"]), void 0);
28
+ });
29
+ await t.step("delete()", async () => {
30
+ await store.delete(["foo", "bar"]);
31
+ assertEquals(await store.get(["foo", "bar"]), void 0);
32
+ });
33
+ }
34
+ });
35
+
36
+ //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fedify/fedify",
3
- "version": "1.6.1-pr.242.858+ae33fee0",
3
+ "version": "1.6.1-pr.242.860+9674ec22",
4
4
  "description": "An ActivityPub server framework",
5
5
  "keywords": [
6
6
  "ActivityPub",