PSA/shared/workflow/bundle/dependencySummaryV1.ts
Hermes 284313f908
Some checks are pending
Bidi Control Character Guard / bidi-control-guard (push) Waiting to run
Circular Dependency Check / Check for new circular dependencies (push) Waiting to run
Citus Migration Smoke / Combined migrations on single-node Citus (push) Waiting to run
E2E Fresh Install Tests / fresh-install-e2e (push) Waiting to run
ext-v2 guardrails / Run ext-v2 guard and ESLint (push) Waiting to run
Integration Tests / Check for relevant changes (push) Waiting to run
Integration Tests / ${{ (github.event_name == 'schedule' || github.event.inputs.suite == 'full') && 'Full integration suite' || 'Tier-1 integration subset' }} (push) Blocked by required conditions
Mobile checks / Mobile lint + typecheck (push) Waiting to run
Mobile checks / Mobile unit tests (push) Waiting to run
Mobile checks / Mobile dependency audit (report) (push) Waiting to run
Mobile checks / Mobile reproducibility checks (push) Waiting to run
Secrets guard (env backups) / Ensure no tracked env backup files (push) Waiting to run
Temporal Readiness / fast-readiness (push) Waiting to run
Temporal Readiness / docker-parity (push) Waiting to run
TypeScript Type Check / Nx affected typecheck (push) Waiting to run
Unit Tests / Skipped-test budget (push) Waiting to run
Unit Tests / Nx affected unit tests (push) Waiting to run
Unit Tests / Server unit coverage (informational) (push) Waiting to run
Validate Tenant Management Schema / Check for relevant changes (push) Waiting to run
Validate Tenant Management Schema / Validate Tenant Management Schema (push) Blocked by required conditions
EE Workflows Build Guard / ee-workflows-build-guard (push) Waiting to run
Initial import of AlgaPSA codebase from PSA server
Excluded: .git, node_modules, secrets/, compose.env, assemblyscript tgz

Source: /opt/alga-psa on psa.joliet.tech
2026-06-22 16:12:17 -05:00

105 lines
4.0 KiB
TypeScript

type ActionRef = { actionId: string; version: number };
export type WorkflowBundleDependencySummaryV1 = {
actions: ActionRef[];
nodeTypes: string[];
schemaRefs: string[];
};
const isPlainObject = (value: unknown): value is Record<string, unknown> => {
if (!value || typeof value !== 'object') return false;
if (Array.isArray(value)) return false;
const proto = Object.getPrototypeOf(value);
return proto === Object.prototype || proto === null;
};
const addSchemaRefsFromDefinition = (definition: any, schemaRefs: Set<string>) => {
if (!isPlainObject(definition)) return;
if (typeof definition.payloadSchemaRef === 'string' && definition.payloadSchemaRef.trim()) {
schemaRefs.add(definition.payloadSchemaRef.trim());
}
const trigger = definition.trigger;
if (
isPlainObject(trigger)
&& trigger.type === 'event'
&& typeof trigger.sourcePayloadSchemaRef === 'string'
&& trigger.sourcePayloadSchemaRef.trim()
) {
schemaRefs.add(trigger.sourcePayloadSchemaRef.trim());
}
};
const walkSteps = (steps: any, actions: Map<string, ActionRef>, nodeTypes: Set<string>) => {
if (!Array.isArray(steps)) return;
for (const step of steps) {
if (!isPlainObject(step)) continue;
const type = step.type;
if (typeof type !== 'string' || !type) continue;
// Only node steps require node type registrations; control.* blocks are handled by the runtime itself.
if (!type.startsWith('control.')) {
nodeTypes.add(type);
}
if (type === 'action.call' && isPlainObject(step.config)) {
const actionId = step.config.actionId;
const version = step.config.version;
if (typeof actionId === 'string' && actionId.trim() && (typeof version === 'number' || typeof version === 'string')) {
const v = Number(version);
if (Number.isFinite(v) && v > 0) {
const normalizedId = actionId.trim();
actions.set(`${normalizedId}@${v}`, { actionId: normalizedId, version: v });
}
}
}
// Recurse into control blocks.
if (type === 'control.if') {
walkSteps((step as any).then, actions, nodeTypes);
walkSteps((step as any).else, actions, nodeTypes);
} else if (type === 'control.forEach') {
walkSteps((step as any).body, actions, nodeTypes);
} else if (type === 'control.tryCatch') {
walkSteps((step as any).try, actions, nodeTypes);
walkSteps((step as any).catch, actions, nodeTypes);
}
}
};
export const collectWorkflowDefinitionDependencySummaryV1 = (definition: any): WorkflowBundleDependencySummaryV1 => {
const actions = new Map<string, ActionRef>();
const nodeTypes = new Set<string>();
const schemaRefs = new Set<string>();
addSchemaRefsFromDefinition(definition, schemaRefs);
if (isPlainObject(definition)) {
walkSteps((definition as any).steps, actions, nodeTypes);
}
return {
actions: Array.from(actions.values()).sort((a, b) => (a.actionId === b.actionId ? a.version - b.version : a.actionId.localeCompare(b.actionId))),
nodeTypes: Array.from(nodeTypes).sort((a, b) => a.localeCompare(b)),
schemaRefs: Array.from(schemaRefs).sort((a, b) => a.localeCompare(b))
};
};
export const mergeDependencySummariesV1 = (
summaries: WorkflowBundleDependencySummaryV1[]
): WorkflowBundleDependencySummaryV1 => {
const actions = new Map<string, ActionRef>();
const nodeTypes = new Set<string>();
const schemaRefs = new Set<string>();
for (const summary of summaries) {
for (const action of summary.actions) actions.set(`${action.actionId}@${action.version}`, action);
for (const nodeType of summary.nodeTypes) nodeTypes.add(nodeType);
for (const schemaRef of summary.schemaRefs) schemaRefs.add(schemaRef);
}
return {
actions: Array.from(actions.values()).sort((a, b) => (a.actionId === b.actionId ? a.version - b.version : a.actionId.localeCompare(b.actionId))),
nodeTypes: Array.from(nodeTypes).sort((a, b) => a.localeCompare(b)),
schemaRefs: Array.from(schemaRefs).sort((a, b) => a.localeCompare(b))
};
};