@sanity/workflows-cli 0.0.0-stage → 0.39.0
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/CHANGELOG.md +1981 -0
- package/LICENSE +21 -0
- package/README.md +848 -2
- package/bin/run.js +8 -0
- package/dist/command-ids.d.ts +10 -0
- package/dist/command-ids.js +10 -0
- package/dist/commands/workflows/abort.d.ts +29 -0
- package/dist/commands/workflows/abort.js +50 -0
- package/dist/commands/workflows/blueprints/generate.d.ts +12 -0
- package/dist/commands/workflows/blueprints/generate.js +46 -0
- package/dist/commands/workflows/codemod/packages.d.ts +13 -0
- package/dist/commands/workflows/codemod/packages.js +41 -0
- package/dist/commands/workflows/definitions/delete.d.ts +44 -0
- package/dist/commands/workflows/definitions/delete.js +74 -0
- package/dist/commands/workflows/definitions/diff.d.ts +23 -0
- package/dist/commands/workflows/definitions/diff.js +55 -0
- package/dist/commands/workflows/definitions/list.d.ts +52 -0
- package/dist/commands/workflows/definitions/list.js +139 -0
- package/dist/commands/workflows/definitions/show.d.ts +66 -0
- package/dist/commands/workflows/definitions/show.js +129 -0
- package/dist/commands/workflows/definitions/validate.d.ts +14 -0
- package/dist/commands/workflows/definitions/validate.js +50 -0
- package/dist/commands/workflows/deploy.d.ts +117 -0
- package/dist/commands/workflows/deploy.js +266 -0
- package/dist/commands/workflows/diagnose.d.ts +53 -0
- package/dist/commands/workflows/diagnose.js +195 -0
- package/dist/commands/workflows/fire-action.d.ts +53 -0
- package/dist/commands/workflows/fire-action.js +182 -0
- package/dist/commands/workflows/list.d.ts +79 -0
- package/dist/commands/workflows/list.js +249 -0
- package/dist/commands/workflows/nuke.d.ts +73 -0
- package/dist/commands/workflows/nuke.js +175 -0
- package/dist/commands/workflows/reset-activity.d.ts +32 -0
- package/dist/commands/workflows/reset-activity.js +60 -0
- package/dist/commands/workflows/show.d.ts +30 -0
- package/dist/commands/workflows/show.js +156 -0
- package/dist/commands/workflows/start.d.ts +57 -0
- package/dist/commands/workflows/start.js +196 -0
- package/dist/commands/workflows/tail.d.ts +24 -0
- package/dist/commands/workflows/tail.js +83 -0
- package/dist/commands/workflows/whoami.d.ts +16 -0
- package/dist/commands/workflows/whoami.js +53 -0
- package/dist/help.d.ts +13 -0
- package/dist/help.js +50 -0
- package/dist/hooks/finally/telemetry.d.ts +3 -0
- package/dist/hooks/finally/telemetry.js +10 -0
- package/dist/hooks/prerun/telemetry.d.ts +33 -0
- package/dist/hooks/prerun/telemetry.js +52 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/lib/base-command.d.ts +14 -0
- package/dist/lib/base-command.js +41 -0
- package/dist/lib/blueprint-emit.d.ts +56 -0
- package/dist/lib/blueprint-emit.js +233 -0
- package/dist/lib/blueprint-needs.d.ts +5 -0
- package/dist/lib/blueprint-needs.js +284 -0
- package/dist/lib/blueprint-stacks.d.ts +6 -0
- package/dist/lib/blueprint-stacks.js +118 -0
- package/dist/lib/cause-detail.d.ts +9 -0
- package/dist/lib/cause-detail.js +112 -0
- package/dist/lib/client.d.ts +27 -0
- package/dist/lib/client.js +45 -0
- package/dist/lib/codemod/ast.d.ts +17 -0
- package/dist/lib/codemod/ast.js +14 -0
- package/dist/lib/codemod/export-rename.d.ts +19 -0
- package/dist/lib/codemod/export-rename.js +337 -0
- package/dist/lib/codemod/manifest-rewrite.d.ts +17 -0
- package/dist/lib/codemod/manifest-rewrite.js +133 -0
- package/dist/lib/codemod/package-map.d.ts +27 -0
- package/dist/lib/codemod/package-map.js +99 -0
- package/dist/lib/codemod/report.d.ts +4 -0
- package/dist/lib/codemod/report.js +51 -0
- package/dist/lib/codemod/run.d.ts +25 -0
- package/dist/lib/codemod/run.js +108 -0
- package/dist/lib/codemod/source-rewrite.d.ts +20 -0
- package/dist/lib/codemod/source-rewrite.js +150 -0
- package/dist/lib/command-context.d.ts +20 -0
- package/dist/lib/command-context.js +24 -0
- package/dist/lib/command-telemetry.d.ts +54 -0
- package/dist/lib/command-telemetry.js +82 -0
- package/dist/lib/context.d.ts +151 -0
- package/dist/lib/context.js +263 -0
- package/dist/lib/default-partition.d.ts +23 -0
- package/dist/lib/default-partition.js +47 -0
- package/dist/lib/definition-files.d.ts +14 -0
- package/dist/lib/definition-files.js +60 -0
- package/dist/lib/definitions.d.ts +63 -0
- package/dist/lib/definitions.js +84 -0
- package/dist/lib/diff.d.ts +12 -0
- package/dist/lib/diff.js +93 -0
- package/dist/lib/env.d.ts +7 -0
- package/dist/lib/env.js +8 -0
- package/dist/lib/fail.d.ts +36 -0
- package/dist/lib/fail.js +55 -0
- package/dist/lib/failure-kind.d.ts +7 -0
- package/dist/lib/failure-kind.js +66 -0
- package/dist/lib/flags.d.ts +53 -0
- package/dist/lib/flags.js +127 -0
- package/dist/lib/follow-up-command.d.ts +18 -0
- package/dist/lib/follow-up-command.js +12 -0
- package/dist/lib/history-rows.d.ts +3 -0
- package/dist/lib/history-rows.js +44 -0
- package/dist/lib/load-config.d.ts +51 -0
- package/dist/lib/load-config.js +108 -0
- package/dist/lib/nuke.d.ts +124 -0
- package/dist/lib/nuke.js +206 -0
- package/dist/lib/operation-args.d.ts +42 -0
- package/dist/lib/operation-args.js +21 -0
- package/dist/lib/ops-report.d.ts +45 -0
- package/dist/lib/ops-report.js +31 -0
- package/dist/lib/params.d.ts +3 -0
- package/dist/lib/params.js +21 -0
- package/dist/lib/pick-resource.d.ts +13 -0
- package/dist/lib/pick-resource.js +82 -0
- package/dist/lib/prompt.d.ts +35 -0
- package/dist/lib/prompt.js +11 -0
- package/dist/lib/read-fanout.d.ts +45 -0
- package/dist/lib/read-fanout.js +45 -0
- package/dist/lib/resource-target.d.ts +10 -0
- package/dist/lib/resource-target.js +12 -0
- package/dist/lib/select-deployment.d.ts +31 -0
- package/dist/lib/select-deployment.js +91 -0
- package/dist/lib/share-definitions.d.ts +101 -0
- package/dist/lib/share-definitions.js +188 -0
- package/dist/lib/telemetry-setup.d.ts +77 -0
- package/dist/lib/telemetry-setup.js +117 -0
- package/dist/lib/telemetry.d.ts +81 -0
- package/dist/lib/telemetry.js +90 -0
- package/dist/lib/ui.d.ts +88 -0
- package/dist/lib/ui.js +114 -0
- package/dist/standalone-argv.d.ts +14 -0
- package/dist/standalone-argv.js +57 -0
- package/oclif.manifest.json +1894 -0
- package/package.json +118 -3
package/bin/run.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {execute} from '@oclif/core'
|
|
3
|
+
|
|
4
|
+
import {rewriteStandaloneArgv} from '../dist/standalone-argv.js'
|
|
5
|
+
|
|
6
|
+
process.argv = [...process.argv.slice(0, 2), ...rewriteStandaloneArgv(process.argv.slice(2))]
|
|
7
|
+
|
|
8
|
+
await execute({dir: import.meta.url})
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const WORKFLOWS_TOPIC = "workflows";
|
|
2
|
+
export declare const WORKFLOWS_TOPIC_PREFIX = "workflows:";
|
|
3
|
+
export declare const WORKFLOWS_DEPLOY_COMMAND_ID = "workflows:deploy";
|
|
4
|
+
/** Standalone binary name from package.json `oclif.bin` / `bin`. */
|
|
5
|
+
export declare const STANDALONE_BIN = "sanity-workflows";
|
|
6
|
+
/** True on `sanity-workflows`, or on a host only for `workflows` / `workflows:*`. */
|
|
7
|
+
export declare function shouldRunWorkflowCliTelemetry(args: {
|
|
8
|
+
bin: string;
|
|
9
|
+
commandId: string | undefined;
|
|
10
|
+
}): boolean;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const WORKFLOWS_TOPIC = 'workflows';
|
|
2
|
+
export const WORKFLOWS_TOPIC_PREFIX = `${WORKFLOWS_TOPIC}:`;
|
|
3
|
+
export const WORKFLOWS_DEPLOY_COMMAND_ID = `${WORKFLOWS_TOPIC}:deploy`;
|
|
4
|
+
export const STANDALONE_BIN = 'sanity-workflows';
|
|
5
|
+
export function shouldRunWorkflowCliTelemetry(args) {
|
|
6
|
+
const { bin, commandId } = args;
|
|
7
|
+
return (bin === STANDALONE_BIN ||
|
|
8
|
+
commandId === WORKFLOWS_TOPIC ||
|
|
9
|
+
commandId?.startsWith(WORKFLOWS_TOPIC_PREFIX) === true);
|
|
10
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { WorkflowInstance } from '@sanity/workflows';
|
|
2
|
+
import { WorkflowCommand } from '../../lib/base-command.ts';
|
|
3
|
+
import { type WriteReport } from '../../lib/ops-report.ts';
|
|
4
|
+
export default class Abort extends WorkflowCommand {
|
|
5
|
+
static description: string;
|
|
6
|
+
static examples: string[];
|
|
7
|
+
static args: {
|
|
8
|
+
instanceId: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
9
|
+
};
|
|
10
|
+
static flags: {
|
|
11
|
+
path: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
|
+
deployment: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
13
|
+
partition: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
14
|
+
reason: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
15
|
+
};
|
|
16
|
+
static telemetry: import("../../lib/command-telemetry.ts").CommandTelemetry;
|
|
17
|
+
run(): Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
interface AbortOutcome {
|
|
20
|
+
changed: boolean;
|
|
21
|
+
instance: Pick<WorkflowInstance, 'currentStage' | 'completedAt'>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Turn an `abortInstance` result into the spinner message. Pure so the
|
|
25
|
+
* aborted / already-terminal permutations can be asserted without driving
|
|
26
|
+
* a real abort.
|
|
27
|
+
*/
|
|
28
|
+
export declare function abortReport(result: AbortOutcome): WriteReport;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { styleText } from 'node:util';
|
|
2
|
+
import { Args, Flags } from '@oclif/core';
|
|
3
|
+
import { WorkflowCommand } from '../../lib/base-command.js';
|
|
4
|
+
import { defineCommandTelemetry } from '../../lib/command-telemetry.js';
|
|
5
|
+
import { resolveInstanceContext } from '../../lib/context.js';
|
|
6
|
+
import { instanceFlags } from '../../lib/flags.js';
|
|
7
|
+
import { cliEngine } from '../../lib/operation-args.js';
|
|
8
|
+
import { runWriteVerb } from '../../lib/ops-report.js';
|
|
9
|
+
const flags = {
|
|
10
|
+
...instanceFlags,
|
|
11
|
+
reason: Flags.string({ description: 'Reason for aborting (recorded in history).' }),
|
|
12
|
+
};
|
|
13
|
+
export default class Abort extends WorkflowCommand {
|
|
14
|
+
static description = 'Abort an in-flight workflow instance — a hard stop: pending effects are cancelled, stage guards removed, and the instance is marked terminal where it stands.';
|
|
15
|
+
static examples = [
|
|
16
|
+
'<%= config.bin %> workflows abort wf-instance.abc123',
|
|
17
|
+
"<%= config.bin %> workflows abort wf-instance.abc123 --reason 'superseded by relaunch'",
|
|
18
|
+
];
|
|
19
|
+
static args = {
|
|
20
|
+
instanceId: Args.string({ required: true, description: 'Workflow instance id.' }),
|
|
21
|
+
};
|
|
22
|
+
static flags = flags;
|
|
23
|
+
static telemetry = defineCommandTelemetry(flags, { redact: ['reason'] });
|
|
24
|
+
async run() {
|
|
25
|
+
const { args, flags } = await this.parse(Abort);
|
|
26
|
+
const { client, scope } = await resolveInstanceContext(flags, args.instanceId);
|
|
27
|
+
await runWriteVerb({
|
|
28
|
+
startLabel: `Aborting ${args.instanceId}…`,
|
|
29
|
+
failLabel: 'Abort rejected',
|
|
30
|
+
failHeadline: 'abort error:',
|
|
31
|
+
run: () => cliEngine(client, scope).abortInstance({
|
|
32
|
+
instanceId: args.instanceId,
|
|
33
|
+
...(flags.reason !== undefined ? { reason: flags.reason } : {}),
|
|
34
|
+
}),
|
|
35
|
+
report: abortReport,
|
|
36
|
+
log: (line) => this.log(line),
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export function abortReport(result) {
|
|
41
|
+
const stage = styleText('bold', result.instance.currentStage);
|
|
42
|
+
if (!result.changed) {
|
|
43
|
+
const at = result.instance.completedAt ?? 'unknown';
|
|
44
|
+
return {
|
|
45
|
+
changed: false,
|
|
46
|
+
message: `abortInstance changed nothing — instance is already terminal (at ${stage} since ${at})`,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
return { changed: true, message: `Aborted — instance hard-stopped at ${stage}` };
|
|
50
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { WorkflowCommand } from '../../../lib/base-command.ts';
|
|
2
|
+
export default class BlueprintGenerate extends WorkflowCommand {
|
|
3
|
+
static hiddenAliases: string[];
|
|
4
|
+
static description: string;
|
|
5
|
+
static examples: string[];
|
|
6
|
+
static flags: {
|
|
7
|
+
path: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
|
+
check: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
9
|
+
verbose: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
10
|
+
};
|
|
11
|
+
run(): Promise<void>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Flags } from '@oclif/core';
|
|
2
|
+
import { WorkflowCommand } from '../../../lib/base-command.js';
|
|
3
|
+
import { checkBlueprint, generateBlueprint } from '../../../lib/blueprint-emit.js';
|
|
4
|
+
import { configFlags } from '../../../lib/flags.js';
|
|
5
|
+
import { loadWorkflowConfigModule } from '../../../lib/load-config.js';
|
|
6
|
+
import { terminalWidth } from '../../../lib/ui.js';
|
|
7
|
+
export default class BlueprintGenerate extends WorkflowCommand {
|
|
8
|
+
static hiddenAliases = ['workflows:blueprint:generate'];
|
|
9
|
+
static description = 'Generate the Sanity Blueprints runtime the definitions require, next to sanity.workflow.ts. Writes the workflow resources, one function per derived need, the effect-handler registry, and a handler stub per declared effect. Covers every deployment in the config, because the emitted resources module declares them all. Document functions deploy from sanity.blueprint.ts to a project stack with a project token; a generated heartbeat deploys from workflows-heartbeat/ to an organization stack with an organization deploy token.';
|
|
10
|
+
static examples = [
|
|
11
|
+
'<%= config.bin %> workflows blueprints generate',
|
|
12
|
+
'<%= config.bin %> workflows blueprints generate --verbose',
|
|
13
|
+
'<%= config.bin %> workflows blueprints generate --check',
|
|
14
|
+
];
|
|
15
|
+
static flags = {
|
|
16
|
+
...configFlags,
|
|
17
|
+
check: Flags.boolean({
|
|
18
|
+
description: 'Verify the tree on disk still matches the definitions; write nothing and exit non-zero on any difference. The CI drift gate.',
|
|
19
|
+
default: false,
|
|
20
|
+
}),
|
|
21
|
+
verbose: Flags.boolean({
|
|
22
|
+
description: 'Print the full runtime-needs report, every file written, and the heartbeat stack instructions even when its files are unchanged, in place of the summary of what changed and what needs you.',
|
|
23
|
+
default: false,
|
|
24
|
+
exclusive: ['check'],
|
|
25
|
+
}),
|
|
26
|
+
};
|
|
27
|
+
async run() {
|
|
28
|
+
const { flags } = await this.parse(BlueprintGenerate);
|
|
29
|
+
const { root, config, configFile, exportedNames } = await loadWorkflowConfigModule(flags.path);
|
|
30
|
+
const log = (line) => this.log(line);
|
|
31
|
+
const width = terminalWidth();
|
|
32
|
+
if (flags.check) {
|
|
33
|
+
checkBlueprint({ root, config, configFile, exportedNames, log, bin: this.config.bin, width });
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
generateBlueprint({
|
|
37
|
+
root,
|
|
38
|
+
config,
|
|
39
|
+
configFile,
|
|
40
|
+
exportedNames,
|
|
41
|
+
log,
|
|
42
|
+
width,
|
|
43
|
+
verbose: flags.verbose,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { WorkflowCommand } from '../../../lib/base-command.ts';
|
|
2
|
+
export default class CodemodPackages extends WorkflowCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static examples: string[];
|
|
5
|
+
static strict: boolean;
|
|
6
|
+
static args: {
|
|
7
|
+
path: import("@oclif/core/interfaces").Arg<string | undefined, Record<string, unknown>>;
|
|
8
|
+
};
|
|
9
|
+
static flags: {
|
|
10
|
+
'dry-run': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
11
|
+
};
|
|
12
|
+
run(): Promise<void>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Args, Flags } from '@oclif/core';
|
|
2
|
+
import { cliPackageVersion } from '../../../hooks/prerun/telemetry.js';
|
|
3
|
+
import { WorkflowCommand } from '../../../lib/base-command.js';
|
|
4
|
+
import { codemodLines } from '../../../lib/codemod/report.js';
|
|
5
|
+
import { runCodemod } from '../../../lib/codemod/run.js';
|
|
6
|
+
import { fail } from '../../../lib/fail.js';
|
|
7
|
+
export default class CodemodPackages extends WorkflowCommand {
|
|
8
|
+
static description = 'Move imports and package.json dependencies from the retired Workflows packages to @sanity/workflows, @sanity/workflows-ui, @sanity/workflows-cli, and @sanity/workflows-test. Rewrites module specifiers in import, export, dynamic import(), require(), and vi.mock() calls, and replaces the old packages in every package.json dependency field. Imports of exports renamed in the same release, such as workflowStudioPlugin, are renamed with every reference to them, as are names after an import() type. A name read through export *, require(), import x = require(), a dynamic import(), a mocked module factory, a computed member, or destructuring from a namespace keeps its old name, so check require() calls, plain JavaScript files, and test mocks by hand. Package names in other strings, comments, and built-up specifiers are listed for you to fix by hand, as are members read through a namespace name the file declares again: rename one if it reads the import. Generated blueprint files are skipped: run blueprints generate after installing. Lockfiles are never edited.';
|
|
9
|
+
static examples = [
|
|
10
|
+
'<%= config.bin %> workflows codemod packages --dry-run',
|
|
11
|
+
'<%= config.bin %> workflows codemod packages',
|
|
12
|
+
'<%= config.bin %> workflows codemod packages apps/studio packages/shared',
|
|
13
|
+
];
|
|
14
|
+
static strict = false;
|
|
15
|
+
static args = {
|
|
16
|
+
path: Args.string({
|
|
17
|
+
description: 'File or directory to rewrite. Pass several to limit the run; defaults to the current directory. Directories skip node_modules, dist, and files git ignores.',
|
|
18
|
+
}),
|
|
19
|
+
};
|
|
20
|
+
static flags = {
|
|
21
|
+
'dry-run': Flags.boolean({
|
|
22
|
+
description: 'Print what would change and write nothing.',
|
|
23
|
+
default: false,
|
|
24
|
+
}),
|
|
25
|
+
};
|
|
26
|
+
async run() {
|
|
27
|
+
const { argv, flags } = await this.parse(CodemodPackages);
|
|
28
|
+
const version = cliPackageVersion(this.config);
|
|
29
|
+
if (version === undefined) {
|
|
30
|
+
fail('Could not read this CLI’s own version to write the new dependency ranges.');
|
|
31
|
+
}
|
|
32
|
+
const paths = argv.length === 0 ? ['.'] : argv.map(String);
|
|
33
|
+
const outcome = runCodemod({
|
|
34
|
+
paths,
|
|
35
|
+
cwd: process.cwd(),
|
|
36
|
+
range: `^${version}`,
|
|
37
|
+
write: !flags['dry-run'],
|
|
38
|
+
});
|
|
39
|
+
codemodLines({ ...outcome, dryRun: flags['dry-run'] }).forEach((line) => this.log(line));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type DeleteDefinitionArgs, type DeleteDefinitionResult } from '@sanity/workflows';
|
|
2
|
+
import { WorkflowCommand } from '../../../lib/base-command.ts';
|
|
3
|
+
import { type EngineScope } from '../../../lib/operation-args.ts';
|
|
4
|
+
export default class DefinitionDelete extends WorkflowCommand {
|
|
5
|
+
static hiddenAliases: string[];
|
|
6
|
+
static description: string;
|
|
7
|
+
static examples: string[];
|
|
8
|
+
static args: {
|
|
9
|
+
name: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
10
|
+
};
|
|
11
|
+
static flags: {
|
|
12
|
+
path: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
13
|
+
deployment: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
14
|
+
partition: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
15
|
+
version: import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
16
|
+
cascade: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
17
|
+
reason: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
18
|
+
};
|
|
19
|
+
static telemetry: import("../../../lib/command-telemetry.ts").CommandTelemetry;
|
|
20
|
+
run(): Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The shared engine args ({@link baseEngineArgs}) plus the delete-specific
|
|
24
|
+
* targeting. `version` and `reason` spread conditionally because the
|
|
25
|
+
* engine's optionals reject an explicit `undefined` under
|
|
26
|
+
* `exactOptionalPropertyTypes`.
|
|
27
|
+
*/
|
|
28
|
+
export declare function buildDeleteArgs({ scope, name, flags, }: {
|
|
29
|
+
scope: EngineScope;
|
|
30
|
+
name: string;
|
|
31
|
+
flags: {
|
|
32
|
+
version?: number | undefined;
|
|
33
|
+
cascade: boolean;
|
|
34
|
+
reason?: string | undefined;
|
|
35
|
+
};
|
|
36
|
+
}): DeleteDefinitionArgs & EngineScope;
|
|
37
|
+
/** What the spinner names: the workflow, or one pinned version of it. */
|
|
38
|
+
export declare function deleteTargetLabel(args: Pick<DeleteDefinitionArgs, 'definition' | 'version'>): string;
|
|
39
|
+
/**
|
|
40
|
+
* Turn a `deleteDefinition` result into the spinner message. Pure so the
|
|
41
|
+
* version / cascade / guard permutations can be asserted without driving
|
|
42
|
+
* a real delete.
|
|
43
|
+
*/
|
|
44
|
+
export declare function deleteReport(result: DeleteDefinitionResult): string;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { styleText } from 'node:util';
|
|
2
|
+
import { Args, Flags } from '@oclif/core';
|
|
3
|
+
import { workflow } from '@sanity/workflows';
|
|
4
|
+
import { WorkflowCommand } from '../../../lib/base-command.js';
|
|
5
|
+
import { defineCommandTelemetry } from '../../../lib/command-telemetry.js';
|
|
6
|
+
import { resolveContext } from '../../../lib/context.js';
|
|
7
|
+
import { deploymentFlags } from '../../../lib/flags.js';
|
|
8
|
+
import { baseEngineArgs } from '../../../lib/operation-args.js';
|
|
9
|
+
import { runWriteVerb } from '../../../lib/ops-report.js';
|
|
10
|
+
const flags = {
|
|
11
|
+
...deploymentFlags,
|
|
12
|
+
version: Flags.integer({
|
|
13
|
+
description: 'Delete only this deployed version (default: every version).',
|
|
14
|
+
}),
|
|
15
|
+
cascade: Flags.boolean({
|
|
16
|
+
description: 'Abort every non-terminal instance pinned to the targeted versions, then delete.',
|
|
17
|
+
default: false,
|
|
18
|
+
}),
|
|
19
|
+
reason: Flags.string({
|
|
20
|
+
description: 'Free-text reason — recorded on each cascade-abort history entry.',
|
|
21
|
+
}),
|
|
22
|
+
};
|
|
23
|
+
export default class DefinitionDelete extends WorkflowCommand {
|
|
24
|
+
static hiddenAliases = ['workflows:definition:delete'];
|
|
25
|
+
static description = 'Delete a deployed workflow definition (every version, or one via --version). ' +
|
|
26
|
+
'Refuses while non-terminal instances exist unless --cascade aborts them first — ' +
|
|
27
|
+
'instances are aborted in place, never deleted.';
|
|
28
|
+
static examples = [
|
|
29
|
+
'<%= config.bin %> workflows definitions delete my-workflow',
|
|
30
|
+
'<%= config.bin %> workflows definitions delete my-workflow --version 2',
|
|
31
|
+
"<%= config.bin %> workflows definitions delete my-workflow --cascade --reason 'workflow retired'",
|
|
32
|
+
];
|
|
33
|
+
static args = {
|
|
34
|
+
name: Args.string({ required: true, description: 'Workflow definition name.' }),
|
|
35
|
+
};
|
|
36
|
+
static flags = flags;
|
|
37
|
+
static telemetry = defineCommandTelemetry(flags, { redact: ['reason'] });
|
|
38
|
+
async run() {
|
|
39
|
+
const { args, flags } = await this.parse(DefinitionDelete);
|
|
40
|
+
const { scope, client } = await resolveContext(flags);
|
|
41
|
+
const deleteArgs = buildDeleteArgs({ scope, name: args.name, flags });
|
|
42
|
+
await runWriteVerb({
|
|
43
|
+
startLabel: `Deleting definition ${deleteTargetLabel(deleteArgs)}…`,
|
|
44
|
+
failLabel: 'Delete rejected',
|
|
45
|
+
failHeadline: 'definitions delete error:',
|
|
46
|
+
run: () => workflow.deleteDefinition({ client, ...deleteArgs }),
|
|
47
|
+
report: (result) => ({ changed: true, message: deleteReport(result) }),
|
|
48
|
+
log: (line) => this.log(line),
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
export function buildDeleteArgs({ scope, name, flags, }) {
|
|
53
|
+
return {
|
|
54
|
+
...baseEngineArgs(scope),
|
|
55
|
+
definition: name,
|
|
56
|
+
cascade: flags.cascade,
|
|
57
|
+
...(flags.version !== undefined ? { version: flags.version } : {}),
|
|
58
|
+
...(flags.reason !== undefined ? { reason: flags.reason } : {}),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
export function deleteTargetLabel(args) {
|
|
62
|
+
return args.version === undefined ? args.definition : `${args.definition} v${args.version}`;
|
|
63
|
+
}
|
|
64
|
+
export function deleteReport(result) {
|
|
65
|
+
const versions = result.deletedVersions.map((v) => `v${v}`).join(', ');
|
|
66
|
+
const parts = [`Deleted ${styleText('bold', result.name)} ${versions}`];
|
|
67
|
+
if (result.abortedInstanceIds.length > 0) {
|
|
68
|
+
parts.push(`aborted ${result.abortedInstanceIds.length} instance(s)`);
|
|
69
|
+
}
|
|
70
|
+
if (result.deletedGuardCount > 0) {
|
|
71
|
+
parts.push(`removed ${result.deletedGuardCount} orphaned guard doc(s)`);
|
|
72
|
+
}
|
|
73
|
+
return parts.join(' — ');
|
|
74
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type WorkflowDefinition } from '@sanity/workflows';
|
|
2
|
+
import { WorkflowCommand } from '../../../lib/base-command.ts';
|
|
3
|
+
export default class DefinitionDiff extends WorkflowCommand {
|
|
4
|
+
static hiddenAliases: string[];
|
|
5
|
+
static description: string;
|
|
6
|
+
static examples: string[];
|
|
7
|
+
static args: {
|
|
8
|
+
name: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
9
|
+
};
|
|
10
|
+
static flags: {
|
|
11
|
+
path: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
|
+
deployment: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
13
|
+
partition: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
14
|
+
version: import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
15
|
+
};
|
|
16
|
+
run(): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Pick the single definition to diff by name and validate it, failing cleanly
|
|
20
|
+
* when it's missing from the deployment or doesn't pass validation. Extracted
|
|
21
|
+
* from `run` so the command's orchestration stays thin and this stays testable.
|
|
22
|
+
*/
|
|
23
|
+
export declare function selectDefinitionToDiff(definitions: WorkflowDefinition[], name: string): WorkflowDefinition;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Args, Flags } from '@oclif/core';
|
|
2
|
+
import { diffEntry } from '@sanity/workflows';
|
|
3
|
+
import ora from 'ora';
|
|
4
|
+
import { WorkflowCommand } from '../../../lib/base-command.js';
|
|
5
|
+
import { resolveContext } from '../../../lib/context.js';
|
|
6
|
+
import { fetchDeployedDefinition, selectDefinitions, validateOrFail, } from '../../../lib/definitions.js';
|
|
7
|
+
import { diffReport } from '../../../lib/diff.js';
|
|
8
|
+
import { deploymentFlags } from '../../../lib/flags.js';
|
|
9
|
+
import { acknowledgeDeployment, deploymentToTarget } from '../../../lib/select-deployment.js';
|
|
10
|
+
export default class DefinitionDiff extends WorkflowCommand {
|
|
11
|
+
static hiddenAliases = ['workflows:definition:diff'];
|
|
12
|
+
static description = 'Diff an in-code definition against the deployed version (latest by default).';
|
|
13
|
+
static examples = [
|
|
14
|
+
'<%= config.bin %> workflows definitions diff product-launch',
|
|
15
|
+
'<%= config.bin %> workflows definitions diff product-launch --version 2',
|
|
16
|
+
];
|
|
17
|
+
static args = {
|
|
18
|
+
name: Args.string({ required: true, description: 'Workflow definition name.' }),
|
|
19
|
+
};
|
|
20
|
+
static flags = {
|
|
21
|
+
...deploymentFlags,
|
|
22
|
+
version: Flags.integer({ description: 'Deployed version to diff against (default: latest).' }),
|
|
23
|
+
};
|
|
24
|
+
async run() {
|
|
25
|
+
const { args, flags } = await this.parse(DefinitionDiff);
|
|
26
|
+
const { deployment, client } = await resolveContext(flags);
|
|
27
|
+
const def = selectDefinitionToDiff(deployment.definitions, args.name);
|
|
28
|
+
const target = deploymentToTarget(acknowledgeDeployment(deployment, [def]));
|
|
29
|
+
const spinner = ora(`Diffing ${args.name} against deployed…`).start();
|
|
30
|
+
let deployed;
|
|
31
|
+
try {
|
|
32
|
+
deployed = await fetchDeployedDefinition({
|
|
33
|
+
client,
|
|
34
|
+
name: args.name,
|
|
35
|
+
partition: target.partition,
|
|
36
|
+
version: flags.version,
|
|
37
|
+
});
|
|
38
|
+
spinner.succeed(`Diffed ${args.name}`);
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
spinner.fail('Diff failed');
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
for (const line of diffReport([diffEntry({ def, latestRaw: deployed, target })]))
|
|
45
|
+
this.log(line);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export function selectDefinitionToDiff(definitions, name) {
|
|
49
|
+
const [def] = selectDefinitions(definitions, { only: name });
|
|
50
|
+
if (def === undefined) {
|
|
51
|
+
throw new Error(`selectDefinitions returned no match for "${name}"`);
|
|
52
|
+
}
|
|
53
|
+
validateOrFail([def]);
|
|
54
|
+
return def;
|
|
55
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { WorkflowCommand } from '../../../lib/base-command.ts';
|
|
2
|
+
interface DefinitionListFlags {
|
|
3
|
+
partition?: string | undefined;
|
|
4
|
+
name?: string | undefined;
|
|
5
|
+
limit: number;
|
|
6
|
+
}
|
|
7
|
+
export interface DefinitionListRow {
|
|
8
|
+
_id: string;
|
|
9
|
+
name: string;
|
|
10
|
+
version: number;
|
|
11
|
+
title: string;
|
|
12
|
+
tag: string;
|
|
13
|
+
stageCount: number;
|
|
14
|
+
inFlightCount: number;
|
|
15
|
+
totalInstances: number;
|
|
16
|
+
_createdAt: string;
|
|
17
|
+
modelVersion?: number | null;
|
|
18
|
+
minReaderModel?: number | null;
|
|
19
|
+
}
|
|
20
|
+
export declare function buildDefinitionListQuery(flags: DefinitionListFlags): {
|
|
21
|
+
groq: string;
|
|
22
|
+
params: Record<string, unknown>;
|
|
23
|
+
};
|
|
24
|
+
export default class DefinitionList extends WorkflowCommand {
|
|
25
|
+
static hiddenAliases: string[];
|
|
26
|
+
static description: string;
|
|
27
|
+
static examples: string[];
|
|
28
|
+
static flags: {
|
|
29
|
+
path: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
30
|
+
'workflow-resource': import("@oclif/core/interfaces").OptionFlag<import("@sanity/workflows").WorkflowResource | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
31
|
+
'project-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
32
|
+
dataset: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
33
|
+
'media-library-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
34
|
+
deployment: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
35
|
+
partition: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
36
|
+
json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
37
|
+
limit: import("@oclif/core/interfaces").OptionFlag<number, import("@oclif/core/interfaces").CustomOptions>;
|
|
38
|
+
name: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
39
|
+
};
|
|
40
|
+
run(): Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
export declare function definitionRow(r: DefinitionListRow): {
|
|
43
|
+
name: string;
|
|
44
|
+
version: number;
|
|
45
|
+
title: string;
|
|
46
|
+
partition: string;
|
|
47
|
+
stageCount: number;
|
|
48
|
+
inFlightCount: number;
|
|
49
|
+
totalInstances: number;
|
|
50
|
+
_createdAt: string;
|
|
51
|
+
};
|
|
52
|
+
export {};
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { Flags } from '@oclif/core';
|
|
2
|
+
import { WORKFLOW_DEFINITION_TYPE, WORKFLOW_INSTANCE_TYPE, assertReadableModel, inFlightFilter, partitionScopeFilter, } from '@sanity/workflows';
|
|
3
|
+
import logSymbols from 'log-symbols';
|
|
4
|
+
import { WorkflowCommand } from '../../../lib/base-command.js';
|
|
5
|
+
import { resolveReadTargets } from '../../../lib/context.js';
|
|
6
|
+
import { jsonFlags, readFlags, resourceFlags } from '../../../lib/flags.js';
|
|
7
|
+
import { logJsonListing, runReadAcrossTargets } from '../../../lib/read-fanout.js';
|
|
8
|
+
import { logClippedTable, searchedScope } from '../../../lib/ui.js';
|
|
9
|
+
export function buildDefinitionListQuery(flags) {
|
|
10
|
+
const params = { limit: flags.limit + 1 };
|
|
11
|
+
const filters = [`_type == "${WORKFLOW_DEFINITION_TYPE}"`];
|
|
12
|
+
const instanceFilters = [
|
|
13
|
+
`_type == "${WORKFLOW_INSTANCE_TYPE}"`,
|
|
14
|
+
'definition == ^.name',
|
|
15
|
+
'pinnedVersion == ^.version',
|
|
16
|
+
'tag == ^.tag',
|
|
17
|
+
];
|
|
18
|
+
if (flags.partition) {
|
|
19
|
+
params.tag = flags.partition;
|
|
20
|
+
filters.push(partitionScopeFilter());
|
|
21
|
+
}
|
|
22
|
+
if (flags.name) {
|
|
23
|
+
params.name = flags.name;
|
|
24
|
+
filters.push('name == $name');
|
|
25
|
+
}
|
|
26
|
+
const instanceMatch = instanceFilters.join(' && ');
|
|
27
|
+
const groq = `*[${filters.join(' && ')}] | order(name asc, version desc) [0...$limit]{
|
|
28
|
+
_id,
|
|
29
|
+
name,
|
|
30
|
+
version,
|
|
31
|
+
title,
|
|
32
|
+
tag,
|
|
33
|
+
_createdAt,
|
|
34
|
+
modelVersion,
|
|
35
|
+
minReaderModel,
|
|
36
|
+
"stageCount": count(stages),
|
|
37
|
+
"inFlightCount": count(*[${instanceMatch} && ${inFlightFilter()}]),
|
|
38
|
+
"totalInstances": count(*[${instanceMatch}])
|
|
39
|
+
}`;
|
|
40
|
+
return { groq, params };
|
|
41
|
+
}
|
|
42
|
+
export default class DefinitionList extends WorkflowCommand {
|
|
43
|
+
static hiddenAliases = ['workflows:definition:list'];
|
|
44
|
+
static description = 'List deployed workflow definitions.';
|
|
45
|
+
static examples = [
|
|
46
|
+
'<%= config.bin %> workflows definitions list',
|
|
47
|
+
'<%= config.bin %> workflows definitions list --partition prod',
|
|
48
|
+
'<%= config.bin %> workflows definitions list --json',
|
|
49
|
+
];
|
|
50
|
+
static flags = {
|
|
51
|
+
...readFlags,
|
|
52
|
+
...resourceFlags,
|
|
53
|
+
limit: Flags.integer({
|
|
54
|
+
description: 'The maximum number of definitions to return.',
|
|
55
|
+
default: 100,
|
|
56
|
+
}),
|
|
57
|
+
name: Flags.string({
|
|
58
|
+
description: 'Filter to a single workflow definition name (e.g. product-launch).',
|
|
59
|
+
}),
|
|
60
|
+
...jsonFlags,
|
|
61
|
+
};
|
|
62
|
+
async run() {
|
|
63
|
+
const { flags } = await this.parse(DefinitionList);
|
|
64
|
+
const { targets, partition } = await resolveReadTargets(flags);
|
|
65
|
+
const { groq, params } = buildDefinitionListQuery({ ...flags, partition });
|
|
66
|
+
if (flags.json) {
|
|
67
|
+
await logJsonListing({
|
|
68
|
+
targets,
|
|
69
|
+
key: 'definitions',
|
|
70
|
+
limit: flags.limit,
|
|
71
|
+
log: (line) => this.log(line),
|
|
72
|
+
fetch: ({ client }) => fetchDefinitionRows({ client, groq, params, limit: flags.limit }),
|
|
73
|
+
toRow: definitionRow,
|
|
74
|
+
});
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const failures = await runReadAcrossTargets({
|
|
78
|
+
targets,
|
|
79
|
+
log: (line) => this.log(line),
|
|
80
|
+
run: async ({ client, resource }) => {
|
|
81
|
+
const fetched = await fetchDefinitionRows({ client, groq, params, limit: flags.limit });
|
|
82
|
+
if (!fetched.rows.length) {
|
|
83
|
+
const scope = searchedScope({
|
|
84
|
+
partition,
|
|
85
|
+
resources: [resource],
|
|
86
|
+
deployment: flags.deployment,
|
|
87
|
+
});
|
|
88
|
+
this.log(`${logSymbols.info} no definitions ${scope}`);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
logClippedTable({
|
|
92
|
+
rows: fetched.rows,
|
|
93
|
+
limit: flags.limit,
|
|
94
|
+
headers: [
|
|
95
|
+
'workflow',
|
|
96
|
+
'title',
|
|
97
|
+
'partition',
|
|
98
|
+
'stages',
|
|
99
|
+
'in flight',
|
|
100
|
+
'instances',
|
|
101
|
+
'created',
|
|
102
|
+
],
|
|
103
|
+
toCells: (r) => {
|
|
104
|
+
const row = definitionRow(r);
|
|
105
|
+
return [
|
|
106
|
+
`${row.name} v${row.version}`,
|
|
107
|
+
row.title,
|
|
108
|
+
row.partition,
|
|
109
|
+
String(row.stageCount),
|
|
110
|
+
String(row.inFlightCount),
|
|
111
|
+
String(row.totalInstances),
|
|
112
|
+
row._createdAt,
|
|
113
|
+
];
|
|
114
|
+
},
|
|
115
|
+
log: (line) => this.log(line),
|
|
116
|
+
});
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
if (failures.length > 0) {
|
|
120
|
+
this.exit(1);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
export function definitionRow(r) {
|
|
125
|
+
return {
|
|
126
|
+
name: r.name,
|
|
127
|
+
version: r.version,
|
|
128
|
+
title: r.title,
|
|
129
|
+
partition: r.tag,
|
|
130
|
+
stageCount: r.stageCount,
|
|
131
|
+
inFlightCount: r.inFlightCount,
|
|
132
|
+
totalInstances: r.totalInstances,
|
|
133
|
+
_createdAt: r._createdAt,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
async function fetchDefinitionRows({ client, groq, params, limit, }) {
|
|
137
|
+
const rows = await client.fetch(groq, params, { tag: 'definition.list' });
|
|
138
|
+
return { rows: rows.map(assertReadableModel), hasMore: rows.length > limit };
|
|
139
|
+
}
|