@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.
- package/README.md +275 -479
- package/dist/src/cli.js +71 -5
- package/dist/src/client.d.ts +28 -12
- package/dist/src/client.js +234 -66
- package/dist/src/commands/component.d.ts +67 -0
- package/dist/src/commands/component.js +299 -27
- package/dist/src/commands/database-tables.d.ts +2 -0
- package/dist/src/commands/{database-schemas.js → database-tables.js} +21 -40
- package/dist/src/commands/database-views.js +21 -18
- package/dist/src/commands/endpoints.js +26 -16
- package/dist/src/commands/events.js +18 -20
- package/dist/src/commands/groups.js +13 -22
- package/dist/src/commands/index.d.ts +2 -1
- package/dist/src/commands/index.js +2 -1
- package/dist/src/commands/job-templates.js +21 -15
- package/dist/src/commands/metadata.js +58 -15
- package/dist/src/commands/migrate.d.ts +6 -0
- package/dist/src/commands/migrate.js +658 -0
- package/dist/src/commands/project.js +4 -4
- package/dist/src/commands/role-groups.js +14 -25
- package/dist/src/commands/schedules.js +19 -20
- 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.js +2 -2
- package/dist/src/commands/terminal.d.ts +31 -4
- package/dist/src/commands/terminal.js +360 -45
- package/dist/src/component-lock.d.ts +12 -2
- package/dist/src/component-lock.js +60 -1
- package/dist/src/diff-details.d.ts +8 -0
- package/dist/src/diff-details.js +152 -0
- package/dist/src/env-sync.js +8 -6
- package/dist/src/http-trace.d.ts +94 -0
- package/dist/src/http-trace.js +226 -0
- package/dist/src/metadata-backfill.d.ts +5 -4
- package/dist/src/metadata-backfill.js +82 -158
- package/dist/src/migration.d.ts +141 -0
- package/dist/src/migration.js +1632 -0
- package/dist/src/resource-inventory.d.ts +28 -0
- package/dist/src/resource-inventory.js +85 -0
- package/dist/src/resource-syncs/{database-schema-sync.d.ts → database-table-sync.d.ts} +13 -3
- package/dist/src/resource-syncs/{database-schema-sync.js → database-table-sync.js} +147 -62
- package/dist/src/resource-syncs/database-view-sync.d.ts +24 -2
- package/dist/src/resource-syncs/database-view-sync.js +156 -68
- package/dist/src/resource-syncs/endpoint-sync.d.ts +27 -0
- package/dist/src/resource-syncs/endpoint-sync.js +362 -82
- package/dist/src/resource-syncs/event-sync.d.ts +27 -0
- package/dist/src/resource-syncs/event-sync.js +123 -26
- package/dist/src/resource-syncs/group-sync.d.ts +7 -0
- package/dist/src/resource-syncs/group-sync.js +60 -14
- package/dist/src/resource-syncs/job-template-sync.d.ts +21 -0
- package/dist/src/resource-syncs/job-template-sync.js +91 -30
- package/dist/src/resource-syncs/role-group-sync.d.ts +7 -0
- package/dist/src/resource-syncs/role-group-sync.js +47 -9
- package/dist/src/resource-syncs/schedule-sync.d.ts +30 -1
- package/dist/src/resource-syncs/schedule-sync.js +114 -20
- package/dist/src/resource-syncs/util.d.ts +3 -0
- package/dist/src/resource-syncs/util.js +8 -6
- package/dist/src/resource-target.d.ts +11 -0
- package/dist/src/resource-target.js +48 -0
- package/dist/src/sync-output.d.ts +29 -1
- package/dist/src/sync-output.js +139 -2
- package/dist/src/tracked-resources.d.ts +1 -1
- package/dist/src/tracked-resources.js +8 -6
- package/dist/src/types.d.ts +3 -0
- package/dist/src/ui.js +18 -9
- package/dist/src/utils.d.ts +2 -0
- package/dist/src/utils.js +17 -0
- package/dist/src/workspace-diff.d.ts +25 -0
- package/dist/src/workspace-diff.js +75 -0
- package/package.json +9 -6
- package/dist/src/commands/database-schemas.d.ts +0 -2
- /package/dist/src/{database-schema-artifacts.d.ts → database-table-artifacts.d.ts} +0 -0
- /package/dist/src/{database-schema-artifacts.js → database-table-artifacts.js} +0 -0
|
@@ -14,6 +14,7 @@ export type ComponentLockEntry = {
|
|
|
14
14
|
remoteHash: string;
|
|
15
15
|
sourceHash: string;
|
|
16
16
|
pulledAt: string;
|
|
17
|
+
defaultRemoved?: boolean;
|
|
17
18
|
environments?: Record<string, ComponentEnvironmentBaseline>;
|
|
18
19
|
};
|
|
19
20
|
export type ComponentEnvironmentBaseline = {
|
|
@@ -22,7 +23,7 @@ export type ComponentEnvironmentBaseline = {
|
|
|
22
23
|
remoteHash: string;
|
|
23
24
|
syncedAt: string;
|
|
24
25
|
};
|
|
25
|
-
export type ComponentLockEntryInput = Omit<ComponentLockEntry, 'identityMode' | 'remoteComponentId'> & Partial<Pick<ComponentLockEntry, 'identityMode' | 'remoteComponentId'>>;
|
|
26
|
+
export type ComponentLockEntryInput = Omit<ComponentLockEntry, 'identityMode' | 'remoteComponentId' | 'defaultRemoved'> & Partial<Pick<ComponentLockEntry, 'identityMode' | 'remoteComponentId'>>;
|
|
26
27
|
export type EnvironmentBaseline = {
|
|
27
28
|
remoteHash: string;
|
|
28
29
|
syncedAt: string;
|
|
@@ -95,10 +96,18 @@ export type DatabaseViewLockEntry = {
|
|
|
95
96
|
stableKey: string;
|
|
96
97
|
path: string;
|
|
97
98
|
sourceHash: string;
|
|
98
|
-
environments: Record<string, EnvironmentBaseline
|
|
99
|
+
environments: Record<string, EnvironmentBaseline & {
|
|
100
|
+
dependencyHash?: string;
|
|
101
|
+
}>;
|
|
102
|
+
};
|
|
103
|
+
export type RevoLockDiagnostics = {
|
|
104
|
+
httpTrace?: {
|
|
105
|
+
enabled: boolean;
|
|
106
|
+
};
|
|
99
107
|
};
|
|
100
108
|
export type RevoLockFile = {
|
|
101
109
|
schemaVersion: 2;
|
|
110
|
+
diagnostics?: RevoLockDiagnostics;
|
|
102
111
|
componentIdentity: ComponentIdentityConfig;
|
|
103
112
|
components: Record<string, ComponentLockEntry>;
|
|
104
113
|
groups: Record<string, GroupLockEntry>;
|
|
@@ -161,3 +170,4 @@ export declare function componentLockMatchesIdentity(lock: RevoLockFile, identit
|
|
|
161
170
|
export declare function getComponentLockEntry(lock: RevoLockFile, identity: ComponentIdentityConfig, component: ComponentRecord, environmentName?: string): ComponentLockEntry | null;
|
|
162
171
|
export declare function getComponentLockEntries(lock: RevoLockFile, identity: ComponentIdentityConfig, environmentName?: string): Record<string, ComponentLockEntry>;
|
|
163
172
|
export declare function upsertComponentLockEntry(projectRoot: string, entry: ComponentLockEntryInput, identity?: ComponentIdentityConfig, environmentName?: string): void;
|
|
173
|
+
export declare function removeComponentLockBaseline(projectRoot: string, identity: ComponentIdentityConfig, key: string, remoteComponentId: string, environmentName?: string): void;
|
|
@@ -25,6 +25,25 @@ const VOLATILE_COMPONENT_FIELDS = new Set([
|
|
|
25
25
|
function isRecord(value) {
|
|
26
26
|
return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
27
27
|
}
|
|
28
|
+
function normalizeDiagnostics(value) {
|
|
29
|
+
if (value === undefined) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
if (!isRecord(value)) {
|
|
33
|
+
throw new Error('revo.lock.json field `diagnostics` must be an object.');
|
|
34
|
+
}
|
|
35
|
+
if (value.httpTrace === undefined) {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
if (!isRecord(value.httpTrace) || typeof value.httpTrace.enabled !== 'boolean') {
|
|
39
|
+
throw new Error('revo.lock.json field `diagnostics.httpTrace.enabled` must be a boolean.');
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
httpTrace: {
|
|
43
|
+
enabled: value.httpTrace.enabled,
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
28
47
|
function normalizeValue(value, fallback = null) {
|
|
29
48
|
return value ?? fallback;
|
|
30
49
|
}
|
|
@@ -146,6 +165,7 @@ export function readComponentLock(projectRoot) {
|
|
|
146
165
|
}
|
|
147
166
|
const raw = readJsonFile(lockPath);
|
|
148
167
|
const componentIdentity = normalizeComponentIdentityConfig(raw.componentIdentity, COMPONENT_IDENTITY_BY_ID);
|
|
168
|
+
const diagnostics = normalizeDiagnostics(raw.diagnostics);
|
|
149
169
|
const components = Object.fromEntries(Object.entries(raw.components && typeof raw.components === 'object' ? raw.components : {})
|
|
150
170
|
.map(([key, entry]) => {
|
|
151
171
|
const remoteComponentId = String(entry.remoteComponentId || entry.componentId || key);
|
|
@@ -179,6 +199,7 @@ export function readComponentLock(projectRoot) {
|
|
|
179
199
|
}));
|
|
180
200
|
return {
|
|
181
201
|
schemaVersion: 2,
|
|
202
|
+
...(diagnostics ? { diagnostics } : {}),
|
|
182
203
|
componentIdentity,
|
|
183
204
|
components,
|
|
184
205
|
groups: Object.fromEntries(Object.entries(raw.groups && typeof raw.groups === 'object' ? raw.groups : {})
|
|
@@ -336,6 +357,7 @@ export function readComponentLock(projectRoot) {
|
|
|
336
357
|
.map(([envName, baseline]) => [envName, {
|
|
337
358
|
remoteHash: String(baseline.remoteHash),
|
|
338
359
|
syncedAt: String(baseline.syncedAt),
|
|
360
|
+
...(typeof baseline.dependencyHash === 'string' ? { dependencyHash: baseline.dependencyHash } : {}),
|
|
339
361
|
}])),
|
|
340
362
|
}])),
|
|
341
363
|
};
|
|
@@ -352,6 +374,7 @@ export function writeComponentLock(projectRoot, lock) {
|
|
|
352
374
|
const sortedDatabaseViews = Object.fromEntries(Object.entries(lock.databaseViews || {}).sort(([left], [right]) => left.localeCompare(right)));
|
|
353
375
|
writeJsonFile(getLockPath(projectRoot), {
|
|
354
376
|
schemaVersion: 2,
|
|
377
|
+
...(lock.diagnostics ? { diagnostics: normalizeDiagnostics(lock.diagnostics) } : {}),
|
|
355
378
|
componentIdentity: normalizeComponentIdentityConfig(lock.componentIdentity),
|
|
356
379
|
components: sortedComponents,
|
|
357
380
|
...(Object.keys(sortedGroups).length > 0 ? { groups: sortedGroups } : {}),
|
|
@@ -376,6 +399,9 @@ export function getComponentLockEntry(lock, identity, component, environmentName
|
|
|
376
399
|
}
|
|
377
400
|
const key = componentLockKey(identity, component);
|
|
378
401
|
const entry = key ? lock.components[key] || null : null;
|
|
402
|
+
if (entry?.defaultRemoved && !environmentName) {
|
|
403
|
+
return null;
|
|
404
|
+
}
|
|
379
405
|
if (!entry || !environmentName) {
|
|
380
406
|
return entry;
|
|
381
407
|
}
|
|
@@ -396,7 +422,7 @@ export function getComponentLockEntries(lock, identity, environmentName) {
|
|
|
396
422
|
return {};
|
|
397
423
|
}
|
|
398
424
|
if (!environmentName) {
|
|
399
|
-
return lock.components;
|
|
425
|
+
return Object.fromEntries(Object.entries(lock.components).filter(([, entry]) => !entry.defaultRemoved));
|
|
400
426
|
}
|
|
401
427
|
return Object.fromEntries(Object.entries(lock.components).flatMap(([key, entry]) => {
|
|
402
428
|
const baseline = entry.environments?.[environmentName];
|
|
@@ -441,6 +467,7 @@ export function upsertComponentLockEntry(projectRoot, entry, identity = COMPONEN
|
|
|
441
467
|
const storedEntry = environmentName
|
|
442
468
|
? {
|
|
443
469
|
...normalizedEntry,
|
|
470
|
+
...(existing?.defaultRemoved ? { defaultRemoved: true } : {}),
|
|
444
471
|
remoteComponentId: existing?.remoteComponentId || normalizedEntry.remoteComponentId,
|
|
445
472
|
remoteVersion: existing?.remoteVersion ?? normalizedEntry.remoteVersion,
|
|
446
473
|
remoteHash: existing?.remoteHash || normalizedEntry.remoteHash,
|
|
@@ -470,6 +497,7 @@ export function upsertComponentLockEntry(projectRoot, entry, identity = COMPONEN
|
|
|
470
497
|
&& existing.remoteVersion === storedEntry.remoteVersion
|
|
471
498
|
&& existing.remoteHash === storedEntry.remoteHash
|
|
472
499
|
&& existing.sourceHash === storedEntry.sourceHash
|
|
500
|
+
&& existing.defaultRemoved === storedEntry.defaultRemoved
|
|
473
501
|
&& JSON.stringify(existing.environments || {}) === JSON.stringify(storedEntry.environments || {})) {
|
|
474
502
|
return;
|
|
475
503
|
}
|
|
@@ -477,3 +505,34 @@ export function upsertComponentLockEntry(projectRoot, entry, identity = COMPONEN
|
|
|
477
505
|
lock.components[key] = storedEntry;
|
|
478
506
|
writeComponentLock(projectRoot, lock);
|
|
479
507
|
}
|
|
508
|
+
export function removeComponentLockBaseline(projectRoot, identity, key, remoteComponentId, environmentName) {
|
|
509
|
+
const lock = readComponentLock(projectRoot);
|
|
510
|
+
if (!componentLockMatchesIdentity(lock, identity)) {
|
|
511
|
+
throw new Error('Component lock identity changed before prune.');
|
|
512
|
+
}
|
|
513
|
+
const entry = lock.components[key];
|
|
514
|
+
const baselineId = environmentName
|
|
515
|
+
? entry?.environments?.[environmentName]?.remoteComponentId
|
|
516
|
+
: entry?.defaultRemoved ? undefined : entry?.remoteComponentId;
|
|
517
|
+
if (!entry || baselineId !== remoteComponentId) {
|
|
518
|
+
throw new Error(`Component lock baseline for "${key}" changed before prune.`);
|
|
519
|
+
}
|
|
520
|
+
if (environmentName) {
|
|
521
|
+
const environments = { ...entry.environments };
|
|
522
|
+
delete environments[environmentName];
|
|
523
|
+
const defaultRemoved = entry.defaultRemoved || entry.remoteComponentId === remoteComponentId;
|
|
524
|
+
if (Object.keys(environments).length === 0 && defaultRemoved) {
|
|
525
|
+
delete lock.components[key];
|
|
526
|
+
}
|
|
527
|
+
else {
|
|
528
|
+
lock.components[key] = { ...entry, ...(defaultRemoved ? { defaultRemoved: true } : {}), environments };
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
else if (Object.keys(entry.environments || {}).length > 0) {
|
|
532
|
+
lock.components[key] = { ...entry, defaultRemoved: true };
|
|
533
|
+
}
|
|
534
|
+
else {
|
|
535
|
+
delete lock.components[key];
|
|
536
|
+
}
|
|
537
|
+
writeComponentLock(projectRoot, lock);
|
|
538
|
+
}
|
|
@@ -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.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
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();
|
|
@@ -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 };
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
4
|
+
import { REVO_PROJECT_DIR } from "./project.js";
|
|
5
|
+
import { writeJsonFile } from "./utils.js";
|
|
6
|
+
const HTTP_TRACE_DIRECTORY = path.join(REVO_PROJECT_DIR, 'logs', 'http-trace');
|
|
7
|
+
const SAFE_PATH_SEGMENTS = new Set([
|
|
8
|
+
'api', 'v1', 'activity', 'automation', 'event', 'schedule', 'template',
|
|
9
|
+
'component', 'databases', 'stats', 'views', 'preview', 'endpoints',
|
|
10
|
+
'groups', 'me', 'role-groups', 'roles', 'search',
|
|
11
|
+
]);
|
|
12
|
+
const SAFE_ERROR_NAMES = new Set(['Error', 'TypeError', 'SyntaxError', 'AbortError', 'TimeoutError']);
|
|
13
|
+
const SAFE_HTTP_METHODS = new Set(['GET', 'HEAD', 'OPTIONS', 'POST', 'PUT', 'PATCH', 'DELETE']);
|
|
14
|
+
const SAFE_TRACE_COMMANDS = new Set([
|
|
15
|
+
'auth', 'component', 'database-tables', 'database-views', 'deploy', 'diff',
|
|
16
|
+
'endpoints', 'env', 'events', 'groups', 'help', 'info', 'job-templates',
|
|
17
|
+
'metadata', 'migrate', 'plan', 'project', 'pull', 'request', 'role-groups',
|
|
18
|
+
'schedules', 'search', 'version', 'overview',
|
|
19
|
+
]);
|
|
20
|
+
const traceStorage = new AsyncLocalStorage();
|
|
21
|
+
function traceFileName(startedAt, suffix = 1) {
|
|
22
|
+
const timestamp = startedAt.toISOString().replace(/[:.]/g, '-');
|
|
23
|
+
return suffix === 1 ? `${timestamp}.json` : `${timestamp}-${suffix}.json`;
|
|
24
|
+
}
|
|
25
|
+
function reserveTraceFile(projectRoot, startedAt) {
|
|
26
|
+
const directory = path.join(projectRoot, HTTP_TRACE_DIRECTORY);
|
|
27
|
+
fs.mkdirSync(directory, { recursive: true });
|
|
28
|
+
for (let suffix = 1;; suffix += 1) {
|
|
29
|
+
const filePath = path.join(directory, traceFileName(startedAt, suffix));
|
|
30
|
+
try {
|
|
31
|
+
fs.closeSync(fs.openSync(filePath, 'wx', 0o600));
|
|
32
|
+
return filePath;
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
if (error.code !== 'EEXIST') {
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export function createHttpTraceSession(projectRoot, metadata) {
|
|
42
|
+
const startedAt = new Date();
|
|
43
|
+
return {
|
|
44
|
+
projectRoot,
|
|
45
|
+
filePath: reserveTraceFile(projectRoot, startedAt),
|
|
46
|
+
startedAt: startedAt.toISOString(),
|
|
47
|
+
startedAtMs: startedAt.getTime(),
|
|
48
|
+
metadata: {
|
|
49
|
+
command: SAFE_TRACE_COMMANDS.has(metadata.command) ? metadata.command : 'unknown',
|
|
50
|
+
...(metadata.dryRun === true ? { dryRun: true } : {}),
|
|
51
|
+
},
|
|
52
|
+
requests: [],
|
|
53
|
+
nextSequence: 1,
|
|
54
|
+
activeRequests: new Map(),
|
|
55
|
+
idleWaiters: new Set(),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export function withHttpTraceSession(session, operation) {
|
|
59
|
+
return traceStorage.run({ session, context: {} }, operation);
|
|
60
|
+
}
|
|
61
|
+
export function withHttpTraceContext(context, operation) {
|
|
62
|
+
const active = traceStorage.getStore();
|
|
63
|
+
if (!active) {
|
|
64
|
+
return operation();
|
|
65
|
+
}
|
|
66
|
+
return traceStorage.run({
|
|
67
|
+
session: active.session,
|
|
68
|
+
context: { ...active.context, ...context },
|
|
69
|
+
}, operation);
|
|
70
|
+
}
|
|
71
|
+
function safeRequestPath(url) {
|
|
72
|
+
return url.pathname.split('/').map((segment) => (segment === '' || SAFE_PATH_SEGMENTS.has(segment) ? segment : '[REDACTED]')).join('/');
|
|
73
|
+
}
|
|
74
|
+
function summarizeRequestBody(body) {
|
|
75
|
+
if (body === undefined || body === null) {
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
bytes: Buffer.byteLength(typeof body === 'string' ? body : String(body)),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function sanitizedError(error) {
|
|
83
|
+
const name = error instanceof Error ? error.name : 'Error';
|
|
84
|
+
return {
|
|
85
|
+
name: SAFE_ERROR_NAMES.has(name) ? name : 'Error',
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
export function beginHttpTraceRequest(input) {
|
|
89
|
+
const active = traceStorage.getStore();
|
|
90
|
+
if (!active) {
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
const requestPath = safeRequestPath(input.url);
|
|
94
|
+
const sequence = active.session.nextSequence;
|
|
95
|
+
active.session.nextSequence += 1;
|
|
96
|
+
const startedAtMs = Date.now();
|
|
97
|
+
const requestBody = summarizeRequestBody(input.body);
|
|
98
|
+
const handle = {
|
|
99
|
+
session: active.session,
|
|
100
|
+
sequence,
|
|
101
|
+
startedAt: new Date(startedAtMs).toISOString(),
|
|
102
|
+
startedAtMs,
|
|
103
|
+
method: SAFE_HTTP_METHODS.has(input.method.toUpperCase()) ? input.method.toUpperCase() : 'UNKNOWN',
|
|
104
|
+
path: requestPath,
|
|
105
|
+
context: {
|
|
106
|
+
stage: input.context?.stage ?? active.context.stage,
|
|
107
|
+
resource: input.context?.resource ?? active.context.resource,
|
|
108
|
+
dependency: input.context?.dependency ?? active.context.dependency,
|
|
109
|
+
operation: input.context?.operation ?? active.context.operation,
|
|
110
|
+
},
|
|
111
|
+
completed: false,
|
|
112
|
+
...(requestBody ? { requestBody } : {}),
|
|
113
|
+
};
|
|
114
|
+
active.session.activeRequests.set(sequence, handle);
|
|
115
|
+
return handle;
|
|
116
|
+
}
|
|
117
|
+
export function completeHttpTraceRequest(handle, completion) {
|
|
118
|
+
if (!handle || handle.completed) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
handle.completed = true;
|
|
122
|
+
handle.session.activeRequests.delete(handle.sequence);
|
|
123
|
+
const finishedAtMs = Date.now();
|
|
124
|
+
handle.session.requests.push({
|
|
125
|
+
sequence: handle.sequence,
|
|
126
|
+
startedAt: handle.startedAt,
|
|
127
|
+
finishedAt: new Date(finishedAtMs).toISOString(),
|
|
128
|
+
durationMs: Math.max(0, finishedAtMs - handle.startedAtMs),
|
|
129
|
+
method: handle.method,
|
|
130
|
+
path: handle.path,
|
|
131
|
+
...handle.context,
|
|
132
|
+
ok: completion.ok,
|
|
133
|
+
...(completion.status === undefined ? {} : { status: completion.status }),
|
|
134
|
+
...(handle.requestBody ? { requestBody: handle.requestBody } : {}),
|
|
135
|
+
...(completion.responseBytes === undefined ? {} : { responseBytes: completion.responseBytes }),
|
|
136
|
+
...(completion.error ? { error: sanitizedError(completion.error) } : {}),
|
|
137
|
+
});
|
|
138
|
+
if (handle.session.activeRequests.size === 0) {
|
|
139
|
+
for (const resolve of handle.session.idleWaiters) {
|
|
140
|
+
resolve();
|
|
141
|
+
}
|
|
142
|
+
handle.session.idleWaiters.clear();
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
export function responseSize(data, headers) {
|
|
146
|
+
const contentLength = headers?.get('content-length');
|
|
147
|
+
if (contentLength && /^\d+$/.test(contentLength)) {
|
|
148
|
+
return Number(contentLength);
|
|
149
|
+
}
|
|
150
|
+
if (data === undefined || data === null) {
|
|
151
|
+
return 0;
|
|
152
|
+
}
|
|
153
|
+
const serialized = typeof data === 'string' ? data : JSON.stringify(data);
|
|
154
|
+
return Buffer.byteLength(serialized);
|
|
155
|
+
}
|
|
156
|
+
function waitForImmediate() {
|
|
157
|
+
return new Promise((resolve) => setImmediate(resolve));
|
|
158
|
+
}
|
|
159
|
+
function waitUntilIdleOrTimeout(session, timeoutMs) {
|
|
160
|
+
return new Promise((resolve) => {
|
|
161
|
+
let timeout;
|
|
162
|
+
const onIdle = () => {
|
|
163
|
+
clearTimeout(timeout);
|
|
164
|
+
session.idleWaiters.delete(onIdle);
|
|
165
|
+
resolve();
|
|
166
|
+
};
|
|
167
|
+
timeout = setTimeout(() => {
|
|
168
|
+
session.idleWaiters.delete(onIdle);
|
|
169
|
+
resolve();
|
|
170
|
+
}, timeoutMs);
|
|
171
|
+
session.idleWaiters.add(onIdle);
|
|
172
|
+
if (session.activeRequests.size === 0) {
|
|
173
|
+
onIdle();
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
async function waitForActiveRequests(session) {
|
|
178
|
+
const deadline = Date.now() + 5_000;
|
|
179
|
+
while (Date.now() < deadline) {
|
|
180
|
+
if (session.activeRequests.size > 0) {
|
|
181
|
+
const remaining = deadline - Date.now();
|
|
182
|
+
await waitUntilIdleOrTimeout(session, remaining);
|
|
183
|
+
}
|
|
184
|
+
await waitForImmediate();
|
|
185
|
+
if (session.activeRequests.size === 0) {
|
|
186
|
+
await waitForImmediate();
|
|
187
|
+
if (session.activeRequests.size === 0) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
function recordIncompleteRequests(session) {
|
|
194
|
+
for (const handle of session.activeRequests.values()) {
|
|
195
|
+
completeHttpTraceRequest(handle, {
|
|
196
|
+
ok: false,
|
|
197
|
+
error: new Error('Request was still in flight when the CLI invocation finished.'),
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
export async function finalizeHttpTraceSession(session, status, error) {
|
|
202
|
+
await waitForActiveRequests(session);
|
|
203
|
+
recordIncompleteRequests(session);
|
|
204
|
+
const finishedAtMs = Date.now();
|
|
205
|
+
const requests = [...session.requests].sort((left, right) => left.sequence - right.sequence);
|
|
206
|
+
const successful = requests.filter((request) => request.ok).length;
|
|
207
|
+
writeJsonFile(session.filePath, {
|
|
208
|
+
schemaVersion: 1,
|
|
209
|
+
run: {
|
|
210
|
+
...session.metadata,
|
|
211
|
+
startedAt: session.startedAt,
|
|
212
|
+
finishedAt: new Date(finishedAtMs).toISOString(),
|
|
213
|
+
durationMs: Math.max(0, finishedAtMs - session.startedAtMs),
|
|
214
|
+
status,
|
|
215
|
+
...(error ? { error: sanitizedError(error) } : {}),
|
|
216
|
+
},
|
|
217
|
+
summary: {
|
|
218
|
+
requests: requests.length,
|
|
219
|
+
successful,
|
|
220
|
+
failed: requests.length - successful,
|
|
221
|
+
},
|
|
222
|
+
requests,
|
|
223
|
+
});
|
|
224
|
+
return session.filePath;
|
|
225
|
+
}
|
|
226
|
+
export { HTTP_TRACE_DIRECTORY };
|