Creating Streaming Functions

Initialize a Streaming Function

Viewing typescript

switch to python

Using the CLI

Initialize your Streaming Function with the moose function init CLI command:

Terminal
npx moose-cli function init --source <SOURCE_DATA_MODEL> --destination <DESTINATION_DATA_MODEL>

This command generates a new Streaming Function file in the /functions directory of your Moose app according to the file structure described previously.

  • Make Sure the Data Models Exist

    SOURCE_DATA_MODEL and DESTINATION_DATA_MODEL must be valid data models that exist in your /datamodels directory.

    You can find a list of your existing data models by running moose-cli ls.

    Manual Initialization

    You can alternatively create a new Streaming Function file manually in the /functions directory of your Moose app. The file name should be in the format SourceDataModel__DestinationDataModel.ts. Inside the file, define the function as follows:

    /functions/SourceDataModel__DestinationDataModel.ts
    import { SourceDataModel } from "../datamodels/path/to/SourceDataModel";
    import { DestinationDataModel } from "../datamodels/path/to/DestinationDataModel";
     
    export default function functionName(
      source: SourceDataModel,
    ): DestinationDataModel[] | DestinationDataModel | null {
      // Transformation logic
    }
    Streaming Function Tips
    • Ensure you import the source and destination Data Models from the correct paths within your application.
    • Replace functionName with a descriptive name that clearly reflects the function's purpose.
    • Substitute SourceDataModel and DestinationDataModel with the actual names of your Data Models.
    • The default export is crucial because Moose uses it to identify the entry point of the Streaming Function.

    Next Steps

    With your Streaming Function initialized, you can now start defining the transformation logic to process data from the source Data Model to the destination Data Model. We'll cover this in more detail in the next section.