@punks/backend-entity-manager 0.0.510 → 0.0.512

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/cjs/index.js CHANGED
@@ -3211,6 +3211,83 @@ class DynamoDbCacheInstance {
3211
3211
  }
3212
3212
  }
3213
3213
 
3214
+ class InMemoryCacheInstance {
3215
+ constructor(instanceName) {
3216
+ this.instanceName = instanceName;
3217
+ this.store = new Map();
3218
+ }
3219
+ async getEntries() {
3220
+ const now = new Date();
3221
+ const entries = [];
3222
+ for (const entry of this.store.values()) {
3223
+ if (!this.isExpired(entry, now)) {
3224
+ entries.push(this.toCacheEntryInfo(entry));
3225
+ }
3226
+ }
3227
+ return entries;
3228
+ }
3229
+ async getEntry(key) {
3230
+ const entry = this.store.get(key);
3231
+ if (!entry || this.isExpired(entry, new Date())) {
3232
+ if (entry) {
3233
+ this.store.delete(key);
3234
+ }
3235
+ return undefined;
3236
+ }
3237
+ return this.toCacheEntryDetail(entry);
3238
+ }
3239
+ async get(key) {
3240
+ const item = await this.getEntry(key);
3241
+ return item?.data;
3242
+ }
3243
+ async set(key, input) {
3244
+ const now = Date.now();
3245
+ this.store.set(key, {
3246
+ key,
3247
+ data: input.value,
3248
+ createdOn: now,
3249
+ updatedOn: now,
3250
+ expiration: backendCore.addTime(new Date(), input.ttl).getTime(),
3251
+ });
3252
+ }
3253
+ async retrieve(key, input) {
3254
+ const item = await this.get(key);
3255
+ if (item !== undefined) {
3256
+ return item;
3257
+ }
3258
+ const value = await input.valueFactory();
3259
+ await this.set(key, { value, ttl: input.ttl });
3260
+ return value;
3261
+ }
3262
+ async delete(key) {
3263
+ this.store.delete(key);
3264
+ }
3265
+ async clear() {
3266
+ this.store.clear();
3267
+ }
3268
+ getInstanceName() {
3269
+ return this.instanceName;
3270
+ }
3271
+ isExpired(entry, when) {
3272
+ return entry.expiration < when.getTime();
3273
+ }
3274
+ toCacheEntryInfo(entry) {
3275
+ return {
3276
+ instanceName: this.instanceName,
3277
+ key: entry.key,
3278
+ expiration: new Date(entry.expiration),
3279
+ createdOn: new Date(entry.createdOn),
3280
+ updatedOn: new Date(entry.updatedOn),
3281
+ };
3282
+ }
3283
+ toCacheEntryDetail(entry) {
3284
+ return {
3285
+ ...this.toCacheEntryInfo(entry),
3286
+ data: entry.data,
3287
+ };
3288
+ }
3289
+ }
3290
+
3214
3291
  class TypeormCacheInstance {
3215
3292
  constructor(instanceName) {
3216
3293
  this.instanceName = instanceName;
@@ -35286,7 +35363,7 @@ let TaskShell = TaskShell_1 = class TaskShell {
35286
35363
  this.logger.info(`Task ${settings.name} -> completed`);
35287
35364
  }
35288
35365
  catch (error) {
35289
- this.logger.exception(`Task ${settings.name} -> failed`, error);
35366
+ this.logger.exception(`Task ${settings.name} -> failed ${error?.message}`, error);
35290
35367
  }
35291
35368
  }
35292
35369
  get operationsLockService() {
@@ -45588,6 +45665,7 @@ exports.EntitySerializer = EntitySerializer;
45588
45665
  exports.EntitySnapshotService = EntitySnapshotService;
45589
45666
  exports.ExclusiveOperationResult = ExclusiveOperationResult;
45590
45667
  exports.IEntityVersionsCursor = IEntityVersionsCursor;
45668
+ exports.InMemoryCacheInstance = InMemoryCacheInstance;
45591
45669
  exports.InvalidCredentialsError = InvalidCredentialsError;
45592
45670
  exports.JobInstance = JobInstance;
45593
45671
  exports.JobSchedule = JobSchedule;