referenceName: getRecordEntry()

in libs/designer/src/lib/core/actions/bjsworkflow/serializer.ts [469:598]


        referenceName: getRecordEntry(rootState.connections.connectionsMapping, operationId),
      },
    },
  };
  const inputs = { ...hostInfo, ...inputPathValue, retryPolicy };
  const serializedType = equals(type, Constants.NODE.TYPE.API_CONNECTION)
    ? Constants.SERIALIZED_TYPE.API_CONNECTION
    : equals(type, Constants.NODE.TYPE.API_CONNECTION_NOTIFICATION)
      ? Constants.SERIALIZED_TYPE.API_CONNECTION_NOTIFICATION
      : equals(type, Constants.NODE.TYPE.API_CONNECTION_WEBHOOK)
        ? Constants.SERIALIZED_TYPE.API_CONNECTION_WEBHOOK
        : type;

  return {
    type: serializedType,
    ...optional('description', operationFromWorkflow.description),
    ...optional('kind', kind),
    ...optional('inputs', inputs),
    ...optional('runAfter', runAfter),
    ...optional('recurrence', recurrence),
    ...serializeSettings(operationId, nodeSettings, nodeStaticResults, isTrigger, rootState),
  };
};

export const serializeAgentConnectorOperation = async (
  rootState: RootState,
  operationId: string
): Promise<LogicAppsV2.OperationDefinition> => {
  const idReplacements = rootState.workflow.idReplacements;
  const operation = getRecordEntry(rootState.operations.operationInfo, operationId);
  if (!operation) {
    throw new AssertionException(AssertionErrorCode.OPERATION_NOT_FOUND, `Operation with id ${operationId} not found`);
  }
  const inputsToSerialize = getOperationInputsToSerialize(rootState, operationId);
  const inputPathValue = serializeParametersFromManifest(inputsToSerialize, ConnectorManifest);
  const operationFromWorkflow = getRecordEntry(rootState.workflow.operations, operationId) as LogicAppsV2.OperationDefinition;
  const runAfter = getRunAfter(operationFromWorkflow, idReplacements);

  return {
    type: operation.type,
    ...optional('description', operationFromWorkflow?.description),
    ...optional('kind', operation.kind),
    ...optional('inputs', inputPathValue),
    ...optional('runAfter', runAfter),
  };
};

const getRunAfter = (operation: LogicAppsV2.ActionDefinition, idReplacements: Record<string, string>): LogicAppsV2.RunAfter => {
  if (!operation.runAfter) {
    return {};
  }
  return Object.entries(operation.runAfter).reduce((acc: LogicAppsV2.RunAfter, [key, value]) => {
    acc[getRecordEntry(idReplacements, key) ?? key] = value;
    return acc;
  }, {});
};

//#region Parameters Serialization
export interface SerializedParameter extends ParameterInfo {
  value: any;
}

export const getOperationInputsToSerialize = (rootState: RootState, operationId: string): SerializedParameter[] => {
  const idReplacements = rootState.workflow.idReplacements;
  return getOperationInputParameters(rootState, operationId).map((input) => ({
    ...input,
    value: parameterValueToString(
      input,
      true /* isDefinitionValue */,
      idReplacements,
      shouldEncodeParameterValueForOperationBasedOnMetadata(rootState.operations.operationInfo[operationId] ?? {})
    ),
  }));
};

const serializeParametersFromManifest = (inputs: SerializedParameter[], manifest: OperationManifest): Record<string, any> => {
  const inputsLocation = (manifest.properties.inputsLocation ?? ['inputs']).slice(1);
  const inputPathValue = constructInputValues('inputs.$', inputs, false /* encodePathComponents */);
  let parametersValue: any = inputPathValue;

  while (inputsLocation.length) {
    const property = inputsLocation.pop() as string;
    parametersValue = property === '[*]' ? [parametersValue] : { [property]: parametersValue };
  }

  return swapInputsLocationIfNeeded(parametersValue, manifest.properties.inputsLocationSwapMap);
};

export const constructInputValues = (key: string, inputs: SerializedParameter[], encodePathComponents: boolean): any => {
  let result: any;

  const rootParameter = first((parameter) => cleanIndexedValue(parameter.parameterKey) === cleanIndexedValue(key), inputs);
  if (rootParameter) {
    result = getJSONValueFromString(rootParameter.value, rootParameter.type);
    if (encodePathComponents) {
      const encodeCount = getEncodeValue(rootParameter.info.encode ?? '');
      result = encodePathValue(result, encodeCount);
    }
    return result !== undefined ? result : rootParameter.required ? null : undefined;
  }
  const propertyNameParameters: SerializedParameter[] = [];
  const pathTemplateParameters: SerializedParameter[] = [];
  const formDataParameters: SerializedParameter[] = [];
  const isPathTemplateParameter = (param: SerializedParameter) =>
    param.info.deserialization?.type === DeserializationType.PathTemplateProperties;
  const isFormDataParameter = (param: SerializedParameter) => param.info.serialization?.property?.type === 'formdata';

  const serializedParameters = inputs
    .filter((item) => isAncestorKey(item.parameterKey, key))
    .map((descendantParameter) => {
      let parameterValue = getJSONValueFromString(descendantParameter.value, descendantParameter.type);
      if (encodePathComponents) {
        const encodeCount = getEncodeValue(descendantParameter.info.encode ?? '');
        parameterValue = encodePathValue(parameterValue, encodeCount);
      }

      const serializedParameter = {
        ...descendantParameter,
        value: parameterValue,
      };
      if (descendantParameter.info.serialization?.property?.type === PropertySerializationType.ParentObject) {
        propertyNameParameters.push(serializedParameter);
      }

      if (isPathTemplateParameter(descendantParameter)) {
        pathTemplateParameters.push(serializedParameter);
      }

      if (isFormDataParameter(descendantParameter)) {
        formDataParameters.push({