@c8y/dataprep-types
v1.0.3
Published
Types, JSON Schemas and CLI for writing, validating, testing and deploying Cumulocity Data Preparation rules.
Maintainers
Readme
@c8y/dataprep-types
TypeScript type declarations for Cumulocity Data Preparation Smart Functions.
A Smart Function transforms raw device messages into Cumulocity domain objects (measurements, alarms, events, operations) — or sends messages back to devices. This package provides the input/output types so rule authors get full type-checking and IntelliSense in their IDE.
It also includes schemas and a small CLI useful for writing, testing and deploying rules with the Data Preparation rules template — see CLI and Schemas below.
Installation
npm install --save-dev @c8y/dataprep-typesUsage
import type { DeviceMessage, DataPrepContext, CumulocityObject, Measurement } from '@c8y/dataprep-types';
export function onMessage(msg: DeviceMessage, context: DataPrepContext): (CumulocityObject | DeviceMessage)[] {
const text = new TextDecoder().decode(msg.payload);
const data = JSON.parse(text);
// ... build and return Cumulocity objects ...
return [];
}Exported types include DeviceMessage, CumulocityObject, Measurement,
Alarm, Event, Operation, ManagedObject, ExternalId, MeasurementValue,
and DataPrepContext.
Schemas
This package includes schemas for validating data-prep.yaml and <test>.yaml files, for use with the Data Preparation rules template.
CLI
Installing the package provides binaries for working with a rules project (run them
from the project root — they operate on ./rules and use the schemas bundled here):
| Binary | Does |
| --- | --- |
| dataprep-validate | Validate every rule's data-prep.yaml and tests/*.yaml against the JSON Schemas |
| dataprep-check | Type-check rule sources against the Data Preparation API |
| dataprep-lint | Lint rule sources |
| dataprep-test | Run rule tests against the live platform and compare outputs with expectedOutput |
| dataprep-deploy | Deploy rules to the live platform |
| dataprep-create-rule | Create a new rule |
API reference
For the generated TypeScript API documentation (TypeDoc), see Data Preparation Smart Function API.
Developing rules
To author, validate, test, and deploy rules from an IDE, we recommend using the Data Preparation rules template.
