@travetto/model 5.0.14 → 5.0.15

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2023 ArcSine Technologies
3
+ Copyright (c) 2020 ArcSine Technologies
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/model",
3
- "version": "5.0.14",
3
+ "version": "5.0.15",
4
4
  "description": "Datastore abstraction for core operations.",
5
5
  "keywords": [
6
6
  "datastore",
@@ -26,14 +26,14 @@
26
26
  "directory": "module/model"
27
27
  },
28
28
  "dependencies": {
29
- "@travetto/config": "^5.0.13",
30
- "@travetto/di": "^5.0.13",
31
- "@travetto/registry": "^5.0.13",
32
- "@travetto/schema": "^5.0.13"
29
+ "@travetto/config": "^5.0.14",
30
+ "@travetto/di": "^5.0.14",
31
+ "@travetto/registry": "^5.0.14",
32
+ "@travetto/schema": "^5.0.14"
33
33
  },
34
34
  "peerDependencies": {
35
- "@travetto/cli": "^5.0.16",
36
- "@travetto/test": "^5.0.15"
35
+ "@travetto/cli": "^5.0.17",
36
+ "@travetto/test": "^5.0.16"
37
37
  },
38
38
  "peerDependenciesMeta": {
39
39
  "@travetto/cli": {
@@ -4,7 +4,7 @@ import { Class, AppError } from '@travetto/runtime';
4
4
  * Represents when a model of cls and id cannot be found
5
5
  */
6
6
  export class NotFoundError extends AppError {
7
- constructor(cls: Class | string, id: string, details?: Record<string, unknown>) {
7
+ constructor(cls: Class | string, id: string, details: Record<string, unknown> = {}) {
8
8
  super(`${typeof cls === 'string' ? cls : cls.name} with id ${id} not found`, { category: 'notfound', details });
9
9
  }
10
10
  }
@@ -3,7 +3,6 @@ import { ShutdownManager, Class, TimeSpan, TimeUtil, Util, castTo } from '@trave
3
3
  import { ModelRegistry } from '../../registry/model';
4
4
  import { ModelExpirySupport } from '../../service/expiry';
5
5
  import { ModelType } from '../../types/model';
6
- import { NotFoundError } from '../../error/not-found';
7
6
 
8
7
  /**
9
8
  * Utils for model expiry
@@ -44,22 +43,4 @@ export class ModelExpiryUtil {
44
43
  })();
45
44
  }
46
45
  }
47
-
48
- /**
49
- * Simple cull operation for a given model type
50
- * @param svc
51
- */
52
- static async naiveDeleteExpired<T extends ModelType>(svc: ModelExpirySupport, cls: Class<T>, suppressErrors = false): Promise<number> {
53
- const deleting = [];
54
- for await (const el of svc.list(cls)) {
55
- if (this.getExpiryState(cls, el).expired) {
56
- deleting.push(svc.delete(cls, el.id).catch(err => {
57
- if (!suppressErrors && !(err instanceof NotFoundError)) {
58
- throw err;
59
- }
60
- }));
61
- }
62
- }
63
- return (await Promise.all(deleting)).length;
64
- }
65
46
  }
@@ -11,10 +11,11 @@ import { NotFoundError } from '../../src/error/not-found';
11
11
  import { BaseModelSuite } from './base';
12
12
 
13
13
  @Model('expiry-user')
14
- class User {
14
+ export class ExpiryUser {
15
15
  id: string;
16
16
  @ExpiresAt()
17
17
  expiresAt?: Date;
18
+ payload?: string;
18
19
  }
19
20
 
20
21
  @Suite()
@@ -33,63 +34,63 @@ export abstract class ModelExpirySuite extends BaseModelSuite<ModelExpirySupport
33
34
  @Test()
34
35
  async basic() {
35
36
  const service = await this.service;
36
- const res = await service.upsert(User, User.from({
37
+ const res = await service.upsert(ExpiryUser, ExpiryUser.from({
37
38
  expiresAt: this.timeFromNow('2s')
38
39
  }));
39
- assert(res instanceof User);
40
+ assert(res instanceof ExpiryUser);
40
41
 
41
- const expiry = ModelExpiryUtil.getExpiryState(User, await service.get(User, res.id));
42
+ const expiry = ModelExpiryUtil.getExpiryState(ExpiryUser, await service.get(ExpiryUser, res.id));
42
43
  assert(!expiry.expired);
43
44
  }
44
45
 
45
46
  @Test()
46
47
  async aging() {
47
48
  const service = await this.service;
48
- const res = await service.upsert(User, User.from({
49
+ const res = await service.upsert(ExpiryUser, ExpiryUser.from({
49
50
  expiresAt: this.timeFromNow(100)
50
51
  }));
51
52
 
52
- assert(res instanceof User);
53
+ assert(res instanceof ExpiryUser);
53
54
 
54
55
  await this.wait(200);
55
56
 
56
- await assert.rejects(() => service.get(User, res.id), NotFoundError);
57
+ await assert.rejects(() => service.get(ExpiryUser, res.id), NotFoundError);
57
58
  }
58
59
 
59
60
  @Test()
60
61
  async updateExpired() {
61
62
  const service = await this.service;
62
- const res = await service.upsert(User, User.from({
63
+ const res = await service.upsert(ExpiryUser, ExpiryUser.from({
63
64
  expiresAt: this.timeFromNow(100)
64
65
  }));
65
66
 
66
- assert(res instanceof User);
67
+ assert(res instanceof ExpiryUser);
67
68
 
68
69
  await this.wait(200);
69
70
 
70
- await assert.rejects(() => service.update(User, User.from({ id: res.id })), NotFoundError);
71
+ await assert.rejects(() => service.update(ExpiryUser, ExpiryUser.from({ id: res.id })), NotFoundError);
71
72
  }
72
73
 
73
74
  @Test()
74
75
  async ageWithExtension() {
75
76
  const service = await this.service;
76
- const res = await service.upsert(User, User.from({
77
+ const res = await service.upsert(ExpiryUser, ExpiryUser.from({
77
78
  expiresAt: this.timeFromNow('2s')
78
79
  }));
79
- assert(res instanceof User);
80
+ assert(res instanceof ExpiryUser);
80
81
 
81
82
  await this.wait(50);
82
83
 
83
- assert(!ModelExpiryUtil.getExpiryState(User, (await service.get(User, res.id))).expired);
84
+ assert(!ModelExpiryUtil.getExpiryState(ExpiryUser, (await service.get(ExpiryUser, res.id))).expired);
84
85
 
85
- await service.updatePartial(User, {
86
+ await service.updatePartial(ExpiryUser, {
86
87
  id: res.id,
87
88
  expiresAt: this.timeFromNow(100)
88
89
  });
89
90
 
90
91
  await this.wait(200);
91
92
 
92
- await assert.rejects(() => service.get(User, res.id), NotFoundError);
93
+ await assert.rejects(() => service.get(ExpiryUser, res.id), NotFoundError);
93
94
  }
94
95
 
95
96
  @Test()
@@ -98,12 +99,12 @@ export abstract class ModelExpirySuite extends BaseModelSuite<ModelExpirySupport
98
99
 
99
100
  let total;
100
101
 
101
- total = await this.getSize(User);
102
+ total = await this.getSize(ExpiryUser);
102
103
  assert(total === 0);
103
104
 
104
105
  // Create
105
106
  await Promise.all(
106
- Array(10).fill(0).map((x, i) => service.upsert(User, User.from({
107
+ Array(10).fill(0).map((x, i) => service.upsert(ExpiryUser, ExpiryUser.from({
107
108
  expiresAt: this.timeFromNow(1000 + i * this.delayFactor)
108
109
  })))
109
110
  );
@@ -111,16 +112,16 @@ export abstract class ModelExpirySuite extends BaseModelSuite<ModelExpirySupport
111
112
  // Let expire
112
113
  await this.wait(1);
113
114
 
114
- total = await this.getSize(User);
115
+ total = await this.getSize(ExpiryUser);
115
116
  assert(total === 10);
116
117
 
117
118
  // Let expire
118
119
  await this.wait(1100);
119
120
 
120
- total = await this.getSize(User);
121
+ total = await this.getSize(ExpiryUser);
121
122
  assert(total === 0);
122
123
 
123
- total = await this.getSize(User);
124
+ total = await this.getSize(ExpiryUser);
124
125
  assert(total === 0);
125
126
  }
126
127
  }