custom

package
v0.14.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 13, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JavascriptProcessor added in v0.13.4

type JavascriptProcessor struct {
	sdk.UnimplementedProcessor
	// contains filtered or unexported fields
}
Example
p := NewJavascriptProcessor(log.Nop())

exampleutil.RunExample(p, exampleutil.Example{
	Summary: "Modify a record's metadata and payload using JavaScript",
	Description: "In this example we use the `custom.javascript` processor to add a metadata key " +
		"to the input record. It also prepends \"hello, \" to `.Payload.After`.",
	Config: config.Config{
		"script": `function process(rec) {
  rec.Metadata["processed"] = "true";
  let existing = String.fromCharCode.apply(String, rec.Payload.After);
  rec.Payload.After = RawData("hello, " + existing);
  return rec;
}`,
	},
	Have: opencdc.Record{
		Metadata: map[string]string{
			"existing-key": "existing-value",
		},
		Payload: opencdc.Change{
			After: opencdc.RawData("world"),
		},
	},
	Want: sdk.SingleRecord{
		Metadata: map[string]string{
			"existing-key": "existing-value",
			"processed":    "true",
		},
		Payload: opencdc.Change{
			After: opencdc.RawData("hello, world"),
		},
	},
})
Output:

processor transformed record:
--- before
+++ after
@@ -1,12 +1,13 @@
 {
   "position": null,
   "operation": "Operation(0)",
   "metadata": {
-    "existing-key": "existing-value"
+    "existing-key": "existing-value",
+    "processed": "true"
   },
   "key": null,
   "payload": {
     "before": null,
-    "after": "world"
+    "after": "hello, world"
   }
 }

func NewJavascriptProcessor

func NewJavascriptProcessor(logger log.CtxLogger) *JavascriptProcessor

func (*JavascriptProcessor) Configure added in v0.13.4

func (p *JavascriptProcessor) Configure(ctx context.Context, c config.Config) error

func (*JavascriptProcessor) Open added in v0.13.4

func (*JavascriptProcessor) Process added in v0.13.4

func (*JavascriptProcessor) Specification added in v0.13.4

func (p *JavascriptProcessor) Specification() (sdk.Specification, error)

func (*JavascriptProcessor) Teardown added in v0.13.4

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL