{
  "operations": [
    {
      "name": "sql",
      "params": [
        "sqlQuery",
        "options"
      ],
      "docs": {
        "description": "Execute an SQL statement",
        "tags": [
          {
            "title": "public",
            "description": null,
            "type": null
          },
          {
            "title": "example",
            "description": "sql('SELECT * FROM users;');",
            "caption": "Text-only Query"
          },
          {
            "title": "example",
            "description": "sql(\"select id from users where first_name = 'Mamadou'\", { writeSql: true });",
            "caption": "Text-only Query with writeSql option"
          },
          {
            "title": "example",
            "description": "sql(\"INSERT INTO users(name, age) VALUES ($1, $2);\", { values: [\"Alice\", 25]});",
            "caption": "Parameterized Query"
          },
          {
            "title": "example",
            "description": "sql(util.format('INSERT INTO users(name, age) VALUES (%L, %L);', 'Alice', 25));",
            "caption": "Format query with util.format"
          },
          {
            "title": "example",
            "description": "sql({\n  // give the query a unique name\n  name: \"fetch-user\",\n  text: \"SELECT * FROM user WHERE id = $1\",\n  values: [1],\n});",
            "caption": "Prepared Statements"
          },
          {
            "title": "function",
            "description": null,
            "name": null
          },
          {
            "title": "param",
            "description": "SQL query string or a query config object.",
            "type": {
              "type": "UnionType",
              "elements": [
                {
                  "type": "NameExpression",
                  "name": "string"
                },
                {
                  "type": "NameExpression",
                  "name": "SqlQueryConfig"
                }
              ]
            },
            "name": "sqlQuery"
          },
          {
            "title": "param",
            "description": "Execution options. (OpenFn only)",
            "type": {
              "type": "OptionalType",
              "expression": {
                "type": "NameExpression",
                "name": "ExecutionOptions"
              }
            },
            "name": "options"
          },
          {
            "title": "state",
            "description": "{PostgresState}"
          },
          {
            "title": "returns",
            "description": null,
            "type": {
              "type": "NameExpression",
              "name": "Operation"
            }
          }
        ]
      },
      "valid": true
    },
    {
      "name": "findValue",
      "params": [
        "filter"
      ],
      "docs": {
        "description": "Fetch a uuid key given a condition",
        "tags": [
          {
            "title": "public",
            "description": null,
            "type": null
          },
          {
            "title": "example",
            "description": "findValue({\n   uuid: 'id',\n   relation: 'users',\n   where: { first_name: 'Mamadou' },\n   operator: { first_name: 'like' }\n })",
            "caption": "Find a user by first name"
          },
          {
            "title": "function",
            "description": null,
            "name": null
          },
          {
            "title": "param",
            "description": "A filter object with the lookup table, a uuid and the condition",
            "type": {
              "type": "NameExpression",
              "name": "FindValueFilter"
            },
            "name": "filter"
          },
          {
            "title": "state",
            "description": "{PostgresState}"
          },
          {
            "title": "state",
            "description": "data - the value of the found uuid"
          },
          {
            "title": "returns",
            "description": null,
            "type": {
              "type": "NameExpression",
              "name": "Operation"
            }
          }
        ]
      },
      "valid": true
    },
    {
      "name": "insert",
      "params": [
        "table",
        "record",
        "options"
      ],
      "docs": {
        "description": "Insert a record",
        "tags": [
          {
            "title": "public",
            "description": null,
            "type": null
          },
          {
            "title": "example",
            "description": "insert('users', { name: 'Elodie', id: 7 }, { setNull: \"'NaN'\", logValues: true });",
            "caption": "Insert a record"
          },
          {
            "title": "function",
            "description": null,
            "name": null
          },
          {
            "title": "param",
            "description": "The target table",
            "type": {
              "type": "NameExpression",
              "name": "string"
            },
            "name": "table"
          },
          {
            "title": "param",
            "description": "Payload data for the record as a JS object or function",
            "type": {
              "type": "NameExpression",
              "name": "object"
            },
            "name": "record"
          },
          {
            "title": "param",
            "description": "Shared options. (OpenFn only)",
            "type": {
              "type": "OptionalType",
              "expression": {
                "type": "NameExpression",
                "name": "GeneralOptions"
              }
            },
            "name": "options"
          },
          {
            "title": "state",
            "description": "{PostgresState}"
          },
          {
            "title": "returns",
            "description": null,
            "type": {
              "type": "NameExpression",
              "name": "Operation"
            }
          }
        ]
      },
      "valid": true
    },
    {
      "name": "insertMany",
      "params": [
        "table",
        "records",
        "options"
      ],
      "docs": {
        "description": "Insert many records, using the keys of the first as the column template",
        "tags": [
          {
            "title": "public",
            "description": null,
            "type": null
          },
          {
            "title": "example",
            "description": "insertMany('users', state => state.data.recordArray, { setNull: \"'undefined'\", logValues: true });",
            "caption": "Insert many records"
          },
          {
            "title": "function",
            "description": null,
            "name": null
          },
          {
            "title": "param",
            "description": "The target table",
            "type": {
              "type": "NameExpression",
              "name": "string"
            },
            "name": "table"
          },
          {
            "title": "param",
            "description": "An array or a function that takes state and returns an array",
            "type": {
              "type": "NameExpression",
              "name": "array"
            },
            "name": "records"
          },
          {
            "title": "param",
            "description": "Shared options. (OpenFn only)",
            "type": {
              "type": "OptionalType",
              "expression": {
                "type": "NameExpression",
                "name": "GeneralOptions"
              }
            },
            "name": "options"
          },
          {
            "title": "state",
            "description": "{PostgresState}"
          },
          {
            "title": "returns",
            "description": null,
            "type": {
              "type": "NameExpression",
              "name": "Operation"
            }
          }
        ]
      },
      "valid": true
    },
    {
      "name": "upsert",
      "params": [
        "table",
        "uuid",
        "record",
        "options"
      ],
      "docs": {
        "description": "Insert or update a record using ON CONFLICT UPDATE",
        "tags": [
          {
            "title": "public",
            "description": null,
            "type": null
          },
          {
            "title": "example",
            "description": "upsert(\n  \"users\", // the DB table\n  \"ON CONSTRAINT users_pkey\", // a DB column with a unique constraint OR a CONSTRAINT NAME\n  { name: \"Elodie\", id: 7 },\n  {\n    setNull: [\"''\", \"'undefined'\"],\n    writeSql: true,\n    logValues: true,\n  }\n);",
            "caption": "Insert or update a record"
          },
          {
            "title": "function",
            "description": null,
            "name": null
          },
          {
            "title": "param",
            "description": "The target table",
            "type": {
              "type": "NameExpression",
              "name": "string"
            },
            "name": "table"
          },
          {
            "title": "param",
            "description": "The uuid column to determine a matching/existing record",
            "type": {
              "type": "NameExpression",
              "name": "string"
            },
            "name": "uuid"
          },
          {
            "title": "param",
            "description": "Payload data for the record as a JS object or function",
            "type": {
              "type": "NameExpression",
              "name": "object"
            },
            "name": "record"
          },
          {
            "title": "param",
            "description": "Shared options. (OpenFn only)",
            "type": {
              "type": "OptionalType",
              "expression": {
                "type": "NameExpression",
                "name": "GeneralOptions"
              }
            },
            "name": "options"
          },
          {
            "title": "state",
            "description": "{PostgresState}"
          },
          {
            "title": "returns",
            "description": null,
            "type": {
              "type": "NameExpression",
              "name": "Operation"
            }
          }
        ]
      },
      "valid": true
    },
    {
      "name": "upsertIf",
      "params": [
        "logical",
        "table",
        "uuid",
        "record",
        "options"
      ],
      "docs": {
        "description": "Insert or update a record based on a logical condition using ON CONFLICT UPDATE",
        "tags": [
          {
            "title": "public",
            "description": null,
            "type": null
          },
          {
            "title": "example",
            "description": "upsertIf(\n  $.data.name,\n  \"users\", // the DB table\n  \"ON CONSTRAINT users_pkey\", // a DB column with a unique constraint OR a CONSTRAINT NAME\n  { name: \"Elodie\", id: 7 },\n  { writeSql: true }\n);",
            "caption": "Insert or update a record conditionally"
          },
          {
            "title": "function",
            "description": null,
            "name": null
          },
          {
            "title": "param",
            "description": "a data to check existing value for.",
            "type": {
              "type": "NameExpression",
              "name": "string"
            },
            "name": "logical"
          },
          {
            "title": "param",
            "description": "The target table",
            "type": {
              "type": "NameExpression",
              "name": "string"
            },
            "name": "table"
          },
          {
            "title": "param",
            "description": "The uuid column to determine a matching/existing record",
            "type": {
              "type": "NameExpression",
              "name": "string"
            },
            "name": "uuid"
          },
          {
            "title": "param",
            "description": "Payload data for the record as a JS object or function",
            "type": {
              "type": "NameExpression",
              "name": "object"
            },
            "name": "record"
          },
          {
            "title": "param",
            "description": "Shared options. (OpenFn only)",
            "type": {
              "type": "OptionalType",
              "expression": {
                "type": "NameExpression",
                "name": "GeneralOptions"
              }
            },
            "name": "options"
          },
          {
            "title": "state",
            "description": "{PostgresState}"
          },
          {
            "title": "returns",
            "description": null,
            "type": {
              "type": "NameExpression",
              "name": "Operation"
            }
          }
        ]
      },
      "valid": true
    },
    {
      "name": "upsertMany",
      "params": [
        "table",
        "uuid",
        "data",
        "options"
      ],
      "docs": {
        "description": "Insert or update multiple records using ON CONFLICT UPDATE and excluded",
        "tags": [
          {
            "title": "public",
            "description": null,
            "type": null
          },
          {
            "title": "example",
            "description": "upsertMany(\n  'users', // the DB table\n  'email', // a DB column with a unique constraint OR a CONSTRAINT NAME\n  [\n    { name: 'one', email: 'one@openfn.org' },\n    { name: 'two', email: 'two@openfn.org' },\n  ]\n)",
            "caption": "Insert or update multiple records"
          },
          {
            "title": "function",
            "description": null,
            "name": null
          },
          {
            "title": "param",
            "description": "The target table",
            "type": {
              "type": "NameExpression",
              "name": "string"
            },
            "name": "table"
          },
          {
            "title": "param",
            "description": "The uuid column to determine a matching/existing record",
            "type": {
              "type": "NameExpression",
              "name": "string"
            },
            "name": "uuid"
          },
          {
            "title": "param",
            "description": "An array of objects or a function that returns an array",
            "type": {
              "type": "NameExpression",
              "name": "array"
            },
            "name": "data"
          },
          {
            "title": "param",
            "description": "Shared options. (OpenFn only)",
            "type": {
              "type": "OptionalType",
              "expression": {
                "type": "NameExpression",
                "name": "GeneralOptions"
              }
            },
            "name": "options"
          },
          {
            "title": "state",
            "description": "{PostgresState}"
          },
          {
            "title": "returns",
            "description": null,
            "type": {
              "type": "NameExpression",
              "name": "Operation"
            }
          }
        ]
      },
      "valid": true
    },
    {
      "name": "describeTable",
      "params": [
        "tableName",
        "options"
      ],
      "docs": {
        "description": "List the columns of a table in a database.",
        "tags": [
          {
            "title": "public",
            "description": null,
            "type": null
          },
          {
            "title": "example",
            "description": "describeTable('clinic_visits')",
            "caption": "Describe a table"
          },
          {
            "title": "function",
            "description": null,
            "name": null
          },
          {
            "title": "param",
            "description": "The name of the table to describe",
            "type": {
              "type": "NameExpression",
              "name": "string"
            },
            "name": "tableName"
          },
          {
            "title": "param",
            "description": "Execution options. (OpenFn only)",
            "type": {
              "type": "OptionalType",
              "expression": {
                "type": "NameExpression",
                "name": "ExecutionOptions"
              }
            },
            "name": "options"
          },
          {
            "title": "state",
            "description": "{PostgresState}"
          },
          {
            "title": "returns",
            "description": null,
            "type": {
              "type": "NameExpression",
              "name": "Operation"
            }
          }
        ]
      },
      "valid": true
    },
    {
      "name": "insertTable",
      "params": [
        "tableName",
        "columns",
        "options"
      ],
      "docs": {
        "description": "Create a table in database when given an array of columns and a table_name.",
        "tags": [
          {
            "title": "public",
            "description": null,
            "type": null
          },
          {
            "title": "example",
            "description": "insertTable('table_name', state => state.data.map(\n  column => ({\n    name: column.name,\n    type: column.type,\n    required: true, // optional\n    unique: false, // optional - to be set to true for unique constraint\n  })\n));"
          },
          {
            "title": "function",
            "description": null,
            "name": null
          },
          {
            "title": "param",
            "description": "The name of the table to create",
            "type": {
              "type": "NameExpression",
              "name": "string"
            },
            "name": "tableName"
          },
          {
            "title": "param",
            "description": "An array of form columns",
            "type": {
              "type": "NameExpression",
              "name": "array"
            },
            "name": "columns"
          },
          {
            "title": "param",
            "description": "Execution options. (OpenFn only)",
            "type": {
              "type": "OptionalType",
              "expression": {
                "type": "NameExpression",
                "name": "ExecutionOptions"
              }
            },
            "name": "options"
          },
          {
            "title": "state",
            "description": "{PostgresState}"
          },
          {
            "title": "returns",
            "description": null,
            "type": {
              "type": "NameExpression",
              "name": "Operation"
            }
          }
        ]
      },
      "valid": true
    },
    {
      "name": "modifyTable",
      "params": [
        "tableName",
        "columns",
        "options"
      ],
      "docs": {
        "description": "Alter an existing table in the database.",
        "tags": [
          {
            "title": "public",
            "description": null,
            "type": null
          },
          {
            "title": "example",
            "description": "modifyTable('table_name', state => state.data.map(\n  newColumn => ({\n    name: newColumn.name,\n    type: newColumn.type,\n    required: true, // optional\n    unique: false, // optional - to be set to true for unique constraint\n  })\n));"
          },
          {
            "title": "function",
            "description": null,
            "name": null
          },
          {
            "title": "param",
            "description": "The name of the table to alter",
            "type": {
              "type": "NameExpression",
              "name": "string"
            },
            "name": "tableName"
          },
          {
            "title": "param",
            "description": "An array of form columns",
            "type": {
              "type": "NameExpression",
              "name": "array"
            },
            "name": "columns"
          },
          {
            "title": "param",
            "description": "Execution options. (OpenFn only)",
            "type": {
              "type": "OptionalType",
              "expression": {
                "type": "NameExpression",
                "name": "ExecutionOptions"
              }
            },
            "name": "options"
          },
          {
            "title": "state",
            "description": "{PostgresState}"
          },
          {
            "title": "returns",
            "description": null,
            "type": {
              "type": "NameExpression",
              "name": "Operation"
            }
          }
        ]
      },
      "valid": true
    }
  ],
  "exports": [],
  "common": [
    {
      "name": "fn",
      "params": [
        "func"
      ],
      "docs": {
        "description": "Creates a custom step (or operation) for more flexible job writing.",
        "tags": [
          {
            "title": "public",
            "description": null,
            "type": null
          },
          {
            "title": "function",
            "description": null,
            "name": null
          },
          {
            "title": "example",
            "description": "fn(state => {\n  // do some things to state\n  return state;\n});"
          },
          {
            "title": "param",
            "description": "is the function",
            "type": {
              "type": "NameExpression",
              "name": "Function"
            },
            "name": "func"
          },
          {
            "title": "returns",
            "description": null,
            "type": {
              "type": "NameExpression",
              "name": "Operation"
            }
          }
        ]
      },
      "valid": true
    },
    {
      "name": "fnIf",
      "params": [
        "condition",
        "operation"
      ],
      "docs": {
        "description": "Execute a function only when the condition returns true",
        "tags": [
          {
            "title": "public",
            "description": null,
            "type": null
          },
          {
            "title": "function",
            "description": null,
            "name": null
          },
          {
            "title": "example",
            "description": "fnIf((state) => state?.data?.name, get(\"https://example.com\"));"
          },
          {
            "title": "param",
            "description": "The condition that returns true",
            "type": {
              "type": "NameExpression",
              "name": "Boolean"
            },
            "name": "condition"
          },
          {
            "title": "param",
            "description": "The operation needed to be executed.",
            "type": {
              "type": "NameExpression",
              "name": "Operation"
            },
            "name": "operation"
          },
          {
            "title": "returns",
            "description": null,
            "type": {
              "type": "NameExpression",
              "name": "Operation"
            }
          }
        ]
      },
      "valid": true
    },
    {
      "name": "sourceValue",
      "params": [
        "path"
      ],
      "docs": {
        "description": "Picks out a single value from source data.\nIf a JSONPath returns more than one value for the reference, the first\nitem will be returned.",
        "tags": [
          {
            "title": "public",
            "description": null,
            "type": null
          },
          {
            "title": "function",
            "description": null,
            "name": null
          },
          {
            "title": "example",
            "description": "sourceValue('$.key')"
          },
          {
            "title": "param",
            "description": "JSONPath referencing a point in `state`.",
            "type": {
              "type": "NameExpression",
              "name": "String"
            },
            "name": "path"
          },
          {
            "title": "returns",
            "description": null,
            "type": {
              "type": "NameExpression",
              "name": "Operation"
            }
          }
        ]
      },
      "valid": true
    },
    {
      "name": "dataPath",
      "params": [
        "path"
      ],
      "docs": {
        "description": "Ensures a path points at the data.",
        "tags": [
          {
            "title": "public",
            "description": null,
            "type": null
          },
          {
            "title": "function",
            "description": null,
            "name": null
          },
          {
            "title": "example",
            "description": "dataPath('key')"
          },
          {
            "title": "param",
            "description": "JSONPath referencing a point in `data`.",
            "type": {
              "type": "NameExpression",
              "name": "string"
            },
            "name": "path"
          },
          {
            "title": "returns",
            "description": null,
            "type": {
              "type": "NameExpression",
              "name": "string"
            }
          }
        ]
      },
      "valid": true
    },
    {
      "name": "dataValue",
      "params": [
        "path"
      ],
      "docs": {
        "description": "Picks out a single value from the source data object—usually `state.data`.\nIf a JSONPath returns more than one value for the reference, the first\nitem will be returned.",
        "tags": [
          {
            "title": "public",
            "description": null,
            "type": null
          },
          {
            "title": "function",
            "description": null,
            "name": null
          },
          {
            "title": "example",
            "description": "dataValue('key')"
          },
          {
            "title": "param",
            "description": "JSONPath referencing a point in `data`.",
            "type": {
              "type": "NameExpression",
              "name": "String"
            },
            "name": "path"
          },
          {
            "title": "returns",
            "description": null,
            "type": {
              "type": "NameExpression",
              "name": "Operation"
            }
          }
        ]
      },
      "valid": true
    },
    {
      "name": "lastReferenceValue",
      "params": [
        "path"
      ],
      "docs": {
        "description": "Picks out the last reference value from source data.",
        "tags": [
          {
            "title": "public",
            "description": null,
            "type": null
          },
          {
            "title": "function",
            "description": null,
            "name": null
          },
          {
            "title": "example",
            "description": "lastReferenceValue('key')"
          },
          {
            "title": "param",
            "description": "JSONPath referencing a point in `references`.",
            "type": {
              "type": "NameExpression",
              "name": "String"
            },
            "name": "path"
          },
          {
            "title": "returns",
            "description": null,
            "type": {
              "type": "NameExpression",
              "name": "Operation"
            }
          }
        ]
      },
      "valid": true
    },
    {
      "name": "each",
      "params": [
        "dataSource",
        "operation"
      ],
      "docs": {
        "description": "Iterates over an array of items and invokes an operation upon each one, where the state\nobject is _scoped_ so that state.data is the item under iteration.\nThe rest of the state object is untouched and can be referenced as usual.\nYou can pass an array directly, or use lazy state or a JSONPath string to\nreference a slice of state.",
        "tags": [
          {
            "title": "public",
            "description": null,
            "type": null
          },
          {
            "title": "function",
            "description": null,
            "name": null
          },
          {
            "title": "example",
            "description": "each(\n  $.data,\n  // Inside the callback operation, `$.data` is scoped to the item under iteration\n  insert(\"patient\", {\n    patient_name: $.data.properties.case_name,\n    patient_id: $.data.case_id,\n  })\n);",
            "caption": "Using lazy state ($) to iterate over items in state.data and pass each into an \"insert\" operation"
          },
          {
            "title": "example",
            "description": "each(\n  $.data,\n  insert(\"patient\", (state) => ({\n    patient_id: state.data.case_id,\n    ...state.data\n  }))\n);",
            "caption": "Iterate over items in state.data and pass each one into an \"insert\" operation"
          },
          {
            "title": "example",
            "description": "each(\n  \"$.data[*]\",\n  insert(\"patient\", (state) => ({\n    patient_name: state.data.properties.case_name,\n    patient_id: state.data.case_id,\n  }))\n);",
            "caption": "Using JSON path to iterate over items in state.data and pass each one into an \"insert\" operation"
          },
          {
            "title": "param",
            "description": "JSONPath referencing a point in `state`.",
            "type": {
              "type": "NameExpression",
              "name": "DataSource"
            },
            "name": "dataSource"
          },
          {
            "title": "param",
            "description": "The operation needed to be repeated.",
            "type": {
              "type": "NameExpression",
              "name": "Operation"
            },
            "name": "operation"
          },
          {
            "title": "returns",
            "description": null,
            "type": {
              "type": "NameExpression",
              "name": "Operation"
            }
          }
        ]
      },
      "valid": true
    },
    {
      "name": "combine",
      "params": [
        "operations"
      ],
      "docs": {
        "description": "Combines two operations into one",
        "tags": [
          {
            "title": "public",
            "description": null,
            "type": null
          },
          {
            "title": "function",
            "description": null,
            "name": null
          },
          {
            "title": "example",
            "description": "combine(\n  create('foo'),\n  delete('bar')\n)"
          },
          {
            "title": "param",
            "description": "Operations to be performed.",
            "type": {
              "type": "NameExpression",
              "name": "Operations"
            },
            "name": "operations"
          },
          {
            "title": "returns",
            "description": null,
            "type": {
              "type": "NameExpression",
              "name": "Operation"
            }
          }
        ]
      },
      "valid": true
    },
    {
      "name": "field",
      "params": [
        "key",
        "value"
      ],
      "docs": {
        "description": "Returns a key, value pair in an array.",
        "tags": [
          {
            "title": "public",
            "description": null,
            "type": null
          },
          {
            "title": "function",
            "description": null,
            "name": null
          },
          {
            "title": "example",
            "description": "field('destination_field_name__c', 'value')"
          },
          {
            "title": "param",
            "description": "Name of the field",
            "type": {
              "type": "NameExpression",
              "name": "string"
            },
            "name": "key"
          },
          {
            "title": "param",
            "description": "The value itself or a sourceable operation.",
            "type": {
              "type": "NameExpression",
              "name": "Value"
            },
            "name": "value"
          },
          {
            "title": "returns",
            "description": null,
            "type": {
              "type": "NameExpression",
              "name": "Field"
            }
          }
        ]
      },
      "valid": true
    },
    {
      "name": "fields",
      "params": [
        "fields"
      ],
      "docs": {
        "description": "Zips key value pairs into an object.",
        "tags": [
          {
            "title": "public",
            "description": null,
            "type": null
          },
          {
            "title": "function",
            "description": null,
            "name": null
          },
          {
            "title": "example",
            "description": "fields(list_of_fields)"
          },
          {
            "title": "param",
            "description": "a list of fields",
            "type": {
              "type": "NameExpression",
              "name": "Fields"
            },
            "name": "fields"
          },
          {
            "title": "returns",
            "description": null,
            "type": {
              "type": "NameExpression",
              "name": "Object"
            }
          }
        ]
      },
      "valid": true
    },
    {
      "name": "merge",
      "params": [
        "dataSource",
        "fields"
      ],
      "docs": {
        "description": "Merges fields into each item in an array.",
        "tags": [
          {
            "title": "public",
            "description": null,
            "type": null
          },
          {
            "title": "example",
            "description": "merge(\n  \"$.books[*]\",\n  fields(\n    field( \"publisher\", sourceValue(\"$.publisher\") )\n  )\n)"
          },
          {
            "title": "function",
            "description": null,
            "name": null
          },
          {
            "title": "public",
            "description": null,
            "type": null
          },
          {
            "title": "param",
            "description": null,
            "type": {
              "type": "NameExpression",
              "name": "DataSource"
            },
            "name": "dataSource"
          },
          {
            "title": "param",
            "description": "Group of fields to merge in.",
            "type": {
              "type": "NameExpression",
              "name": "Object"
            },
            "name": "fields"
          },
          {
            "title": "returns",
            "description": null,
            "type": {
              "type": "NameExpression",
              "name": "DataSource"
            }
          }
        ]
      },
      "valid": true
    },
    {
      "name": "group",
      "params": [
        "arrayOfObjects",
        "keyPath",
        "callback"
      ],
      "docs": {
        "description": "Groups an array of objects by a specified key path.",
        "tags": [
          {
            "title": "public",
            "description": null,
            "type": null
          },
          {
            "title": "example",
            "description": "const users = [\n  { name: 'Alice', age: 25, city: 'New York' },\n  { name: 'Bob', age: 30, city: 'San Francisco' },\n  { name: 'Charlie', age: 25, city: 'New York' },\n  { name: 'David', age: 30, city: 'San Francisco' }\n];\ngroup(users, 'city');\n// state is { data: { 'New York': [/Alice, Charlie/], 'San Francisco': [ /Bob, David / ] }"
          },
          {
            "title": "function",
            "description": null,
            "name": null
          },
          {
            "title": "public",
            "description": null,
            "type": null
          },
          {
            "title": "param",
            "description": "The array of objects to be grouped.",
            "type": {
              "type": "TypeApplication",
              "expression": {
                "type": "NameExpression",
                "name": "Array"
              },
              "applications": [
                {
                  "type": "NameExpression",
                  "name": "Object"
                }
              ]
            },
            "name": "arrayOfObjects"
          },
          {
            "title": "param",
            "description": "The key path to group by.",
            "type": {
              "type": "NameExpression",
              "name": "string"
            },
            "name": "keyPath"
          },
          {
            "title": "param",
            "description": "(Optional) Callback function",
            "type": {
              "type": "NameExpression",
              "name": "function"
            },
            "name": "callback"
          },
          {
            "title": "returns",
            "description": null,
            "type": {
              "type": "NameExpression",
              "name": "Operation"
            }
          }
        ]
      },
      "valid": true
    },
    {
      "name": "arrayToString",
      "params": [
        "arr",
        "separator"
      ],
      "docs": {
        "description": "Turns an array into a string, separated by X.",
        "tags": [
          {
            "title": "public",
            "description": null,
            "type": null
          },
          {
            "title": "function",
            "description": null,
            "name": null
          },
          {
            "title": "example",
            "description": "field(\"destination_string__c\", function(state) {\n  return arrayToString(dataValue(\"path_of_array\")(state), ', ')\n})"
          },
          {
            "title": "param",
            "description": "Array of toString'able primatives.",
            "type": {
              "type": "NameExpression",
              "name": "array"
            },
            "name": "arr"
          },
          {
            "title": "param",
            "description": "Separator string.",
            "type": {
              "type": "NameExpression",
              "name": "string"
            },
            "name": "separator"
          },
          {
            "title": "returns",
            "description": null,
            "type": {
              "type": "NameExpression",
              "name": "string"
            }
          }
        ]
      },
      "valid": true
    },
    {
      "name": "cursor",
      "params": [
        "value",
        "options"
      ],
      "docs": {
        "description": "Sets a cursor property on state.\nSupports natural language dates like `now`, `today`, `yesterday`, `n hours ago`, `n days ago`, and `start`,\nwhich will be converted relative to the environment (ie, the Lightning or CLI locale). Custom timezones\nare not yet supported.\nYou can provide a formatter to customise the final cursor value, which is useful for normalising\ndifferent inputs. The custom formatter runs after natural language date conversion.\nSee the usage guide at {@link https://docs.openfn.org/documentation/jobs/job-writing-guide#using-cursors}",
        "tags": [
          {
            "title": "public",
            "description": null,
            "type": null
          },
          {
            "title": "function",
            "description": null,
            "name": null
          },
          {
            "title": "example",
            "description": "cursor($.cursor, { defaultValue: 'today' })",
            "caption": "Use a cursor from state if present, or else use the default value"
          },
          {
            "title": "example",
            "description": "cursor(22)",
            "caption": "Use a pagination cursor"
          },
          {
            "title": "param",
            "description": "the cursor value. Usually an ISO date, natural language date, or page number",
            "type": {
              "type": "NameExpression",
              "name": "any"
            },
            "name": "value"
          },
          {
            "title": "param",
            "description": "options to control the cursor.",
            "type": {
              "type": "NameExpression",
              "name": "object"
            },
            "name": "options"
          },
          {
            "title": "param",
            "description": "set the cursor key. Will persist through the whole run.",
            "type": {
              "type": "NameExpression",
              "name": "string"
            },
            "name": "options.key"
          },
          {
            "title": "param",
            "description": "the value to use if value is falsy",
            "type": {
              "type": "NameExpression",
              "name": "any"
            },
            "name": "options.defaultValue"
          },
          {
            "title": "param",
            "description": "custom formatter for the final cursor value",
            "type": {
              "type": "NameExpression",
              "name": "Function"
            },
            "name": "options.format"
          },
          {
            "title": "returns",
            "description": null,
            "type": {
              "type": "NameExpression",
              "name": "Operation"
            }
          }
        ]
      },
      "valid": false
    },
    {
      "name": "assert",
      "params": [
        "expression",
        "errorMessage"
      ],
      "docs": {
        "description": "Asserts the given expression or function resolves to `true`, or else throws an exception. Optionally accepts and error message.",
        "tags": [
          {
            "title": "public",
            "description": null,
            "type": null
          },
          {
            "title": "function",
            "description": null,
            "name": null
          },
          {
            "title": "example",
            "description": "assert('a' === 'b', '\"a\" is not equal to \"b\"')"
          },
          {
            "title": "param",
            "description": "The expression or function to be evaluated.",
            "type": {
              "type": "NameExpression",
              "name": "any"
            },
            "name": "expression"
          },
          {
            "title": "param",
            "description": "The error message thrown in case of a failed state.",
            "type": {
              "type": "NameExpression",
              "name": "string"
            },
            "name": "errorMessage"
          },
          {
            "title": "returns",
            "description": null,
            "type": {
              "type": "NameExpression",
              "name": "operation"
            }
          }
        ]
      },
      "valid": true
    },
    {
      "name": "log",
      "params": [
        "args"
      ],
      "docs": {
        "description": "Outputs a message, like calling `console.log`. Use this at the top level of your job code, but not inside callbacks.",
        "tags": [
          {
            "title": "public",
            "description": null,
            "type": null
          },
          {
            "title": "function",
            "description": null,
            "name": null
          },
          {
            "title": "example",
            "description": "log('Patient List::', $.patients);",
            "caption": "Log values from state"
          },
          {
            "title": "example",
            "description": "fn((state) => {\n  console.log(state.data);\n  return state;\n})",
            "caption": "Use console.log inside a callback or fn block"
          },
          {
            "title": "param",
            "description": "A value or message to display in the logs",
            "type": {
              "type": "NameExpression",
              "name": "any"
            },
            "name": "args"
          },
          {
            "title": "returns",
            "description": null,
            "type": {
              "type": "NameExpression",
              "name": "Operation"
            }
          }
        ]
      },
      "valid": true
    },
    {
      "name": "as",
      "params": [
        "key",
        "operation"
      ],
      "docs": {
        "description": "Run an operation and save the result to a custom key in state instead of overwriting state.data.",
        "tags": [
          {
            "title": "public",
            "description": null,
            "type": null
          },
          {
            "title": "function",
            "description": null,
            "name": null
          },
          {
            "title": "example",
            "description": "as('cceData', collections.get('cce-data-dhis2', { key: `*:*:${$.syncedAt}*` }));",
            "caption": "Fetch cce-data from collections and store them under state.cceData"
          },
          {
            "title": "param",
            "description": "The state key to assign the result of the operation to.",
            "type": {
              "type": "NameExpression",
              "name": "string"
            },
            "name": "key"
          },
          {
            "title": "param",
            "description": " An operation that returns a new state object with a `data` property",
            "type": {
              "type": "NameExpression",
              "name": "function"
            },
            "name": "operation"
          },
          {
            "title": "returns",
            "description": null,
            "type": {
              "type": "NameExpression",
              "name": "Operation"
            }
          }
        ]
      },
      "valid": true
    }
  ]
}