Skip to content

Commit b784961

Browse files
committed
Revert "Use ohash for cache key generation"
This reverts commit 002f644.
1 parent 002f644 commit b784961

6 files changed

Lines changed: 19 additions & 16 deletions

File tree

.github/dependabot.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ updates:
3030
# yargs v18 needs ESM, see https://github.com/yargs/yargs/releases/tag/v18.0.0, we'll stay on v17 until we can use ESM
3131
- dependency-name: 'yargs'
3232
update-types: ['version-update:semver-major']
33-
# ohash v2 needs ESM, https://github.com/unjs/ohash/releases/tag/v2.0.1, we'll stay on v1 until we can use ESM
34-
- dependency-name: 'ohash'
35-
update-types: ['version-update:semver-major']
3633
- package-ecosystem: 'github-actions'
3734
directory: '/'
3835
schedule:

packages/connectivity/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"coverage": "jest --coverage",
3737
"lint": "eslint --ext .ts . && prettier . --config ../../.prettierrc --ignore-path ../../.prettierignore -c",
3838
"lint:fix": "set TIMING=1 && eslint --ext .ts . --fix --quiet && prettier . --config ../../.prettierrc --ignore-path ../../.prettierignore -w --log-level error",
39-
"check:dependencies": "depcheck . --ignores=ohash",
39+
"check:dependencies": "depcheck .",
4040
"readme": "ts-node ../../scripts/replace-common-readme.ts"
4141
},
4242
"dependencies": {

packages/connectivity/src/http-agent/http-agent.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@ import { readFile } from 'node:fs/promises';
22
import http from 'node:http';
33
import https from 'node:https';
44
import * as jks from 'jks-js';
5-
// @ts-expect-error - ts fails to detect that this package provides CJS exports
6-
import * as ohash from 'ohash';
75
import { createLogger, last } from '@sap-cloud-sdk/util';
86
/* Careful the proxy imports cause circular dependencies if imported from scp directly */
97
// eslint-disable-next-line import/no-internal-modules
108
import { getProtocolOrDefault } from '../scp-cf/get-protocol';
119
// eslint-disable-next-line import/no-internal-modules
12-
import { Cache } from '../scp-cf/cache';
10+
import { Cache, hashCacheKey } from '../scp-cf/cache';
1311
import {
1412
addProxyConfigurationInternet,
1513
getProxyConfig,
@@ -309,7 +307,8 @@ function createAgent(
309307
options: https.AgentOptions
310308
): HttpAgentConfig | HttpsAgentConfig {
311309
const protocol = getProtocolOrDefault(destination);
312-
const cacheKey = ohash.hash({ protocol, options });
310+
const cacheKey = hashCacheKey({ protocol, options });
311+
313312
return agentCreateCache.getOrInsertComputed(cacheKey, () => {
314313
logger.debug(
315314
`Creating new ${protocol.toUpperCase()} agent for destination ${destination.name || '<unknown>'}`

packages/connectivity/src/scp-cf/cache.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { createHash } from 'node:crypto';
2+
13
interface CacheInterface<T> {
24
hasKey(key: string): boolean;
35
get(key: string | undefined): T | undefined;
@@ -147,6 +149,17 @@ export class Cache<T> implements CacheInterface<T> {
147149
}
148150
}
149151

152+
/**
153+
* Hashes the given value to create a cache key.
154+
* @internal
155+
* @param value - The value to hash.
156+
* @returns A hash of the given value using a cryptographic hash function.
157+
*/
158+
export function hashCacheKey(value: Record<string, unknown>): string {
159+
const serialized = JSON.stringify(value);
160+
return createHash('blake2s256').update(serialized).digest('hex');
161+
}
162+
150163
function isExpired<T>(item: CacheEntry<T>): boolean {
151164
if (item.expires === undefined) {
152165
return false;

packages/http-client/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,14 @@
3636
"coverage": "yarn node --experimental-vm-modules ../../node_modules/jest/bin/jest.js --coverage",
3737
"lint": "eslint --ext .ts . && prettier . --config ../../.prettierrc --ignore-path ../../.prettierignore -c",
3838
"lint:fix": "set TIMING=1 && eslint --ext .ts . --fix --quiet && prettier . --config ../../.prettierrc --ignore-path ../../.prettierignore -w --log-level error",
39-
"check:dependencies": "depcheck . --ignores=ohash",
39+
"check:dependencies": "depcheck .",
4040
"readme": "ts-node ../../scripts/replace-common-readme.ts"
4141
},
4242
"dependencies": {
4343
"@sap-cloud-sdk/connectivity": "^4.6.0",
4444
"@sap-cloud-sdk/resilience": "^4.6.0",
4545
"@sap-cloud-sdk/util": "^4.6.0",
46-
"axios": "^1.15.0",
47-
"ohash": "^1.1.6"
46+
"axios": "^1.15.0"
4847
},
4948
"devDependencies": {
5049
"https-proxy-agent": "^7.0.6",

yarn.lock

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7342,11 +7342,6 @@ object.values@^1.2.1:
73427342
define-properties "^1.2.1"
73437343
es-object-atoms "^1.0.0"
73447344

7345-
ohash@^1.1.6:
7346-
version "1.1.6"
7347-
resolved "https://registry.npmjs.org/ohash/-/ohash-1.1.6.tgz#9ff7b0271d7076290794537d68ec2b40a60d133e"
7348-
integrity sha512-TBu7PtV8YkAZn0tSxobKY2n2aAQva936lhRrj6957aDaCf9IEtqsKbgMzXE/F/sjqYOwmrukeORHNLe5glk7Cg==
7349-
73507345
[email protected], on-finished@^2.4.1, on-finished@~2.4.1:
73517346
version "2.4.1"
73527347
resolved "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz#58c8c44116e54845ad57f14ab10b03533184ac3f"

0 commit comments

Comments
 (0)