# JavaScript API for Data Transforms

> For the complete documentation index, see [llms.txt](https://docs.redpanda.com/llms.txt). Component-specific: [streaming-full.txt](https://docs.redpanda.com/streaming-full.txt)

---
title: JavaScript API for Data Transforms
latest-redpanda-tag: v25.2.1
latest-console-tag: v3.7.3
latest-operator-version: v26.1.4
# EOL = End-of-Life (support lifecycle status)
page-is-nearing-eol: "true"
page-is-past-eol: "false"
page-eol-date: July 31, 2026
latest-connect-version: 4.93.0
docname: data-transforms/js/js-sdk
page-component-name: streaming
page-version: "25.2"
page-component-version: "25.2"
page-component-title: Streaming
page-relative-src-path: data-transforms/js/js-sdk.adoc
page-edit-url: https://github.com/redpanda-data/docs/edit/v/25.2/modules/reference/pages/data-transforms/js/js-sdk.adoc
description: Work with data transforms using JavaScript.
page-git-created-date: "2024-07-31"
page-git-modified-date: "2025-04-08"
support-status: nearing end-of-life
---

<!-- Source: https://docs.redpanda.com/streaming/25.2/reference/data-transforms/js/js-sdk.md -->

This page contains the API reference for the data transforms client library of the JavaScript SDK.

## [](#functions)Functions

### [](#OnRecordWritten)onRecordWritten()

onRecordWritten (\`cb\`): \`void\`

Registers a callback to be fired when a record is written to the input topic. This callback is triggered after the record has been written, fsynced to disk, and acknowledged by the producer. This method should be called in your script’s entry point.

#### [](#parameters)Parameters

-   [`cb`](#OnRecordWrittenCallback)


#### [](#returns)Returns

`void`

#### [](#example)Example

```ts
import {onRecordWritten} from "@redpanda-data/transform-sdk";

// Copy the input data to the output topic.
onRecordWritten((event, writer) => {
  writer.write(event.record);
});
```

## [](#interfaces)Interfaces

### [](#OnRecordWrittenCallback)OnRecordWrittenCallback()

OnRecordWrittenCallback : (\`event\`, \`writer\`) => \`void\`

The callback type for [`OnRecordWritten`](#OnRecordWritten).

#### [](#parameters-2)Parameters

-   [`event`](#OnRecordWrittenEvent): The event object representing the written record.

-   [`writer`](#RecordWriter): The writer object used to write transformed records to the output topics.


#### [](#returns-2)Returns

`void`

### [](#OnRecordWrittenEvent)OnRecordWrittenEvent

An event generated after a write event within the broker.

#### [](#properties)Properties

-   [`record`](#WrittenRecord) (read only): The record that was written as part of this event.


### [](#Record)Record

A record within Redpanda, generated as a result of any transforms acting upon a written record.

#### [](#properties-2)Properties

-   [`headers`](#RecordHeader) (optional, read only): The headers attached to this record.

-   `key` (optional, read only): The key for this record. The key can be `string`, `ArrayBuffer`, `Uint8Array`, or [`RecordData`](#RecordData).

-   `value` (optional, read only): The value for this record. The value can be `string`, `ArrayBuffer`, `Uint8Array`, or [`RecordData`](#RecordData).


### [](#RecordData)RecordData

A wrapper around the underlying raw data in a record, similar to a JavaScript response object.

#### [](#methods)Methods

-   `array()`: Returns the data as a raw byte array (`Uint8Array`).

-   `json()`: Parses the data as JSON. This is a more efficient version of `JSON.parse(text())`. Returns the parsed JSON. Throws an error if the payload is not valid JSON.

-   `text()`: Parses the data as a UTF-8 string. Returns the parsed string. Throws an error if the payload is not valid UTF-8.


### [](#RecordHeader)RecordHeader

Records may have a collection of headers attached to them. Headers are opaque to the broker and are only a mechanism for the producer and consumers to pass information.

#### [](#properties-3)Properties

-   `key` (optional, read only): The key for this header. The key can be `string`, `ArrayBuffer`, `Uint8Array`, or [`RecordData`](#RecordData).

-   `value` (optional, read only): The value for this header. The value can be `string`, `ArrayBuffer`, `Uint8Array`, or [`RecordData`](#RecordData).


### [](#RecordWriter)RecordWriter

A writer for transformed records that are written to the output topics.

### [](#methods-2)Methods

-   `write([record](#Record))`: Write a record to the output topic. Returns `void`. Throws an error if there are errors writing the record.


### [](#WrittenRecord)WrittenRecord

A persisted record written to a topic within Redpanda. It is similar to a `Record`, except that it only contains `RecordData` or `null`.

#### [](#properties-4)Properties

-   [`headers`](#RecordHeader) (read only): The headers attached to this record.

-   `key` (read only): The key for this record.

-   [`value`](#RecordData) (optional, read only): The value for this record.


### [](#WrittenRecordHeader)WrittenRecordHeader

Records may have a collection of headers attached to them. Headers are opaque to the broker and are only a mechanism for the producer and consumers to pass information. This interface is similar to a [`RecordHeader`](#RecordHeader), except that it only contains `RecordData` or `null`.

#### [](#properties-5)Properties

-   `key` (optional, read only): The key for this header.

-   `value` (optional, read only): The value for this header.


## [](#suggested-reading)Suggested reading

[JavaScript Schema Registry API for Data Transforms](https://docs.redpanda.com/streaming/25.2/reference/data-transforms/js/js-sdk-sr/)