New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@travetto/cache

Package Overview
Dependencies
Maintainers
1
Versions
330
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@travetto/cache - npm Package Compare versions

Comparing version 5.1.0 to 6.0.0-rc.0

10

package.json
{
"name": "@travetto/cache",
"version": "5.1.0",
"version": "6.0.0-rc.0",
"description": "Caching functionality with decorators for declarative use.",

@@ -28,8 +28,8 @@ "keywords": [

"dependencies": {
"@travetto/di": "^5.1.0",
"@travetto/model": "^5.1.0"
"@travetto/di": "^6.0.0-rc.0",
"@travetto/model": "^6.0.0-rc.0"
},
"peerDependencies": {
"@travetto/test": "^5.1.0",
"@travetto/transformer": "^5.1.0"
"@travetto/test": "^6.0.0-rc.0",
"@travetto/transformer": "^6.0.0-rc.0"
},

@@ -36,0 +36,0 @@ "peerDependenciesMeta": {

import { ExpiresAt, Index, Model, ModelExpirySupport, NotFoundError } from '@travetto/model';
import { Text } from '@travetto/schema';
import { Inject, Injectable } from '@travetto/di';
import { AppError, Runtime, TimeUtil } from '@travetto/runtime';
import { AppError, Runtime, TimeUtil, Util } from '@travetto/runtime';
import { isIndexedSupported, isStorageSupported } from '@travetto/model/src/internal/service/common';

@@ -78,3 +78,3 @@

const res = await this.#modelService.get(CacheRecord, id);
return CacheUtil.fromSafeJSON(res.entry);
return Util.decodeSafeJSON(res.entry);
}

@@ -88,3 +88,3 @@

async set(id: string, keySpace: string, entry: unknown, maxAge?: number): Promise<unknown> {
const entryText = CacheUtil.toSafeJSON(entry);
const entryText = Util.encodeSafeJSON(entry);

@@ -101,3 +101,3 @@ const store = await this.#modelService.upsert(CacheRecord,

return CacheUtil.fromSafeJSON(store.entry);
return Util.decodeSafeJSON(store.entry);
}

@@ -104,0 +104,0 @@

@@ -1,2 +0,2 @@

import { BinaryUtil } from '@travetto/runtime';
import { BinaryUtil, Util } from '@travetto/runtime';

@@ -11,23 +11,2 @@ import { CoreCacheConfig } from './types';

/**
* Convert value to safe JSON for persistence
* @param value The value to make safe for storage
* @param all Should functions and regex be included
*/
static toSafeJSON(value: unknown, all = false): string {
const replacer = all ?
((key: string, val: unknown): unknown => (val && val instanceof RegExp) ? val.source : (typeof val === 'function' ? val.toString() : val)) :
undefined;
return Buffer.from(JSON.stringify(value, replacer)).toString('base64');
}
/**
* Read safe JSON back into an object
* @param value The value to read as safe JSON
*/
static fromSafeJSON(value: string | undefined): unknown {
return value ? JSON.parse(Buffer.from(value, 'base64').toString('utf8')) : undefined;
}
/**
* Generate key given config, cache source and input params

@@ -38,5 +17,5 @@ */

const keyParams = config.key?.(...input) ?? input;
const key = `${config.keySpace!}_${this.toSafeJSON(keyParams)}`;
const key = `${config.keySpace!}_${Util.encodeSafeJSON(keyParams)}`;
return BinaryUtil.hash(key, 32);
}
}

@@ -15,3 +15,2 @@ import assert from 'node:assert';

import { CacheModelSymbol, CacheService } from '../../src/service';
import { CacheUtil } from '../../src/util';

@@ -174,4 +173,2 @@ @Schema()

assert.deepStrictEqual(val3, val5);
assert(CacheUtil.toSafeJSON(/abc/, true) !== CacheUtil.toSafeJSON(/cde/, true));
}

@@ -178,0 +175,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc