@adobe/spacecat-shared-data-access 1.61.4 → 1.61.5

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/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # [@adobe/spacecat-shared-data-access-v1.61.5](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.61.4...@adobe/spacecat-shared-data-access-v1.61.5) (2024-12-30)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * replace expiresAt with recordExporesAt in ImportUrl ([#511](https://github.com/adobe/spacecat-shared/issues/511)) ([7349c9c](https://github.com/adobe/spacecat-shared/commit/7349c9c66659fae4b62edb27e2e03a83a0af2e13))
7
+
1
8
  # [@adobe/spacecat-shared-data-access-v1.61.4](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.61.3...@adobe/spacecat-shared-data-access-v1.61.4) (2024-12-30)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/spacecat-shared-data-access",
3
- "version": "1.61.4",
3
+ "version": "1.61.5",
4
4
  "description": "Shared modules of the Spacecat Services - Data Access",
5
5
  "type": "module",
6
6
  "engines": {
@@ -204,6 +204,14 @@ class BaseModel {
204
204
  return this.record.updatedAt;
205
205
  }
206
206
 
207
+ /**
208
+ * Gets the expiration timestamp of the current entity.
209
+ * @returns {string} - The ISO string representing when the entity will expire.
210
+ */
211
+ getRecordExpiresAt() {
212
+ return this.record.recordExpiresAt;
213
+ }
214
+
207
215
  /**
208
216
  * Removes the current entity from the database. This method also removes any dependent
209
217
  * entities associated with the current entity. For example, if the current entity has
@@ -21,6 +21,7 @@ export interface BaseModel {
21
21
  _remove(): Promise<this>;
22
22
  getCreatedAt(): string;
23
23
  getId(): string;
24
+ getRecordExpiresAt(): string;
24
25
  getUpdatedAt(): string;
25
26
  remove(): Promise<this>;
26
27
  save(): Promise<this>;
@@ -22,6 +22,7 @@ import {
22
22
  entityNameToAllPKValue,
23
23
  entityNameToIdName,
24
24
  isNonEmptyArray,
25
+ isPositiveInteger,
25
26
  } from '../../util/util.js';
26
27
 
27
28
  import BaseModel from './base.model.js';
@@ -186,6 +187,29 @@ class SchemaBuilder {
186
187
  return this;
187
188
  }
188
189
 
190
+ /**
191
+ * Sets an expiry time for records in this entity.
192
+ * The record will be automatically removed by DynamoDB
193
+ *
194
+ * @param {number} ttlInDays - The time-to-live (TTL) in days.
195
+ * @returns {SchemaBuilder}
196
+ */
197
+ withRecordExpiry(ttlInDays) {
198
+ if (!isPositiveInteger(ttlInDays)) {
199
+ throw new SchemaBuilderError(this, 'TTL must be a positive integer.');
200
+ }
201
+
202
+ this.addAttribute('recordExpiresAt', {
203
+ type: 'number',
204
+ required: true,
205
+ readOnly: true,
206
+ default: () => Date.now() + ttlInDays * 24 * 60 * 60 * 1000,
207
+ set: () => Date.now() + ttlInDays * 24 * 60 * 60 * 1000,
208
+ });
209
+
210
+ return this;
211
+ }
212
+
189
213
  /**
190
214
  * By default a schema allows removes. This method allows
191
215
  * to disable removes for this entity. Note that this does
@@ -12,7 +12,7 @@
12
12
 
13
13
  /* c8 ignore start */
14
14
 
15
- import { isIsoDate, isValidUrl } from '@adobe/spacecat-shared-utils';
15
+ import { isValidUrl } from '@adobe/spacecat-shared-utils';
16
16
 
17
17
  import SchemaBuilder from '../base/schema.builder.js';
18
18
  import ImportUrl from './import-url.model.js';
@@ -26,17 +26,8 @@ Indexes Doc: https://electrodb.dev/en/modeling/indexes/
26
26
  */
27
27
 
28
28
  const schema = new SchemaBuilder(ImportUrl, ImportUrlCollection)
29
+ .withRecordExpiry(ImportUrl.IMPORT_URL_EXPIRES_IN_DAYS)
29
30
  .addReference('belongs_to', 'ImportJob', ['status'])
30
- .addAttribute('expiresAt', {
31
- type: 'string',
32
- required: true,
33
- validate: (value) => isIsoDate(value),
34
- default: () => {
35
- const date = new Date();
36
- date.setDate(date.getDate() + ImportUrl.IMPORT_URL_EXPIRES_IN_DAYS);
37
- return date.toISOString();
38
- },
39
- })
40
31
  .addAttribute('file', {
41
32
  type: 'string',
42
33
  })
@@ -13,7 +13,6 @@
13
13
  import type { BaseCollection, BaseModel, ImportJob } from '../index';
14
14
 
15
15
  export interface ImportUrl extends BaseModel {
16
- getExpiresAt(): string,
17
16
  getFile(): string,
18
17
  getImportJob(): Promise<ImportJob>,
19
18
  getImportJobId(): string,
@@ -21,7 +20,6 @@ export interface ImportUrl extends BaseModel {
21
20
  getReason(): string,
22
21
  getStatus(): string,
23
22
  getUrl(): string,
24
- setExpiresAt(expiresAt: string): void,
25
23
  setFile(file: string): void,
26
24
  setImportJobId(importJobId: string): void,
27
25
  setPath(path: string): void,