insta 0.1.10 → 0.1.11

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.
@@ -3,13 +3,22 @@ import { constants as osConstants } from 'node:os';
3
3
  import { ApiClient, ApiError, requireProject } from '../api.js';
4
4
  import { info, printJson, handleApproval, relayExitCode } from '../util.js';
5
5
  import { parseVolumeGib, q, resolveSoleService } from './services.js';
6
- // Toggle a postgres service between scale-to-zero (the default: instance suspends when idle,
7
- // cold-starts on the next connection) and always-on (instance stays warm; idle RAM bills at
8
- // actual usage). Thin wrapper over PATCH /database/settings {scaleToZero} — insta-db-backed
9
- // postgres only.
10
- export async function dbAlwaysOn(mode, service, opts) {
11
- if (mode !== 'on' && mode !== 'off')
6
+ export function alwaysOnArgs(first, second) {
7
+ if (first === 'on' || first === 'off')
8
+ return { mode: first, service: second };
9
+ if (second !== undefined)
12
10
  throw new Error('mode must be on|off');
11
+ return { service: first };
12
+ }
13
+ export function alwaysOnLine(group, scaleToZero) {
14
+ return `postgres ${group}: always-on ${scaleToZero === false ? 'on — instance stays warm' : scaleToZero === true ? 'off — scales to zero when idle' : 'unknown — the provider did not report it'}`;
15
+ }
16
+ // Show or set a postgres service's idle mode: scale-to-zero (the default: instance suspends when
17
+ // idle, cold-starts on the next connection) or always-on (instance stays warm; idle RAM bills at
18
+ // actual usage). Reads GET /database/instance, sets PATCH /database/settings {scaleToZero} —
19
+ // insta-db-backed postgres only.
20
+ export async function dbAlwaysOn(first, second, opts) {
21
+ const { mode, service } = alwaysOnArgs(first, second);
13
22
  const api = await ApiClient.load();
14
23
  const p = await requireProject();
15
24
  const qs = new URLSearchParams();
@@ -18,7 +27,19 @@ export async function dbAlwaysOn(mode, service, opts) {
18
27
  qs.set('branch', branch);
19
28
  if (service)
20
29
  qs.set('group', service);
21
- const res = await api.rawRequest('PATCH', `/projects/${p.projectId}/database/settings${qs.toString() ? `?${qs}` : ''}`, { scaleToZero: mode !== 'on' });
30
+ const suffix = qs.toString() ? `?${qs}` : '';
31
+ if (!mode) {
32
+ const read = await fetchDbInstance(api, p.projectId, suffix);
33
+ if (read.kind === 'no-instance') {
34
+ info(`postgres ${service ?? 'default'}: no manageable instance (this service manages its own resources)`);
35
+ return;
36
+ }
37
+ if (opts.json)
38
+ return printJson(read.body);
39
+ info(alwaysOnLine(service ?? 'default', read.body?.scaleToZero));
40
+ return;
41
+ }
42
+ const res = await api.rawRequest('PATCH', `/projects/${p.projectId}/database/settings${suffix}`, { scaleToZero: mode !== 'on' });
22
43
  if (handleApproval(res, opts.json))
23
44
  return;
24
45
  if (opts.json)
package/dist/index.js CHANGED
@@ -438,7 +438,7 @@ pg.command('volume [service]').description("Show or grow a postgres service's pr
438
438
  .option('--size <gi>', 'new size in whole Gi, e.g. 10 (must be ≥ the current size)')
439
439
  .option('--json').option('--branch <branch>', 'branch (default: current)')
440
440
  .action(guard((service, o) => pgCmd.dbVolume(service, o)));
441
- pg.command('always-on <mode> [service]').description('Set a postgres service always-on (mode: on|off). on = instance stays warm, no cold starts; off = default scale-to-zero (idle instance suspends; first connection cold-starts). insta-db-backed services only')
441
+ pg.command('always-on [mode] [service]').description('Show or set a postgres service always-on (mode: on|off; no mode = print the current setting). on = instance stays warm, no cold starts; off = default scale-to-zero (idle instance suspends; first connection cold-starts). insta-db-backed services only')
442
442
  .option('--json').option('--branch <branch>', 'branch (default: current)')
443
443
  .action(guard((mode, service, o) => pgCmd.dbAlwaysOn(mode, service, o)));
444
444
  addObservability(pg, 'db', 'postgres');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "insta",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
4
4
  "type": "module",
5
5
  "description": "InstaCloud CLI — a thin client of the platform control-plane API.",
6
6
  "keywords": [