@revoengine/cli 1.0.11 → 1.0.13

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.
Files changed (81) hide show
  1. package/README.md +275 -479
  2. package/dist/src/cli.js +71 -5
  3. package/dist/src/client.d.ts +28 -12
  4. package/dist/src/client.js +234 -66
  5. package/dist/src/commands/component.d.ts +67 -0
  6. package/dist/src/commands/component.js +299 -27
  7. package/dist/src/commands/database-tables.d.ts +2 -0
  8. package/dist/src/commands/{database-schemas.js → database-tables.js} +21 -40
  9. package/dist/src/commands/database-views.js +21 -18
  10. package/dist/src/commands/endpoints.js +26 -16
  11. package/dist/src/commands/events.js +18 -20
  12. package/dist/src/commands/groups.js +13 -22
  13. package/dist/src/commands/index.d.ts +2 -1
  14. package/dist/src/commands/index.js +2 -1
  15. package/dist/src/commands/job-templates.js +21 -15
  16. package/dist/src/commands/metadata.js +58 -15
  17. package/dist/src/commands/migrate.d.ts +6 -0
  18. package/dist/src/commands/migrate.js +658 -0
  19. package/dist/src/commands/project.js +4 -4
  20. package/dist/src/commands/role-groups.js +14 -25
  21. package/dist/src/commands/schedules.js +19 -20
  22. package/dist/src/commands/terminal-browser.d.ts +16 -0
  23. package/dist/src/commands/terminal-browser.js +92 -0
  24. package/dist/src/commands/terminal-image.d.ts +7 -0
  25. package/dist/src/commands/terminal-image.js +40 -0
  26. package/dist/src/commands/terminal-patch-worker.d.ts +1 -0
  27. package/dist/src/commands/terminal-patch-worker.js +24 -0
  28. package/dist/src/commands/terminal-patch.d.ts +2 -0
  29. package/dist/src/commands/terminal-patch.js +156 -0
  30. package/dist/src/commands/terminal-sandbox.d.ts +8 -0
  31. package/dist/src/commands/terminal-sandbox.js +87 -0
  32. package/dist/src/commands/terminal-service.js +2 -2
  33. package/dist/src/commands/terminal.d.ts +31 -4
  34. package/dist/src/commands/terminal.js +360 -45
  35. package/dist/src/component-lock.d.ts +12 -2
  36. package/dist/src/component-lock.js +60 -1
  37. package/dist/src/diff-details.d.ts +8 -0
  38. package/dist/src/diff-details.js +152 -0
  39. package/dist/src/env-sync.js +8 -6
  40. package/dist/src/http-trace.d.ts +94 -0
  41. package/dist/src/http-trace.js +226 -0
  42. package/dist/src/metadata-backfill.d.ts +5 -4
  43. package/dist/src/metadata-backfill.js +82 -158
  44. package/dist/src/migration.d.ts +141 -0
  45. package/dist/src/migration.js +1632 -0
  46. package/dist/src/resource-inventory.d.ts +28 -0
  47. package/dist/src/resource-inventory.js +85 -0
  48. package/dist/src/resource-syncs/{database-schema-sync.d.ts → database-table-sync.d.ts} +13 -3
  49. package/dist/src/resource-syncs/{database-schema-sync.js → database-table-sync.js} +147 -62
  50. package/dist/src/resource-syncs/database-view-sync.d.ts +24 -2
  51. package/dist/src/resource-syncs/database-view-sync.js +156 -68
  52. package/dist/src/resource-syncs/endpoint-sync.d.ts +27 -0
  53. package/dist/src/resource-syncs/endpoint-sync.js +362 -82
  54. package/dist/src/resource-syncs/event-sync.d.ts +27 -0
  55. package/dist/src/resource-syncs/event-sync.js +123 -26
  56. package/dist/src/resource-syncs/group-sync.d.ts +7 -0
  57. package/dist/src/resource-syncs/group-sync.js +60 -14
  58. package/dist/src/resource-syncs/job-template-sync.d.ts +21 -0
  59. package/dist/src/resource-syncs/job-template-sync.js +91 -30
  60. package/dist/src/resource-syncs/role-group-sync.d.ts +7 -0
  61. package/dist/src/resource-syncs/role-group-sync.js +47 -9
  62. package/dist/src/resource-syncs/schedule-sync.d.ts +30 -1
  63. package/dist/src/resource-syncs/schedule-sync.js +114 -20
  64. package/dist/src/resource-syncs/util.d.ts +3 -0
  65. package/dist/src/resource-syncs/util.js +8 -6
  66. package/dist/src/resource-target.d.ts +11 -0
  67. package/dist/src/resource-target.js +48 -0
  68. package/dist/src/sync-output.d.ts +29 -1
  69. package/dist/src/sync-output.js +139 -2
  70. package/dist/src/tracked-resources.d.ts +1 -1
  71. package/dist/src/tracked-resources.js +8 -6
  72. package/dist/src/types.d.ts +3 -0
  73. package/dist/src/ui.js +18 -9
  74. package/dist/src/utils.d.ts +2 -0
  75. package/dist/src/utils.js +17 -0
  76. package/dist/src/workspace-diff.d.ts +25 -0
  77. package/dist/src/workspace-diff.js +75 -0
  78. package/package.json +9 -6
  79. package/dist/src/commands/database-schemas.d.ts +0 -2
  80. /package/dist/src/{database-schema-artifacts.d.ts → database-table-artifacts.d.ts} +0 -0
  81. /package/dist/src/{database-schema-artifacts.js → database-table-artifacts.js} +0 -0
@@ -1,14 +1,15 @@
1
+ import { type ResourceRecord as MetadataResourceRecord } from './resource-inventory.ts';
1
2
  import type { RevoClient } from './client.ts';
2
- import { type TrackedResource } from './tracked-resources.ts';
3
- import type { ComponentRecord, DatabaseSchemaRecord, DatabaseViewRecord, EndpointRecord, EventRecord, GroupRecord, JobTemplateRecord, RoleGroupRecord, ScheduleRecord } from './types.ts';
3
+ import { type TrackableResourceType, type TrackedResource } from './tracked-resources.ts';
4
4
  export type MetadataBackfillAction = 'update' | 'skip' | 'blocked' | 'failed';
5
- type MetadataBackfillResourceType = 'component' | 'endpoint' | 'group' | 'role-group' | 'job-template' | 'schedule' | 'event' | 'database-schema' | 'database-view';
6
- type MetadataResourceRecord = ComponentRecord | DatabaseSchemaRecord | DatabaseViewRecord | EndpointRecord | GroupRecord | RoleGroupRecord | JobTemplateRecord | ScheduleRecord | EventRecord;
5
+ type MetadataBackfillResourceType = TrackableResourceType;
7
6
  export type MetadataBackfillPlanItem = {
8
7
  resourceType: MetadataBackfillResourceType;
8
+ resourceKind?: 'resource' | 'database-partition' | 'database-column';
9
9
  resourceId: string;
10
10
  name: string;
11
11
  category: string | null;
12
+ parentName?: string;
12
13
  action: Exclude<MetadataBackfillAction, 'failed'>;
13
14
  metadataField: 'metadata' | 'definition[].metadata';
14
15
  stableKeyName: string;
@@ -1,30 +1,11 @@
1
1
  import { randomBytes } from 'node:crypto';
2
- import { isDatabaseBackupArtifact } from "./database-schema-artifacts.js";
2
+ import { readResourceInventory, resourceIdOf, unwrapResource, } from "./resource-inventory.js";
3
+ import { isDatabaseBackupArtifact } from "./database-table-artifacts.js";
3
4
  import { buildStableKey, buildResourceIdentityStableKeyValue, normalizeStableKeyValue, readConfiguredResourceMetadataStableKey, sanitizeUserMetadata, } from "./resource-metadata.js";
4
5
  import { shouldTrackResource } from "./tracked-resources.js";
5
6
  function isRecord(value) {
6
7
  return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
7
8
  }
8
- function unwrapResource(value) {
9
- if (isRecord(value) && isRecord(value.data)) {
10
- return value.data;
11
- }
12
- return value;
13
- }
14
- function resourceIdOf(resource) {
15
- return String(('databaseId' in resource && resource.databaseId)
16
- || ('databaseViewId' in resource && resource.databaseViewId)
17
- || ('jobTemplateId' in resource && resource.jobTemplateId)
18
- || ('endpointId' in resource && resource.endpointId)
19
- || ('scheduleId' in resource && resource.scheduleId)
20
- || ('jobEventId' in resource && resource.jobEventId)
21
- || ('eventId' in resource && resource.eventId)
22
- || ('groupId' in resource && resource.groupId)
23
- || resource.componentId
24
- || resource.roleGroupId
25
- || resource.id
26
- || '');
27
- }
28
9
  function normalizeValue(value, fallback = null) {
29
10
  return value ?? fallback;
30
11
  }
@@ -148,6 +129,9 @@ function groupMetadataBackfillReason(group, existingStableKey, force) {
148
129
  }
149
130
  return `${baseReason}; backend-reserved metadata keys excluded: ${[...reservedKeys].sort((left, right) => left.localeCompare(right)).join(', ')}`;
150
131
  }
132
+ function groupExclusionReason(group) {
133
+ return group.deletedAt || group.deletedBy ? 'deleted group is excluded' : null;
134
+ }
151
135
  function waitForMutationSlot() {
152
136
  return new Promise((resolve) => setTimeout(resolve, 100));
153
137
  }
@@ -285,14 +269,11 @@ export async function buildMetadataBackfillPlan(input) {
285
269
  const { client, envName, stableKeyName, trackedResources, force = false, skipPartitions = false } = input;
286
270
  const items = [];
287
271
  if (shouldTrackResource(trackedResources, 'component')) {
288
- const { components } = await client.listAllComponents();
289
- for (const summary of components) {
290
- const summaryId = resourceIdOf(summary);
291
- if (!summaryId) {
272
+ for await (const { listedId, resource: component } of readResourceInventory(client, 'component')) {
273
+ if (!listedId) {
292
274
  continue;
293
275
  }
294
- const component = unwrapResource(await client.getComponent(summaryId));
295
- const resourceId = resourceIdOf(component) || summaryId;
276
+ const resourceId = resourceIdOf(component) || listedId;
296
277
  const existingStableKey = readConfiguredResourceMetadataStableKey(component, stableKeyName);
297
278
  const stableKey = existingStableKey && !force
298
279
  ? undefined
@@ -313,9 +294,8 @@ export async function buildMetadataBackfillPlan(input) {
313
294
  });
314
295
  }
315
296
  }
316
- if (shouldTrackResource(trackedResources, 'database-schema') && typeof client.listAllDatabaseSchemas === 'function') {
317
- const { databases } = await client.listAllDatabaseSchemas({ projection: 'pull', skipPartitions });
318
- for (const database of databases) {
297
+ if (shouldTrackResource(trackedResources, 'database-table') && typeof client.listAllDatabaseSchemas === 'function') {
298
+ for await (const { resource: database } of readResourceInventory(client, 'database-table', { skipPartitions })) {
319
299
  if (isDatabaseBackupArtifact(database)) {
320
300
  continue;
321
301
  }
@@ -325,12 +305,20 @@ export async function buildMetadataBackfillPlan(input) {
325
305
  }
326
306
  const category = normalizeValue(database.category);
327
307
  const name = String(database.name || '');
308
+ const partition = isDatabaseSchemaPartition(database);
309
+ const parentName = typeof database.parent === 'string' && database.parent.trim()
310
+ ? database.parent.trim()
311
+ : typeof database.parentId === 'string' && database.parentId.trim()
312
+ ? database.parentId.trim()
313
+ : undefined;
328
314
  const rawStableKey = rawConfiguredStableKey(database, stableKeyName);
329
315
  const invalidDatabaseStableKey = rawStableKey.present && (typeof rawStableKey.value !== 'string' || !rawStableKey.value.trim());
330
316
  if (invalidDatabaseStableKey) {
331
- const reason = `Invalid database-schema stableKey on ${resourceId}: metadata.${stableKeyName} must be a non-empty string.`;
317
+ const reason = `Invalid database-table stableKey on ${resourceId}: metadata.${stableKeyName} must be a non-empty string.`;
332
318
  items.push({
333
- resourceType: 'database-schema', resourceId, name, category, action: 'blocked',
319
+ resourceType: 'database-table', resourceId, name, category, action: 'blocked',
320
+ resourceKind: partition ? 'database-partition' : 'resource',
321
+ ...(parentName ? { parentName } : {}),
334
322
  metadataField: 'metadata', stableKeyName, reason,
335
323
  });
336
324
  }
@@ -338,13 +326,15 @@ export async function buildMetadataBackfillPlan(input) {
338
326
  const existingStableKey = readConfiguredResourceMetadataStableKey(database, stableKeyName);
339
327
  const stableKey = existingStableKey || buildNamedResourceGeneratedStableKey(database);
340
328
  items.push({
341
- resourceType: 'database-schema', resourceId, name, category,
329
+ resourceType: 'database-table', resourceId, name, category,
330
+ resourceKind: partition ? 'database-partition' : 'resource',
331
+ ...(parentName ? { parentName } : {}),
342
332
  action: existingStableKey ? 'skip' : 'update', metadataField: 'metadata', stableKeyName,
343
333
  stableKey,
344
334
  reason: existingStableKey ? 'stable key already exists' : 'assign-stable-key',
345
335
  });
346
336
  }
347
- if (isDatabaseSchemaPartition(database)) {
337
+ if (partition) {
348
338
  continue;
349
339
  }
350
340
  const definitions = databaseDefinitions(database);
@@ -411,7 +401,8 @@ export async function buildMetadataBackfillPlan(input) {
411
401
  ? 'column stable key already exists'
412
402
  : 'assign-column-stable-key';
413
403
  items.push({
414
- resourceType: 'database-schema',
404
+ resourceType: 'database-table',
405
+ resourceKind: 'database-column',
415
406
  resourceId,
416
407
  name: `${name}.${columnName || '<unnamed>'}`,
417
408
  category,
@@ -431,8 +422,7 @@ export async function buildMetadataBackfillPlan(input) {
431
422
  }
432
423
  }
433
424
  if (shouldTrackResource(trackedResources, 'database-view') && typeof client.listAllDatabaseViewsForSync === 'function') {
434
- const views = await client.listAllDatabaseViewsForSync();
435
- for (const view of views) {
425
+ for await (const { resource: view } of readResourceInventory(client, 'database-view')) {
436
426
  const resourceId = resourceIdOf(view);
437
427
  if (!resourceId) {
438
428
  continue;
@@ -461,14 +451,11 @@ export async function buildMetadataBackfillPlan(input) {
461
451
  }
462
452
  }
463
453
  if (shouldTrackResource(trackedResources, 'endpoint') && typeof client.listAllEndpoints === 'function') {
464
- const { endpoints } = await client.listAllEndpoints();
465
- for (const summary of endpoints) {
466
- const summaryId = resourceIdOf(summary);
467
- if (!summaryId) {
454
+ for await (const { listedId, resource: endpoint } of readResourceInventory(client, 'endpoint')) {
455
+ if (!listedId) {
468
456
  continue;
469
457
  }
470
- const endpoint = unwrapResource(await client.getEndpoint(summaryId));
471
- const resourceId = resourceIdOf(endpoint) || summaryId;
458
+ const resourceId = resourceIdOf(endpoint) || listedId;
472
459
  const category = normalizeValue(endpoint.category);
473
460
  const name = String(endpoint.name || '');
474
461
  const exclusionReason = endpointExclusionReason(endpoint);
@@ -499,14 +486,11 @@ export async function buildMetadataBackfillPlan(input) {
499
486
  }
500
487
  }
501
488
  if (shouldTrackResource(trackedResources, 'role-group') && typeof client.listAllRoleGroups === 'function') {
502
- const { roleGroups } = await client.listAllRoleGroups();
503
- for (const summary of roleGroups) {
504
- const summaryId = resourceIdOf(summary);
505
- if (!summaryId) {
489
+ for await (const { listedId, resource: roleGroup } of readResourceInventory(client, 'role-group')) {
490
+ if (!listedId) {
506
491
  continue;
507
492
  }
508
- const roleGroup = unwrapResource(await client.getRoleGroup(summaryId));
509
- const resourceId = resourceIdOf(roleGroup) || summaryId;
493
+ const resourceId = resourceIdOf(roleGroup) || listedId;
510
494
  const existingStableKey = readConfiguredResourceMetadataStableKey(roleGroup, stableKeyName);
511
495
  const stableKey = existingStableKey && !force
512
496
  ? undefined
@@ -528,14 +512,25 @@ export async function buildMetadataBackfillPlan(input) {
528
512
  }
529
513
  }
530
514
  if (shouldTrackResource(trackedResources, 'group') && typeof client.listAllGroups === 'function') {
531
- const { groups } = await client.listAllGroups();
532
- for (const summary of groups) {
533
- const summaryId = resourceIdOf(summary);
534
- if (!summaryId) {
515
+ for await (const { listedId, resource: group } of readResourceInventory(client, 'group')) {
516
+ if (!listedId) {
517
+ continue;
518
+ }
519
+ const resourceId = resourceIdOf(group) || listedId;
520
+ const exclusionReason = groupExclusionReason(group);
521
+ if (exclusionReason) {
522
+ items.push({
523
+ resourceType: 'group',
524
+ resourceId,
525
+ name: String(group.name || ''),
526
+ category: normalizeValue(group.category),
527
+ action: 'skip',
528
+ metadataField: 'metadata',
529
+ stableKeyName,
530
+ reason: exclusionReason,
531
+ });
535
532
  continue;
536
533
  }
537
- const group = unwrapResource(await client.getGroup(summaryId));
538
- const resourceId = resourceIdOf(group) || summaryId;
539
534
  const existingStableKey = readConfiguredResourceMetadataStableKey(group, stableKeyName);
540
535
  const stableKey = existingStableKey && !force
541
536
  ? undefined
@@ -555,13 +550,11 @@ export async function buildMetadataBackfillPlan(input) {
555
550
  }
556
551
  }
557
552
  if (shouldTrackResource(trackedResources, 'job-template') && typeof client.listAllJobTemplates === 'function') {
558
- const { jobTemplates } = await client.listAllJobTemplates();
559
- for (const summary of jobTemplates) {
560
- const summaryId = resourceIdOf(summary);
561
- if (!summaryId)
553
+ for await (const { listedId, resource: jobTemplate } of readResourceInventory(client, 'job-template')) {
554
+ if (!listedId) {
562
555
  continue;
563
- const jobTemplate = unwrapResource(await client.getJobTemplate(summaryId));
564
- const resourceId = resourceIdOf(jobTemplate) || summaryId;
556
+ }
557
+ const resourceId = resourceIdOf(jobTemplate) || listedId;
565
558
  const rawStableKey = rawConfiguredStableKey(jobTemplate, stableKeyName);
566
559
  if (rawStableKey.present && (typeof rawStableKey.value !== 'string' || !rawStableKey.value.trim())) {
567
560
  const reason = `Invalid job-template stableKey on ${resourceId}: metadata.${stableKeyName} must be a non-empty string.`;
@@ -590,14 +583,11 @@ export async function buildMetadataBackfillPlan(input) {
590
583
  }
591
584
  }
592
585
  if (shouldTrackResource(trackedResources, 'schedule') && typeof client.listAllSchedules === 'function') {
593
- const { schedules } = await client.listAllSchedules();
594
- for (const summary of schedules) {
595
- const summaryId = resourceIdOf(summary);
596
- if (!summaryId) {
586
+ for await (const { listedId, resource: schedule } of readResourceInventory(client, 'schedule')) {
587
+ if (!listedId) {
597
588
  continue;
598
589
  }
599
- const schedule = unwrapResource(await client.getSchedule(summaryId));
600
- const resourceId = resourceIdOf(schedule) || summaryId;
590
+ const resourceId = resourceIdOf(schedule) || listedId;
601
591
  const category = normalizeValue(schedule.category);
602
592
  const name = String(schedule.name || '');
603
593
  const exclusionReason = scheduleExclusionReason(schedule);
@@ -628,14 +618,11 @@ export async function buildMetadataBackfillPlan(input) {
628
618
  }
629
619
  }
630
620
  if (shouldTrackResource(trackedResources, 'event') && typeof client.listAllEvents === 'function') {
631
- const { events } = await client.listAllEvents({ includeDeleted: true });
632
- for (const summary of events) {
633
- const summaryId = resourceIdOf(summary);
634
- if (!summaryId) {
621
+ for await (const { listedId, resource: event } of readResourceInventory(client, 'event')) {
622
+ if (!listedId) {
635
623
  continue;
636
624
  }
637
- const event = unwrapResource(await client.getEvent(summaryId));
638
- const resourceId = resourceIdOf(event) || summaryId;
625
+ const resourceId = resourceIdOf(event) || listedId;
639
626
  const category = normalizeValue(event.category);
640
627
  const name = String(event.name || '');
641
628
  const exclusionReason = eventExclusionReason(event);
@@ -725,88 +712,21 @@ export async function applyMetadataBackfillPlan(input) {
725
712
  }
726
713
  const currentResources = new Map();
727
714
  const resourceTypes = new Set(plan.items.map((item) => item.resourceType));
728
- if (resourceTypes.has('component')) {
729
- const { components } = await client.listAllComponents();
730
- for (const summary of components) {
731
- const id = resourceIdOf(summary);
732
- if (id)
733
- currentResources.set(`component:${id}`, unwrapResource(await client.getComponent(id)));
715
+ const readOrder = [
716
+ 'component', 'database-table', 'database-view', 'endpoint',
717
+ 'role-group', 'group', 'job-template', 'schedule', 'event',
718
+ ];
719
+ for (const resourceType of readOrder) {
720
+ if (!resourceTypes.has(resourceType)) {
721
+ continue;
734
722
  }
735
- }
736
- if (resourceTypes.has('database-schema')) {
737
- const { databases } = await client.listAllDatabaseSchemas({
738
- projection: 'pull',
723
+ for await (const { listedId, resource } of readResourceInventory(client, resourceType, {
739
724
  skipPartitions: plan.skipPartitions,
740
- });
741
- for (const database of databases) {
742
- if (isDatabaseBackupArtifact(database)) {
725
+ })) {
726
+ if (!listedId || (resourceType === 'database-table' && isDatabaseBackupArtifact(resource))) {
743
727
  continue;
744
728
  }
745
- const id = resourceIdOf(database);
746
- if (id) {
747
- currentResources.set(`database-schema:${id}`, database);
748
- }
749
- }
750
- }
751
- if (resourceTypes.has('database-view')) {
752
- const views = await client.listAllDatabaseViewsForSync();
753
- for (const view of views) {
754
- const id = resourceIdOf(view);
755
- if (id) {
756
- currentResources.set(`database-view:${id}`, view);
757
- }
758
- }
759
- }
760
- if (resourceTypes.has('endpoint')) {
761
- const { endpoints } = await client.listAllEndpoints();
762
- for (const summary of endpoints) {
763
- const id = resourceIdOf(summary);
764
- if (id) {
765
- currentResources.set(`endpoint:${id}`, unwrapResource(await client.getEndpoint(id)));
766
- }
767
- }
768
- }
769
- if (resourceTypes.has('role-group')) {
770
- const { roleGroups } = await client.listAllRoleGroups();
771
- for (const summary of roleGroups) {
772
- const id = resourceIdOf(summary);
773
- if (id)
774
- currentResources.set(`role-group:${id}`, unwrapResource(await client.getRoleGroup(id)));
775
- }
776
- }
777
- if (resourceTypes.has('group')) {
778
- const { groups } = await client.listAllGroups();
779
- for (const summary of groups) {
780
- const id = resourceIdOf(summary);
781
- if (id) {
782
- currentResources.set(`group:${id}`, unwrapResource(await client.getGroup(id)));
783
- }
784
- }
785
- }
786
- if (resourceTypes.has('job-template')) {
787
- const { jobTemplates } = await client.listAllJobTemplates();
788
- for (const summary of jobTemplates) {
789
- const id = resourceIdOf(summary);
790
- if (id)
791
- currentResources.set(`job-template:${id}`, unwrapResource(await client.getJobTemplate(id)));
792
- }
793
- }
794
- if (resourceTypes.has('schedule')) {
795
- const { schedules } = await client.listAllSchedules();
796
- for (const summary of schedules) {
797
- const id = resourceIdOf(summary);
798
- if (id) {
799
- currentResources.set(`schedule:${id}`, unwrapResource(await client.getSchedule(id)));
800
- }
801
- }
802
- }
803
- if (resourceTypes.has('event')) {
804
- const { events } = await client.listAllEvents({ includeDeleted: true });
805
- for (const summary of events) {
806
- const id = resourceIdOf(summary);
807
- if (id) {
808
- currentResources.set(`event:${id}`, unwrapResource(await client.getEvent(id)));
809
- }
729
+ currentResources.set(`${resourceType}:${listedId}`, resource);
810
730
  }
811
731
  }
812
732
  const stableKeyOwners = new Map();
@@ -857,7 +777,7 @@ export async function applyMetadataBackfillPlan(input) {
857
777
  let databaseMutationStarted = false;
858
778
  const columnUpdatesByDatabase = new Map();
859
779
  for (const item of plan.items) {
860
- if (item.resourceType === 'database-schema' && item.metadataField === 'definition[].metadata' && item.action === 'update') {
780
+ if (item.resourceType === 'database-table' && item.metadataField === 'definition[].metadata' && item.action === 'update') {
861
781
  columnUpdatesByDatabase.set(item.resourceId, [
862
782
  ...(columnUpdatesByDatabase.get(item.resourceId) || []),
863
783
  item,
@@ -899,8 +819,8 @@ export async function applyMetadataBackfillPlan(input) {
899
819
  });
900
820
  continue;
901
821
  }
902
- if (item.resourceType === 'database-schema') {
903
- const listed = currentResources.get(`database-schema:${item.resourceId}`);
822
+ if (item.resourceType === 'database-table') {
823
+ const listed = currentResources.get(`database-table:${item.resourceId}`);
904
824
  if (!listed) {
905
825
  throw new Error('database schema no longer exists');
906
826
  }
@@ -975,7 +895,7 @@ export async function applyMetadataBackfillPlan(input) {
975
895
  }
976
896
  const rawStableKey = rawConfiguredStableKey(live, plan.stableKeyName);
977
897
  if (rawStableKey.present) {
978
- throw new Error(`Invalid database-schema stableKey appeared before apply on ${item.resourceId}; refusing to overwrite it.`);
898
+ throw new Error(`Invalid database-table stableKey appeared before apply on ${item.resourceId}; refusing to overwrite it.`);
979
899
  }
980
900
  if (databaseMutationStarted) {
981
901
  await waitForMutationSlot();
@@ -1058,6 +978,10 @@ export async function applyMetadataBackfillPlan(input) {
1058
978
  if (!group) {
1059
979
  throw new Error('group no longer exists');
1060
980
  }
981
+ const exclusionReason = groupExclusionReason(group);
982
+ if (exclusionReason) {
983
+ throw new Error(`group moved outside migration scope: ${exclusionReason}`);
984
+ }
1061
985
  const currentStableKey = readConfiguredResourceMetadataStableKey(group, plan.stableKeyName);
1062
986
  if (currentStableKey && !plan.force) {
1063
987
  results.push({ resourceType: item.resourceType, resourceId: item.resourceId, stableKey: currentStableKey, action: 'skip' });
@@ -1138,7 +1062,7 @@ export async function applyMetadataBackfillPlan(input) {
1138
1062
  });
1139
1063
  }
1140
1064
  }
1141
- if (resourceTypes.has('database-schema')) {
1065
+ if (resourceTypes.has('database-table')) {
1142
1066
  try {
1143
1067
  const { databases } = await client.listAllDatabaseSchemas({
1144
1068
  projection: 'pull',
@@ -1147,7 +1071,7 @@ export async function applyMetadataBackfillPlan(input) {
1147
1071
  const verified = new Map(databases
1148
1072
  .filter((database) => !isDatabaseBackupArtifact(database))
1149
1073
  .map((database) => [resourceIdOf(database), database]));
1150
- for (const result of results.filter((candidate) => candidate.resourceType === 'database-schema' && candidate.action === 'update')) {
1074
+ for (const result of results.filter((candidate) => candidate.resourceType === 'database-table' && candidate.action === 'update')) {
1151
1075
  const database = verified.get(result.resourceId);
1152
1076
  const definition = result.columnName && database
1153
1077
  ? databaseDefinitions(database).find((candidate) => candidate.name === result.columnName)
@@ -1166,7 +1090,7 @@ export async function applyMetadataBackfillPlan(input) {
1166
1090
  }
1167
1091
  }
1168
1092
  catch (error) {
1169
- for (const result of results.filter((candidate) => candidate.resourceType === 'database-schema' && candidate.action === 'update')) {
1093
+ for (const result of results.filter((candidate) => candidate.resourceType === 'database-table' && candidate.action === 'update')) {
1170
1094
  result.action = 'failed';
1171
1095
  result.error = `final verification failed: ${error instanceof Error ? error.message : String(error)}`;
1172
1096
  }
@@ -0,0 +1,141 @@
1
+ import { RevoClient } from './client.ts';
2
+ import { type ComponentPlan, type ComponentSyncResult } from './commands/component.ts';
3
+ import { type DatabaseSchemaMigrationPolicy, type DatabaseSchemaPullResult, type DatabaseSchemaPushResult, type DatabaseSchemasPlan } from './resource-syncs/database-table-sync.ts';
4
+ import { type DatabaseViewPullResult, type DatabaseViewPushResult, type DatabaseViewsPlan } from './resource-syncs/database-view-sync.ts';
5
+ import { type EndpointPlan, type EndpointPullResult, type EndpointPushResult } from './resource-syncs/endpoint-sync.ts';
6
+ import { type EventPullResult, type EventPushResult, type EventsPlan } from './resource-syncs/event-sync.ts';
7
+ import { type GroupPullResult, type GroupPushResult, type GroupsPlan } from './resource-syncs/group-sync.ts';
8
+ import { type JobTemplatePullResult, type JobTemplatePushResult, type JobTemplatesPlan } from './resource-syncs/job-template-sync.ts';
9
+ import { type SchedulePullResult, type SchedulePushResult, type SchedulesPlan } from './resource-syncs/schedule-sync.ts';
10
+ import { type RoleGroupPullResult, type RoleGroupPushResult, type RoleGroupsPlan } from './resource-syncs/role-group-sync.ts';
11
+ export type MigrationResource = 'database-table' | 'database-view' | 'component' | 'job-template' | 'endpoint' | 'schedule' | 'event' | 'group' | 'role-group';
12
+ export type MigrationVerdict = 'ready' | 'ready-with-warnings' | 'blocked';
13
+ export type MigrationOperations = Record<'noop' | 'create' | 'update' | 'adopt' | 'excluded' | 'blocked', number>;
14
+ type MigrationPushResult = DatabaseSchemaPushResult | DatabaseViewPushResult | ComponentSyncResult | JobTemplatePushResult | EndpointPushResult | SchedulePushResult | EventPushResult | GroupPushResult | RoleGroupPushResult;
15
+ export type MigrationPhasePlan = {
16
+ order: number;
17
+ resource: MigrationResource;
18
+ needsChanges: boolean;
19
+ readyToMigrate: boolean;
20
+ verdict: MigrationVerdict;
21
+ operations: MigrationOperations;
22
+ warnings: string[];
23
+ blockers: string[];
24
+ };
25
+ export type MigrationSourcePullSummary = {
26
+ mode: 'temporary' | 'workspace' | 'repository';
27
+ pulled: number;
28
+ pruned: number;
29
+ skipped: number;
30
+ byResource: Partial<Record<MigrationResource, {
31
+ pulled: number;
32
+ pruned: number;
33
+ skipped: number;
34
+ }>>;
35
+ };
36
+ export type MigrationPlan = {
37
+ schemaVersion: 2;
38
+ command: 'plan';
39
+ from: string;
40
+ to: string;
41
+ resources: MigrationResource[];
42
+ policy: DatabaseSchemaMigrationPolicy & {
43
+ mode: 'upsert';
44
+ };
45
+ needsChanges: boolean;
46
+ readyToMigrate: boolean;
47
+ verdict: MigrationVerdict;
48
+ operations: MigrationOperations;
49
+ sourcePull: MigrationSourcePullSummary;
50
+ phases: MigrationPhasePlan[];
51
+ databaseSchemas?: DatabaseSchemasPlan;
52
+ databaseViews?: DatabaseViewsPlan;
53
+ components?: ComponentPlan;
54
+ jobTemplates?: JobTemplatesPlan;
55
+ endpoints?: EndpointPlan;
56
+ schedules?: SchedulesPlan;
57
+ events?: EventsPlan;
58
+ groups?: GroupsPlan;
59
+ roleGroups?: RoleGroupsPlan;
60
+ warnings: string[];
61
+ blockers: string[];
62
+ };
63
+ export type MigrationRun = {
64
+ schemaVersion: 2;
65
+ command: 'run';
66
+ from: string;
67
+ to: string;
68
+ resources: MigrationResource[];
69
+ policy: DatabaseSchemaMigrationPolicy & {
70
+ mode: 'upsert';
71
+ };
72
+ verdict: 'succeeded' | 'blocked' | 'failed';
73
+ sourcePull: {
74
+ databaseSchemas?: DatabaseSchemaPullResult;
75
+ databaseViews?: DatabaseViewPullResult;
76
+ components?: ComponentSyncResult[];
77
+ jobTemplates?: JobTemplatePullResult;
78
+ endpoints?: EndpointPullResult;
79
+ schedules?: SchedulePullResult;
80
+ events?: EventPullResult;
81
+ groups?: GroupPullResult;
82
+ roleGroups?: RoleGroupPullResult;
83
+ };
84
+ plan: MigrationPlan;
85
+ results: MigrationPushResult[];
86
+ phaseResults: Partial<Record<MigrationResource, MigrationPushResult[]>>;
87
+ verification?: MigrationPlan;
88
+ };
89
+ type MigrationInputBase = {
90
+ cwd: string;
91
+ from: string;
92
+ to: string;
93
+ resources?: MigrationResource[];
94
+ withStats?: boolean;
95
+ allowDestructive?: boolean;
96
+ detailedDiff?: boolean;
97
+ };
98
+ export type MigrationInput = MigrationInputBase & ({
99
+ sourceMode: 'workspace';
100
+ targetClient: RevoClient;
101
+ targetKey: string;
102
+ targetLabel: string;
103
+ } | {
104
+ sourceMode?: 'environment';
105
+ targetClient?: never;
106
+ targetKey?: never;
107
+ targetLabel?: never;
108
+ });
109
+ export type ResourcePullResults = {
110
+ databaseSchemas?: DatabaseSchemaPullResult;
111
+ databaseViews?: DatabaseViewPullResult;
112
+ components?: ComponentSyncResult[];
113
+ jobTemplates?: JobTemplatePullResult;
114
+ endpoints?: EndpointPullResult;
115
+ schedules?: SchedulePullResult;
116
+ events?: EventPullResult;
117
+ groups?: GroupPullResult;
118
+ roleGroups?: RoleGroupPullResult;
119
+ };
120
+ export type ResourcePullInput = {
121
+ cwd: string;
122
+ client: RevoClient;
123
+ sourceKey: string;
124
+ sourceLabel: string;
125
+ resources?: MigrationResource[];
126
+ force?: boolean;
127
+ pruneOrphans?: boolean;
128
+ };
129
+ export type ResourcePullRun = {
130
+ schemaVersion: 1;
131
+ command: 'pull';
132
+ source: string;
133
+ sourceKey: string;
134
+ resources: MigrationResource[];
135
+ summary: MigrationSourcePullSummary;
136
+ results: ResourcePullResults;
137
+ };
138
+ export declare function pullResourcesToWorkspace(input: ResourcePullInput): Promise<ResourcePullRun>;
139
+ export declare function buildMigrationPlan(input: MigrationInput): Promise<MigrationPlan>;
140
+ export declare function runMigration(input: MigrationInput): Promise<MigrationRun>;
141
+ export {};