@fabrika/cli 0.9.0-dev.48 → 0.9.0-dev.49

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fabrika/cli",
3
- "version": "0.9.0-dev.48",
3
+ "version": "0.9.0-dev.49",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -32,21 +32,21 @@
32
32
  "dependencies": {
33
33
  "jose": "^5.9.0",
34
34
  "zod": "^3.25.76",
35
- "@fabrika/app": "0.9.0-dev.48",
36
- "@fabrika/auth-core": "0.9.0-dev.48",
37
- "@fabrika/control-contract": "0.9.0-dev.48",
38
- "@fabrika/iam-contract": "0.9.0-dev.48",
39
- "@fabrika/operations-contract": "0.9.0-dev.48",
40
- "@fabrika/provider-contract": "0.9.0-dev.48",
41
- "@fabrika/db": "0.9.0-dev.48",
42
- "@fabrika/platform": "0.9.0-dev.48",
43
- "@fabrika/platform-node": "0.9.0-dev.48",
44
- "@fabrika/check": "0.9.0-dev.48"
35
+ "@fabrika/app": "0.9.0-dev.49",
36
+ "@fabrika/auth-core": "0.9.0-dev.49",
37
+ "@fabrika/control-contract": "0.9.0-dev.49",
38
+ "@fabrika/iam-contract": "0.9.0-dev.49",
39
+ "@fabrika/operations-contract": "0.9.0-dev.49",
40
+ "@fabrika/provider-contract": "0.9.0-dev.49",
41
+ "@fabrika/db": "0.9.0-dev.49",
42
+ "@fabrika/platform": "0.9.0-dev.49",
43
+ "@fabrika/platform-node": "0.9.0-dev.49",
44
+ "@fabrika/check": "0.9.0-dev.49"
45
45
  },
46
46
  "peerDependencies": {
47
- "@fabrika/builder": "0.9.0-dev.48",
48
- "@fabrika/provider-cloudflare": "0.9.0-dev.48",
49
- "@fabrika/provider-zerops": "0.9.0-dev.48"
47
+ "@fabrika/builder": "0.9.0-dev.49",
48
+ "@fabrika/provider-cloudflare": "0.9.0-dev.49",
49
+ "@fabrika/provider-zerops": "0.9.0-dev.49"
50
50
  },
51
51
  "peerDependenciesMeta": {
52
52
  "@fabrika/builder": {
package/src/data.ts CHANGED
@@ -3,6 +3,7 @@
3
3
 
4
4
  import { RpcError } from '@fabrika/app'
5
5
  import {
6
+ OPS_MIGRATION_FAILURES,
6
7
  OPS_ROW_COUNT_CAP,
7
8
  type OpsContentView,
8
9
  type OpsView,
@@ -10,7 +11,13 @@ import {
10
11
  parseOpsContentView,
11
12
  parseOpsView,
12
13
  } from '@fabrika/auth-core'
13
- import { type DataBackupDto, type DataBackupScheduleDto, type DataOperationDto, startDataOperationInputSchema } from '@fabrika/control-contract'
14
+ import {
15
+ DATA_OPERATION_RESOLUTIONS,
16
+ type DataBackupDto,
17
+ type DataBackupScheduleDto,
18
+ type DataOperationDto,
19
+ startDataOperationInputSchema,
20
+ } from '@fabrika/control-contract'
14
21
  import { z } from 'zod'
15
22
  import { ApprovalPendingError, connectControl, type ControlClient, directWrite, withoutControlKey } from './control.js'
16
23
 
@@ -20,7 +27,7 @@ Usage:
20
27
  fabrika env inspect <app> <env> [--content] [--json]
21
28
  fabrika env maintenance <app> <env> <open|read-only|closed> [--wait] [--json]
22
29
  fabrika env operations <app> <env> [--json]
23
- fabrika env recover <app> <env> <operationId> <resume|open> [--wait] [--json]
30
+ fabrika env recover <app> <env> <operationId> <resume|open|rollback> [--wait] [--json]
24
31
  fabrika env backups <app> <env> [--json]
25
32
  fabrika env backups schedule <app> <env> [on|off] [--wait] [--json]
26
33
  fabrika env restore <app> <env> --at=<time> [--wait] [--json]
@@ -38,8 +45,10 @@ and needs \`data.content.read\` granted globally.
38
45
  <id> <kind> <state> <step> <target mode> <generation> <error code> <created at>.
39
46
 
40
47
  \`recover\` fences an environment whose operation is stuck in \`closed\` at a fresh generation, then \`resume\`s that
41
- operation from its recorded step, or \`open\`s the environment. A failed operation can only be opened past. It needs
42
- \`data.manage\`.
48
+ operation from its recorded step, or \`open\`s the environment. A failed operation can only be opened past, or, for a
49
+ failed migration whose data holds nothing of it (\`rollbackAndOpen\` in \`--json\`), rolled back: \`rollback\` fences
50
+ it in \`inspect\`, deploys the last succeeded commit again as a new run, waits until the failed version is gone and
51
+ opens it. It needs \`data.manage\`.
43
52
 
44
53
  \`backups\` lists the environment's consistent backups, newest first, one row each:
45
54
  <id> <object> <state> <created at> <size bytes> <parts> <tables> <rehearsal> <rehearsal code> <error code> <expired>
@@ -93,7 +102,7 @@ const COMMAND_FORMS: Readonly<Record<string, string>> = {
93
102
  inspect: '<app> <env> [--content] [--json]',
94
103
  maintenance: '<app> <env> <open|read-only|closed> [--wait] [--json]',
95
104
  operations: '<app> <env> [--json]',
96
- recover: '<app> <env> <operationId> <resume|open> [--wait] [--json]',
105
+ recover: '<app> <env> <operationId> <resume|open|rollback> [--wait] [--json]',
97
106
  backups: '<app> <env> [--json]',
98
107
  'backups schedule': '<app> <env> [on|off] [--wait] [--json]',
99
108
  restore: '<app> <env> --at=<time> [--wait] [--json]',
@@ -166,9 +175,19 @@ const dataOperationSchema: z.ZodType<DataOperationDto, z.ZodTypeDef, unknown> =
166
175
  updatedAt: z.number().int().nonnegative(),
167
176
  finishedAt: z.number().int().nonnegative().nullable(),
168
177
  recoversOperationId: z.string().uuid().nullable(),
169
- resolution: z.enum(['resume', 'open']).nullable(),
178
+ resolution: z.enum(DATA_OPERATION_RESOLUTIONS).nullable(),
170
179
  // Absent from a Control before the migration phase.
171
180
  runId: z.string().uuid().nullable().default(null),
181
+ // Absent from a Control before the migrating deploy without a read-only window.
182
+ recordsBookmark: z.boolean().default(false),
183
+ migrationFailure: z.enum(OPS_MIGRATION_FAILURES).nullable().default(null),
184
+ revertRunId: z.string().uuid().nullable().default(null),
185
+ candidateRecovered: z.boolean().default(false),
186
+ // Absent from a Control before the in-place rewind.
187
+ rewound: z.boolean().default(false),
188
+ rewindRefusal: z.string().regex(ERROR_CODE).nullable().default(null),
189
+ // Absent from a Control before the roll back and open recovery.
190
+ rollbackAndOpen: z.boolean().default(false),
172
191
  })
173
192
 
174
193
  interface Target {
@@ -241,7 +260,6 @@ const parseSchedule = (value: unknown, target: Target): DataBackupScheduleDto =>
241
260
  }
242
261
 
243
262
  const MAINTENANCE_MODES = ['open', 'read-only', 'closed'] as const
244
- const RESOLUTIONS = ['resume', 'open'] as const
245
263
  const SCHEDULE_SWITCHES = ['on', 'off'] as const
246
264
 
247
265
  const oneOf = <T extends string>(value: string, allowed: readonly T[]): T | undefined => allowed.find((candidate) => candidate === value)
@@ -360,8 +378,8 @@ const runOperations = async (args: EnvArgs, env: Environment): Promise<void> =>
360
378
 
361
379
  const runRecover = async (args: EnvArgs, env: Environment): Promise<void> => {
362
380
  const [appId = '', environment = '', operationId = '', requested = ''] = words('recover', args, 4)
363
- const resolution = oneOf(requested, RESOLUTIONS)
364
- if (resolution === undefined) throw new Error(`The resolution is resume or open, not "${requested}"`)
381
+ const resolution = oneOf(requested, DATA_OPERATION_RESOLUTIONS)
382
+ if (resolution === undefined) throw new Error(`The resolution is resume, open or rollback, not "${requested}"`)
365
383
  const client = controlClient(args, env)
366
384
  const result = await directWrite(client, args, () => client.data.recover({ appId, env: environment, operationId, resolution }))
367
385
  if (result === null) return
@@ -1,4 +1,4 @@
1
- declare const USAGE = "fabrika env \u2014 an application environment's data, through the control plane\n\nUsage:\n fabrika env inspect <app> <env> [--content] [--json]\n fabrika env maintenance <app> <env> <open|read-only|closed> [--wait] [--json]\n fabrika env operations <app> <env> [--json]\n fabrika env recover <app> <env> <operationId> <resume|open> [--wait] [--json]\n fabrika env backups <app> <env> [--json]\n fabrika env backups schedule <app> <env> [on|off] [--wait] [--json]\n fabrika env restore <app> <env> --at=<time> [--wait] [--json]\n\n`inspect` prints the environment's data view: the object's maintenance mode and generation, the database size and\neach table's row count (a count at 100000 reads `100000+`: it is capped), the applied migrations,\nthe scheduler's alarm, each job's last run, file and webhook counts, and when the application last failed to boot.\nIt needs `data.read`. `--content` adds the boot failure's message and stack, which are the application's own text,\nand needs `data.content.read` granted globally.\n\n`maintenance` puts the environment into a mode: `read-only` refuses writes, `closed` refuses every request, and\n`open` serves again. It starts a data operation and prints it; `operations` follows it. It needs `data.manage`.\n\n`operations` lists the environment's data operations, newest first, one row each:\n<id> <kind> <state> <step> <target mode> <generation> <error code> <created at>.\n\n`recover` fences an environment whose operation is stuck in `closed` at a fresh generation, then `resume`s that\noperation from its recorded step, or `open`s the environment. A failed operation can only be opened past. It needs\n`data.manage`.\n\n`backups` lists the environment's consistent backups, newest first, one row each:\n<id> <object> <state> <created at> <size bytes> <parts> <tables> <rehearsal> <rehearsal code> <error code> <expired>\n<pre-migration>.\nA backup counts as `succeeded` only once its rehearsal, an import into a scratch object, passed. One older than 30\ndays is `expired` and never offered for a restore. The last column is `pre-migration` for the backup a migration\ntakes before its deploy, and `-` for any other, such as a daily backup or a restore's. It needs `data.read`.\n\n`backups schedule` prints whether the environment takes a daily backup; `on` or `off` sets it, which needs\n`data.manage`. Turning it off stops the daily backup only: the backup before a migration still runs.\n\n`restore` brings back the environment's data as it was at `--at`, an ISO 8601 time with an offset in the past. It\nis a side restore: the serving object is frozen read-only and backed up, the backup is imported into a new clone\nobject, ordinary traffic is pointed at the clone, which serves the current data from then on, and the original is\nrewound to that time and kept in `inspect`, serving nothing, for inspection. It starts a data operation and prints\nit; `operations` follows it. It needs `data.manage`.\n\nOn a protected environment whose `data` category waits for a person (ADR-0083), a write by a key or an agent does not\napply: Control stores it as an approval request, the request's `<id> <state> <url>` goes to stdout, and the command\nexits 75. Hand the person the link. `--wait` follows the request to its end instead and succeeds only when it executed.\n\nA release of the control plane that does not offer a command answers that it is not available; retrying does not\nchange that. An environment the caller may not see answers `not_found`, as one that does not exist.\n\nstdout carries data only; progress and follow-up commands go to stderr. `--json` prints the result as JSON.\n\nThe control origin takes either form:\n\n --url=<origin> FABRIKA_CONTROL_URL\n\nThe credential is read from the ENVIRONMENT ONLY and has no flag; one of:\n\n FABRIKA_CONTROL_KEY a machine `px_` credential for the control app\n FABRIKA_CONTROL_CREDENTIAL_HELPER the helper a `fabrika control auth device` grant is stored through\n";
1
+ declare const USAGE = "fabrika env \u2014 an application environment's data, through the control plane\n\nUsage:\n fabrika env inspect <app> <env> [--content] [--json]\n fabrika env maintenance <app> <env> <open|read-only|closed> [--wait] [--json]\n fabrika env operations <app> <env> [--json]\n fabrika env recover <app> <env> <operationId> <resume|open|rollback> [--wait] [--json]\n fabrika env backups <app> <env> [--json]\n fabrika env backups schedule <app> <env> [on|off] [--wait] [--json]\n fabrika env restore <app> <env> --at=<time> [--wait] [--json]\n\n`inspect` prints the environment's data view: the object's maintenance mode and generation, the database size and\neach table's row count (a count at 100000 reads `100000+`: it is capped), the applied migrations,\nthe scheduler's alarm, each job's last run, file and webhook counts, and when the application last failed to boot.\nIt needs `data.read`. `--content` adds the boot failure's message and stack, which are the application's own text,\nand needs `data.content.read` granted globally.\n\n`maintenance` puts the environment into a mode: `read-only` refuses writes, `closed` refuses every request, and\n`open` serves again. It starts a data operation and prints it; `operations` follows it. It needs `data.manage`.\n\n`operations` lists the environment's data operations, newest first, one row each:\n<id> <kind> <state> <step> <target mode> <generation> <error code> <created at>.\n\n`recover` fences an environment whose operation is stuck in `closed` at a fresh generation, then `resume`s that\noperation from its recorded step, or `open`s the environment. A failed operation can only be opened past, or, for a\nfailed migration whose data holds nothing of it (`rollbackAndOpen` in `--json`), rolled back: `rollback` fences\nit in `inspect`, deploys the last succeeded commit again as a new run, waits until the failed version is gone and\nopens it. It needs `data.manage`.\n\n`backups` lists the environment's consistent backups, newest first, one row each:\n<id> <object> <state> <created at> <size bytes> <parts> <tables> <rehearsal> <rehearsal code> <error code> <expired>\n<pre-migration>.\nA backup counts as `succeeded` only once its rehearsal, an import into a scratch object, passed. One older than 30\ndays is `expired` and never offered for a restore. The last column is `pre-migration` for the backup a migration\ntakes before its deploy, and `-` for any other, such as a daily backup or a restore's. It needs `data.read`.\n\n`backups schedule` prints whether the environment takes a daily backup; `on` or `off` sets it, which needs\n`data.manage`. Turning it off stops the daily backup only: the backup before a migration still runs.\n\n`restore` brings back the environment's data as it was at `--at`, an ISO 8601 time with an offset in the past. It\nis a side restore: the serving object is frozen read-only and backed up, the backup is imported into a new clone\nobject, ordinary traffic is pointed at the clone, which serves the current data from then on, and the original is\nrewound to that time and kept in `inspect`, serving nothing, for inspection. It starts a data operation and prints\nit; `operations` follows it. It needs `data.manage`.\n\nOn a protected environment whose `data` category waits for a person (ADR-0083), a write by a key or an agent does not\napply: Control stores it as an approval request, the request's `<id> <state> <url>` goes to stdout, and the command\nexits 75. Hand the person the link. `--wait` follows the request to its end instead and succeeds only when it executed.\n\nA release of the control plane that does not offer a command answers that it is not available; retrying does not\nchange that. An environment the caller may not see answers `not_found`, as one that does not exist.\n\nstdout carries data only; progress and follow-up commands go to stderr. `--json` prints the result as JSON.\n\nThe control origin takes either form:\n\n --url=<origin> FABRIKA_CONTROL_URL\n\nThe credential is read from the ENVIRONMENT ONLY and has no flag; one of:\n\n FABRIKA_CONTROL_KEY a machine `px_` credential for the control app\n FABRIKA_CONTROL_CREDENTIAL_HELPER the helper a `fabrika control auth device` grant is stored through\n";
2
2
  type Environment = Readonly<Record<string, string | undefined>>;
3
3
  /** Every control character but tab and line feed: an answer must not drive the operator's terminal. */
4
4
  export declare const printable: (text: string) => string;