@travetto/cache 7.0.0-rc.3 → 7.0.0-rc.4

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": "7.0.0-rc.3",
3
+ "version": "7.0.0-rc.4",
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": "^7.0.0-rc.2",
29
- "@travetto/model": "^7.0.0-rc.2"
28
+ "@travetto/di": "^7.0.0-rc.3",
29
+ "@travetto/model": "^7.0.0-rc.3"
30
30
  },
31
31
  "peerDependencies": {
32
- "@travetto/test": "^7.0.0-rc.2",
33
- "@travetto/transformer": "^7.0.0-rc.2"
32
+ "@travetto/test": "^7.0.0-rc.3",
33
+ "@travetto/transformer": "^7.0.0-rc.3"
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, ModelStorageUtil, ModelIndexedUtil } from '@travetto/model';
2
2
  import { Text } from '@travetto/schema';
3
3
  import { Inject, Injectable } from '@travetto/di';
4
- import { AppError, Runtime, TimeUtil, Util } from '@travetto/runtime';
4
+ import { AppError, JSONUtil, TimeUtil } from '@travetto/runtime';
5
5
 
6
6
  import { CacheError } from './error.ts';
7
7
  import { CacheUtil } from './util.ts';
@@ -14,7 +14,7 @@ const INFINITE_MAX_AGE = TimeUtil.asMillis(10, 'y');
14
14
  type: 'unsorted',
15
15
  fields: [{ keySpace: 1 }]
16
16
  })
17
- @Model({ autoCreate: false })
17
+ @Model({ autoCreate: 'production' })
18
18
  export class CacheRecord {
19
19
  id: string;
20
20
  @Text()
@@ -37,12 +37,6 @@ export class CacheService {
37
37
  this.#modelService = modelService;
38
38
  }
39
39
 
40
- async postConstruct(): Promise<void> {
41
- if (ModelStorageUtil.isSupported(this.#modelService) && (Runtime.dynamic || this.#modelService.config?.autoCreate)) {
42
- await this.#modelService.createModel?.(CacheRecord);
43
- }
44
- }
45
-
46
40
  /**
47
41
  * Get an item throwing an error if missing or expired. Allows for extending expiry based on access
48
42
  * @param id Record identifier
@@ -72,7 +66,7 @@ export class CacheService {
72
66
  }
73
67
  }
74
68
 
75
- return Util.decodeSafeJSON(entry);
69
+ return JSONUtil.parseBase64(entry);
76
70
  }
77
71
 
78
72
  /**
@@ -81,7 +75,7 @@ export class CacheService {
81
75
  * @returns
82
76
  */
83
77
  async set(id: string, keySpace: string, entry: unknown, maxAge?: number): Promise<unknown> {
84
- const entryText = Util.encodeSafeJSON(entry);
78
+ const entryText = JSONUtil.stringifyBase64(entry);
85
79
 
86
80
  const store = await this.#modelService.upsert(CacheRecord,
87
81
  CacheRecord.from({
@@ -93,7 +87,7 @@ export class CacheService {
93
87
  }),
94
88
  );
95
89
 
96
- return Util.decodeSafeJSON(store.entry);
90
+ return JSONUtil.parseBase64(store.entry);
97
91
  }
98
92
 
99
93
  /**
package/src/types.ts CHANGED
@@ -22,7 +22,7 @@ export interface CoreCacheConfig {
22
22
  keySpace?: string;
23
23
 
24
24
  /**
25
- * How to reconstitute the cached value after JSON.parse
25
+ * How to reconstitute the cached value after JSON parsing
26
26
  */
27
27
  reinstate?: (input: unknown) => unknown;
28
28
  }
package/src/util.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { BinaryUtil, Util } from '@travetto/runtime';
1
+ import { BinaryUtil, JSONUtil } from '@travetto/runtime';
2
2
 
3
3
  import { CoreCacheConfig } from './types.ts';
4
4
 
@@ -13,7 +13,7 @@ export class CacheUtil {
13
13
  static generateKey(config: CoreCacheConfig, params: unknown[]): string {
14
14
  const input = config.params?.(params) ?? params;
15
15
  const keyParams = config.key?.(...input) ?? input;
16
- const key = `${config.keySpace!}_${Util.encodeSafeJSON(keyParams)}`;
16
+ const key = `${config.keySpace!}_${JSONUtil.stringifyBase64(keyParams)}`;
17
17
  return BinaryUtil.hash(key, 32);
18
18
  }
19
19
  }