@revoengine/cli 1.0.12 → 1.0.14

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 (31) hide show
  1. package/README.md +16 -2
  2. package/dist/src/cli.js +4 -0
  3. package/dist/src/client.d.ts +5 -0
  4. package/dist/src/client.js +41 -42
  5. package/dist/src/commands/component.js +26 -25
  6. package/dist/src/commands/migrate.js +10 -0
  7. package/dist/src/commands/terminal-browser.d.ts +40 -6
  8. package/dist/src/commands/terminal-browser.js +480 -19
  9. package/dist/src/commands/terminal-image.js +59 -1
  10. package/dist/src/commands/terminal-operational-log.d.ts +18 -0
  11. package/dist/src/commands/terminal-operational-log.js +119 -0
  12. package/dist/src/commands/terminal-policy.d.ts +23 -0
  13. package/dist/src/commands/terminal-policy.js +48 -0
  14. package/dist/src/commands/terminal-pty.d.ts +4 -0
  15. package/dist/src/commands/terminal-pty.js +39 -0
  16. package/dist/src/commands/terminal-reconnect-grace.d.ts +11 -0
  17. package/dist/src/commands/terminal-reconnect-grace.js +29 -0
  18. package/dist/src/commands/terminal-sandbox.d.ts +5 -1
  19. package/dist/src/commands/terminal-sandbox.js +19 -5
  20. package/dist/src/commands/terminal-secure-browser.d.ts +25 -0
  21. package/dist/src/commands/terminal-secure-browser.js +58 -0
  22. package/dist/src/commands/terminal.d.ts +5 -2
  23. package/dist/src/commands/terminal.js +259 -44
  24. package/dist/src/migration.js +10 -10
  25. package/dist/src/request-queue.d.ts +20 -0
  26. package/dist/src/request-queue.js +80 -0
  27. package/dist/src/resource-inventory.js +9 -10
  28. package/dist/src/resource-syncs/endpoint-sync.js +12 -46
  29. package/dist/src/types.d.ts +2 -0
  30. package/package.json +4 -3
  31. package/scripts/ensure-pty-helper.mjs +9 -0
@@ -867,11 +867,21 @@ function workspaceDesiredPulls(input) {
867
867
  } : {}),
868
868
  };
869
869
  }
870
+ function migrationComponentIdentity(cwd) {
871
+ const projectRoot = resolveProjectRoot(cwd) || cwd;
872
+ const identity = readProjectMetadata(cwd)
873
+ ? readProjectComponentIdentity(cwd)
874
+ : readComponentLock(projectRoot).componentIdentity;
875
+ return identity.mode === 'stableKey'
876
+ ? identity
877
+ : { mode: 'stableKey', metadataProperty: readProjectStableKeyName(cwd) };
878
+ }
870
879
  function componentCommandContext(input) {
871
880
  return {
872
881
  args: { _: ['component', input.operation], all: true, force: true, yes: true },
873
882
  client: input.client,
874
883
  componentEnvironment: input.envName,
884
+ componentIdentity: migrationComponentIdentity(input.cwd),
875
885
  cwd: input.cwd,
876
886
  packageVersion: 'migration',
877
887
  print: () => undefined,
@@ -879,15 +889,6 @@ function componentCommandContext(input) {
879
889
  error: () => undefined,
880
890
  };
881
891
  }
882
- function requireStableComponentIdentity(cwd) {
883
- const projectRoot = resolveProjectRoot(cwd) || cwd;
884
- const identity = readProjectMetadata(cwd)
885
- ? readProjectComponentIdentity(cwd)
886
- : readComponentLock(projectRoot).componentIdentity;
887
- if (identity.mode !== 'stableKey') {
888
- throw new Error('Component migration requires componentIdentity.mode "stableKey" in project metadata or the shared lock.');
889
- }
890
- }
891
892
  export async function pullResourcesToWorkspace(input) {
892
893
  requireProject(input);
893
894
  const resources = selectedResources(input);
@@ -915,7 +916,6 @@ export async function pullResourcesToWorkspace(input) {
915
916
  }));
916
917
  }
917
918
  if (resources.includes('component')) {
918
- requireStableComponentIdentity(input.cwd);
919
919
  pulls.components = await runMigrationStage('source pull', 'component', input.sourceLabel, () => pullAllComponents(componentCommandContext({
920
920
  cwd: input.cwd,
921
921
  envName: input.sourceKey,
@@ -0,0 +1,20 @@
1
+ export declare const HTTP_REQUEST_CONCURRENCY = 6;
2
+ export declare const DEFAULT_QUEUE_TIMEOUT_MS: number;
3
+ export declare class RequestQueue {
4
+ private active;
5
+ private pendingReads;
6
+ private pendingMutations;
7
+ private readonly concurrency;
8
+ constructor(concurrency?: number);
9
+ run<T>(task: () => Promise<T>, options?: {
10
+ signal?: AbortSignal;
11
+ timeoutMs?: number;
12
+ priority?: 'read' | 'mutation';
13
+ }): Promise<T>;
14
+ private pendingFor;
15
+ private removePending;
16
+ private clearWait;
17
+ private drain;
18
+ }
19
+ export declare function withRequestQueue<T>(command: () => Promise<T>): Promise<T>;
20
+ export declare function currentRequestQueue(): RequestQueue | undefined;
@@ -0,0 +1,80 @@
1
+ import { AsyncLocalStorage } from 'node:async_hooks';
2
+ export const HTTP_REQUEST_CONCURRENCY = 6;
3
+ export const DEFAULT_QUEUE_TIMEOUT_MS = 5 * 60_000;
4
+ export class RequestQueue {
5
+ active = 0;
6
+ pendingReads = [];
7
+ pendingMutations = [];
8
+ concurrency;
9
+ constructor(concurrency = HTTP_REQUEST_CONCURRENCY) {
10
+ this.concurrency = concurrency;
11
+ }
12
+ run(task, options = {}) {
13
+ if (options.signal?.aborted) {
14
+ return Promise.reject(options.signal.reason ?? new DOMException('Request cancelled.', 'AbortError'));
15
+ }
16
+ return new Promise((resolve, reject) => {
17
+ const entry = {
18
+ task, resolve: (value) => resolve(value), reject,
19
+ signal: options.signal,
20
+ priority: options.priority ?? 'read',
21
+ };
22
+ if (options.signal) {
23
+ entry.onAbort = () => this.removePending(entry, options.signal?.reason ?? new DOMException('Request cancelled.', 'AbortError'));
24
+ options.signal.addEventListener('abort', entry.onAbort, { once: true });
25
+ }
26
+ const timeoutMs = options.timeoutMs ?? DEFAULT_QUEUE_TIMEOUT_MS;
27
+ entry.timer = setTimeout(() => this.removePending(entry, new Error(`HTTP request queue wait timed out after ${timeoutMs} ms.`)), timeoutMs);
28
+ this.pendingFor(entry).push(entry);
29
+ this.drain();
30
+ });
31
+ }
32
+ pendingFor(entry) {
33
+ return entry.priority === 'mutation' ? this.pendingMutations : this.pendingReads;
34
+ }
35
+ removePending(entry, error) {
36
+ const pending = this.pendingFor(entry);
37
+ const index = pending.indexOf(entry);
38
+ if (index < 0) {
39
+ return;
40
+ }
41
+ pending.splice(index, 1);
42
+ this.clearWait(entry);
43
+ entry.reject(error);
44
+ }
45
+ clearWait(entry) {
46
+ if (entry.timer) {
47
+ clearTimeout(entry.timer);
48
+ }
49
+ if (entry.signal && entry.onAbort) {
50
+ entry.signal.removeEventListener('abort', entry.onAbort);
51
+ }
52
+ }
53
+ drain() {
54
+ while (this.active < this.concurrency && (this.pendingMutations.length > 0 || this.pendingReads.length > 0)) {
55
+ const entry = this.pendingMutations.shift() || this.pendingReads.shift();
56
+ this.clearWait(entry);
57
+ if (entry.signal?.aborted) {
58
+ entry.reject(entry.signal.reason ?? new DOMException('Request cancelled.', 'AbortError'));
59
+ continue;
60
+ }
61
+ this.active += 1;
62
+ Promise.resolve().then(entry.task).then((value) => {
63
+ this.active -= 1;
64
+ this.drain();
65
+ entry.resolve(value);
66
+ }, (error) => {
67
+ this.active -= 1;
68
+ this.drain();
69
+ entry.reject(error);
70
+ });
71
+ }
72
+ }
73
+ }
74
+ const commandQueue = new AsyncLocalStorage();
75
+ export function withRequestQueue(command) {
76
+ return commandQueue.run(new RequestQueue(), command);
77
+ }
78
+ export function currentRequestQueue() {
79
+ return commandQueue.getStore();
80
+ }
@@ -1,3 +1,5 @@
1
+ import { HTTP_REQUEST_CONCURRENCY } from "./request-queue.js";
2
+ import { mapWithConcurrency } from "./utils.js";
1
3
  export function unwrapResource(value) {
2
4
  if (value && typeof value === 'object' && !Array.isArray(value) && 'data' in value) {
3
5
  const data = value.data;
@@ -22,16 +24,13 @@ export function resourceIdOf(resource) {
22
24
  || '');
23
25
  }
24
26
  async function* readDetails(summaries, getDetail) {
25
- for (let offset = 0; offset < summaries.length; offset += 10) {
26
- const chunk = summaries.slice(offset, offset + 10);
27
- const entries = await Promise.all(chunk.map(async (summary) => {
28
- const listedId = resourceIdOf(summary);
29
- const resource = listedId ? unwrapResource(await getDetail(listedId)) : summary;
30
- return { listedId, resource };
31
- }));
32
- for (const entry of entries) {
33
- yield entry;
34
- }
27
+ const entries = await mapWithConcurrency(summaries, async (summary) => {
28
+ const listedId = resourceIdOf(summary);
29
+ const resource = listedId ? unwrapResource(await getDetail(listedId)) : summary;
30
+ return { listedId, resource };
31
+ }, HTTP_REQUEST_CONCURRENCY);
32
+ for (const entry of entries) {
33
+ yield entry;
35
34
  }
36
35
  }
37
36
  const readers = {
@@ -3,14 +3,14 @@ import { describeFieldChanges } from "../diff-details.js";
3
3
  import { hashPortableComponentSource, hashStable, readComponentLock, writeComponentLock } from "../component-lock.js";
4
4
  import { withHttpTraceContext } from "../http-trace.js";
5
5
  import { readConfiguredResourceMetadataStableKey, sanitizeUserMetadata } from "../resource-metadata.js";
6
- import { readJsonFile, sanitizeSegment } from "../utils.js";
6
+ import { HTTP_REQUEST_CONCURRENCY } from "../request-queue.js";
7
+ import { mapWithConcurrency, readJsonFile, sanitizeSegment } from "../utils.js";
7
8
  import { hydrateWorkspaceComponentElementDetails } from "../workspace-component.js";
8
9
  import { findManifestFiles, isRecord, localTargetPath, removeRelocatedManifest, requireProjectLayout, stableKeySuffix, toPortableRelativePath, unwrapData, writePulledManifest, } from "./util.js";
9
10
  export const ENDPOINTS_DIRECTORY = 'Endpoints';
10
11
  export const ENDPOINT_MANIFEST_FILE = 'endpoint.json';
11
12
  const ENDPOINT_DEFAULT_TIMEOUT_SECONDS = 60;
12
13
  const ENDPOINT_DEFAULT_MEMORY_MB = 32;
13
- const REMOTE_DETAIL_BATCH_SIZE = 10;
14
14
  const REMOTE_DETAIL_REQUEST_TIMEOUT_MS = 30_000;
15
15
  const ENDPOINT_PLAN_STATUS_ORDER = [
16
16
  'create', 'restore', 'safe-update', 'remote-changed', 'conflict', 'missing-lock',
@@ -212,41 +212,9 @@ function readWorkspaceComponents(cwd, stableKeyName) {
212
212
  }
213
213
  return result;
214
214
  }
215
- function createRemoteDetailScheduler() {
216
- let available = REMOTE_DETAIL_BATCH_SIZE;
217
- const waiting = [];
218
- return async (task) => {
219
- if (available > 0) {
220
- available -= 1;
221
- }
222
- else {
223
- await new Promise((resolve) => waiting.push(resolve));
224
- }
225
- try {
226
- return await task();
227
- }
228
- finally {
229
- const next = waiting.shift();
230
- if (next) {
231
- next();
232
- }
233
- else {
234
- available += 1;
235
- }
236
- }
237
- };
238
- }
239
- async function mapInBatches(items, mapper, schedule) {
240
- const results = [];
241
- for (let offset = 0; offset < items.length; offset += REMOTE_DETAIL_BATCH_SIZE) {
242
- const batch = items.slice(offset, offset + REMOTE_DETAIL_BATCH_SIZE);
243
- results.push(...await Promise.all(batch.map((item) => schedule(() => mapper(item)))));
244
- }
245
- return results;
246
- }
247
- async function loadRemoteEndpoints(client, schedule = createRemoteDetailScheduler()) {
215
+ async function loadRemoteEndpoints(client) {
248
216
  const { endpoints } = await withHttpTraceContext({ operation: 'list' }, () => client.listAllEndpoints());
249
- return mapInBatches(endpoints, async (summary) => {
217
+ return mapWithConcurrency(endpoints, async (summary) => {
250
218
  const endpointId = endpointIdOf(summary);
251
219
  if (!endpointId) {
252
220
  return summary;
@@ -256,11 +224,11 @@ async function loadRemoteEndpoints(client, schedule = createRemoteDetailSchedule
256
224
  entityId: endpointId,
257
225
  ...(typeof summary.name === 'string' ? { entityName: summary.name } : {}),
258
226
  }, () => client.getEndpoint(endpointId, { timeoutMs: REMOTE_DETAIL_REQUEST_TIMEOUT_MS })));
259
- }, schedule);
227
+ }, HTTP_REQUEST_CONCURRENCY);
260
228
  }
261
- async function loadRemoteComponents(client, schedule = createRemoteDetailScheduler()) {
229
+ async function loadRemoteComponents(client) {
262
230
  const { components } = await withHttpTraceContext({ dependency: 'component', operation: 'list' }, () => client.listAllComponents());
263
- return mapInBatches(components, async (summary) => {
231
+ return mapWithConcurrency(components, async (summary) => {
264
232
  const componentId = componentIdOf(summary);
265
233
  if (!componentId) {
266
234
  return summary;
@@ -271,7 +239,7 @@ async function loadRemoteComponents(client, schedule = createRemoteDetailSchedul
271
239
  entityId: componentId,
272
240
  ...(typeof summary.name === 'string' ? { entityName: summary.name } : {}),
273
241
  }, () => client.getComponent(componentId, { timeoutMs: REMOTE_DETAIL_REQUEST_TIMEOUT_MS })));
274
- }, schedule);
242
+ }, HTTP_REQUEST_CONCURRENCY);
275
243
  }
276
244
  async function componentBinding(input) {
277
245
  const component = input.componentsById.get(input.componentId);
@@ -361,10 +329,9 @@ async function manifestFromRecord(input) {
361
329
  }
362
330
  export async function pullEndpointsToWorkspace(input) {
363
331
  const { projectRoot, workspaceRoot } = requireProjectLayout(input.cwd, 'Endpoint');
364
- const scheduleDetail = createRemoteDetailScheduler();
365
332
  const [records, components] = await Promise.all([
366
- loadRemoteEndpoints(input.client, scheduleDetail),
367
- loadRemoteComponents(input.client, scheduleDetail),
333
+ loadRemoteEndpoints(input.client),
334
+ loadRemoteComponents(input.client),
368
335
  ]);
369
336
  const componentsById = new Map(components.map((component) => [componentIdOf(component), component]));
370
337
  const manifests = [];
@@ -761,10 +728,9 @@ export async function buildEndpointsPlan(input) {
761
728
  }
762
729
  }
763
730
  }
764
- const scheduleDetail = createRemoteDetailScheduler();
765
731
  const [targetEndpoints, targetComponents] = await Promise.all([
766
- loadRemoteEndpoints(input.client, scheduleDetail),
767
- loadRemoteComponents(input.client, scheduleDetail),
732
+ loadRemoteEndpoints(input.client),
733
+ loadRemoteComponents(input.client),
768
734
  ]);
769
735
  const workspaceComponents = readWorkspaceComponents(input.cwd, input.stableKeyName);
770
736
  const targetComponentsByKey = targetComponentsByStableKey(targetComponents, input.stableKeyName);
@@ -1,4 +1,5 @@
1
1
  import type { RevoClient } from './client.ts';
2
+ import type { ComponentIdentityConfig } from './resource-metadata.ts';
2
3
  export type ParsedArgs = {
3
4
  _: string[];
4
5
  [key: string]: string | boolean | string[] | undefined;
@@ -7,6 +8,7 @@ export type CommandContext = {
7
8
  args: ParsedArgs;
8
9
  client: RevoClient;
9
10
  componentEnvironment?: string;
11
+ componentIdentity?: ComponentIdentityConfig;
10
12
  cwd: string;
11
13
  packageVersion: string;
12
14
  print: (value: unknown) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@revoengine/cli",
3
- "version": "1.0.12",
3
+ "version": "1.0.14",
4
4
  "description": "CLI package for the RevoEngine Platform API",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",
@@ -11,14 +11,15 @@
11
11
  "scripts": {
12
12
  "build": "npm run clean && tsc -p tsconfig.build.json",
13
13
  "clean": "node --input-type=module -e \"import fs from 'node:fs'; fs.rmSync('dist', { recursive: true, force: true });\"",
14
- "check": "node --input-type=module -e \"await import('./src/config.ts'); await import('./src/legacy.ts'); await import('./src/http-trace.ts'); await import('./src/client.ts'); await import('./src/component-lock.ts'); await import('./src/diff-details.ts'); await import('./src/resource-metadata.ts'); await import('./src/tracked-resources.ts'); await import('./src/resource-inventory.ts'); await import('./src/metadata-backfill.ts'); await import('./src/workspace-component.ts'); await import('./src/workspace-resource.ts'); await import('./src/database-table-artifacts.ts'); await import('./src/project.ts'); await import('./src/prompt.ts'); await import('./src/runtime-view.ts'); await import('./src/spinner.ts'); await import('./src/types.ts'); await import('./src/utils.ts'); await import('./src/resource-syncs/util.ts'); await import('./src/resource-syncs/database-table-sync.ts'); await import('./src/resource-syncs/database-view-sync.ts'); await import('./src/resource-syncs/endpoint-sync.ts'); await import('./src/resource-syncs/group-sync.ts'); await import('./src/resource-syncs/role-group-sync.ts'); await import('./src/resource-syncs/job-template-sync.ts'); await import('./src/resource-syncs/schedule-sync.ts'); await import('./src/resource-syncs/event-sync.ts'); await import('./src/migration.ts'); await import('./src/workspace-diff.ts'); await import('./src/sync-output.ts'); await import('./src/ui.ts'); await import('./src/update-notifier.ts'); await import('./src/env-sync.ts'); await import('./src/commands/auth.ts'); await import('./src/commands/component.ts'); await import('./src/commands/database-tables.ts'); await import('./src/commands/database-views.ts'); await import('./src/commands/endpoints.ts'); await import('./src/commands/env.ts'); await import('./src/commands/events.ts'); await import('./src/commands/groups.ts'); await import('./src/commands/info.ts'); await import('./src/commands/job-templates.ts'); await import('./src/commands/metadata.ts'); await import('./src/commands/migrate.ts'); await import('./src/commands/request.ts'); await import('./src/commands/role-groups.ts'); await import('./src/commands/search.ts'); await import('./src/commands/schedules.ts'); await import('./src/commands/terminal-service.ts'); await import('./src/commands/terminal-browser.ts'); await import('./src/commands/terminal-image.ts'); await import('./src/commands/terminal-sandbox.ts'); await import('./src/commands/terminal-patch.ts'); await import('./src/commands/terminal-patch-worker.ts'); await import('./src/commands/terminal.ts'); await import('./src/cli.ts'); await import('./src/index.ts'); await import('./bin/revo.ts'); await import('./scripts/dev.ts')\"",
14
+ "check": "node --input-type=module -e \"await import('./src/config.ts'); await import('./src/legacy.ts'); await import('./src/http-trace.ts'); await import('./src/request-queue.ts'); await import('./src/client.ts'); await import('./src/component-lock.ts'); await import('./src/diff-details.ts'); await import('./src/resource-metadata.ts'); await import('./src/tracked-resources.ts'); await import('./src/resource-inventory.ts'); await import('./src/metadata-backfill.ts'); await import('./src/workspace-component.ts'); await import('./src/workspace-resource.ts'); await import('./src/database-table-artifacts.ts'); await import('./src/project.ts'); await import('./src/prompt.ts'); await import('./src/runtime-view.ts'); await import('./src/spinner.ts'); await import('./src/types.ts'); await import('./src/utils.ts'); await import('./src/resource-syncs/util.ts'); await import('./src/resource-syncs/database-table-sync.ts'); await import('./src/resource-syncs/database-view-sync.ts'); await import('./src/resource-syncs/endpoint-sync.ts'); await import('./src/resource-syncs/group-sync.ts'); await import('./src/resource-syncs/role-group-sync.ts'); await import('./src/resource-syncs/job-template-sync.ts'); await import('./src/resource-syncs/schedule-sync.ts'); await import('./src/resource-syncs/event-sync.ts'); await import('./src/migration.ts'); await import('./src/workspace-diff.ts'); await import('./src/sync-output.ts'); await import('./src/ui.ts'); await import('./src/update-notifier.ts'); await import('./src/env-sync.ts'); await import('./src/commands/auth.ts'); await import('./src/commands/component.ts'); await import('./src/commands/database-tables.ts'); await import('./src/commands/database-views.ts'); await import('./src/commands/endpoints.ts'); await import('./src/commands/env.ts'); await import('./src/commands/events.ts'); await import('./src/commands/groups.ts'); await import('./src/commands/info.ts'); await import('./src/commands/job-templates.ts'); await import('./src/commands/metadata.ts'); await import('./src/commands/migrate.ts'); await import('./src/commands/request.ts'); await import('./src/commands/role-groups.ts'); await import('./src/commands/search.ts'); await import('./src/commands/schedules.ts'); await import('./src/commands/terminal-service.ts'); await import('./src/commands/terminal-browser.ts'); await import('./src/commands/terminal-image.ts'); await import('./src/commands/terminal-sandbox.ts'); await import('./src/commands/terminal-patch.ts'); await import('./src/commands/terminal-patch-worker.ts'); await import('./src/commands/terminal.ts'); await import('./src/cli.ts'); await import('./src/index.ts'); await import('./bin/revo.ts'); await import('./scripts/dev.ts')\"",
15
15
  "dev": "node ./scripts/dev.ts",
16
16
  "prepack": "npm run build",
17
17
  "test": "node --test ./test/*.test.ts",
18
- "postinstall": "playwright-core install --only-shell chromium"
18
+ "postinstall": "node scripts/ensure-pty-helper.mjs && playwright-core install --only-shell chromium"
19
19
  },
20
20
  "files": [
21
21
  "dist/",
22
+ "scripts/ensure-pty-helper.mjs",
22
23
  "README.md",
23
24
  "tsconfig.json",
24
25
  "tsconfig.build.json"
@@ -0,0 +1,9 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { fileURLToPath, pathToFileURL } from 'node:url';
4
+
5
+ const packageRoot = fileURLToPath(new URL('..', import.meta.url));
6
+ const source = fs.existsSync(path.join(packageRoot, 'dist/src/commands/terminal-pty.js'))
7
+ ? 'dist/src/commands/terminal-pty.js' : 'src/commands/terminal-pty.ts';
8
+ const { ensurePtyHelperExecutable } = await import(pathToFileURL(path.join(packageRoot, source)).href);
9
+ ensurePtyHelperExecutable();