@revoengine/cli 1.0.16 → 1.0.18

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.
@@ -89,6 +89,7 @@ export declare function buildJobTemplatesPlan(input: {
89
89
  stableKeyName: string;
90
90
  projectedComponents?: ProjectedComponentDependency[];
91
91
  projectedServiceAccounts?: string[];
92
+ pruneBeforeUpsertIds?: readonly string[];
92
93
  }): Promise<JobTemplatesPlan>;
93
94
  export declare function pullJobTemplatesToWorkspace(input: {
94
95
  client: RevoClient;
@@ -328,6 +328,33 @@ export async function buildJobTemplatesPlan(input) {
328
328
  localByKey.set(entry.manifest.stableKey, [...(localByKey.get(entry.manifest.stableKey) || []), entry]);
329
329
  }
330
330
  const targetRecordsByKey = new Map();
331
+ const targetRecordsByName = new Map();
332
+ for (const record of targetRecords) {
333
+ if (typeof record.name !== 'string')
334
+ continue;
335
+ const matches = targetRecordsByName.get(record.name) || [];
336
+ matches.push(record);
337
+ targetRecordsByName.set(record.name, matches);
338
+ }
339
+ const nameCollisionKeys = new Set();
340
+ const localNames = new Map();
341
+ for (const [stableKey, entries] of localByKey) {
342
+ const desired = entries[0].manifest;
343
+ const previous = localNames.get(desired.name);
344
+ if (previous && previous !== stableKey) {
345
+ blockers.push(`Duplicate local job-template name "${desired.name}" for "${previous}" and "${stableKey}".`);
346
+ nameCollisionKeys.add(previous);
347
+ nameCollisionKeys.add(stableKey);
348
+ }
349
+ localNames.set(desired.name, stableKey);
350
+ for (const record of targetRecordsByName.get(desired.name) || []) {
351
+ if (readConfiguredResourceMetadataStableKey(record, input.stableKeyName) === stableKey
352
+ || input.pruneBeforeUpsertIds?.includes(jobTemplateIdOf(record)))
353
+ continue;
354
+ blockers.push(`Job-template name "${desired.name}" is already used by target "${jobTemplateIdOf(record)}" with a different or missing Stable Key; review its identity or an explicit workspace prune.`);
355
+ nameCollisionKeys.add(stableKey);
356
+ }
357
+ }
331
358
  for (const record of targetRecords) {
332
359
  const stableKey = readConfiguredResourceMetadataStableKey(record, input.stableKeyName);
333
360
  if (!stableKey) {
@@ -387,6 +414,10 @@ export async function buildJobTemplatesPlan(input) {
387
414
  continue;
388
415
  }
389
416
  const desired = entries[0].manifest;
417
+ if (nameCollisionKeys.has(stableKeyIdentity)) {
418
+ items.push({ status: 'collision', stableKey: desired.stableKey, name: desired.name, reason: 'job-template name is already in use' });
419
+ continue;
420
+ }
390
421
  const lockEntry = lockEntriesByKey.get(stableKeyIdentity);
391
422
  if (!desired.executionPrincipal && (desired.migration?.executionPrincipal === 'excluded' || lockEntry?.migration?.executionPrincipal === 'excluded')) {
392
423
  warnings.push(`Job template "${desired.stableKey}": execution principal excluded; manual target execution principal configuration is required.`);
@@ -132,7 +132,6 @@ export function printSyncPlan(println, input) {
132
132
  for (const item of input.items) {
133
133
  const mark = PLAN_STATUS_MARKS[item.status] || { symbol: '-', code: ANSI.dim };
134
134
  const target = item.target || item.stableKey || item.name || 'unknown';
135
- println(`${paint(mark.symbol, mark.code)} ${paint(item.status.padEnd(14), mark.code)} ${paint(target, ANSI.cyan)}`);
136
135
  const lineDiffFields = new Set((item.details || []).filter((detail) => detail.label === 'rawQuery diff' && detail.lines?.length)
137
136
  .map(() => 'rawQuery'));
138
137
  const fieldChanges = item.status === 'create'
@@ -156,6 +155,13 @@ export function printSyncPlan(println, input) {
156
155
  ...(item.details || []),
157
156
  ...(input.showHints === true ? item.hints || [] : []),
158
157
  ];
158
+ const inlineDetails = details.filter((detail) => detail.label !== 'reason'
159
+ && (detail.label !== 'hints' || input.showHints === true) && !detail.lines?.length && !detail.diffs?.length)
160
+ .map((detail) => {
161
+ const value = planDetailValue(detail.values).replace(/\s+/g, ' ').trim();
162
+ return value ? `${detail.label.replace(/\s+/g, ' ')}: ${value}` : '';
163
+ }).filter(Boolean);
164
+ println(`${paint(mark.symbol, mark.code)} ${paint(item.status.padEnd(14), mark.code)} ${paint(target.replace(/\s+/g, ' '), ANSI.cyan)}${inlineDetails.length ? ` | ${inlineDetails.join(' | ')}` : ''}`);
159
165
  for (const detail of details) {
160
166
  if (detail.label === 'reason') {
161
167
  continue;
@@ -179,10 +185,6 @@ export function printSyncPlan(println, input) {
179
185
  }
180
186
  continue;
181
187
  }
182
- const value = planDetailValue(detail.values);
183
- if (value) {
184
- println(` ${paint(detail.label.padEnd(14), ANSI.dim)} ${value}`);
185
- }
186
188
  }
187
189
  }
188
190
  const summary = Object.entries(input.counts)
package/dist/src/ui.js CHANGED
@@ -175,8 +175,8 @@ function renderCommandCatalog() {
175
175
  commandRow('revo metadata apply [--project <name>] --yes [--skip-partitions]', 'Populate missing stable-key metadata'),
176
176
  commandRow('revo pull --all|--resources <list> --yes [--skip-groups] [--force] [--json]', 'Build the repository workspace from the configured runtime source'),
177
177
  commandRow('revo diff [--json]', 'Show only workspace-to-target resource differences without writes'),
178
- commandRow('revo plan [--force] [--strict] [--json] [--hints]', 'Plan deployment of tracked workspace resources to the configured runtime target without writes'),
179
- commandRow('revo deploy --yes [--force] [--json]', 'Deploy tracked workspace resources to the configured runtime target in dependency order'),
178
+ commandRow('revo plan [--prune] [--out file] [--force] [--strict] [--json] [--hints]', 'Plan tracked workspace upserts and optional Stable Key deletions without writes'),
179
+ commandRow('revo deploy [--yes] [--prune] [--reviewed-plan file] [--force] [--json]', 'Review, confirm, deploy and prune tracked resources in dependency order'),
180
180
  commandRow('revo migrate plan --from <env> --to <env> [--resources <list>] [--skip-groups] [--force] [--json] [--hints]', 'Preview ten resource families and identity dependencies'),
181
181
  commandRow('revo migrate run --from <env> --to <env> [--resources <list>] [--skip-groups] --yes [--force] [--json]', 'Pull, plan, migrate, and verify resources in dependency order'),
182
182
  commandRow('revo migrate verify --from <env> --to <env> [--resources <list>] [--json]', 'Verify target resources against a fresh temporary source pull'),
@@ -0,0 +1,42 @@
1
+ import type { RevoClient } from './client.ts';
2
+ import { type ResourceRecord } from './resource-inventory.ts';
3
+ import type { WorkspaceSyncResult } from './sync-output.ts';
4
+ import type { TrackableResourceType } from './tracked-resources.ts';
5
+ export type WorkspacePruneItem = {
6
+ resource: TrackableResourceType;
7
+ stableKey: string;
8
+ targetId: string;
9
+ name: string;
10
+ version: number | null;
11
+ targetHash: string;
12
+ beforeUpserts?: true;
13
+ };
14
+ export type WorkspacePrunePlan = {
15
+ items: WorkspacePruneItem[];
16
+ blockers: string[];
17
+ };
18
+ type Inventory = Partial<Record<TrackableResourceType, ResourceRecord[]>>;
19
+ type LocalManifests = Partial<Record<TrackableResourceType, Map<string, Record<string, unknown>>>>;
20
+ export declare function readPruneManifests(cwd: string, resources: readonly TrackableResourceType[]): LocalManifests;
21
+ export declare function planWorkspacePrune(input: {
22
+ resources: readonly TrackableResourceType[];
23
+ inventory: Inventory;
24
+ local: LocalManifests;
25
+ stableKeyName: string;
26
+ actorId?: string;
27
+ }): WorkspacePrunePlan;
28
+ export declare function buildWorkspacePrunePlan(input: {
29
+ cwd: string;
30
+ client: RevoClient;
31
+ resources: readonly TrackableResourceType[];
32
+ }): Promise<WorkspacePrunePlan>;
33
+ export declare function samePrunePlan(left: WorkspacePrunePlan, right: WorkspacePrunePlan): boolean;
34
+ export declare function applyWorkspacePrune(input: {
35
+ cwd: string;
36
+ client: RevoClient;
37
+ resources: readonly TrackableResourceType[];
38
+ envName: string;
39
+ plan: WorkspacePrunePlan;
40
+ beforeUpsertsOnly?: boolean;
41
+ }): Promise<WorkspaceSyncResult[]>;
42
+ export {};
@@ -0,0 +1,416 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { hashStable, readComponentLock, removeComponentLockBaseline, writeComponentLock } from "./component-lock.js";
4
+ import { readProjectStableKeyName } from "./project.js";
5
+ import { readResourceInventory, resourceIdOf } from "./resource-inventory.js";
6
+ import { normalizeStableKeyValue, readConfiguredResourceMetadataStableKey } from "./resource-metadata.js";
7
+ import { findManifestFiles, isRecord, requireProjectLayout } from "./resource-syncs/util.js";
8
+ const manifests = {
9
+ component: ['Components', 'component.json'],
10
+ 'job-template': ['JobTemplates', 'job-template.json'],
11
+ endpoint: ['Endpoints', 'endpoint.json'],
12
+ schedule: ['Schedules', 'schedule.json'],
13
+ event: ['Events', 'event.json'],
14
+ 'database-table': ['DatabaseTables', 'database-table.json'],
15
+ 'database-view': ['DatabaseViews', 'database-view.json'],
16
+ group: ['Groups', 'group.json'],
17
+ 'role-group': ['RoleGroups', 'role-group.json'],
18
+ 'service-account': ['ServiceAccounts', 'service-account.json'],
19
+ };
20
+ const deletionOrder = [
21
+ 'event', 'schedule', 'endpoint', 'job-template', 'component',
22
+ 'database-view', 'database-table', 'role-group', 'service-account', 'group',
23
+ ];
24
+ function key(resource, identity) {
25
+ return `${resource}:${normalizeStableKeyValue(identity)}`;
26
+ }
27
+ function active(record) {
28
+ return !record.deletedAt && !record.deletedBy;
29
+ }
30
+ export function readPruneManifests(cwd, resources) {
31
+ const { workspaceRoot } = requireProjectLayout(cwd, 'Workspace prune');
32
+ const stableKeyName = readProjectStableKeyName(cwd);
33
+ const result = {};
34
+ for (const resource of resources) {
35
+ const [directory, file] = manifests[resource];
36
+ const files = findManifestFiles(path.join(workspaceRoot, directory), file);
37
+ if (resource === 'database-table') {
38
+ files.push(...findManifestFiles(path.join(workspaceRoot, 'DatabaseSchemas'), 'database-schema.json'));
39
+ }
40
+ const entries = new Map();
41
+ for (const filename of files) {
42
+ const manifest = JSON.parse(fs.readFileSync(filename, 'utf8'));
43
+ if (!isRecord(manifest))
44
+ throw new Error(`Invalid prune manifest: ${filename}.`);
45
+ const stableKey = resource === 'component'
46
+ ? readConfiguredResourceMetadataStableKey(manifest, stableKeyName)
47
+ : typeof manifest.stableKey === 'string' ? manifest.stableKey : null;
48
+ if (!stableKey)
49
+ continue;
50
+ const identity = normalizeStableKeyValue(stableKey);
51
+ if (!identity)
52
+ throw new Error(`Empty Stable Key in ${filename}.`);
53
+ if (entries.has(identity))
54
+ throw new Error(`Duplicate local ${resource} Stable Key "${stableKey}"; prune blocked.`);
55
+ entries.set(identity, manifest);
56
+ }
57
+ result[resource] = entries;
58
+ }
59
+ return result;
60
+ }
61
+ function localReferences(resource, manifest) {
62
+ const refs = [];
63
+ const add = (family, value) => {
64
+ if (typeof value === 'string' && value)
65
+ refs.push({ resource: family, identity: value });
66
+ };
67
+ if (resource === 'job-template' && isRecord(manifest.component))
68
+ add('component', manifest.component.stableKey);
69
+ if (resource === 'endpoint') {
70
+ for (const binding of [manifest.execution, manifest.schema]) {
71
+ if (isRecord(binding))
72
+ add('component', binding.stableKey);
73
+ }
74
+ }
75
+ if ((resource === 'event' || resource === 'schedule') && isRecord(manifest.target)) {
76
+ add('job-template', manifest.target.jobTemplateStableKey);
77
+ add('database-view', manifest.target.databaseViewStableKey);
78
+ }
79
+ if (resource === 'database-view' && Array.isArray(manifest.sources)) {
80
+ for (const source of manifest.sources)
81
+ if (isRecord(source))
82
+ add('database-table', source.databaseStableKey);
83
+ }
84
+ if (resource === 'database-table')
85
+ add('database-table', manifest.parentStableKey);
86
+ if (isRecord(manifest.owner)) {
87
+ if (manifest.owner.type === 'group')
88
+ add('group', manifest.owner.stableKey);
89
+ if (manifest.owner.type === 'service-account')
90
+ add('service-account', manifest.owner.stableKey);
91
+ }
92
+ if (isRecord(manifest.executionPrincipal))
93
+ add('service-account', manifest.executionPrincipal.stableKey);
94
+ return refs;
95
+ }
96
+ function remoteReferences(resource, record, tables) {
97
+ const refs = [];
98
+ const add = (family, value) => {
99
+ if (typeof value === 'string' && value)
100
+ refs.push({ resource: family, identity: value });
101
+ };
102
+ if (resource === 'job-template' || resource === 'endpoint')
103
+ add('component', record.componentId);
104
+ if (resource === 'endpoint' && isRecord(record.options))
105
+ add('component', record.options.componentSchemaId);
106
+ if (resource === 'job-template')
107
+ add('service-account', record.triggerUser);
108
+ if (resource === 'schedule' || resource === 'event') {
109
+ add(record.targetType === 'JOB_TEMPLATE' ? 'job-template' : 'database-view', record.targetId);
110
+ }
111
+ if (resource === 'database-view' && Array.isArray(record.sourceDatabaseIds)) {
112
+ for (const id of record.sourceDatabaseIds)
113
+ add('database-table', id);
114
+ }
115
+ if (resource === 'database-table') {
116
+ add('database-table', record.parentDatabaseId || record.parentId);
117
+ if (isRecord(record.parent))
118
+ add('database-table', record.parent.databaseId || record.parent.id);
119
+ const name = typeof record.parent === 'string' ? record.parent : isRecord(record.parent) ? record.parent.name : undefined;
120
+ if (typeof name === 'string') {
121
+ // The API can return a partition parent by physical name rather than ID.
122
+ // Include every matching parent; ambiguity must not hide a dependency.
123
+ for (const table of tables)
124
+ if (table.name === name)
125
+ add('database-table', resourceIdOf(table));
126
+ }
127
+ }
128
+ if (record.ownerType === 'GROUP')
129
+ add('group', record.ownerId);
130
+ if (record.ownerType === 'USER')
131
+ add('service-account', record.ownerId);
132
+ return refs;
133
+ }
134
+ function resourceHash(record) {
135
+ // Definition/version changes fence deletion. Audit timestamps, counts and activity
136
+ // can change while upserts run without changing the definition being reviewed.
137
+ const { lastUpdateAt, lastUpdateBy, createdAt, createdBy, memberCount, ...definition } = record;
138
+ return hashStable(definition);
139
+ }
140
+ export function planWorkspacePrune(input) {
141
+ const blockers = [];
142
+ const candidates = new Map();
143
+ const byId = new Map();
144
+ for (const [family, records] of Object.entries(input.inventory)) {
145
+ const resource = family;
146
+ const keys = new Set();
147
+ for (const record of records || []) {
148
+ if (!active(record))
149
+ continue;
150
+ const id = resourceIdOf(record);
151
+ if (!id)
152
+ throw new Error(`Invalid ${resource} inventory: missing target ID.`);
153
+ if (byId.has(key(resource, id)))
154
+ throw new Error(`Repeated ${resource} target ID "${id}".`);
155
+ const stableKey = readConfiguredResourceMetadataStableKey(record, input.stableKeyName);
156
+ byId.set(key(resource, id), { resource, record, stableKey });
157
+ if (!stableKey)
158
+ continue;
159
+ const identity = normalizeStableKeyValue(stableKey);
160
+ if (keys.has(identity))
161
+ blockers.push(`Duplicate target ${resource} Stable Key "${stableKey}"; prune blocked.`);
162
+ keys.add(identity);
163
+ if (!input.resources.includes(resource) || input.local[resource]?.has(identity))
164
+ continue;
165
+ if (resource === 'service-account' && (record.serviceAccount !== true || id === input.actorId)) {
166
+ blockers.push(`Cannot prune the authenticated account or a human account "${stableKey}".`);
167
+ }
168
+ if (resource === 'service-account' && !input.actorId)
169
+ blockers.push('Cannot determine authenticated account identity; service-account prune blocked.');
170
+ if (record.systemManaged === true || record.system === true) {
171
+ blockers.push(`Cannot prune system-managed ${resource} "${stableKey}".`);
172
+ }
173
+ if (resource === 'component' && [...(input.local.component?.values() || [])].some((manifest) => manifest.componentId === id || manifest.id === id)) {
174
+ blockers.push(`Local component still has target ID "${id}"; prune blocked.`);
175
+ }
176
+ candidates.set(key(resource, id), {
177
+ resource, stableKey, targetId: id, name: String(record.name || stableKey),
178
+ version: typeof record.version === 'number' ? record.version : null,
179
+ targetHash: resourceHash(record),
180
+ });
181
+ }
182
+ }
183
+ const removedKeys = new Set([...candidates.values()].map((item) => key(item.resource, item.stableKey)));
184
+ for (const [family, entries] of Object.entries(input.local)) {
185
+ for (const [identity, manifest] of entries || []) {
186
+ for (const reference of localReferences(family, manifest)) {
187
+ if (removedKeys.has(key(reference.resource, reference.identity))) {
188
+ blockers.push(`Retained ${family} "${identity}" references ${reference.resource} "${reference.identity}" planned for deletion.`);
189
+ }
190
+ }
191
+ }
192
+ }
193
+ const dependencies = new Map();
194
+ const consumers = new Map();
195
+ for (const [idKey, target] of byId) {
196
+ for (const reference of remoteReferences(target.resource, target.record, input.inventory['database-table'] || [])) {
197
+ const referenced = key(reference.resource, reference.identity);
198
+ if (!candidates.has(referenced))
199
+ continue;
200
+ const usages = consumers.get(referenced) || new Set();
201
+ usages.add(idKey);
202
+ consumers.set(referenced, usages);
203
+ if (candidates.has(idKey)) {
204
+ const dependents = dependencies.get(referenced) || new Set();
205
+ dependents.add(idKey);
206
+ dependencies.set(referenced, dependents);
207
+ }
208
+ else {
209
+ const desired = target.stableKey ? input.local[target.resource]?.get(normalizeStableKeyValue(target.stableKey)) : undefined;
210
+ const removed = candidates.get(referenced);
211
+ // A managed retained consumer can release the old reference during upsert.
212
+ // An unmanaged or out-of-scope consumer must never be removed implicitly.
213
+ const preservesReference = desired && (((target.resource === 'group' || target.resource === 'service-account') && !isRecord(desired.owner))
214
+ || (target.resource === 'job-template' && removed.resource === 'service-account' && !isRecord(desired.executionPrincipal)));
215
+ if (!desired || preservesReference || localReferences(target.resource, desired).some((ref) => key(ref.resource, ref.identity) === key(removed.resource, removed.stableKey))) {
216
+ blockers.push(`${removed.resource} "${removed.stableKey}" is still referenced by retained ${target.resource} "${target.stableKey || resourceIdOf(target.record)}".`);
217
+ }
218
+ }
219
+ }
220
+ }
221
+ // Names are unique independently of Stable Key. Release only reviewed name
222
+ // conflicts and their obsolete consumers before upserts; retained consumers
223
+ // cannot detach during this phase, even if their desired manifest moves later.
224
+ const beforeUpserts = new Set();
225
+ const templatesByName = new Map();
226
+ for (const [idKey, target] of byId) {
227
+ if (target.resource !== 'job-template' || typeof target.record.name !== 'string')
228
+ continue;
229
+ const matches = templatesByName.get(target.record.name) || [];
230
+ matches.push(idKey);
231
+ templatesByName.set(target.record.name, matches);
232
+ }
233
+ for (const manifest of input.local['job-template']?.values() || []) {
234
+ if (typeof manifest.name !== 'string')
235
+ continue;
236
+ for (const idKey of templatesByName.get(manifest.name) || []) {
237
+ const target = byId.get(idKey);
238
+ if (target.stableKey === manifest.stableKey)
239
+ continue;
240
+ if (candidates.has(idKey))
241
+ beforeUpserts.add(idKey);
242
+ else
243
+ blockers.push(`Job-template name "${manifest.name}" is already used by retained or unmanaged target "${resourceIdOf(target.record)}".`);
244
+ }
245
+ }
246
+ const pending = [...beforeUpserts];
247
+ for (const idKey of pending) {
248
+ for (const consumer of consumers.get(idKey) || []) {
249
+ if (!candidates.has(consumer)) {
250
+ const target = byId.get(consumer);
251
+ blockers.push(`Cannot delete ${candidates.get(idKey).resource} "${candidates.get(idKey).stableKey}" before upserts: retained ${target.resource} "${target.stableKey || resourceIdOf(target.record)}" still references it.`);
252
+ }
253
+ else if (!beforeUpserts.has(consumer)) {
254
+ beforeUpserts.add(consumer);
255
+ pending.push(consumer);
256
+ }
257
+ }
258
+ }
259
+ for (const idKey of beforeUpserts)
260
+ candidates.get(idKey).beforeUpserts = true;
261
+ const items = [];
262
+ const remaining = new Map(candidates);
263
+ while (remaining.size) {
264
+ const next = [...remaining.entries()]
265
+ .filter(([idKey]) => ![...(dependencies.get(idKey) || [])].some((dependent) => remaining.has(dependent)))
266
+ .sort(([, left], [, right]) => deletionOrder.indexOf(left.resource) - deletionOrder.indexOf(right.resource)
267
+ || left.stableKey.localeCompare(right.stableKey))[0];
268
+ if (!next) {
269
+ blockers.push('Deletion dependency cycle; prune blocked.');
270
+ break;
271
+ }
272
+ items.push(next[1]);
273
+ remaining.delete(next[0]);
274
+ }
275
+ return { items, blockers: [...new Set(blockers)].sort() };
276
+ }
277
+ export async function buildWorkspacePrunePlan(input) {
278
+ const resources = new Set(input.resources);
279
+ // Include unmanaged and out-of-scope consumers in dependency checks.
280
+ if (resources.has('component')) {
281
+ resources.add('job-template');
282
+ resources.add('endpoint');
283
+ }
284
+ if (resources.has('job-template')) {
285
+ resources.add('event');
286
+ resources.add('schedule');
287
+ }
288
+ if (resources.has('database-table')) {
289
+ resources.add('database-view');
290
+ }
291
+ if (resources.has('database-view')) {
292
+ resources.add('event');
293
+ resources.add('schedule');
294
+ }
295
+ if (resources.has('group') || resources.has('service-account')) {
296
+ resources.add('group');
297
+ resources.add('service-account');
298
+ resources.add('job-template');
299
+ }
300
+ const local = readPruneManifests(input.cwd, input.resources);
301
+ const inventory = {};
302
+ for (const resource of resources) {
303
+ const records = [];
304
+ if (resource === 'service-account') {
305
+ // Human owners also block Group/Account deletion. Keep the client sanitization
306
+ // and sensitive-account trace redaction; never inventory credentials.
307
+ const { serviceAccounts } = await input.client.listAllServiceAccounts({ includeHumans: true });
308
+ for (const account of serviceAccounts) {
309
+ const id = resourceIdOf(account);
310
+ const detail = await input.client.getAccount(id);
311
+ if (!id || resourceIdOf(detail) !== id)
312
+ throw new Error('Incomplete account ownership inventory; prune blocked.');
313
+ records.push(detail);
314
+ }
315
+ inventory[resource] = records;
316
+ continue;
317
+ }
318
+ for await (const entry of readResourceInventory(input.client, resource)) {
319
+ if (!entry.resource || resourceIdOf(entry.resource) !== entry.listedId)
320
+ throw new Error(`Incomplete ${resource} inventory; prune blocked.`);
321
+ records.push(entry.resource);
322
+ }
323
+ inventory[resource] = records;
324
+ }
325
+ const me = resources.has('service-account') ? await input.client.me() : undefined;
326
+ const profile = isRecord(me) && isRecord(me.data) ? me.data : me;
327
+ const actorId = isRecord(profile) && isRecord(profile.user) ? String(profile.user.userId || '')
328
+ : isRecord(profile) ? String(profile.userId || '') : undefined;
329
+ return planWorkspacePrune({ resources: input.resources, local, inventory, stableKeyName: readProjectStableKeyName(input.cwd), actorId });
330
+ }
331
+ export function samePrunePlan(left, right) {
332
+ return hashStable(left) === hashStable(right);
333
+ }
334
+ function clearPruneBaseline(cwd, envName, item) {
335
+ const { projectRoot } = requireProjectLayout(cwd, 'Workspace prune');
336
+ const lock = readComponentLock(projectRoot);
337
+ if (item.resource === 'component') {
338
+ const identity = { mode: 'stableKey', metadataProperty: readProjectStableKeyName(cwd) };
339
+ const match = Object.entries(lock.components).find(([entryKey, value]) => normalizeStableKeyValue(value.stableKey || entryKey) === normalizeStableKeyValue(item.stableKey));
340
+ if (match?.[1].environments?.[envName]?.remoteComponentId === item.targetId) {
341
+ removeComponentLockBaseline(projectRoot, identity, match[0], item.targetId, envName);
342
+ }
343
+ return;
344
+ }
345
+ const fields = {
346
+ 'job-template': 'jobTemplates', endpoint: 'endpoints', schedule: 'schedules', event: 'events',
347
+ 'database-table': 'databaseSchemas', 'database-view': 'databaseViews', group: 'groups',
348
+ 'role-group': 'roleGroups', 'service-account': 'serviceAccounts',
349
+ };
350
+ const entries = lock[fields[item.resource]];
351
+ const entry = Object.values(entries).find((value) => normalizeStableKeyValue(value.stableKey) === normalizeStableKeyValue(item.stableKey));
352
+ if (entry?.environments[envName]) {
353
+ if (item.resource === 'database-table' && 'parentStableKey' in entry && entry.parentStableKey) {
354
+ lock.databaseSchemas[entry.stableKey].environments[envName] = {
355
+ remoteHash: entry.environments[envName].remoteHash,
356
+ tombstone: { deletedAt: new Date().toISOString(), parentStableKey: entry.parentStableKey },
357
+ };
358
+ }
359
+ else
360
+ delete entry.environments[envName];
361
+ writeComponentLock(projectRoot, lock);
362
+ }
363
+ }
364
+ export async function applyWorkspacePrune(input) {
365
+ if (input.plan.blockers.length)
366
+ throw new Error('Workspace prune plan is blocked.');
367
+ const results = [];
368
+ const deleted = new Set();
369
+ for (const item of input.plan.items.filter((item) => !input.beforeUpsertsOnly || item.beforeUpserts)) {
370
+ let accepted = false;
371
+ try {
372
+ if (readPruneManifests(input.cwd, input.resources)[item.resource]?.has(normalizeStableKeyValue(item.stableKey))) {
373
+ throw new Error('local manifest reappeared after planning');
374
+ }
375
+ // Early template replacement needs its event/schedule graph, including
376
+ // unmanaged and out-of-scope consumers. Avoid reloading unrelated tables,
377
+ // identities and components for every early delete. Cascades still fence
378
+ // the complete remaining plan.
379
+ if (input.beforeUpsertsOnly || item.resource === 'database-table' || item.resource === 'database-view') {
380
+ const resources = input.beforeUpsertsOnly
381
+ ? input.resources.filter((resource) => resource === 'job-template' || resource === 'event' || resource === 'schedule')
382
+ : input.resources;
383
+ const fresh = await buildWorkspacePrunePlan({ ...input, resources });
384
+ const remaining = input.plan.items.filter((candidate) => resources.includes(candidate.resource)
385
+ && !deleted.has(key(candidate.resource, candidate.targetId)));
386
+ if (!samePrunePlan({ ...input.plan, items: remaining }, fresh)) {
387
+ throw new Error('remaining deletion dependencies changed after planning');
388
+ }
389
+ }
390
+ let current;
391
+ for await (const entry of readResourceInventory(input.client, item.resource)) {
392
+ if (resourceIdOf(entry.resource) === item.targetId && active(entry.resource))
393
+ current = entry.resource;
394
+ }
395
+ if (!current || readConfiguredResourceMetadataStableKey(current, readProjectStableKeyName(input.cwd)) !== item.stableKey
396
+ || resourceHash(current) !== item.targetHash)
397
+ throw new Error('target changed after deletion was reviewed');
398
+ await input.client.deleteWorkspaceResource(item.resource, item.targetId);
399
+ accepted = true;
400
+ for await (const entry of readResourceInventory(input.client, item.resource)) {
401
+ if (resourceIdOf(entry.resource) === item.targetId && active(entry.resource))
402
+ throw new Error('delete did not remove the resource from the active catalog');
403
+ }
404
+ clearPruneBaseline(input.cwd, input.envName, item);
405
+ deleted.add(key(item.resource, item.targetId));
406
+ results.push({ status: 'pruned', targetPath: `${item.resource}:${item.stableKey}` });
407
+ }
408
+ catch (error) {
409
+ results.push({ status: accepted ? 'write-unverified' : 'failed', targetPath: `${item.resource}:${item.stableKey}`,
410
+ reason: error instanceof Error ? error.message : String(error) });
411
+ // Never continue into deletion of dependencies after a failed consumer delete.
412
+ break;
413
+ }
414
+ }
415
+ return results;
416
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@revoengine/cli",
3
- "version": "1.0.16",
3
+ "version": "1.0.18",
4
4
  "description": "CLI package for the RevoEngine Platform API",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",
@@ -11,7 +11,7 @@
11
11
  "scripts": {
12
12
  "build": "npm run clean && tsc -p tsconfig.build.json",
13
13
  "clean": "node --input-type=module -e \"import fs from 'node:fs'; fs.rmSync('dist', { recursive: true, force: true });\"",
14
- "check": "node --input-type=module -e \"await import('./src/config.ts'); await import('./src/legacy.ts'); await import('./src/http-trace.ts'); await import('./src/request-queue.ts'); await import('./src/client.ts'); await import('./src/component-lock.ts'); await import('./src/diff-details.ts'); await import('./src/resource-metadata.ts'); await import('./src/tracked-resources.ts'); await import('./src/resource-inventory.ts'); await import('./src/metadata-backfill.ts'); await import('./src/workspace-component.ts'); await import('./src/workspace-resource.ts'); await import('./src/database-table-artifacts.ts'); await import('./src/project.ts'); await import('./src/prompt.ts'); await import('./src/runtime-view.ts'); await import('./src/spinner.ts'); await import('./src/types.ts'); await import('./src/utils.ts'); await import('./src/resource-syncs/util.ts'); await import('./src/resource-syncs/database-table-sync.ts'); await import('./src/resource-syncs/database-view-sync.ts'); await import('./src/resource-syncs/endpoint-sync.ts'); await import('./src/resource-syncs/group-sync.ts'); await import('./src/resource-syncs/role-group-sync.ts'); await import('./src/resource-syncs/job-template-sync.ts'); await import('./src/resource-syncs/schedule-sync.ts'); await import('./src/resource-syncs/event-sync.ts'); await import('./src/resource-syncs/account-principal.ts'); await import('./src/resource-syncs/identity-migration.ts'); await import('./src/resource-syncs/service-account-sync.ts'); await import('./src/commands/service-accounts.ts'); await import('./src/migration.ts'); await import('./src/workspace-diff.ts'); await import('./src/sync-output.ts'); await import('./src/ui.ts'); await import('./src/update-notifier.ts'); await import('./src/env-sync.ts'); await import('./src/commands/auth.ts'); await import('./src/commands/component.ts'); await import('./src/commands/database-tables.ts'); await import('./src/commands/database-views.ts'); await import('./src/commands/endpoints.ts'); await import('./src/commands/env.ts'); await import('./src/commands/events.ts'); await import('./src/commands/groups.ts'); await import('./src/commands/info.ts'); await import('./src/commands/job-templates.ts'); await import('./src/commands/metadata.ts'); await import('./src/commands/migrate.ts'); await import('./src/commands/request.ts'); await import('./src/commands/role-groups.ts'); await import('./src/commands/search.ts'); await import('./src/commands/schedules.ts'); await import('./src/commands/terminal-service.ts'); await import('./src/commands/terminal-browser.ts'); await import('./src/commands/terminal-image.ts'); await import('./src/commands/terminal-sandbox.ts'); await import('./src/commands/terminal-patch.ts'); await import('./src/commands/terminal-patch-worker.ts'); await import('./src/commands/terminal.ts'); await import('./src/cli.ts'); await import('./src/index.ts'); await import('./bin/revo.ts'); await import('./scripts/dev.ts')\"",
14
+ "check": "node --input-type=module -e \"await import('./src/config.ts'); await import('./src/legacy.ts'); await import('./src/http-trace.ts'); await import('./src/request-queue.ts'); await import('./src/client.ts'); await import('./src/component-lock.ts'); await import('./src/diff-details.ts'); await import('./src/resource-metadata.ts'); await import('./src/tracked-resources.ts'); await import('./src/resource-inventory.ts'); await import('./src/metadata-backfill.ts'); await import('./src/workspace-component.ts'); await import('./src/workspace-resource.ts'); await import('./src/database-table-artifacts.ts'); await import('./src/project.ts'); await import('./src/prompt.ts'); await import('./src/runtime-view.ts'); await import('./src/spinner.ts'); await import('./src/types.ts'); await import('./src/utils.ts'); await import('./src/resource-syncs/util.ts'); await import('./src/resource-syncs/database-table-sync.ts'); await import('./src/resource-syncs/database-view-sync.ts'); await import('./src/resource-syncs/endpoint-sync.ts'); await import('./src/resource-syncs/group-sync.ts'); await import('./src/resource-syncs/role-group-sync.ts'); await import('./src/resource-syncs/job-template-sync.ts'); await import('./src/resource-syncs/schedule-sync.ts'); await import('./src/resource-syncs/event-sync.ts'); await import('./src/resource-syncs/account-principal.ts'); await import('./src/resource-syncs/identity-migration.ts'); await import('./src/resource-syncs/service-account-sync.ts'); await import('./src/commands/service-accounts.ts'); await import('./src/migration-actions.ts'); await import('./src/migration.ts'); await import('./src/workspace-diff.ts'); await import('./src/workspace-prune.ts'); await import('./src/sync-output.ts'); await import('./src/ui.ts'); await import('./src/update-notifier.ts'); await import('./src/env-sync.ts'); await import('./src/commands/auth.ts'); await import('./src/commands/component.ts'); await import('./src/commands/database-tables.ts'); await import('./src/commands/database-views.ts'); await import('./src/commands/endpoints.ts'); await import('./src/commands/env.ts'); await import('./src/commands/events.ts'); await import('./src/commands/groups.ts'); await import('./src/commands/info.ts'); await import('./src/commands/job-templates.ts'); await import('./src/commands/metadata.ts'); await import('./src/commands/migrate.ts'); await import('./src/commands/request.ts'); await import('./src/commands/role-groups.ts'); await import('./src/commands/search.ts'); await import('./src/commands/schedules.ts'); await import('./src/commands/terminal-service.ts'); await import('./src/commands/terminal-browser.ts'); await import('./src/commands/terminal-image.ts'); await import('./src/commands/terminal-sandbox.ts'); await import('./src/commands/terminal-patch.ts'); await import('./src/commands/terminal-patch-worker.ts'); await import('./src/commands/terminal.ts'); await import('./src/cli.ts'); await import('./src/index.ts'); await import('./bin/revo.ts'); await import('./scripts/dev.ts')\"",
15
15
  "dev": "node ./scripts/dev.ts",
16
16
  "prepack": "npm run build",
17
17
  "test": "node --test ./test/*.test.ts",