@ls-stack/utils 2.14.0 → 2.14.1

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/dist/cache.cjs CHANGED
@@ -20,7 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/cache.ts
21
21
  var cache_exports = {};
22
22
  __export(cache_exports, {
23
- RejectValue: () => RejectValue,
23
+ SkipCaching: () => SkipCaching,
24
24
  WithExpiration: () => WithExpiration,
25
25
  cachedGetter: () => cachedGetter,
26
26
  createCache: () => createCache
@@ -61,7 +61,7 @@ function cachedGetter(getter) {
61
61
  }
62
62
  };
63
63
  }
64
- var RejectValue = class {
64
+ var SkipCaching = class {
65
65
  value;
66
66
  constructor(value) {
67
67
  this.value = value;
@@ -126,7 +126,7 @@ function createCache({
126
126
  return { value, timestamp: now, expiration: void 0 };
127
127
  }
128
128
  const utils = {
129
- reject: (value) => new RejectValue(value),
129
+ skipCaching: (value) => new SkipCaching(value),
130
130
  withExpiration: (value, expiration) => {
131
131
  return new WithExpiration(value, expiration);
132
132
  }
@@ -137,10 +137,10 @@ function createCache({
137
137
  const entry = cache.get(cacheKey);
138
138
  if (!entry || isExpired(entry, now)) {
139
139
  const value = val(utils);
140
- if (value instanceof RejectValue) {
140
+ if (value instanceof SkipCaching) {
141
141
  return value.value;
142
142
  }
143
- if (options?.rejectWhen?.(value)) {
143
+ if (options?.skipCachingWhen?.(value)) {
144
144
  return value;
145
145
  }
146
146
  const unwrappedValue = unwrapValue(value, now);
@@ -166,14 +166,14 @@ function createCache({
166
166
  return entry.value;
167
167
  }
168
168
  const promise = val(utils).then((result) => {
169
- if (result instanceof RejectValue) {
169
+ if (result instanceof SkipCaching) {
170
170
  const cacheValue = cache.get(cacheKey);
171
171
  if (cacheValue?.value === promise) {
172
172
  cache.delete(cacheKey);
173
173
  }
174
174
  return result.value;
175
175
  }
176
- if (options?.rejectWhen?.(result)) {
176
+ if (options?.skipCachingWhen?.(result)) {
177
177
  const cacheValue = cache.get(cacheKey);
178
178
  if (cacheValue?.value === promise) {
179
179
  cache.delete(cacheKey);
@@ -223,7 +223,7 @@ function createCache({
223
223
  },
224
224
  async setAsync(cacheKey, value) {
225
225
  const promise = value(utils).then((result) => {
226
- if (result instanceof RejectValue) {
226
+ if (result instanceof SkipCaching) {
227
227
  const cacheValue = cache.get(cacheKey);
228
228
  if (cacheValue?.value === promise) {
229
229
  cache.delete(cacheKey);
@@ -253,7 +253,7 @@ function createCache({
253
253
  }
254
254
  // Annotate the CommonJS export names for ESM import in node:
255
255
  0 && (module.exports = {
256
- RejectValue,
256
+ SkipCaching,
257
257
  WithExpiration,
258
258
  cachedGetter,
259
259
  createCache
package/dist/cache.d.cts CHANGED
@@ -20,7 +20,7 @@ type Options = {
20
20
  */
21
21
  expirationThrottle?: number;
22
22
  };
23
- declare class RejectValue<T> {
23
+ declare class SkipCaching<T> {
24
24
  value: T;
25
25
  constructor(value: T);
26
26
  }
@@ -34,7 +34,7 @@ declare class WithExpiration<T> {
34
34
  constructor(value: T, expiration: DurationObj);
35
35
  }
36
36
  type Utils<T> = {
37
- reject: (value: T) => RejectValue<T>;
37
+ skipCaching: (value: T) => SkipCaching<T>;
38
38
  /**
39
39
  * Create a new WithExpiration object with the given value and expiration time.
40
40
  * @param value - The value to store in the cache.
@@ -49,11 +49,11 @@ type GetOptions<T> = {
49
49
  * @param value The value to check
50
50
  * @returns true if the value should be rejected, false otherwise
51
51
  */
52
- rejectWhen?: (value: T) => boolean;
52
+ skipCachingWhen?: (value: T) => boolean;
53
53
  };
54
54
  type Cache<T> = {
55
- getOrInsert: (cacheKey: string, val: (utils: Utils<T>) => T | RejectValue<T>, options?: GetOptions<T>) => T;
56
- getOrInsertAsync: (cacheKey: string, val: (utils: Utils<T>) => Promise<T | RejectValue<T>>, options?: GetOptions<T>) => Promise<T>;
55
+ getOrInsert: (cacheKey: string, val: (utils: Utils<T>) => T | SkipCaching<T>, options?: GetOptions<T>) => T;
56
+ getOrInsertAsync: (cacheKey: string, val: (utils: Utils<T>) => Promise<T | SkipCaching<T>>, options?: GetOptions<T>) => Promise<T>;
57
57
  clear: () => void;
58
58
  get: (cacheKey: string) => T | undefined;
59
59
  set: (cacheKey: string, value: T | WithExpiration<T>) => void;
@@ -69,4 +69,4 @@ type Cache<T> = {
69
69
  };
70
70
  declare function createCache<T>({ maxCacheSize, maxItemAge, expirationThrottle, }?: Options): Cache<T>;
71
71
 
72
- export { type Cache, RejectValue, WithExpiration, cachedGetter, createCache };
72
+ export { type Cache, SkipCaching, WithExpiration, cachedGetter, createCache };
package/dist/cache.d.ts CHANGED
@@ -20,7 +20,7 @@ type Options = {
20
20
  */
21
21
  expirationThrottle?: number;
22
22
  };
23
- declare class RejectValue<T> {
23
+ declare class SkipCaching<T> {
24
24
  value: T;
25
25
  constructor(value: T);
26
26
  }
@@ -34,7 +34,7 @@ declare class WithExpiration<T> {
34
34
  constructor(value: T, expiration: DurationObj);
35
35
  }
36
36
  type Utils<T> = {
37
- reject: (value: T) => RejectValue<T>;
37
+ skipCaching: (value: T) => SkipCaching<T>;
38
38
  /**
39
39
  * Create a new WithExpiration object with the given value and expiration time.
40
40
  * @param value - The value to store in the cache.
@@ -49,11 +49,11 @@ type GetOptions<T> = {
49
49
  * @param value The value to check
50
50
  * @returns true if the value should be rejected, false otherwise
51
51
  */
52
- rejectWhen?: (value: T) => boolean;
52
+ skipCachingWhen?: (value: T) => boolean;
53
53
  };
54
54
  type Cache<T> = {
55
- getOrInsert: (cacheKey: string, val: (utils: Utils<T>) => T | RejectValue<T>, options?: GetOptions<T>) => T;
56
- getOrInsertAsync: (cacheKey: string, val: (utils: Utils<T>) => Promise<T | RejectValue<T>>, options?: GetOptions<T>) => Promise<T>;
55
+ getOrInsert: (cacheKey: string, val: (utils: Utils<T>) => T | SkipCaching<T>, options?: GetOptions<T>) => T;
56
+ getOrInsertAsync: (cacheKey: string, val: (utils: Utils<T>) => Promise<T | SkipCaching<T>>, options?: GetOptions<T>) => Promise<T>;
57
57
  clear: () => void;
58
58
  get: (cacheKey: string) => T | undefined;
59
59
  set: (cacheKey: string, value: T | WithExpiration<T>) => void;
@@ -69,4 +69,4 @@ type Cache<T> = {
69
69
  };
70
70
  declare function createCache<T>({ maxCacheSize, maxItemAge, expirationThrottle, }?: Options): Cache<T>;
71
71
 
72
- export { type Cache, RejectValue, WithExpiration, cachedGetter, createCache };
72
+ export { type Cache, SkipCaching, WithExpiration, cachedGetter, createCache };
package/dist/cache.js CHANGED
@@ -17,7 +17,7 @@ function cachedGetter(getter) {
17
17
  }
18
18
  };
19
19
  }
20
- var RejectValue = class {
20
+ var SkipCaching = class {
21
21
  value;
22
22
  constructor(value) {
23
23
  this.value = value;
@@ -82,7 +82,7 @@ function createCache({
82
82
  return { value, timestamp: now, expiration: void 0 };
83
83
  }
84
84
  const utils = {
85
- reject: (value) => new RejectValue(value),
85
+ skipCaching: (value) => new SkipCaching(value),
86
86
  withExpiration: (value, expiration) => {
87
87
  return new WithExpiration(value, expiration);
88
88
  }
@@ -93,10 +93,10 @@ function createCache({
93
93
  const entry = cache.get(cacheKey);
94
94
  if (!entry || isExpired(entry, now)) {
95
95
  const value = val(utils);
96
- if (value instanceof RejectValue) {
96
+ if (value instanceof SkipCaching) {
97
97
  return value.value;
98
98
  }
99
- if (options?.rejectWhen?.(value)) {
99
+ if (options?.skipCachingWhen?.(value)) {
100
100
  return value;
101
101
  }
102
102
  const unwrappedValue = unwrapValue(value, now);
@@ -122,14 +122,14 @@ function createCache({
122
122
  return entry.value;
123
123
  }
124
124
  const promise = val(utils).then((result) => {
125
- if (result instanceof RejectValue) {
125
+ if (result instanceof SkipCaching) {
126
126
  const cacheValue = cache.get(cacheKey);
127
127
  if (cacheValue?.value === promise) {
128
128
  cache.delete(cacheKey);
129
129
  }
130
130
  return result.value;
131
131
  }
132
- if (options?.rejectWhen?.(result)) {
132
+ if (options?.skipCachingWhen?.(result)) {
133
133
  const cacheValue = cache.get(cacheKey);
134
134
  if (cacheValue?.value === promise) {
135
135
  cache.delete(cacheKey);
@@ -179,7 +179,7 @@ function createCache({
179
179
  },
180
180
  async setAsync(cacheKey, value) {
181
181
  const promise = value(utils).then((result) => {
182
- if (result instanceof RejectValue) {
182
+ if (result instanceof SkipCaching) {
183
183
  const cacheValue = cache.get(cacheKey);
184
184
  if (cacheValue?.value === promise) {
185
185
  cache.delete(cacheKey);
@@ -208,7 +208,7 @@ function createCache({
208
208
  };
209
209
  }
210
210
  export {
211
- RejectValue,
211
+ SkipCaching,
212
212
  WithExpiration,
213
213
  cachedGetter,
214
214
  createCache
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ls-stack/utils",
3
3
  "description": "Typescript utils",
4
- "version": "2.14.0",
4
+ "version": "2.14.1",
5
5
  "license": "MIT",
6
6
  "files": [
7
7
  "dist"