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.
Interfaces
OnRecordWrittenCallback()
OnRecordWrittenCallback : (`event`, `writer`) => `void`
The callback type for OnRecordWritten
.
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 bestring
,ArrayBuffer
,Uint8Array
, orRecordData
. -
value
(optional, read only): The value for this record. The value can bestring
,ArrayBuffer
,Uint8Array
, orRecordData
.
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 ofJSON.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 bestring
,ArrayBuffer
,Uint8Array
, orRecordData
. -
value
(optional, read only): The value for this header. The value can bestring
,ArrayBuffer
,Uint8Array
, orRecordData
.
Methods
-
write(record)
: Write a record to the output topic. Returnsvoid
. 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
.
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
.