@fedify/fedify 1.6.1-pr.242.857 → 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.
- package/dist/deno.js +1 -1
- package/dist/node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/_common/dirname.js +1 -1
- package/dist/node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/_common/from_file_url.js +1 -1
- package/dist/node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/posix/dirname.js +1 -1
- package/dist/node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/posix/from_file_url.js +1 -1
- package/dist/node_modules/.pnpm/@jsr_std__path@1.0.9/node_modules/@jsr/std__path/windows/from_file_url.js +1 -1
- package/dist/vocab/vocab.js +176 -176
- package/dist/x/cfworkers.js +7 -3
- package/dist/x/cfworkers.test.d.ts +2 -0
- package/dist/x/cfworkers.test.js +36 -0
- package/package.json +1 -1
package/dist/x/cfworkers.js
CHANGED
@@ -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.
|
23
|
-
return
|
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
|
-
|
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,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
|