@revoengine/cli 1.0.10 → 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.
- package/README.md +314 -239
- package/dist/src/cli.js +126 -9
- package/dist/src/client.d.ts +373 -6
- package/dist/src/client.js +1005 -53
- package/dist/src/commands/auth.js +4 -2
- package/dist/src/commands/component.d.ts +67 -0
- package/dist/src/commands/component.js +555 -164
- package/dist/src/commands/database-tables.d.ts +2 -0
- package/dist/src/commands/database-tables.js +169 -0
- package/dist/src/commands/database-views.d.ts +2 -0
- package/dist/src/commands/database-views.js +126 -0
- package/dist/src/commands/endpoints.js +124 -0
- package/dist/src/commands/env.js +44 -24
- package/dist/src/commands/events.d.ts +2 -0
- package/dist/src/commands/events.js +144 -0
- package/dist/src/commands/groups.d.ts +2 -0
- package/dist/src/commands/groups.js +160 -0
- package/dist/src/commands/index.d.ts +9 -0
- package/dist/src/commands/index.js +9 -0
- package/dist/src/commands/job-templates.d.ts +2 -0
- package/dist/src/commands/job-templates.js +107 -0
- package/dist/src/commands/metadata.js +75 -10
- package/dist/src/commands/migrate.d.ts +6 -0
- package/dist/src/commands/migrate.js +658 -0
- package/dist/src/commands/project.js +10 -3
- package/dist/src/commands/role-groups.d.ts +2 -0
- package/dist/src/commands/role-groups.js +141 -0
- package/dist/src/commands/schedules.d.ts +2 -0
- package/dist/src/commands/schedules.js +140 -0
- package/dist/src/commands/terminal-browser.d.ts +16 -0
- package/dist/src/commands/terminal-browser.js +92 -0
- package/dist/src/commands/terminal-image.d.ts +7 -0
- package/dist/src/commands/terminal-image.js +40 -0
- package/dist/src/commands/terminal-patch-worker.d.ts +1 -0
- package/dist/src/commands/terminal-patch-worker.js +24 -0
- package/dist/src/commands/terminal-patch.d.ts +2 -0
- package/dist/src/commands/terminal-patch.js +156 -0
- package/dist/src/commands/terminal-sandbox.d.ts +8 -0
- package/dist/src/commands/terminal-sandbox.js +87 -0
- package/dist/src/commands/terminal-service.d.ts +38 -0
- package/dist/src/commands/terminal-service.js +210 -0
- package/dist/src/commands/terminal.d.ts +49 -0
- package/dist/src/commands/terminal.js +826 -0
- package/dist/src/component-lock.d.ts +111 -3
- package/dist/src/component-lock.js +363 -15
- package/dist/src/config.d.ts +10 -2
- package/dist/src/config.js +49 -14
- package/dist/src/database-table-artifacts.d.ts +7 -0
- package/dist/src/database-table-artifacts.js +8 -0
- package/dist/src/diff-details.d.ts +8 -0
- package/dist/src/diff-details.js +152 -0
- package/dist/src/env-sync.d.ts +0 -3
- package/dist/src/env-sync.js +11 -25
- package/dist/src/http-trace.d.ts +94 -0
- package/dist/src/http-trace.js +226 -0
- package/dist/src/metadata-backfill.d.ts +18 -7
- package/dist/src/metadata-backfill.js +1002 -27
- package/dist/src/migration.d.ts +141 -0
- package/dist/src/migration.js +1632 -0
- package/dist/src/project.d.ts +2 -0
- package/dist/src/project.js +4 -17
- package/dist/src/prompt.js +10 -18
- package/dist/src/resource-inventory.d.ts +28 -0
- package/dist/src/resource-inventory.js +85 -0
- package/dist/src/resource-metadata.d.ts +1 -0
- package/dist/src/resource-metadata.js +3 -0
- package/dist/src/resource-syncs/database-table-sync.d.ts +127 -0
- package/dist/src/resource-syncs/database-table-sync.js +2374 -0
- package/dist/src/resource-syncs/database-view-sync.d.ts +146 -0
- package/dist/src/resource-syncs/database-view-sync.js +1405 -0
- package/dist/src/resource-syncs/endpoint-sync.d.ts +123 -0
- package/dist/src/resource-syncs/endpoint-sync.js +1563 -0
- package/dist/src/resource-syncs/event-sync.d.ts +126 -0
- package/dist/src/resource-syncs/event-sync.js +1046 -0
- package/dist/src/resource-syncs/group-sync.d.ts +93 -0
- package/dist/src/resource-syncs/group-sync.js +928 -0
- package/dist/src/resource-syncs/job-template-sync.d.ts +106 -0
- package/dist/src/resource-syncs/job-template-sync.js +843 -0
- package/dist/src/resource-syncs/role-group-sync.d.ts +90 -0
- package/dist/src/resource-syncs/role-group-sync.js +635 -0
- package/dist/src/resource-syncs/schedule-sync.d.ts +140 -0
- package/dist/src/resource-syncs/schedule-sync.js +1396 -0
- package/dist/src/resource-syncs/util.d.ts +22 -0
- package/dist/src/resource-syncs/util.js +118 -0
- package/dist/src/resource-target.d.ts +11 -0
- package/dist/src/resource-target.js +48 -0
- package/dist/src/runtime-view.d.ts +1 -0
- package/dist/src/runtime-view.js +6 -1
- package/dist/src/sync-output.d.ts +66 -0
- package/dist/src/sync-output.js +268 -0
- package/dist/src/tracked-resources.d.ts +1 -1
- package/dist/src/tracked-resources.js +28 -2
- package/dist/src/types.d.ts +227 -0
- package/dist/src/ui.d.ts +3 -0
- package/dist/src/ui.js +76 -18
- package/dist/src/utils.d.ts +4 -0
- package/dist/src/utils.js +81 -0
- package/dist/src/workspace-component.d.ts +2 -0
- package/dist/src/workspace-component.js +34 -0
- package/dist/src/workspace-diff.d.ts +25 -0
- package/dist/src/workspace-diff.js +75 -0
- package/dist/src/workspace-resource.d.ts +2 -0
- package/dist/src/workspace-resource.js +52 -0
- package/package.json +12 -4
package/dist/src/config.js
CHANGED
|
@@ -75,11 +75,13 @@ export function saveStoredConfig(nextConfig) {
|
|
|
75
75
|
const current = readStoredConfigFile();
|
|
76
76
|
const instance = nextConfig.instance || current.instance || '';
|
|
77
77
|
const environments = nextConfig.environments ?? current.environments;
|
|
78
|
+
const activeEnvironment = nextConfig.activeEnvironment ?? current.activeEnvironment;
|
|
78
79
|
const config = {
|
|
79
80
|
baseUrl: nextConfig.baseUrl || current.baseUrl || DEFAULT_BASE_URL,
|
|
80
81
|
token: nextConfig.token || current.token || '',
|
|
81
82
|
...(instance ? { instance } : {}),
|
|
82
83
|
...(environments && Object.keys(environments).length > 0 ? { environments } : {}),
|
|
84
|
+
...(activeEnvironment && activeEnvironment !== DEFAULT_ENV_NAME ? { activeEnvironment } : {}),
|
|
83
85
|
};
|
|
84
86
|
writeJsonFile(configFile, config);
|
|
85
87
|
removeFileIfExists(credentialsFile);
|
|
@@ -88,13 +90,15 @@ export function clearStoredConfig() {
|
|
|
88
90
|
const { dir, configFile, credentialsFile, authStateFile } = getConfigPaths();
|
|
89
91
|
// Logout clears the default login but must not destroy named environment
|
|
90
92
|
// profiles stored alongside it.
|
|
91
|
-
const
|
|
93
|
+
const stored = readStoredConfigFile();
|
|
94
|
+
const environments = stored.environments;
|
|
92
95
|
if (environments && Object.keys(environments).length > 0) {
|
|
93
96
|
ensureDirectory(dir);
|
|
94
97
|
writeJsonFile(configFile, {
|
|
95
98
|
baseUrl: DEFAULT_BASE_URL,
|
|
96
99
|
token: '',
|
|
97
100
|
environments,
|
|
101
|
+
...(stored.activeEnvironment ? { activeEnvironment: stored.activeEnvironment } : {}),
|
|
98
102
|
});
|
|
99
103
|
for (const filePath of [credentialsFile, authStateFile]) {
|
|
100
104
|
try {
|
|
@@ -181,6 +185,7 @@ function parseEnvironmentProfiles(value) {
|
|
|
181
185
|
baseUrl: entry.baseUrl,
|
|
182
186
|
token: entry.token,
|
|
183
187
|
...(typeof entry.instance === 'string' && isUuid(entry.instance) ? { instance: entry.instance } : {}),
|
|
188
|
+
...(entry.production === true ? { production: true } : {}),
|
|
184
189
|
};
|
|
185
190
|
}
|
|
186
191
|
return Object.keys(environments).length > 0 ? environments : null;
|
|
@@ -195,6 +200,11 @@ function parseFlatConfig(raw, credentials) {
|
|
|
195
200
|
? credentials.token
|
|
196
201
|
: '';
|
|
197
202
|
const environments = parseEnvironmentProfiles(raw.environments);
|
|
203
|
+
const activeEnvironment = typeof raw.activeEnvironment === 'string'
|
|
204
|
+
&& raw.activeEnvironment !== DEFAULT_ENV_NAME
|
|
205
|
+
&& environments?.[raw.activeEnvironment]
|
|
206
|
+
? raw.activeEnvironment
|
|
207
|
+
: undefined;
|
|
198
208
|
return {
|
|
199
209
|
baseUrl: typeof raw.baseUrl === 'string'
|
|
200
210
|
? raw.baseUrl
|
|
@@ -203,6 +213,7 @@ function parseFlatConfig(raw, credentials) {
|
|
|
203
213
|
: DEFAULT_BASE_URL,
|
|
204
214
|
...(typeof raw.instance === 'string' && isUuid(raw.instance) ? { instance: raw.instance } : {}),
|
|
205
215
|
...(environments ? { environments } : {}),
|
|
216
|
+
...(activeEnvironment ? { activeEnvironment } : {}),
|
|
206
217
|
token,
|
|
207
218
|
};
|
|
208
219
|
}
|
|
@@ -225,6 +236,11 @@ function parseMappedConfig(raw) {
|
|
|
225
236
|
? configuredDefault
|
|
226
237
|
: Object.keys(instances)[0] || '';
|
|
227
238
|
const environments = parseEnvironmentProfiles(raw.environments);
|
|
239
|
+
const activeEnvironment = typeof raw.activeEnvironment === 'string'
|
|
240
|
+
&& raw.activeEnvironment !== DEFAULT_ENV_NAME
|
|
241
|
+
&& environments?.[raw.activeEnvironment]
|
|
242
|
+
? raw.activeEnvironment
|
|
243
|
+
: undefined;
|
|
228
244
|
const selected = defaultInstance ? instances[defaultInstance] : undefined;
|
|
229
245
|
const base = selected
|
|
230
246
|
? {
|
|
@@ -233,7 +249,11 @@ function parseMappedConfig(raw) {
|
|
|
233
249
|
token: selected.token,
|
|
234
250
|
}
|
|
235
251
|
: emptyStoredConfigFile();
|
|
236
|
-
return
|
|
252
|
+
return {
|
|
253
|
+
...base,
|
|
254
|
+
...(environments ? { environments } : {}),
|
|
255
|
+
...(activeEnvironment ? { activeEnvironment } : {}),
|
|
256
|
+
};
|
|
237
257
|
}
|
|
238
258
|
function parseLegacyConfig(config, credentials) {
|
|
239
259
|
const baseUrl = isRecord(config) && typeof config.baseUrl === 'string'
|
|
@@ -319,9 +339,19 @@ export function listEnvironmentProfiles() {
|
|
|
319
339
|
export function getEnvironmentProfile(name) {
|
|
320
340
|
return listEnvironmentProfiles()[name] || null;
|
|
321
341
|
}
|
|
322
|
-
export
|
|
342
|
+
export const DEFAULT_ENV_NAME = 'default';
|
|
343
|
+
export function getActiveEnvironmentName() {
|
|
344
|
+
return readStoredConfigFile().activeEnvironment || DEFAULT_ENV_NAME;
|
|
345
|
+
}
|
|
346
|
+
export function setActiveEnvironmentName(name) {
|
|
347
|
+
if (name !== DEFAULT_ENV_NAME && !getEnvironmentProfile(name)) {
|
|
348
|
+
throw new Error(`Unknown project "${name}". Run 'revo projects list' to see saved projects.`);
|
|
349
|
+
}
|
|
350
|
+
saveStoredConfig({ activeEnvironment: name });
|
|
351
|
+
}
|
|
352
|
+
export function saveEnvironmentProfile(name, profile, options = {}) {
|
|
323
353
|
const environments = { ...listEnvironmentProfiles(), [name]: profile };
|
|
324
|
-
saveStoredConfig({ environments });
|
|
354
|
+
saveStoredConfig({ environments, ...(options.activate ? { activeEnvironment: name } : {}) });
|
|
325
355
|
}
|
|
326
356
|
export function removeEnvironmentProfile(name) {
|
|
327
357
|
const environments = listEnvironmentProfiles();
|
|
@@ -329,7 +359,10 @@ export function removeEnvironmentProfile(name) {
|
|
|
329
359
|
return false;
|
|
330
360
|
}
|
|
331
361
|
delete environments[name];
|
|
332
|
-
saveStoredConfig({
|
|
362
|
+
saveStoredConfig({
|
|
363
|
+
environments,
|
|
364
|
+
...(getActiveEnvironmentName() === name ? { activeEnvironment: DEFAULT_ENV_NAME } : {}),
|
|
365
|
+
});
|
|
333
366
|
return true;
|
|
334
367
|
}
|
|
335
368
|
export function buildAuthValidationKey(runtime) {
|
|
@@ -422,31 +455,33 @@ export function clearAuthValidationState(key) {
|
|
|
422
455
|
}
|
|
423
456
|
}
|
|
424
457
|
}
|
|
425
|
-
export const DEFAULT_ENV_NAME = 'default';
|
|
426
458
|
export function resolveRuntimeConfig(options = {}) {
|
|
427
459
|
const env = {
|
|
428
460
|
baseUrl: resolveEnvValue(['REVO_URL', 'REVO_BASE_URL', 'REVOENGINE_URL', 'REVOENGINE_BASE_URL']),
|
|
429
461
|
instance: resolveEnvValue(['REVO_INSTANCE', 'REVOENGINE_INSTANCE']),
|
|
430
462
|
token: resolveEnvValue(['REVO_TOKEN', 'REVO_API_KEY', 'REVOENGINE_TOKEN', 'REVOENGINE_API_KEY']),
|
|
431
463
|
};
|
|
432
|
-
const stored =
|
|
464
|
+
const stored = readStoredConfigFile();
|
|
433
465
|
// A named profile is an explicit selection and resolves exclusively: no
|
|
434
466
|
// fallback to env vars or the stored default, or --from/--to could silently
|
|
435
467
|
// mix one environment's URL with another environment's token or instance.
|
|
436
|
-
|
|
437
|
-
|
|
468
|
+
const envName = options.envName || stored.activeEnvironment || DEFAULT_ENV_NAME;
|
|
469
|
+
if (envName !== DEFAULT_ENV_NAME) {
|
|
470
|
+
const profile = stored.environments?.[envName];
|
|
438
471
|
if (!profile) {
|
|
439
|
-
throw new Error(`Unknown
|
|
472
|
+
throw new Error(`Unknown project "${envName}". Run 'revo projects list' to see saved projects.`);
|
|
440
473
|
}
|
|
441
474
|
return {
|
|
442
475
|
baseUrl: options.baseUrl || profile.baseUrl || DEFAULT_BASE_URL,
|
|
443
|
-
instance: options.instance
|
|
476
|
+
instance: options.instance ?? (profile.instance || ''),
|
|
444
477
|
token: options.token || profile.token || '',
|
|
478
|
+
...(profile.production ? { production: true } : {}),
|
|
445
479
|
};
|
|
446
480
|
}
|
|
481
|
+
const defaultStored = mergeWithLegacy(stored);
|
|
447
482
|
return {
|
|
448
|
-
baseUrl: options.baseUrl || env.baseUrl ||
|
|
449
|
-
instance: options.instance
|
|
450
|
-
token: options.token || env.token ||
|
|
483
|
+
baseUrl: options.baseUrl || env.baseUrl || defaultStored.baseUrl || DEFAULT_BASE_URL,
|
|
484
|
+
instance: options.instance ?? (env.instance || defaultStored.instance || ''),
|
|
485
|
+
token: options.token || env.token || defaultStored.token || '',
|
|
451
486
|
};
|
|
452
487
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const DATABASE_BACKUP_CATEGORY = "Database Backup";
|
|
2
|
+
export declare function isDatabaseBackupArtifact(value: {
|
|
3
|
+
category?: unknown;
|
|
4
|
+
}): boolean;
|
|
5
|
+
export declare function excludeDatabaseBackupArtifacts<T extends {
|
|
6
|
+
category?: unknown;
|
|
7
|
+
}>(records: readonly T[]): T[];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const DATABASE_BACKUP_CATEGORY = 'Database Backup';
|
|
2
|
+
export function isDatabaseBackupArtifact(value) {
|
|
3
|
+
return typeof value.category === 'string'
|
|
4
|
+
&& value.category.trim() === DATABASE_BACKUP_CATEGORY;
|
|
5
|
+
}
|
|
6
|
+
export function excludeDatabaseBackupArtifacts(records) {
|
|
7
|
+
return records.filter((record) => !isDatabaseBackupArtifact(record));
|
|
8
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type FieldChange = {
|
|
2
|
+
field: string;
|
|
3
|
+
target: string;
|
|
4
|
+
workspace: string;
|
|
5
|
+
};
|
|
6
|
+
export declare function formatDiffValue(value: unknown, field?: string): string;
|
|
7
|
+
export declare function describeFieldChanges(workspace: unknown, target: unknown, fields: ReadonlyArray<string>): FieldChange[];
|
|
8
|
+
export declare function unifiedLineDiff(target: string, workspace: string): string[];
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
const SENSITIVE_KEY = /authorization|cookie|password|secret|token|api[-_]?key/i;
|
|
3
|
+
function safeValue(value, key = '') {
|
|
4
|
+
if (SENSITIVE_KEY.test(key)) {
|
|
5
|
+
return '<redacted>';
|
|
6
|
+
}
|
|
7
|
+
if (Array.isArray(value)) {
|
|
8
|
+
return value.map((item) => safeValue(item));
|
|
9
|
+
}
|
|
10
|
+
if (value !== null && typeof value === 'object') {
|
|
11
|
+
return Object.fromEntries(Object.entries(value).sort(([left], [right]) => left.localeCompare(right))
|
|
12
|
+
.map(([childKey, childValue]) => [childKey, safeValue(childValue, childKey)]));
|
|
13
|
+
}
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
export function formatDiffValue(value, field = '') {
|
|
17
|
+
if (value === undefined) {
|
|
18
|
+
return '<absent>';
|
|
19
|
+
}
|
|
20
|
+
const serialized = JSON.stringify(safeValue(value, field)) ?? String(value);
|
|
21
|
+
if (serialized.length <= 500) {
|
|
22
|
+
return serialized;
|
|
23
|
+
}
|
|
24
|
+
const hash = createHash('sha256').update(serialized).digest('hex').slice(0, 12);
|
|
25
|
+
return `${serialized.slice(0, 500)}… [${serialized.length} chars, sha256:${hash}]`;
|
|
26
|
+
}
|
|
27
|
+
function valueAtPath(value, field) {
|
|
28
|
+
return field.split('.').reduce((current, key) => {
|
|
29
|
+
if (current === null || typeof current !== 'object') {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
return current[key];
|
|
33
|
+
}, value);
|
|
34
|
+
}
|
|
35
|
+
export function describeFieldChanges(workspace, target, fields) {
|
|
36
|
+
return fields.map((field) => {
|
|
37
|
+
const targetValue = valueAtPath(target, field);
|
|
38
|
+
const workspaceValue = valueAtPath(workspace, field);
|
|
39
|
+
const targetText = formatDiffValue(targetValue, field);
|
|
40
|
+
const workspaceText = formatDiffValue(workspaceValue, field);
|
|
41
|
+
return {
|
|
42
|
+
field,
|
|
43
|
+
target: targetText,
|
|
44
|
+
workspace: targetText === workspaceText && JSON.stringify(targetValue) !== JSON.stringify(workspaceValue)
|
|
45
|
+
? `${workspaceText} (value differs; sensitive content redacted)`
|
|
46
|
+
: workspaceText,
|
|
47
|
+
};
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
function replacementLineDiff(oldLines, newLines) {
|
|
51
|
+
let prefix = 0;
|
|
52
|
+
while (prefix < oldLines.length && prefix < newLines.length && oldLines[prefix] === newLines[prefix]) {
|
|
53
|
+
prefix++;
|
|
54
|
+
}
|
|
55
|
+
let suffix = 0;
|
|
56
|
+
while (suffix < oldLines.length - prefix && suffix < newLines.length - prefix
|
|
57
|
+
&& oldLines[oldLines.length - suffix - 1] === newLines[newLines.length - suffix - 1]) {
|
|
58
|
+
suffix++;
|
|
59
|
+
}
|
|
60
|
+
const contextBefore = Math.min(prefix, 3);
|
|
61
|
+
const contextAfter = Math.min(suffix, 3);
|
|
62
|
+
const oldStart = oldLines.length === 0 ? 0 : prefix - contextBefore + 1;
|
|
63
|
+
const newStart = newLines.length === 0 ? 0 : prefix - contextBefore + 1;
|
|
64
|
+
const oldChanged = oldLines.slice(prefix, oldLines.length - suffix);
|
|
65
|
+
const newChanged = newLines.slice(prefix, newLines.length - suffix);
|
|
66
|
+
const limit = 120;
|
|
67
|
+
const visibleOld = oldChanged.slice(0, limit);
|
|
68
|
+
const visibleNew = newChanged.slice(0, limit);
|
|
69
|
+
return [
|
|
70
|
+
`@@ -${oldStart},${contextBefore + oldChanged.length + contextAfter} +${newStart},${contextBefore + newChanged.length + contextAfter} @@`,
|
|
71
|
+
...oldLines.slice(prefix - contextBefore, prefix).map((line) => ` ${line}`),
|
|
72
|
+
...visibleOld.map((line) => `-${line}`),
|
|
73
|
+
...(oldChanged.length > limit ? [`... ${oldChanged.length - limit} more target lines`] : []),
|
|
74
|
+
...visibleNew.map((line) => `+${line}`),
|
|
75
|
+
...(newChanged.length > limit ? [`... ${newChanged.length - limit} more workspace lines`] : []),
|
|
76
|
+
...oldLines.slice(oldLines.length - contextAfter).map((line) => ` ${line}`),
|
|
77
|
+
];
|
|
78
|
+
}
|
|
79
|
+
export function unifiedLineDiff(target, workspace) {
|
|
80
|
+
if (target === workspace) {
|
|
81
|
+
return [];
|
|
82
|
+
}
|
|
83
|
+
const oldLines = target === '' ? [] : target.split('\n');
|
|
84
|
+
const newLines = workspace === '' ? [] : workspace.split('\n');
|
|
85
|
+
if (oldLines.length * newLines.length > 250_000) {
|
|
86
|
+
return replacementLineDiff(oldLines, newLines);
|
|
87
|
+
}
|
|
88
|
+
const lengths = Array.from({ length: oldLines.length + 1 }, () => new Uint32Array(newLines.length + 1));
|
|
89
|
+
for (let oldIndex = oldLines.length - 1; oldIndex >= 0; oldIndex--) {
|
|
90
|
+
for (let newIndex = newLines.length - 1; newIndex >= 0; newIndex--) {
|
|
91
|
+
lengths[oldIndex][newIndex] = oldLines[oldIndex] === newLines[newIndex]
|
|
92
|
+
? lengths[oldIndex + 1][newIndex + 1] + 1
|
|
93
|
+
: Math.max(lengths[oldIndex + 1][newIndex], lengths[oldIndex][newIndex + 1]);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const operations = [];
|
|
97
|
+
let oldIndex = 0;
|
|
98
|
+
let newIndex = 0;
|
|
99
|
+
while (oldIndex < oldLines.length || newIndex < newLines.length) {
|
|
100
|
+
if (oldIndex < oldLines.length && newIndex < newLines.length
|
|
101
|
+
&& oldLines[oldIndex] === newLines[newIndex]) {
|
|
102
|
+
operations.push({ mark: ' ', line: oldLines[oldIndex] });
|
|
103
|
+
oldIndex++;
|
|
104
|
+
newIndex++;
|
|
105
|
+
}
|
|
106
|
+
else if (oldIndex < oldLines.length
|
|
107
|
+
&& (newIndex === newLines.length || lengths[oldIndex + 1][newIndex] >= lengths[oldIndex][newIndex + 1])) {
|
|
108
|
+
operations.push({ mark: '-', line: oldLines[oldIndex] });
|
|
109
|
+
oldIndex++;
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
operations.push({ mark: '+', line: newLines[newIndex] });
|
|
113
|
+
newIndex++;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const ranges = [];
|
|
117
|
+
for (let index = 0; index < operations.length; index++) {
|
|
118
|
+
if (operations[index].mark === ' ') {
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
const start = Math.max(0, index - 3);
|
|
122
|
+
const end = Math.min(operations.length, index + 4);
|
|
123
|
+
const last = ranges.at(-1);
|
|
124
|
+
if (last && start <= last.end) {
|
|
125
|
+
last.end = Math.max(last.end, end);
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
ranges.push({ start, end });
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const lines = [];
|
|
132
|
+
let oldBefore = 0;
|
|
133
|
+
let newBefore = 0;
|
|
134
|
+
let previousEnd = 0;
|
|
135
|
+
for (const range of ranges) {
|
|
136
|
+
for (const operation of operations.slice(previousEnd, range.start)) {
|
|
137
|
+
oldBefore += operation.mark !== '+' ? 1 : 0;
|
|
138
|
+
newBefore += operation.mark !== '-' ? 1 : 0;
|
|
139
|
+
}
|
|
140
|
+
const hunk = operations.slice(range.start, range.end);
|
|
141
|
+
const oldCount = hunk.filter((operation) => operation.mark !== '+').length;
|
|
142
|
+
const newCount = hunk.filter((operation) => operation.mark !== '-').length;
|
|
143
|
+
const oldStart = oldCount === 0 ? oldBefore : oldBefore + 1;
|
|
144
|
+
const newStart = newCount === 0 ? newBefore : newBefore + 1;
|
|
145
|
+
lines.push(`@@ -${oldStart},${oldCount} +${newStart},${newCount} @@`);
|
|
146
|
+
lines.push(...hunk.map(({ mark, line }) => `${mark}${line}`));
|
|
147
|
+
oldBefore += oldCount;
|
|
148
|
+
newBefore += newCount;
|
|
149
|
+
previousEnd = range.end;
|
|
150
|
+
}
|
|
151
|
+
return lines.length > 240 ? [...lines.slice(0, 240), `... ${lines.length - 240} more diff lines`] : lines;
|
|
152
|
+
}
|
package/dist/src/env-sync.d.ts
CHANGED
|
@@ -69,8 +69,6 @@ export declare function buildStableKey(component: ComponentRecord, stableKeyName
|
|
|
69
69
|
export declare function captureEnvSnapshot(client: RevoClient, envName: string, options?: {
|
|
70
70
|
stableKeyName?: string;
|
|
71
71
|
}): Promise<EnvSnapshot>;
|
|
72
|
-
declare const PORTABLE_METADATA_FIELDS: readonly ["name", "category", "desc", "active", "type", "async"];
|
|
73
|
-
export type PortableMetadataField = (typeof PORTABLE_METADATA_FIELDS)[number];
|
|
74
72
|
export declare function buildEnvSyncPlan(source: EnvSnapshot, target: EnvSnapshot, options: {
|
|
75
73
|
prune: boolean;
|
|
76
74
|
scope?: EnvSyncScope;
|
|
@@ -83,4 +81,3 @@ export declare function applyEnvSyncPlan(input: {
|
|
|
83
81
|
stableKeyName?: string;
|
|
84
82
|
onItem?: (result: EnvApplyItemResult) => void;
|
|
85
83
|
}): Promise<EnvApplyItemResult[]>;
|
|
86
|
-
export {};
|
package/dist/src/env-sync.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { hashPortableComponentSource, normalizePortableComponentSource, sanitizeComponentSource, } from "./component-lock.js";
|
|
1
|
+
import { buildPortableComponentUpdatePayload, diffPortableComponentSource, hashPortableComponentSource, normalizePortableComponentSource, sanitizeComponentSource, } from "./component-lock.js";
|
|
2
2
|
import { buildStableKey as buildComponentStableKey, DEFAULT_STABLE_KEY_NAME, NULL_CATEGORY_KEY, sanitizeUserMetadata, } from "./resource-metadata.js";
|
|
3
|
+
import { mapWithConcurrency } from "./utils.js";
|
|
3
4
|
export function normalizeKeyPart(value) {
|
|
4
5
|
return (value ?? '').trim().replace(/\s+/g, ' ').toLowerCase();
|
|
5
6
|
}
|
|
@@ -21,11 +22,9 @@ function componentIdOf(component) {
|
|
|
21
22
|
export async function captureEnvSnapshot(client, envName, options = {}) {
|
|
22
23
|
const { components: summaries } = await client.listAllComponents();
|
|
23
24
|
const byStableKey = new Map();
|
|
24
|
-
|
|
25
|
+
const validSummaries = summaries.filter((summary) => Boolean(componentIdOf(summary)));
|
|
26
|
+
const entries = await mapWithConcurrency(validSummaries, async (summary) => {
|
|
25
27
|
const componentId = componentIdOf(summary);
|
|
26
|
-
if (!componentId) {
|
|
27
|
-
continue;
|
|
28
|
-
}
|
|
29
28
|
const component = unwrapComponent(await client.getComponent(componentId));
|
|
30
29
|
const stableKey = buildStableKey(component, options.stableKeyName);
|
|
31
30
|
const entry = {
|
|
@@ -35,12 +34,15 @@ export async function captureEnvSnapshot(client, envName, options = {}) {
|
|
|
35
34
|
portable: normalizePortableComponentSource(component),
|
|
36
35
|
portableHash: hashPortableComponentSource(component),
|
|
37
36
|
};
|
|
38
|
-
|
|
37
|
+
return entry;
|
|
38
|
+
});
|
|
39
|
+
for (const entry of entries) {
|
|
40
|
+
const bucket = byStableKey.get(entry.stableKey);
|
|
39
41
|
if (bucket) {
|
|
40
42
|
bucket.push(entry);
|
|
41
43
|
}
|
|
42
44
|
else {
|
|
43
|
-
byStableKey.set(stableKey, [entry]);
|
|
45
|
+
byStableKey.set(entry.stableKey, [entry]);
|
|
44
46
|
}
|
|
45
47
|
}
|
|
46
48
|
const components = new Map();
|
|
@@ -69,10 +71,6 @@ export async function captureEnvSnapshot(client, envName, options = {}) {
|
|
|
69
71
|
collisions,
|
|
70
72
|
};
|
|
71
73
|
}
|
|
72
|
-
const PORTABLE_METADATA_FIELDS = ['name', 'category', 'desc', 'active', 'type', 'async'];
|
|
73
|
-
function diffMetadataFields(source, target) {
|
|
74
|
-
return PORTABLE_METADATA_FIELDS.filter((field) => source[field] !== target[field]);
|
|
75
|
-
}
|
|
76
74
|
function diffElementKeys(source, target) {
|
|
77
75
|
const sourceByKey = new Map(source.elements.map((element) => [element.key, element]));
|
|
78
76
|
const targetByKey = new Map(target.elements.map((element) => [element.key, element]));
|
|
@@ -174,7 +172,7 @@ export function buildEnvSyncPlan(source, target, options) {
|
|
|
174
172
|
items.push({ ...base, action: 'noop', reason: 'up to date' });
|
|
175
173
|
continue;
|
|
176
174
|
}
|
|
177
|
-
const changedFields =
|
|
175
|
+
const changedFields = diffPortableComponentSource(sourceEntry.component, targetEntry.component).configurationFields;
|
|
178
176
|
const elementDiff = diffElementKeys(sourceEntry.portable, targetEntry.portable);
|
|
179
177
|
items.push({
|
|
180
178
|
...base,
|
|
@@ -240,18 +238,6 @@ function buildCreatePayload(component) {
|
|
|
240
238
|
elements: buildPortableElementPayload(component),
|
|
241
239
|
};
|
|
242
240
|
}
|
|
243
|
-
function buildMetadataPayload(source, target, changedFields) {
|
|
244
|
-
if (!Number.isInteger(target.version)) {
|
|
245
|
-
throw new Error('target component version is required to update component metadata');
|
|
246
|
-
}
|
|
247
|
-
const payload = { version: target.version };
|
|
248
|
-
for (const field of PORTABLE_METADATA_FIELDS) {
|
|
249
|
-
if (changedFields.includes(field)) {
|
|
250
|
-
payload[field] = source[field];
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
return payload;
|
|
254
|
-
}
|
|
255
241
|
async function verifyAppliedComponent(targetClient, componentId, expectedHash) {
|
|
256
242
|
const component = unwrapComponent(await targetClient.getComponent(componentId));
|
|
257
243
|
return hashPortableComponentSource(component) === expectedHash;
|
|
@@ -300,7 +286,7 @@ async function applyPlanItem(targetClient, item, source, target, stableKeyName =
|
|
|
300
286
|
throw new Error('component disappeared from the snapshot');
|
|
301
287
|
}
|
|
302
288
|
if (item.changedFields && item.changedFields.length > 0) {
|
|
303
|
-
await targetClient.updateComponent(targetEntry.componentId,
|
|
289
|
+
await targetClient.updateComponent(targetEntry.componentId, buildPortableComponentUpdatePayload(sourceEntry.component, targetEntry.component, item.changedFields));
|
|
304
290
|
}
|
|
305
291
|
const hasElementChanges = Boolean(item.addedElementKeys?.length || item.removedElementKeys?.length || item.changedElementKeys?.length);
|
|
306
292
|
if (hasElementChanges) {
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
declare const HTTP_TRACE_DIRECTORY: string;
|
|
2
|
+
export type HttpTraceContext = {
|
|
3
|
+
stage?: string;
|
|
4
|
+
resource?: string;
|
|
5
|
+
dependency?: string;
|
|
6
|
+
environment?: string;
|
|
7
|
+
operation?: string;
|
|
8
|
+
entityId?: string;
|
|
9
|
+
entityName?: string;
|
|
10
|
+
stableKey?: string;
|
|
11
|
+
};
|
|
12
|
+
export type HttpTraceRunMetadata = {
|
|
13
|
+
command: string;
|
|
14
|
+
dryRun?: boolean;
|
|
15
|
+
};
|
|
16
|
+
export type HttpTraceRequestHandle = {
|
|
17
|
+
session: HttpTraceSession;
|
|
18
|
+
sequence: number;
|
|
19
|
+
startedAt: string;
|
|
20
|
+
startedAtMs: number;
|
|
21
|
+
method: string;
|
|
22
|
+
path: string;
|
|
23
|
+
context: HttpTraceContext;
|
|
24
|
+
completed: boolean;
|
|
25
|
+
requestBody?: {
|
|
26
|
+
bytes: number;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
export type HttpTraceCompletion = {
|
|
30
|
+
status?: number;
|
|
31
|
+
ok: boolean;
|
|
32
|
+
responseHeaders?: Headers;
|
|
33
|
+
responseData?: unknown;
|
|
34
|
+
responseBytes?: number;
|
|
35
|
+
error?: unknown;
|
|
36
|
+
};
|
|
37
|
+
type HttpTraceRequest = {
|
|
38
|
+
sequence: number;
|
|
39
|
+
startedAt: string;
|
|
40
|
+
finishedAt: string;
|
|
41
|
+
durationMs: number;
|
|
42
|
+
method: string;
|
|
43
|
+
path: string;
|
|
44
|
+
ok: boolean;
|
|
45
|
+
status?: number;
|
|
46
|
+
stage?: string;
|
|
47
|
+
resource?: string;
|
|
48
|
+
dependency?: string;
|
|
49
|
+
operation?: string;
|
|
50
|
+
requestBody?: {
|
|
51
|
+
bytes: number;
|
|
52
|
+
};
|
|
53
|
+
responseBytes?: number;
|
|
54
|
+
error?: {
|
|
55
|
+
name: string;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
export type HttpTraceSession = {
|
|
59
|
+
projectRoot: string;
|
|
60
|
+
filePath: string;
|
|
61
|
+
startedAt: string;
|
|
62
|
+
startedAtMs: number;
|
|
63
|
+
metadata: HttpTraceRunMetadata;
|
|
64
|
+
requests: HttpTraceRequest[];
|
|
65
|
+
nextSequence: number;
|
|
66
|
+
activeRequests: Map<number, HttpTraceRequestHandle>;
|
|
67
|
+
idleWaiters: Set<() => void>;
|
|
68
|
+
};
|
|
69
|
+
export declare function createHttpTraceSession(projectRoot: string, metadata: HttpTraceRunMetadata): {
|
|
70
|
+
projectRoot: string;
|
|
71
|
+
filePath: string;
|
|
72
|
+
startedAt: string;
|
|
73
|
+
startedAtMs: number;
|
|
74
|
+
metadata: {
|
|
75
|
+
dryRun?: true | undefined;
|
|
76
|
+
command: string;
|
|
77
|
+
};
|
|
78
|
+
requests: never[];
|
|
79
|
+
nextSequence: number;
|
|
80
|
+
activeRequests: Map<any, any>;
|
|
81
|
+
idleWaiters: Set<() => void>;
|
|
82
|
+
};
|
|
83
|
+
export declare function withHttpTraceSession<T>(session: HttpTraceSession, operation: () => T): T;
|
|
84
|
+
export declare function withHttpTraceContext<T>(context: HttpTraceContext, operation: () => T): T;
|
|
85
|
+
export declare function beginHttpTraceRequest(input: {
|
|
86
|
+
method: string;
|
|
87
|
+
url: URL;
|
|
88
|
+
body?: BodyInit | null;
|
|
89
|
+
context?: HttpTraceContext;
|
|
90
|
+
}): HttpTraceRequestHandle | undefined;
|
|
91
|
+
export declare function completeHttpTraceRequest(handle: HttpTraceRequestHandle | undefined, completion: HttpTraceCompletion): void;
|
|
92
|
+
export declare function responseSize(data: unknown, headers?: Headers): number;
|
|
93
|
+
export declare function finalizeHttpTraceSession(session: HttpTraceSession, status: 'succeeded' | 'failed', error?: unknown): Promise<string>;
|
|
94
|
+
export { HTTP_TRACE_DIRECTORY };
|