@travetto/cache 5.0.17 → 6.0.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/cache",
3
- "version": "5.0.17",
3
+ "version": "6.0.0-rc.0",
4
4
  "description": "Caching functionality with decorators for declarative use.",
5
5
  "keywords": [
6
6
  "typescript",
@@ -25,12 +25,12 @@
25
25
  "directory": "module/cache"
26
26
  },
27
27
  "dependencies": {
28
- "@travetto/di": "^5.0.16",
29
- "@travetto/model": "^5.0.17"
28
+ "@travetto/di": "^6.0.0-rc.0",
29
+ "@travetto/model": "^6.0.0-rc.0"
30
30
  },
31
31
  "peerDependencies": {
32
- "@travetto/test": "^5.0.18",
33
- "@travetto/transformer": "^5.0.13"
32
+ "@travetto/test": "^6.0.0-rc.0",
33
+ "@travetto/transformer": "^6.0.0-rc.0"
34
34
  },
35
35
  "peerDependenciesMeta": {
36
36
  "@travetto/transformer": {
package/src/service.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ExpiresAt, Index, Model, ModelExpirySupport, NotFoundError } from '@travetto/model';
2
2
  import { Text } from '@travetto/schema';
3
3
  import { Inject, Injectable } from '@travetto/di';
4
- import { AppError, Runtime, TimeUtil } from '@travetto/runtime';
4
+ import { AppError, Runtime, TimeUtil, Util } from '@travetto/runtime';
5
5
  import { isIndexedSupported, isStorageSupported } from '@travetto/model/src/internal/service/common';
6
6
 
7
7
  import { CacheError } from './error';
@@ -75,7 +75,7 @@ export class CacheService {
75
75
  }
76
76
 
77
77
  const res = await this.#modelService.get(CacheRecord, id);
78
- return CacheUtil.fromSafeJSON(res.entry);
78
+ return Util.decodeSafeJSON(res.entry);
79
79
  }
80
80
 
81
81
  /**
@@ -84,7 +84,7 @@ export class CacheService {
84
84
  * @returns
85
85
  */
86
86
  async set(id: string, keySpace: string, entry: unknown, maxAge?: number): Promise<unknown> {
87
- const entryText = CacheUtil.toSafeJSON(entry);
87
+ const entryText = Util.encodeSafeJSON(entry);
88
88
 
89
89
  const store = await this.#modelService.upsert(CacheRecord,
90
90
  CacheRecord.from({
@@ -96,7 +96,7 @@ export class CacheService {
96
96
  }),
97
97
  );
98
98
 
99
- return CacheUtil.fromSafeJSON(store.entry);
99
+ return Util.decodeSafeJSON(store.entry);
100
100
  }
101
101
 
102
102
  /**
package/src/util.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { BinaryUtil } from '@travetto/runtime';
1
+ import { BinaryUtil, Util } from '@travetto/runtime';
2
2
 
3
3
  import { CoreCacheConfig } from './types';
4
4
 
@@ -7,34 +7,13 @@ import { CoreCacheConfig } from './types';
7
7
  */
8
8
  export class CacheUtil {
9
9
 
10
- /**
11
- * Convert value to safe JSON for persistence
12
- * @param value The value to make safe for storage
13
- * @param all Should functions and regex be included
14
- */
15
- static toSafeJSON(value: unknown, all = false): string {
16
- const replacer = all ?
17
- ((key: string, val: unknown): unknown => (val && val instanceof RegExp) ? val.source : (typeof val === 'function' ? val.toString() : val)) :
18
- undefined;
19
-
20
- return Buffer.from(JSON.stringify(value, replacer)).toString('base64');
21
- }
22
-
23
- /**
24
- * Read safe JSON back into an object
25
- * @param value The value to read as safe JSON
26
- */
27
- static fromSafeJSON(value: string | undefined): unknown {
28
- return value ? JSON.parse(Buffer.from(value, 'base64').toString('utf8')) : undefined;
29
- }
30
-
31
10
  /**
32
11
  * Generate key given config, cache source and input params
33
12
  */
34
13
  static generateKey(config: CoreCacheConfig, params: unknown[]): string {
35
14
  const input = config.params?.(params) ?? params;
36
15
  const keyParams = config.key?.(...input) ?? input;
37
- const key = `${config.keySpace!}_${this.toSafeJSON(keyParams)}`;
16
+ const key = `${config.keySpace!}_${Util.encodeSafeJSON(keyParams)}`;
38
17
  return BinaryUtil.hash(key, 32);
39
18
  }
40
19
  }
@@ -12,7 +12,6 @@ import { Schema } from '@travetto/schema';
12
12
 
13
13
  import { Cache, EvictCache } from '../../src/decorator';
14
14
  import { CacheModelSymbol, CacheService } from '../../src/service';
15
- import { CacheUtil } from '../../src/util';
16
15
 
17
16
  @Schema()
18
17
  class User { }
@@ -170,8 +169,6 @@ export abstract class CacheServiceSuite {
170
169
  const val5 = await service.complexInput({ a: /abc/ }, 20);
171
170
  assert(val3 !== val4);
172
171
  assert.deepStrictEqual(val3, val5);
173
-
174
- assert(CacheUtil.toSafeJSON(/abc/, true) !== CacheUtil.toSafeJSON(/cde/, true));
175
172
  }
176
173
 
177
174
  @Test()
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2020 ArcSine Technologies
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.