From a5ae466c9aaeed97bd91a8ed18bcd5bc3b2c154b Mon Sep 17 00:00:00 2001 From: belopash Date: Thu, 19 Dec 2024 22:07:04 +0300 Subject: [PATCH] feat: extract defaults to separate method --- src/manifest.ts | 186 +++++++++++++++++++++++++----------------------- 1 file changed, 95 insertions(+), 91 deletions(-) diff --git a/src/manifest.ts b/src/manifest.ts index 8e9e79a..92141f6 100644 --- a/src/manifest.ts +++ b/src/manifest.ts @@ -45,97 +45,7 @@ export class Manifest { delete this.deploy.migrate; } - if (this.scale) { - defaultsDeep(this, >{ - scale: { - dedicated: true, - }, - }); - } - - if (this.deploy?.api) { - defaultsDeep(this, >{ - scale: { - api: { - replicas: 1, - profile: 'small', - }, - }, - }); - } - - if (this.deploy?.processor) { - defaultsDeep(this, { - scale: { - processor: { - profile: 'small', - }, - }, - }); - } - - if (this.deploy?.addons?.postgres) { - defaultsDeep(this, >{ - deploy: { - addons: { - postgres: { - config: {}, - }, - }, - init: { - cmd: [...DEFAULT_MIGRATION], - }, - }, - scale: { - addons: { - postgres: { - storage: '10Gi', - profile: 'small', - default_storage: !this.scale?.addons?.postgres?.storage, - }, - }, - }, - }); - } - - if (this.deploy?.addons?.neon) { - defaultsDeep(this, >{ - deploy: { - addons: { - neon: {}, - }, - init: { - cmd: [...DEFAULT_MIGRATION], - }, - }, - scale: { - addons: { - neon: { - autoscaling_limit_min_cu: '0.25', - autoscaling_limit_max_cu: '0.25', - }, - }, - }, - }); - } - - if (this.deploy?.addons?.hasura) { - defaultsDeep(this, { - deploy: { - addons: { - hasura: {}, - }, - }, - scale: { - addons: { - hasura: { - replicas: 1, - profile: 'small', - }, - }, - }, - }); - } + Manifest.setDefaults(this); } squidName() { @@ -325,6 +235,100 @@ export class Manifest { }, }); } + + static setDefaults(manifest: Partial) { + if (manifest.scale) { + defaultsDeep(manifest, >{ + scale: { + dedicated: true, + }, + }); + } + + if (manifest.deploy?.api) { + defaultsDeep(manifest, >{ + scale: { + api: { + replicas: 1, + profile: 'small', + }, + }, + }); + } + + if (manifest.deploy?.processor) { + defaultsDeep(manifest, { + scale: { + processor: { + profile: 'small', + }, + }, + }); + } + + if (manifest.deploy?.addons?.postgres) { + defaultsDeep(manifest, >{ + deploy: { + addons: { + postgres: { + config: {}, + }, + }, + init: { + cmd: [...DEFAULT_MIGRATION], + }, + }, + scale: { + addons: { + postgres: { + storage: '10Gi', + profile: 'small', + default_storage: !manifest.scale?.addons?.postgres?.storage, + }, + }, + }, + }); + } + + if (manifest.deploy?.addons?.neon) { + defaultsDeep(manifest, >{ + deploy: { + addons: { + neon: {}, + }, + init: { + cmd: [...DEFAULT_MIGRATION], + }, + }, + scale: { + addons: { + neon: { + autoscaling_limit_min_cu: '0.25', + autoscaling_limit_max_cu: '0.25', + }, + }, + }, + }); + } + + if (manifest.deploy?.addons?.hasura) { + defaultsDeep(manifest, { + deploy: { + addons: { + hasura: {}, + }, + }, + scale: { + addons: { + hasura: { + replicas: 1, + profile: 'small', + }, + }, + }, + }); + } + } } function getError(path: string, expression: string | undefined, error: unknown) {