This repository has been archived by the owner on Jun 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: replace prettier/eslint with biome
a update biome
- Loading branch information
Showing
174 changed files
with
4,932 additions
and
6,514 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
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,32 @@ | ||
{ | ||
"$schema": "https://biomejs.dev/schemas/1.7.0/schema.json", | ||
"organizeImports": { | ||
"enabled": true | ||
}, | ||
"linter": { | ||
"enabled": true, | ||
"rules": { | ||
"recommended": true, | ||
"style": { | ||
"noNonNullAssertion": "off", | ||
"useSelfClosingElements": "off" | ||
}, | ||
"a11y": { | ||
"noSvgWithoutTitle": "off" | ||
} | ||
} | ||
}, | ||
"vcs": { | ||
"enabled": true, | ||
"clientKind": "git", | ||
"useIgnoreFile": true | ||
}, | ||
"files": { | ||
"ignore": [ | ||
"./dist/**", | ||
"./node_modules/**", | ||
"./.next/**", | ||
"./.react-email/**" | ||
] | ||
} | ||
} |
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,45 +1,42 @@ | ||
{ | ||
"name": "@pedaki/common", | ||
"version": "0.5.3", | ||
"author": "Nathan David <me@vahor.fr>", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/PedakiHQ/pedaki", | ||
"directory": "packages/common" | ||
}, | ||
"homepage": "https://www.pedaki.fr", | ||
"license": "CC-BY-NC-SA-4.0", | ||
"private": false, | ||
"type": "module", | ||
"publishConfig": { | ||
"directory": "dist" | ||
}, | ||
"scripts": { | ||
"build": "tsup", | ||
"lint": "eslint .", | ||
"typecheck": "tsc --noEmit", | ||
"format": "prettier --write .", | ||
"format:check": "prettier --check ." | ||
}, | ||
"devDependencies": { | ||
"@pedaki/eslint-config": "0.5.3", | ||
"@pedaki/prettier-config": "0.5.3", | ||
"@types/bcryptjs": "^2.4.6", | ||
"@types/memory-cache": "latest", | ||
"@types/react": "^18.2.79", | ||
"react": "^18.2.0" | ||
}, | ||
"peerDependencies": { | ||
"bcryptjs": "^2.4.3", | ||
"memory-cache": "^0.2.0", | ||
"nanoid": "^5.0.0", | ||
"sonner": "^1.0.0" | ||
}, | ||
"engines": { | ||
"node": "^18 || ^20", | ||
"pnpm": ">=9.0.0", | ||
"yarn": "use-pnpm", | ||
"npm": "use-pnpm" | ||
}, | ||
"prettier": "@pedaki/prettier-config" | ||
} | ||
"name": "@pedaki/common", | ||
"version": "0.5.3", | ||
"author": "Nathan David <me@vahor.fr>", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/PedakiHQ/pedaki", | ||
"directory": "packages/common" | ||
}, | ||
"homepage": "https://www.pedaki.fr", | ||
"license": "CC-BY-NC-SA-4.0", | ||
"private": false, | ||
"type": "module", | ||
"publishConfig": { | ||
"directory": "dist" | ||
}, | ||
"scripts": { | ||
"build": "tsup", | ||
"format": "pnpx @biomejs/biome format ./ --write", | ||
"lint": "pnpx @biomejs/biome lint ./ --apply", | ||
"format:check": "pnpx @biomejs/biome format ./", | ||
"typecheck": "tsc --noEmit" | ||
}, | ||
"devDependencies": { | ||
"@types/bcryptjs": "^2.4.6", | ||
"@types/memory-cache": "latest", | ||
"@types/react": "^18.2.79", | ||
"react": "^18.2.0" | ||
}, | ||
"peerDependencies": { | ||
"bcryptjs": "^2.4.3", | ||
"memory-cache": "^0.2.0", | ||
"nanoid": "^5.0.0", | ||
"sonner": "^1.0.0" | ||
}, | ||
"engines": { | ||
"node": "^18 || ^20", | ||
"pnpm": ">=9.0.0", | ||
"yarn": "use-pnpm", | ||
"npm": "use-pnpm" | ||
} | ||
} |
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 |
---|---|---|
@@ -1,114 +1,120 @@ | ||
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'; | ||
import { cache, getCache, isStale, revalidate, revalidateAll } from './cache.ts'; | ||
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest"; | ||
import { | ||
cache, | ||
getCache, | ||
isStale, | ||
revalidate, | ||
revalidateAll, | ||
} from "./cache.ts"; | ||
|
||
describe('cache - memory', () => { | ||
const value = 'test'; | ||
const asyncFn = () => Promise.resolve(value); | ||
const syncFn = () => value; | ||
const key = 'key'; | ||
const mock = vi.fn().mockImplementation(asyncFn); | ||
describe("cache - memory", () => { | ||
const value = "test"; | ||
const asyncFn = () => Promise.resolve(value); | ||
const syncFn = () => value; | ||
const key = "key"; | ||
const mock = vi.fn().mockImplementation(asyncFn); | ||
|
||
beforeEach(() => { | ||
revalidateAll(); | ||
}); | ||
beforeEach(() => { | ||
revalidateAll(); | ||
}); | ||
|
||
afterEach(() => { | ||
vi.restoreAllMocks(); | ||
}); | ||
afterEach(() => { | ||
vi.restoreAllMocks(); | ||
}); | ||
|
||
test('cache a value (async)', async () => { | ||
const result = await cache(asyncFn, key); | ||
expect(result).toBe(value); | ||
}); | ||
test("cache a value (async)", async () => { | ||
const result = await cache(asyncFn, key); | ||
expect(result).toBe(value); | ||
}); | ||
|
||
test('cache a value (sync)', async () => { | ||
const result = await cache(syncFn, key); | ||
expect(result).toBe(value); | ||
}); | ||
test("cache a value (sync)", async () => { | ||
const result = await cache(syncFn, key); | ||
expect(result).toBe(value); | ||
}); | ||
|
||
describe('with ttl', () => { | ||
test('without keepStale', async () => { | ||
await cache(value, key, { ttl: 1000, keepStale: false }); | ||
describe("with ttl", () => { | ||
test("without keepStale", async () => { | ||
await cache(value, key, { ttl: 1000, keepStale: false }); | ||
|
||
let cached = await getCache(key); | ||
expect(isStale(cached!, 1000)).toBe(false); | ||
let cached = await getCache(key); | ||
expect(isStale(cached!, 1000)).toBe(false); | ||
|
||
vi.useFakeTimers(); | ||
vi.advanceTimersByTime(10000); | ||
vi.useFakeTimers(); | ||
vi.advanceTimersByTime(10000); | ||
|
||
cached = await getCache(key); | ||
expect(cached).toBeNull(); | ||
}); | ||
cached = await getCache(key); | ||
expect(cached).toBeNull(); | ||
}); | ||
|
||
test('with keepStale', async () => { | ||
await cache(value, key, { ttl: 1000, keepStale: true }); | ||
test("with keepStale", async () => { | ||
await cache(value, key, { ttl: 1000, keepStale: true }); | ||
|
||
let cached = await getCache(key); | ||
expect(isStale(cached!, 1000)).toBe(false); | ||
let cached = await getCache(key); | ||
expect(isStale(cached!, 1000)).toBe(false); | ||
|
||
vi.useFakeTimers(); | ||
vi.advanceTimersByTime(10000); | ||
vi.useFakeTimers(); | ||
vi.advanceTimersByTime(10000); | ||
|
||
cached = await getCache(key); | ||
expect(cached).not.toBeNull(); | ||
cached = await getCache(key); | ||
expect(cached).not.toBeNull(); | ||
|
||
expect(isStale(cached!, 1000)).toBe(true); | ||
}); | ||
}); | ||
expect(isStale(cached!, 1000)).toBe(true); | ||
}); | ||
}); | ||
|
||
describe('ignoreCache', () => { | ||
test('without ignoreCache', async () => { | ||
await cache(mock, key, { ignoreCache: false }); | ||
await cache(mock, key, { ignoreCache: false }); | ||
describe("ignoreCache", () => { | ||
test("without ignoreCache", async () => { | ||
await cache(mock, key, { ignoreCache: false }); | ||
await cache(mock, key, { ignoreCache: false }); | ||
|
||
expect(mock).toHaveBeenCalledTimes(1); | ||
}); | ||
expect(mock).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
test('with ignoreCache', async () => { | ||
await cache(mock, key, { ignoreCache: true }); | ||
await cache(mock, key, { ignoreCache: true }); | ||
test("with ignoreCache", async () => { | ||
await cache(mock, key, { ignoreCache: true }); | ||
await cache(mock, key, { ignoreCache: true }); | ||
|
||
expect(mock).toHaveBeenCalledTimes(2); | ||
}); | ||
}); | ||
expect(mock).toHaveBeenCalledTimes(2); | ||
}); | ||
}); | ||
|
||
describe('revalidate', () => { | ||
test('revalidate a key', async () => { | ||
await cache(mock, key); | ||
await cache(mock, key); | ||
describe("revalidate", () => { | ||
test("revalidate a key", async () => { | ||
await cache(mock, key); | ||
await cache(mock, key); | ||
|
||
expect(mock).toHaveBeenCalledTimes(1); | ||
expect(mock).toHaveBeenCalledTimes(1); | ||
|
||
const before = await getCache(key); | ||
expect(before).not.toBeNull(); | ||
const before = await getCache(key); | ||
expect(before).not.toBeNull(); | ||
|
||
revalidate(key); | ||
revalidate(key); | ||
|
||
const after = await getCache(key); | ||
expect(after).toBeNull(); | ||
const after = await getCache(key); | ||
expect(after).toBeNull(); | ||
|
||
await cache(mock, key); | ||
await cache(mock, key); | ||
|
||
expect(mock).toHaveBeenCalledTimes(2); | ||
}); | ||
expect(mock).toHaveBeenCalledTimes(2); | ||
}); | ||
|
||
test('revalidate all keys', async () => { | ||
await cache(mock, key); | ||
await cache(mock, key); | ||
test("revalidate all keys", async () => { | ||
await cache(mock, key); | ||
await cache(mock, key); | ||
|
||
expect(mock).toHaveBeenCalledTimes(1); | ||
expect(mock).toHaveBeenCalledTimes(1); | ||
|
||
const before = await getCache(key); | ||
expect(before).not.toBeNull(); | ||
const before = await getCache(key); | ||
expect(before).not.toBeNull(); | ||
|
||
revalidateAll(); | ||
revalidateAll(); | ||
|
||
const after = await getCache(key); | ||
expect(after).toBeNull(); | ||
const after = await getCache(key); | ||
expect(after).toBeNull(); | ||
|
||
await cache(mock, key); | ||
await cache(mock, key); | ||
|
||
expect(mock).toHaveBeenCalledTimes(2); | ||
}); | ||
}); | ||
expect(mock).toHaveBeenCalledTimes(2); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.