apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: json-transform
  labels:
    dagweave.io/catalog-item: json-transform
  annotations:
    # The catalog semver this manifest was authored at. The dagweave app records
    # (catalog-item-id, semver) -> content-hash -> base-vN when it mints the tenant
    # cluster name via ResolveOrMint. Keep in sync with metadata.yaml `version`.
    dagweave.io/catalog-version: "1.0.0"
    dagweave.io/catalog-category: "Data"
spec:
  entrypoint: transform
  templates:
    - name: transform
      inputs:
        parameters:
          # The JSON document to transform, as a string.
          - name: input-json
          # A jq program applied to the parsed input; its output is printed to stdout.
          - name: jq-filter
            default: "."
      container:
        # Pinned by digest per the catalog convention: an image rebuild can never
        # silently change the behaviour of an already-released item version.
        # ghcr.io/jqlang/jq:1.8.2
        image: ghcr.io/jqlang/jq@sha256:b9c68867e5766576263a222e91db3de422d802069c7af70440e667a95344e486
        # This is a minimal (shell-less) image whose only binary is /jq, so jq runs
        # directly. The untrusted document is read from the INPUT_JSON env var via
        # jq's `env` builtin (never interpolated into a shell); the jq-filter is the
        # program itself, so it is placed in the argv program string. -n means "no
        # input file", -c compact output.
        command: [/jq]
        args:
          - -n
          - -c
          - "(env.INPUT_JSON | fromjson) | ({{inputs.parameters.jq-filter}})"
        env:
          - name: INPUT_JSON
            value: "{{inputs.parameters.input-json}}"
