@webiny/background-tasks 6.5.0-beta.0 → 6.5.0-beta.2

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.
@@ -32,11 +32,13 @@ class UpdateBackgroundTaskSettingsRepositoryImpl {
32
32
  });
33
33
  if (entryResult.isFail()) return Result.fail(BackgroundTaskPersistenceError.from(entryResult.error));
34
34
  const storedValue = input.retentionDays === this.defaultRetentionDays ? null : input.retentionDays;
35
- const { entry } = await this.updateEntryDataFactory.create(model, {
35
+ const dataResult = await this.updateEntryDataFactory.create(model, {
36
36
  values: {
37
37
  retentionDays: storedValue
38
38
  }
39
39
  }, entryResult.value);
40
+ if (dataResult.isFail()) return Result.fail(BackgroundTaskPersistenceError.from(dataResult.error));
41
+ const { entry } = dataResult.value;
40
42
  const updateResult = await this.updateEntryRepository.execute(model, entry);
41
43
  if (updateResult.isFail()) return Result.fail(BackgroundTaskPersistenceError.from(updateResult.error));
42
44
  const settings = {
@@ -1 +1 @@
1
- {"version":3,"file":"api/features/UpdateBackgroundTaskSettings/UpdateBackgroundTaskSettingsRepository.js","sources":["../../../../src/api/features/UpdateBackgroundTaskSettings/UpdateBackgroundTaskSettingsRepository.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { createCacheKey } from \"@webiny/utils\";\nimport { GetModelRepository } from \"@webiny/api-headless-cms/features/contentModel/GetModel/index.js\";\nimport { GetLatestRevisionByEntryIdRepository } from \"@webiny/api-headless-cms/features/contentEntry/GetLatestRevisionByEntryId/index.js\";\nimport { UpdateEntryRepository } from \"@webiny/api-headless-cms/features/contentEntry/UpdateEntry/index.js\";\nimport { UpdateEntryDataFactory } from \"@webiny/api-headless-cms/exports/api/cms/entry.js\";\nimport { BuildParams } from \"@webiny/api-core/features/buildParams/index.js\";\nimport { GetBackgroundTaskSettingsRepository } from \"~/api/features/GetBackgroundTaskSettings/abstractions.js\";\nimport {\n UpdateBackgroundTaskSettingsRepository as RepositoryAbstraction,\n type IUpdateBackgroundTaskSettingsInput\n} from \"./abstractions.js\";\nimport {\n BackgroundTaskModelNotFoundError,\n BackgroundTaskPersistenceError\n} from \"~/api/domain/errors.js\";\nimport {\n BACKGROUND_TASK_SETTINGS_MODEL_ID,\n BACKGROUND_TASK_DEFAULT_RETENTION_DAYS\n} from \"~/api/domain/constants.js\";\nimport type { IBackgroundTaskSettings } from \"~/api/domain/BackgroundTaskSettings.js\";\n\ninterface BackgroundTaskSettingsValues {\n retentionDays?: number | null;\n}\n\nclass UpdateBackgroundTaskSettingsRepositoryImpl implements RepositoryAbstraction.Interface {\n private readonly defaultRetentionDays: number;\n\n constructor(\n private readonly getModelRepository: GetModelRepository.Interface,\n private readonly getSettingsRepository: GetBackgroundTaskSettingsRepository.Interface,\n private readonly getLatestRevisionRepository: GetLatestRevisionByEntryIdRepository.Interface,\n private readonly updateEntryRepository: UpdateEntryRepository.Interface,\n private readonly updateEntryDataFactory: UpdateEntryDataFactory.Interface,\n buildParams: BuildParams.Interface\n ) {\n this.defaultRetentionDays =\n buildParams.get<number>(\"BackgroundTasks.RetentionDays\") ??\n BACKGROUND_TASK_DEFAULT_RETENTION_DAYS;\n }\n\n async execute(\n input: IUpdateBackgroundTaskSettingsInput\n ): Promise<Result<IBackgroundTaskSettings, RepositoryAbstraction.Error>> {\n try {\n /* Ensure the singleton entry exists (creates if missing). */\n const getResult = await this.getSettingsRepository.execute();\n if (getResult.isFail()) {\n return getResult;\n }\n\n const modelResult = await this.getModelRepository.execute(\n BACKGROUND_TASK_SETTINGS_MODEL_ID\n );\n if (modelResult.isFail()) {\n return Result.fail(\n new BackgroundTaskModelNotFoundError(BACKGROUND_TASK_SETTINGS_MODEL_ID)\n );\n }\n\n const model = modelResult.value;\n const singletonId = createCacheKey(model.modelId);\n const entryId = `${singletonId}#0001`;\n\n const entryResult =\n await this.getLatestRevisionRepository.execute<BackgroundTaskSettingsValues>(\n model,\n { id: entryId }\n );\n\n if (entryResult.isFail()) {\n return Result.fail(BackgroundTaskPersistenceError.from(entryResult.error));\n }\n\n /* Store null when the value matches the default so the default stays in control. */\n const storedValue =\n input.retentionDays === this.defaultRetentionDays ? null : input.retentionDays;\n\n const { entry } =\n await this.updateEntryDataFactory.create<BackgroundTaskSettingsValues>(\n model,\n {\n values: {\n retentionDays: storedValue\n }\n },\n entryResult.value\n );\n\n const updateResult = await this.updateEntryRepository.execute(model, entry);\n if (updateResult.isFail()) {\n return Result.fail(BackgroundTaskPersistenceError.from(updateResult.error));\n }\n\n const settings: IBackgroundTaskSettings = {\n retentionDays: entry.values.retentionDays ?? this.defaultRetentionDays\n };\n\n return Result.ok(settings);\n } catch (error) {\n return Result.fail(BackgroundTaskPersistenceError.from(error));\n }\n }\n}\n\nexport const UpdateBackgroundTaskSettingsRepository = RepositoryAbstraction.createImplementation({\n implementation: UpdateBackgroundTaskSettingsRepositoryImpl,\n dependencies: [\n GetModelRepository,\n GetBackgroundTaskSettingsRepository,\n GetLatestRevisionByEntryIdRepository,\n UpdateEntryRepository,\n UpdateEntryDataFactory,\n BuildParams\n ]\n});\n"],"names":["UpdateBackgroundTaskSettingsRepositoryImpl","getModelRepository","getSettingsRepository","getLatestRevisionRepository","updateEntryRepository","updateEntryDataFactory","buildParams","BACKGROUND_TASK_DEFAULT_RETENTION_DAYS","input","getResult","modelResult","BACKGROUND_TASK_SETTINGS_MODEL_ID","Result","BackgroundTaskModelNotFoundError","model","singletonId","createCacheKey","entryId","entryResult","BackgroundTaskPersistenceError","storedValue","entry","updateResult","settings","error","UpdateBackgroundTaskSettingsRepository","RepositoryAbstraction","GetModelRepository","GetBackgroundTaskSettingsRepository","GetLatestRevisionByEntryIdRepository","UpdateEntryRepository","UpdateEntryDataFactory","BuildParams"],"mappings":";;;;;;;;;;;AA0BA,MAAMA;IAGF,YACqBC,kBAAgD,EAChDC,qBAAoE,EACpEC,2BAA2E,EAC3EC,qBAAsD,EACtDC,sBAAwD,EACzEC,WAAkC,CACpC;aANmBL,kBAAkB,GAAlBA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OT,OAAO,EAAE,CAACW;QACrB,EAAE,OAAOC,OAAO;YACZ,OAAOZ,OAAO,IAAI,CAACO,+BAA+B,IAAI,CAACK;QAC3D;IACJ;AACJ;AAEO,MAAMC,gFAAyCC,uCAAAA,oBAA0C,CAAC;IAC7F,gBAAgB1B;IAChB,cAAc;QACV2B;QACAC;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
1
+ {"version":3,"file":"api/features/UpdateBackgroundTaskSettings/UpdateBackgroundTaskSettingsRepository.js","sources":["../../../../src/api/features/UpdateBackgroundTaskSettings/UpdateBackgroundTaskSettingsRepository.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { createCacheKey } from \"@webiny/utils\";\nimport { GetModelRepository } from \"@webiny/api-headless-cms/features/contentModel/GetModel/index.js\";\nimport { GetLatestRevisionByEntryIdRepository } from \"@webiny/api-headless-cms/features/contentEntry/GetLatestRevisionByEntryId/index.js\";\nimport { UpdateEntryRepository } from \"@webiny/api-headless-cms/features/contentEntry/UpdateEntry/index.js\";\nimport { UpdateEntryDataFactory } from \"@webiny/api-headless-cms/exports/api/cms/entry.js\";\nimport { BuildParams } from \"@webiny/api-core/features/buildParams/index.js\";\nimport { GetBackgroundTaskSettingsRepository } from \"~/api/features/GetBackgroundTaskSettings/abstractions.js\";\nimport {\n UpdateBackgroundTaskSettingsRepository as RepositoryAbstraction,\n type IUpdateBackgroundTaskSettingsInput\n} from \"./abstractions.js\";\nimport {\n BackgroundTaskModelNotFoundError,\n BackgroundTaskPersistenceError\n} from \"~/api/domain/errors.js\";\nimport {\n BACKGROUND_TASK_SETTINGS_MODEL_ID,\n BACKGROUND_TASK_DEFAULT_RETENTION_DAYS\n} from \"~/api/domain/constants.js\";\nimport type { IBackgroundTaskSettings } from \"~/api/domain/BackgroundTaskSettings.js\";\n\ninterface BackgroundTaskSettingsValues {\n retentionDays?: number | null;\n}\n\nclass UpdateBackgroundTaskSettingsRepositoryImpl implements RepositoryAbstraction.Interface {\n private readonly defaultRetentionDays: number;\n\n constructor(\n private readonly getModelRepository: GetModelRepository.Interface,\n private readonly getSettingsRepository: GetBackgroundTaskSettingsRepository.Interface,\n private readonly getLatestRevisionRepository: GetLatestRevisionByEntryIdRepository.Interface,\n private readonly updateEntryRepository: UpdateEntryRepository.Interface,\n private readonly updateEntryDataFactory: UpdateEntryDataFactory.Interface,\n buildParams: BuildParams.Interface\n ) {\n this.defaultRetentionDays =\n buildParams.get<number>(\"BackgroundTasks.RetentionDays\") ??\n BACKGROUND_TASK_DEFAULT_RETENTION_DAYS;\n }\n\n async execute(\n input: IUpdateBackgroundTaskSettingsInput\n ): Promise<Result<IBackgroundTaskSettings, RepositoryAbstraction.Error>> {\n try {\n /* Ensure the singleton entry exists (creates if missing). */\n const getResult = await this.getSettingsRepository.execute();\n if (getResult.isFail()) {\n return getResult;\n }\n\n const modelResult = await this.getModelRepository.execute(\n BACKGROUND_TASK_SETTINGS_MODEL_ID\n );\n if (modelResult.isFail()) {\n return Result.fail(\n new BackgroundTaskModelNotFoundError(BACKGROUND_TASK_SETTINGS_MODEL_ID)\n );\n }\n\n const model = modelResult.value;\n const singletonId = createCacheKey(model.modelId);\n const entryId = `${singletonId}#0001`;\n\n const entryResult =\n await this.getLatestRevisionRepository.execute<BackgroundTaskSettingsValues>(\n model,\n { id: entryId }\n );\n\n if (entryResult.isFail()) {\n return Result.fail(BackgroundTaskPersistenceError.from(entryResult.error));\n }\n\n /* Store null when the value matches the default so the default stays in control. */\n const storedValue =\n input.retentionDays === this.defaultRetentionDays ? null : input.retentionDays;\n\n const dataResult =\n await this.updateEntryDataFactory.create<BackgroundTaskSettingsValues>(\n model,\n {\n values: {\n retentionDays: storedValue\n }\n },\n entryResult.value\n );\n if (dataResult.isFail()) {\n return Result.fail(BackgroundTaskPersistenceError.from(dataResult.error));\n }\n const { entry } = dataResult.value;\n\n const updateResult = await this.updateEntryRepository.execute(model, entry);\n if (updateResult.isFail()) {\n return Result.fail(BackgroundTaskPersistenceError.from(updateResult.error));\n }\n\n const settings: IBackgroundTaskSettings = {\n retentionDays: entry.values.retentionDays ?? this.defaultRetentionDays\n };\n\n return Result.ok(settings);\n } catch (error) {\n return Result.fail(BackgroundTaskPersistenceError.from(error));\n }\n }\n}\n\nexport const UpdateBackgroundTaskSettingsRepository = RepositoryAbstraction.createImplementation({\n implementation: UpdateBackgroundTaskSettingsRepositoryImpl,\n dependencies: [\n GetModelRepository,\n GetBackgroundTaskSettingsRepository,\n GetLatestRevisionByEntryIdRepository,\n UpdateEntryRepository,\n UpdateEntryDataFactory,\n BuildParams\n ]\n});\n"],"names":["UpdateBackgroundTaskSettingsRepositoryImpl","getModelRepository","getSettingsRepository","getLatestRevisionRepository","updateEntryRepository","updateEntryDataFactory","buildParams","BACKGROUND_TASK_DEFAULT_RETENTION_DAYS","input","getResult","modelResult","BACKGROUND_TASK_SETTINGS_MODEL_ID","Result","BackgroundTaskModelNotFoundError","model","singletonId","createCacheKey","entryId","entryResult","BackgroundTaskPersistenceError","storedValue","dataResult","entry","updateResult","settings","error","UpdateBackgroundTaskSettingsRepository","RepositoryAbstraction","GetModelRepository","GetBackgroundTaskSettingsRepository","GetLatestRevisionByEntryIdRepository","UpdateEntryRepository","UpdateEntryDataFactory","BuildParams"],"mappings":";;;;;;;;;;;AA0BA,MAAMA;IAGF,YACqBC,kBAAgD,EAChDC,qBAAoE,EACpEC,2BAA2E,EAC3EC,qBAAsD,EACtDC,sBAAwD,EACzEC,WAAkC,CACpC;aANmBL,kBAAkB,GAAlBA;aACAC,qBAAqB,GAArBA;aACAC,2BAA2B,GAA3BA;aACAC,qBAAqB,GAArBA;aACAC,sBAAsB,GAAtBA;QAGjB,IAAI,CAAC,oBAAoB,GACrBC,YAAY,GAAG,CAAS,oCACxBC;IACR;IAEA,MAAM,QACFC,KAAyC,EAC4B;QACrE,IAAI;YAEA,MAAMC,YAAY,MAAM,IAAI,CAAC,qBAAqB,CAAC,OAAO;YAC1D,IAAIA,UAAU,MAAM,IAChB,OAAOA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AgB3B;IAChB,cAAc;QACV4B;QACAC;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/background-tasks",
3
- "version": "6.5.0-beta.0",
3
+ "version": "6.5.0-beta.2",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./index.js",
@@ -19,22 +19,22 @@
19
19
  },
20
20
  "license": "MIT",
21
21
  "dependencies": {
22
- "@webiny/admin-ui": "6.5.0-beta.0",
23
- "@webiny/api": "6.5.0-beta.0",
24
- "@webiny/api-core": "6.5.0-beta.0",
25
- "@webiny/api-headless-cms": "6.5.0-beta.0",
26
- "@webiny/app": "6.5.0-beta.0",
27
- "@webiny/app-admin": "6.5.0-beta.0",
28
- "@webiny/aws-sdk": "6.5.0-beta.0",
29
- "@webiny/error": "6.5.0-beta.0",
30
- "@webiny/feature": "6.5.0-beta.0",
31
- "@webiny/handler": "6.5.0-beta.0",
32
- "@webiny/handler-aws": "6.5.0-beta.0",
33
- "@webiny/handler-graphql": "6.5.0-beta.0",
34
- "@webiny/icons": "6.5.0-beta.0",
35
- "@webiny/plugins": "6.5.0-beta.0",
36
- "@webiny/sdk": "6.5.0-beta.0",
37
- "@webiny/utils": "6.5.0-beta.0",
22
+ "@webiny/admin-ui": "6.5.0-beta.2",
23
+ "@webiny/api": "6.5.0-beta.2",
24
+ "@webiny/api-core": "6.5.0-beta.2",
25
+ "@webiny/api-headless-cms": "6.5.0-beta.2",
26
+ "@webiny/app": "6.5.0-beta.2",
27
+ "@webiny/app-admin": "6.5.0-beta.2",
28
+ "@webiny/aws-sdk": "6.5.0-beta.2",
29
+ "@webiny/error": "6.5.0-beta.2",
30
+ "@webiny/feature": "6.5.0-beta.2",
31
+ "@webiny/handler": "6.5.0-beta.2",
32
+ "@webiny/handler-aws": "6.5.0-beta.2",
33
+ "@webiny/handler-graphql": "6.5.0-beta.2",
34
+ "@webiny/icons": "6.5.0-beta.2",
35
+ "@webiny/plugins": "6.5.0-beta.2",
36
+ "@webiny/sdk": "6.5.0-beta.2",
37
+ "@webiny/utils": "6.5.0-beta.2",
38
38
  "deep-equal": "2.2.3",
39
39
  "lodash": "4.18.1",
40
40
  "mobx": "6.16.1",
@@ -46,8 +46,8 @@
46
46
  "zod": "4.4.3"
47
47
  },
48
48
  "devDependencies": {
49
- "@webiny/build-tools": "6.5.0-beta.0",
50
- "@webiny/project-utils": "6.5.0-beta.0",
49
+ "@webiny/build-tools": "6.5.0-beta.2",
50
+ "@webiny/project-utils": "6.5.0-beta.2",
51
51
  "rimraf": "6.1.3",
52
52
  "type-fest": "5.8.0",
53
53
  "typescript": "7.0.2",