@travetto/cache 7.1.4 → 8.0.0-alpha.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": "7.1.4",
3
+ "version": "8.0.0-alpha.0",
4
4
  "type": "module",
5
5
  "description": "Caching functionality with decorators for declarative use.",
6
6
  "keywords": [
@@ -26,12 +26,12 @@
26
26
  "directory": "module/cache"
27
27
  },
28
28
  "dependencies": {
29
- "@travetto/di": "^7.1.4",
30
- "@travetto/model": "^7.1.4"
29
+ "@travetto/di": "^8.0.0-alpha.0",
30
+ "@travetto/model": "^8.0.0-alpha.0"
31
31
  },
32
32
  "peerDependencies": {
33
- "@travetto/test": "^7.1.4",
34
- "@travetto/transformer": "^7.1.3"
33
+ "@travetto/test": "^8.0.0-alpha.0",
34
+ "@travetto/transformer": "^8.0.0-alpha.0"
35
35
  },
36
36
  "peerDependenciesMeta": {
37
37
  "@travetto/transformer": {
package/src/decorator.ts CHANGED
@@ -16,7 +16,7 @@ export function Cache<F extends string, U extends Record<F, CacheService>>(
16
16
  ): MethodDecorator {
17
17
  if (input !== undefined) {
18
18
  if (typeof input === 'string' || typeof input === 'number') {
19
- config.maxAge = TimeUtil.asMillis(input);
19
+ config.maxAge = TimeUtil.duration(input, 'ms');
20
20
  } else {
21
21
  config = input;
22
22
  }
package/src/error.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AppError } from '@travetto/runtime';
1
+ import { RuntimeError } from '@travetto/runtime';
2
2
 
3
3
  /** Cache Error Class */
4
- export class CacheError extends AppError { }
4
+ export class CacheError extends RuntimeError { }
package/src/service.ts CHANGED
@@ -1,13 +1,13 @@
1
1
  import { ExpiresAt, Index, Model, type 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, JSONUtil, TimeUtil } from '@travetto/runtime';
4
+ import { RuntimeError, JSONUtil, TimeUtil } from '@travetto/runtime';
5
5
 
6
6
  import { CacheError } from './error.ts';
7
7
  import { CacheUtil } from './util.ts';
8
8
  import { type CacheAware, CacheConfigSymbol, CacheModelSymbol, EvictConfigSymbol } from './types.ts';
9
9
 
10
- const INFINITE_MAX_AGE = TimeUtil.asMillis(10, 'y');
10
+ const INFINITE_MAX_AGE = TimeUtil.duration('10y', 'ms');
11
11
 
12
12
  @Index({
13
13
  name: 'keySpace',
@@ -65,7 +65,7 @@ export class CacheService {
65
65
  }
66
66
  }
67
67
 
68
- return JSONUtil.parseBase64(entry);
68
+ return JSONUtil.fromBase64(entry);
69
69
  }
70
70
 
71
71
  /**
@@ -74,7 +74,7 @@ export class CacheService {
74
74
  * @returns
75
75
  */
76
76
  async set(id: string, keySpace: string, entry: unknown, maxAge?: number): Promise<unknown> {
77
- const entryText = JSONUtil.stringifyBase64(entry);
77
+ const entryText = JSONUtil.toBase64(entry);
78
78
 
79
79
  const store = await this.#modelService.upsert(CacheRecord,
80
80
  CacheRecord.from({
@@ -86,7 +86,7 @@ export class CacheService {
86
86
  }),
87
87
  );
88
88
 
89
- return JSONUtil.parseBase64(store.entry);
89
+ return JSONUtil.fromBase64(store.entry);
90
90
  }
91
91
 
92
92
  /**
@@ -109,7 +109,7 @@ export class CacheService {
109
109
  }
110
110
  await Promise.all(removes);
111
111
  } else {
112
- throw new AppError('Unable to delete all on an un-indexed database');
112
+ throw new RuntimeError('Unable to delete all on an un-indexed database');
113
113
  }
114
114
  }
115
115
 
package/src/util.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { BinaryUtil, JSONUtil } from '@travetto/runtime';
1
+ import { BinaryMetadataUtil, JSONUtil } from '@travetto/runtime';
2
2
 
3
3
  import type { 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!}_${JSONUtil.stringifyBase64(keyParams)}`;
17
- return BinaryUtil.hash(key, 32);
16
+ const key = `${config.keySpace!}_${JSONUtil.toBase64(keyParams)}`;
17
+ return BinaryMetadataUtil.hash(key, { length: 32 });
18
18
  }
19
19
  }
@@ -96,7 +96,7 @@ export abstract class CacheServiceSuite {
96
96
 
97
97
  @Test()
98
98
  async basic() {
99
- const service = await this.testService;
99
+ const service = this.testService;
100
100
  let start = Date.now();
101
101
  let res = await service.basic(10);
102
102
  let diff = Date.now() - start;
@@ -112,7 +112,7 @@ export abstract class CacheServiceSuite {
112
112
 
113
113
  @Test()
114
114
  async aging() {
115
- const service = await this.testService;
115
+ const service = this.testService;
116
116
 
117
117
  let start = Date.now();
118
118
  let res = await service.agesQuickly(10);
@@ -131,7 +131,7 @@ export abstract class CacheServiceSuite {
131
131
 
132
132
  @Test()
133
133
  async ageWithExtension() {
134
- const service = await this.testService;
134
+ const service = this.testService;
135
135
 
136
136
  let start = Date.now();
137
137
  let res = await service.ageExtension(10);
@@ -159,7 +159,7 @@ export abstract class CacheServiceSuite {
159
159
 
160
160
  @Test()
161
161
  async complex() {
162
- const service = await this.testService;
162
+ const service = this.testService;
163
163
 
164
164
  const val = await service.complexInput({ a: 5, b: 20 }, 20);
165
165
  const val2 = await service.complexInput({ a: 5, b: 20 }, 20);
@@ -174,7 +174,7 @@ export abstract class CacheServiceSuite {
174
174
 
175
175
  @Test()
176
176
  async customKey() {
177
- const service = await this.testService;
177
+ const service = this.testService;
178
178
 
179
179
  const val4 = await service.customKey({ a: 5, b: 20 }, 20);
180
180
  const val5 = await service.customKey({ b: 5, a: 20 }, 30);
@@ -186,7 +186,7 @@ export abstract class CacheServiceSuite {
186
186
 
187
187
  @Test()
188
188
  async reinstating() {
189
- const service = await this.testService;
189
+ const service = this.testService;
190
190
 
191
191
  const user = await service.getUser('200');
192
192
  assert(user instanceof User);
@@ -197,7 +197,7 @@ export abstract class CacheServiceSuite {
197
197
 
198
198
  @Test()
199
199
  async eviction() {
200
- const service = await this.testService;
200
+ const service = this.testService;
201
201
 
202
202
  await service.getUser('200');
203
203
  const start = Date.now();
@@ -221,7 +221,7 @@ export abstract class CacheServiceSuite {
221
221
  return;
222
222
  }
223
223
 
224
- const service = await this.testService;
224
+ const service = this.testService;
225
225
 
226
226
  // Prime cache
227
227
  for (let i = 0; i < 10; i++) {