-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
481 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
export { STATUS_CODE, STATUS_TEXT } from "jsr:@std/http@^1.0.6"; | ||
|
||
export * from "jsr:@std/media-types@^1.0.2"; | ||
export * from "jsr:@std/path@^1.0.1"; | ||
|
||
export { encodeHex } from "jsr:@std/encoding@^1.0.1/hex"; | ||
export { assertEquals } from "jsr:@std/assert@^1.0.5"; | ||
export { assertExists } from "jsr:@std/assert@^1.0.5"; | ||
export { assert } from "jsr:@std/assert@^1.0.5"; | ||
|
||
export { h } from "https://esm.sh/[email protected]"; | ||
export type { | ||
ComponentChild, | ||
ComponentChildren, | ||
JSX, | ||
VNode, | ||
} from "https://esm.sh/[email protected]"; | ||
export { | ||
renderToString, | ||
renderToStringAsync, | ||
} from "https://esm.sh/[email protected][email protected]"; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { assert, assertEquals } from "./deps.ts"; | ||
import { Store } from "./store.ts"; | ||
|
||
Deno.test("ExpiringMap: should set and get a value", async () => { | ||
const expiringMap = new Store<string, string>(1000); // 1 second TTL | ||
expiringMap.set("key1", "value1"); | ||
assertEquals(await expiringMap.get("key1"), "value1"); | ||
}); | ||
|
||
Deno.test("ExpiringMap: should return undefined for expired keys", async () => { | ||
const expiringMap = new Store<string, string>(100); | ||
expiringMap.set("key1", "value1"); | ||
await new Promise((resolve) => setTimeout(resolve, 200)); | ||
assertEquals(await expiringMap.get("key1"), undefined); | ||
}); | ||
|
||
Deno.test("ExpiringMap: should check if a key exists", async () => { | ||
const expiringMap = new Store<string, string>(100); | ||
expiringMap.set("key1", "value1"); | ||
assert(expiringMap.has("key1")); | ||
await new Promise((resolve) => setTimeout(resolve, 200)); | ||
assert(!expiringMap.has("key1")); | ||
}); | ||
|
||
Deno.test("ExpiringMap: should delete a key", async () => { | ||
const expiringMap = new Store<string, string>(); | ||
expiringMap.set("key1", "value1"); | ||
assert(expiringMap.delete("key1")); | ||
assertEquals(await expiringMap.get("key1"), undefined); | ||
}); | ||
|
||
Deno.test("ExpiringMap: should clear all entries", () => { | ||
const expiringMap = new Store<string, string>(); | ||
expiringMap.set("key1", "value1"); | ||
expiringMap.set("key2", "value2"); | ||
expiringMap.clear(); | ||
assertEquals(expiringMap.size(), 0); | ||
}); | ||
|
||
Deno.test("ExpiringMap: should get the size of the map", () => { | ||
const expiringMap = new Store<string, string>(); | ||
expiringMap.set("key1", "value1"); | ||
expiringMap.set("key2", "value2"); | ||
assertEquals(expiringMap.size(), 2); | ||
}); | ||
|
||
Deno.test("ExpiringMap: should iterate over valid entries using forEach", () => { | ||
const expiringMap = new Store<string, string>(1000); | ||
expiringMap.set("key1", "value1"); | ||
expiringMap.set("key2", "value2"); | ||
|
||
const entries: [string, string][] = []; | ||
expiringMap.forEach((value, key) => { | ||
entries.push([key, value]); | ||
}); | ||
|
||
assertEquals(entries.length, 2); | ||
assertEquals(entries, [["key1", "value1"], ["key2", "value2"]]); | ||
}); | ||
|
||
Deno.test("ExpiringMap: should set a key with custom TTL", async () => { | ||
const expiringMap = new Store<string, string>(2000); | ||
expiringMap.set("key1", "value1", 1000); | ||
assertEquals(await expiringMap.get("key1"), "value1"); | ||
await new Promise((resolve) => setTimeout(resolve, 1100)); | ||
assertEquals(await expiringMap.get("key1"), undefined); | ||
}); | ||
|
||
Deno.test("ExpiringMap: save it to github", async () => { | ||
const token = Deno.env.get("GITHUB_TOKEN"); | ||
if (!token) return; | ||
const expiringMap = new Store<string, number>(2000, { | ||
owner: "fastrodev", | ||
repo: "fastro", | ||
path: "modules/store/records.json", | ||
token, | ||
}); | ||
const d = new Date(); | ||
expiringMap.set("key1", d.getTime(), 1000); | ||
const c = await expiringMap.commit(); | ||
assertEquals(c?.data.content?.name, "records.json"); | ||
}); |
Oops, something went wrong.