@travetto/cache
Advanced tools
Comparing version 5.1.0 to 6.0.0-rc.0
{ | ||
"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 @@ |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
29154
538
1
+ Added@travetto/config@6.0.0-rc.1(transitive)
+ Added@travetto/di@6.0.0-rc.1(transitive)
+ Added@travetto/manifest@6.0.0-rc.1(transitive)
+ Added@travetto/model@6.0.0-rc.1(transitive)
+ Added@travetto/registry@6.0.0-rc.1(transitive)
+ Added@travetto/runtime@6.0.0-rc.1(transitive)
+ Added@travetto/schema@6.0.0-rc.1(transitive)
+ Added@travetto/terminal@6.0.0-rc.1(transitive)
+ Added@travetto/test@6.0.0-rc.1(transitive)
+ Added@travetto/transformer@6.0.0-rc.2(transitive)
+ Added@travetto/worker@6.0.0-rc.1(transitive)
+ Addedchalk@5.4.1(transitive)
- Removed@travetto/config@5.1.0(transitive)
- Removed@travetto/di@5.1.0(transitive)
- Removed@travetto/manifest@5.1.0(transitive)
- Removed@travetto/model@5.1.0(transitive)
- Removed@travetto/registry@5.1.0(transitive)
- Removed@travetto/runtime@5.1.0(transitive)
- Removed@travetto/schema@5.1.0(transitive)
- Removed@travetto/terminal@5.1.0(transitive)
- Removed@travetto/test@5.1.0(transitive)
- Removed@travetto/transformer@5.1.0(transitive)
- Removed@travetto/worker@5.1.0(transitive)
- Removedansi-styles@4.3.0(transitive)
- Removedchalk@4.1.2(transitive)
- Removedcolor-convert@2.0.1(transitive)
- Removedcolor-name@1.1.4(transitive)
- Removedhas-flag@4.0.0(transitive)
- Removedsupports-color@7.2.0(transitive)
Updated@travetto/di@^6.0.0-rc.0
Updated@travetto/model@^6.0.0-rc.0