Skip to content

Commit

Permalink
feat: extract set defaults to a separeate method
Browse files Browse the repository at this point in the history
  • Loading branch information
belopash committed Dec 19, 2024
1 parent a80d8ad commit 561867c
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 92 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@subsquid/manifest",
"type": "commonjs",
"version": "2.0.0-beta.13",
"version": "2.0.0-beta.14",
"homepage": "https://www.subsquid.io",
"repository": "https://github.com/subsquid/manifest.git",
"license": "GPL-3.0-or-later",
Expand Down
184 changes: 93 additions & 91 deletions src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,97 +45,7 @@ export class Manifest {
delete this.deploy.migrate;
}

if (this.scale) {
defaultsDeep(this, <DeepPartial<ManifestValue>>{
scale: {
dedicated: true,
},
});
}

if (this.deploy?.api) {
defaultsDeep(this, <DeepPartial<ManifestValue>>{
scale: {
api: {
replicas: 1,
profile: 'small',
},
},
});
}

if (this.deploy?.processor) {
defaultsDeep(this, {
scale: {
processor: {
profile: 'small',
},
},
});
}

if (this.deploy?.addons?.postgres) {
defaultsDeep(this, <DeepPartial<ManifestValue>>{
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, <DeepPartial<ManifestValue>>{
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() {
Expand Down Expand Up @@ -325,6 +235,98 @@ export class Manifest {
},
});
}

static setDefaults(manifest: Partial<ManifestValue>) {
defaultsDeep(manifest, <DeepPartial<ManifestValue>>{
scale: {
dedicated: true,
},
});

if (manifest.deploy?.api) {
defaultsDeep(manifest, <DeepPartial<ManifestValue>>{
scale: {
api: {
replicas: 1,
profile: 'small',
},
},
});
}

if (manifest.deploy?.processor) {
defaultsDeep(manifest, {
scale: {
processor: {
profile: 'small',
},
},
});
}

if (manifest.deploy?.addons?.postgres) {
defaultsDeep(manifest, <DeepPartial<ManifestValue>>{
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, <DeepPartial<ManifestValue>>{
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(this, {
deploy: {
addons: {
hasura: {},
},
},
scale: {
addons: {
hasura: {
replicas: 1,
profile: 'small',
},
},
},
});
}
}
}

function getError(path: string, expression: string | undefined, error: unknown) {
Expand Down

0 comments on commit 561867c

Please sign in to comment.