JSONata Transform

Action ID: roadiehq:utils:jsonata
NPM Package:

@roadiehq/scaffolder-backend-module-utils

Description

Allows performing JSONata operations and transformations on input objects and produces the output result as a step output.

Input Schema

PropertyTypeDescriptionRequired
dataany-
expressionstring-

Output Schema

PropertyTypeDescriptionRequired
resultobject-

Usage Examples

Normalize service metadata and compute env map

Use this to derive a service slug, count owners, and convert an array of env pairs into an object for templating. Place it early so later steps like fetch:template can use the computed values.

Copy
steps:
  - id: normalize
    action: roadiehq:utils:jsonata
    input:
      data:
        name: ${{ parameters.name }}
        owners: ${{ parameters.owners }}
        env: ${{ parameters.env }}
      expression: |
        (
          $slug := $replace($lowercase(name), /[^a-z0-9]+/, "-");
          {
            "service": {
              "name": name,
              "slug": $slug
            },
            "envObject": $merge(env.{(name): value}),
            "ownerCount": $count(owners)
          }
        )

  - id: fetch-skeleton
    action: fetch:template
    input:
      url: ./skeleton
      targetPath: .
      values:
        name: ${{ parameters.name }}
        slug: ${{ steps.normalize.output.result.service.slug }}
        ownerCount: ${{ steps.normalize.output.result.ownerCount }}
        env: ${{ steps.normalize.output.result.envObject }}

Build a public API index from a list of APIs

Use this to filter only public APIs from a parameter list and produce a keyed object by API name with selected fields. The result can be fed into fetch:template to render gateway configs or documentation.

Copy
steps:
  - id: api-transform
    action: roadiehq:utils:jsonata
    input:
      data:
        apis: ${{ parameters.apis }}
      expression: |
        (
          $public := apis[public = true];
          {
            "apis": $merge($public.{(name): {
              "basePath": basePath,
              "owner": owner,
              "tags": tags ? tags : []
            }}),
            "summary": {
              "count": $count(apis),
              "publicCount": $count($public)
            }
          }
        )

  - id: fetch-gateway-config
    action: fetch:template
    input:
      url: ./gateway-template
      targetPath: .
      values:
        apiIndex: ${{ steps.api-transform.output.result.apis }}
        summary: ${{ steps.api-transform.output.result.summary }}