export function getDefaultBoxedExpressionForDevWebapp()

in packages/boxed-expression-component/stories/dev/getDefaultBoxedExpressionForDevWebapp.ts [44:301]


export function getDefaultBoxedExpressionForDevWebapp(
  logicType: BoxedExpression["__$$element"] | undefined,
  typeRef: string | undefined
): Normalized<BoxedExpression> {
  if (logicType === "literalExpression") {
    const literalExpression: Normalized<BoxedLiteral> = {
      __$$element: "literalExpression",
      "@_id": generateUuid(),
      "@_typeRef": typeRef,
    };
    return literalExpression;
  } else if (logicType === "functionDefinition") {
    const functionExpression: Normalized<BoxedFunction> = {
      __$$element: "functionDefinition",
      "@_id": generateUuid(),
      "@_typeRef": typeRef,
      "@_kind": BoxedFunctionKind.Feel,
      expression: undefined!,
    };
    return functionExpression;
  } else if (logicType === "context") {
    const contextExpression: Normalized<BoxedContext> = {
      __$$element: "context",
      "@_id": generateUuid(),
      "@_typeRef": typeRef,
      contextEntry: [
        {
          "@_id": generateUuid(),
          variable: {
            "@_id": generateUuid(),
            "@_name": "ContextEntry-1",
          },
          expression: undefined!,
        },
        {
          "@_id": generateUuid(),
          variable: {
            "@_id": generateUuid(),
            "@_name": "ContextEntry-2",
          },
          expression: undefined!,
        },
        {
          "@_id": generateUuid(),
          expression: undefined!,
        },
      ],
    };
    return contextExpression;
  } else if (logicType === "list") {
    const listExpression: Normalized<BoxedList> = {
      __$$element: "list",
      "@_id": generateUuid(),
      "@_typeRef": typeRef,
      expression: [undefined!, undefined!, undefined!],
    };
    return listExpression;
  } else if (logicType === "invocation") {
    const invocationExpression: Normalized<BoxedInvocation> = {
      __$$element: "invocation",
      "@_id": generateUuid(),
      "@_typeRef": typeRef,
      binding: [
        {
          parameter: {
            "@_id": generateUuid(),
            "@_name": INVOCATION_EXPRESSION_DEFAULT_PARAMETER_NAME,
            "@_typeRef": undefined,
          },
        },
      ],
      expression: {
        __$$element: "literalExpression",
        "@_id": generateUuid(),
        text: { __$$text: "FUNCTION" },
      },
    };
    return invocationExpression;
  } else if (logicType === "relation") {
    const relationExpression: Normalized<BoxedRelation> = {
      __$$element: "relation",
      "@_id": generateUuid(),
      "@_typeRef": typeRef,
      column: [
        {
          "@_id": generateUuid(),
          "@_name": "column-1",
        },
        {
          "@_id": generateUuid(),
          "@_name": "column-2",
        },
        {
          "@_id": generateUuid(),
          "@_name": "column-3",
        },
      ],
      row: [
        {
          "@_id": generateUuid(),
          expression: [
            {
              __$$element: "literalExpression",
              "@_id": generateUuid(),
              text: { __$$text: "" },
            },
            {
              __$$element: "literalExpression",
              "@_id": generateUuid(),
              text: { __$$text: "" },
            },
            {
              __$$element: "literalExpression",
              "@_id": generateUuid(),
              text: { __$$text: "" },
            },
          ],
        },
      ],
    };
    return relationExpression;
  } else if (logicType === "decisionTable") {
    const decisionTableExpression: Normalized<BoxedDecisionTable> = {
      __$$element: "decisionTable",
      "@_id": generateUuid(),
      "@_typeRef": typeRef,
      "@_hitPolicy": "UNIQUE",
      input: [
        {
          "@_id": generateUuid(),
          inputExpression: {
            "@_id": generateUuid(),
            text: { __$$text: "input-1" },
          },
        },
        {
          "@_id": generateUuid(),
          inputExpression: {
            "@_id": generateUuid(),
            text: { __$$text: "input-2" },
          },
        },
      ],
      output: [
        {
          "@_id": generateUuid(),
          "@_label": "output-1",
        },
        {
          "@_id": generateUuid(),
          "@_label": "output-2",
        },
        {
          "@_id": generateUuid(),
          "@_label": "output-3",
        },
      ],
      annotation: [
        {
          "@_name": "Annotations",
        },
      ],
      rule: [
        {
          "@_id": generateUuid(),
          inputEntry: [
            { "@_id": generateUuid(), text: { __$$text: DECISION_TABLE_INPUT_DEFAULT_VALUE } },
            { "@_id": generateUuid(), text: { __$$text: DECISION_TABLE_INPUT_DEFAULT_VALUE } },
          ],
          outputEntry: [
            { "@_id": generateUuid(), text: { __$$text: DECISION_TABLE_OUTPUT_DEFAULT_VALUE } },
            { "@_id": generateUuid(), text: { __$$text: DECISION_TABLE_OUTPUT_DEFAULT_VALUE } },
            { "@_id": generateUuid(), text: { __$$text: DECISION_TABLE_OUTPUT_DEFAULT_VALUE } },
          ],
          annotationEntry: [{ text: { __$$text: "// Your annotations here" } }],
        },
      ],
    };
    return decisionTableExpression;
  } else if (logicType === "conditional") {
    const conditionalExpression: Normalized<BoxedConditional> = {
      "@_id": generateUuid(),
      __$$element: "conditional",
      if: {
        "@_id": generateUuid(),
        expression: undefined as any,
      },
      then: {
        "@_id": generateUuid(),
        expression: undefined as any,
      },
      else: {
        "@_id": generateUuid(),
        expression: undefined as any,
      },
    };

    return conditionalExpression;
  } else if (logicType === "for") {
    const forExpression: Normalized<BoxedFor> = {
      "@_id": generateUuid(),
      __$$element: "for",
      return: {
        "@_id": generateUuid(),
        expression: undefined as any,
      },
      in: {
        "@_id": generateUuid(),
        expression: undefined as any,
      },
    };
    return forExpression;
  } else if (logicType == "some") {
    const someExpression: Normalized<BoxedSome> = {
      "@_id": generateUuid(),
      __$$element: "some",
      satisfies: {
        "@_id": generateUuid(),
        expression: undefined as any,
      },
      in: {
        "@_id": generateUuid(),
        expression: undefined as any,
      },
    };
    return someExpression;
  } else if (logicType === "every") {
    const everyExpression: Normalized<BoxedEvery> = {
      "@_id": generateUuid(),
      __$$element: "every",
      satisfies: {
        "@_id": generateUuid(),
        expression: undefined as any,
      },
      in: {
        "@_id": generateUuid(),
        expression: undefined as any,
      },
    };
    return everyExpression;
  } else if (logicType === "filter") {
    const filterExpression: Normalized<BoxedFilter> = {
      "@_id": generateUuid(),
      __$$element: "filter",
      match: {
        "@_id": generateUuid(),
        expression: undefined as any,
      },
      in: {
        "@_id": generateUuid(),
        expression: undefined as any,
      },
    };
    return filterExpression;
  } else {
    throw new Error(`No default expression available for ${logicType}`);
  }
}