PSA/shared/workflow/expression-authoring/adapters/workflowContextAdapter.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

123 lines
3.6 KiB
TypeScript

import type { SharedExpressionContextRoot, SharedExpressionSchemaNode, SharedExpressionPathOption } from '../context';
import { buildPathOptionsFromContextRoots } from '../pathDiscovery';
const DEFAULT_META_SCHEMA: SharedExpressionSchemaNode = {
type: 'object',
properties: {
state: { type: 'string', description: 'Workflow state' },
traceId: { type: 'string', description: 'Workflow trace identifier' },
tags: { type: 'object', description: 'Workflow metadata tags' },
},
};
const DEFAULT_ERROR_SCHEMA: SharedExpressionSchemaNode = {
type: 'object',
properties: {
name: { type: 'string', description: 'Error class name' },
message: { type: 'string', description: 'Error message' },
stack: { type: 'string', description: 'Error stack trace' },
nodePath: { type: 'string', description: 'Workflow node path where error occurred' },
},
};
export type WorkflowForEachAdapterContext = {
itemVar: string;
indexVar?: string;
itemSchema?: SharedExpressionSchemaNode;
};
export type BuildWorkflowExpressionContextRootsParams = {
allowPayloadRoot?: boolean;
payloadSchema?: SharedExpressionSchemaNode;
varsSchema?: SharedExpressionSchemaNode;
varsByName?: Record<string, SharedExpressionSchemaNode>;
metaSchema?: SharedExpressionSchemaNode;
errorSchema?: SharedExpressionSchemaNode;
includeErrorRoot?: boolean;
forEach?: WorkflowForEachAdapterContext;
};
const createVarsSchema = (
varsSchema: SharedExpressionSchemaNode | undefined,
varsByName: Record<string, SharedExpressionSchemaNode> | undefined
): SharedExpressionSchemaNode => {
if (varsSchema) {
return varsSchema;
}
return {
type: 'object',
properties: varsByName ?? {},
};
};
export const buildWorkflowExpressionContextRoots = (
params: BuildWorkflowExpressionContextRootsParams = {}
): SharedExpressionContextRoot[] => {
const roots: SharedExpressionContextRoot[] = [];
if (params.allowPayloadRoot !== false) {
roots.push({
key: 'payload',
label: 'Payload',
description: 'Workflow input payload',
schema: params.payloadSchema ?? { type: 'object', properties: {} },
allowInModes: ['expression'],
});
}
roots.push({
key: 'vars',
label: 'Variables',
description: 'Saved outputs from previous workflow steps',
schema: createVarsSchema(params.varsSchema, params.varsByName),
allowInModes: ['expression'],
});
roots.push({
key: 'meta',
label: 'Meta',
description: 'Workflow runtime metadata',
schema: params.metaSchema ?? DEFAULT_META_SCHEMA,
allowInModes: ['expression'],
});
if (params.includeErrorRoot || params.errorSchema) {
roots.push({
key: 'error',
label: 'Error',
description: 'Error context available in catch blocks',
schema: params.errorSchema ?? DEFAULT_ERROR_SCHEMA,
allowInModes: ['expression'],
});
}
if (params.forEach?.itemVar) {
roots.push({
key: params.forEach.itemVar,
label: params.forEach.itemVar,
description: 'Current foreach item',
schema: params.forEach.itemSchema ?? { type: 'object', properties: {} },
allowInModes: ['expression'],
});
}
if (params.forEach?.indexVar) {
roots.push({
key: params.forEach.indexVar,
label: params.forEach.indexVar,
description: 'Current foreach loop index',
schema: { type: 'number' },
allowInModes: ['expression'],
});
}
return roots;
};
export const buildWorkflowExpressionPathOptions = (
params: BuildWorkflowExpressionContextRootsParams = {}
): SharedExpressionPathOption[] =>
buildPathOptionsFromContextRoots(buildWorkflowExpressionContextRoots(params), {
mode: 'expression',
});