Skip to content

Commit

Permalink
chore(deps): bump flat-cache from 3.1.0 to 6.1.1 (#1102)
Browse files Browse the repository at this point in the history
Bumps
[flat-cache](https://github.com/jaredwray/cacheable/tree/HEAD/packages/flat-cache)
from 3.1.0 to 6.1.1.
<details>
<summary>Commits</summary>
<ul>
<li>See full diff in <a
href="https://github.com/jaredwray/cacheable/commits/HEAD/packages/flat-cache">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=flat-cache&package-manager=npm_and_yarn&previous-version=3.1.0&new-version=6.1.1)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Andrii Andreiev <[email protected]>
  • Loading branch information
dependabot[bot] and AndriiAndreiev authored Nov 15, 2024
1 parent 650f088 commit 42a610e
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 43 deletions.
116 changes: 96 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"dependencies": {
"content-type": "^1.0.5",
"find-cache-dir": "^3.3.2",
"flat-cache": "^3.0.4",
"flat-cache": "^6.1.1",
"lodash": "^4.17.15",
"ssri": "^12.0.0",
"timeout-signal": "^1.1.0",
Expand Down
12 changes: 7 additions & 5 deletions packages/node/src/lib/get-project-base-url.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import crypto from 'crypto';

import findCacheDir from 'find-cache-dir';
import flatCache from 'flat-cache';
import { FlatCache } from 'flat-cache';
import timeoutSignal from 'timeout-signal';

import pkg from '../../package.json';
import config from '../config';

import { logger } from './logger';

export const cache = new FlatCache();

export function getCache(readmeApiKey: string) {
const encodedApiKey = Buffer.from(`${readmeApiKey}:`).toString('base64');
const cacheDir = findCacheDir({ name: pkg.name, create: true });
Expand All @@ -18,16 +20,16 @@ export function getCache(readmeApiKey: string) {
// automatically get refreshed when the package is updated/installed.
const cacheKey = `${pkg.name}-${pkg.version}-${fsSafeApikey}`;

return flatCache.load(cacheKey, cacheDir);
return cache.load(cacheKey, cacheDir);
}

export async function getProjectBaseUrl(readmeApiKey: string, requestTimeout = config.timeout): Promise<string> {
const encodedApiKey = Buffer.from(`${readmeApiKey}:`).toString('base64');

const cache = getCache(readmeApiKey);
getCache(readmeApiKey);
// Does the cache exist? If it doesn't, let's fill it. If it does, let's see if it's stale. Caches should have a TTL
// of 1 day.
const lastUpdated = cache.getKey('lastUpdated');
const lastUpdated = cache.getKey<number>('lastUpdated');

if (
lastUpdated === undefined ||
Expand Down Expand Up @@ -76,7 +78,7 @@ export async function getProjectBaseUrl(readmeApiKey: string, requestTimeout = c

return baseUrl;
}
const cachedBaseUrl = cache.getKey('baseUrl');
const cachedBaseUrl = cache.getKey<string>('baseUrl');
logger.verbose({ message: 'Retrieved baseUrl from cache.', args: { baseUrl: cachedBaseUrl } });
return cachedBaseUrl;
}
10 changes: 5 additions & 5 deletions packages/node/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { describe, afterAll, beforeEach, afterEach, expect, it } from 'vitest';
import pkg from '../package.json';
import * as readmeio from '../src';
import config from '../src/config';
import { getCache } from '../src/lib/get-project-base-url';
import { getCache, cache } from '../src/lib/get-project-base-url';
import { setBackoff } from '../src/lib/metrics-log';

import getReadMeApiMock from './helpers/getReadMeApiMock';
Expand Down Expand Up @@ -60,7 +60,7 @@ function doMetricsHeadersMatch(headers: Headers) {
describe('#metrics', function () {
beforeEach(function () {
server.listen();
const cache = getCache(apiKey);
getCache(apiKey);

cache.setKey('lastUpdated', Date.now());
cache.setKey('baseUrl', 'https://docs.example.com');
Expand All @@ -69,7 +69,7 @@ describe('#metrics', function () {

afterEach(function () {
server.resetHandlers();
getCache(apiKey).destroy();
cache.destroy();
});

// Close server after all tests
Expand Down Expand Up @@ -146,7 +146,7 @@ describe('#metrics', function () {
app = express();
app.use((req, res, next) => {
const logId = readmeio.log(apiKey, req, res, incomingGroup, { logger: mockLogger });
res.setHeader('x-log-id', logId);
res.setHeader('x-log-id', logId!);
return next();
});
app.get('/test', (req, res) => res.sendStatus(200));
Expand Down Expand Up @@ -531,7 +531,7 @@ describe('#metrics', function () {
it('should fetch the `baseLogUrl` if not passed', function () {
expect.assertions(1);
// Invalidating the cache so we do a fetch from the API
const cache = getCache(apiKey);
getCache(apiKey);
const lastUpdated = new Date();
lastUpdated.setDate(lastUpdated.getDate() - 2);
cache.setKey('lastUpdated', lastUpdated.getTime());
Expand Down
Loading

0 comments on commit 42a610e

Please sign in to comment.