Docs Self-Managed Reference Data Transforms SDKs JavaScript Data Transforms API You are viewing the Self-Managed v24.3 beta documentation. We welcome your feedback at the Redpanda Community Slack #beta-feedback channel. To view the latest available version of the docs, see v24.2. JavaScript API for Data Transforms This page contains the API reference for the data transforms client library of the JavaScript SDK. Functions 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 cb Returns void Example import {onRecordWritten} from "@redpanda-data/transform-sdk"; // Copy the input data to the output topic. onRecordWritten((event, writer) => { writer.write(event.record); }); Interfaces OnRecordWrittenCallback() OnRecordWrittenCallback : (`event`, `writer`) => `void` The callback type for OnRecordWritten. Parameters event: The event object representing the written record. writer: The writer object used to write transformed records to the output topics. Returns void OnRecordWrittenEvent An event generated after a write event within the broker. Properties record (read only): The record that was written as part of this event. Record A record within Redpanda, generated as a result of any transforms acting upon a written record. Properties headers (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. value (optional, read only): The value for this record. The value can be string, ArrayBuffer, Uint8Array, or RecordData. RecordData A wrapper around the underlying raw data in a record, similar to a JavaScript response object. 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 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 key (optional, read only): The key for this header. The key can be string, ArrayBuffer, Uint8Array, or RecordData. value (optional, read only): The value for this header. The value can be string, ArrayBuffer, Uint8Array, or RecordData. RecordWriter A writer for transformed records that are written to the output topics. Methods write(record): Write a record to the output topic. Returns void. Throws an error if there are errors writing the record. 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 headers (read only): The headers attached to this record. key (read only): The key for this record. value (optional, read only): The value for this record. 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, except that it only contains RecordData or null. Properties key (optional, read only): The key for this header. value (optional, read only): The value for this header. Suggested reading JavaScript Schema Registry API for Data Transforms Back to top × Simple online edits For simple changes, such as fixing a typo, you can edit the content directly on GitHub. Edit on GitHub Or, open an issue to let us know about something that you want us to change. Open an issue Contribution guide For extensive content updates, or if you prefer to work locally, read our contribution guide . Was this helpful? thumb_up thumb_down group Ask in the community mail Share your feedback group_add Make a contribution JavaScript Schema Registry API