Readonly aggregateWrapper for aggregate API
See Swagger UI, MongoDB docs
Readonly createCreate one or multiple records.
This method will create new records.
Readonly createCreate/update one or multiple records.
This method will update existing records or create new ones.
Readonly getGet settings for the app
Readonly getReadonly getSearch records in provided dataset
This method is good for getting a small amount of records from dataset
Readonly getSearch records in provided dataset
This method is designed for obtaining a huge amount of records from dataset (10000+)
Readonly producePost data to the /api/v1/message_producer/ endpoint using context.api.produceMessages method. The method will work for both stream and scheduled types of apps.
/* eslint-disable @typescript-eslint/require-await */
import { CollectionRecord, Corva, ScheduledDataTimeEvent, StreamTimeEvent } from '@corva/node-sdk';
const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
export const producer = new Corva().stream(async (event: StreamTimeEvent, { api }) => {
const data = [
{
timestamp: 1,
company_id: 42,
asset_id: event.asset_id,
data: { answer: 10 },
},
{
timestamp: 2,
company_id: 42,
asset_id: event.asset_id,
data: { answer: 11 },
},
];
await api.provider('my-provider').dataset('quiz-answers').createEntries(data);
// do some other computations
for (let i = 0; i < 3; i++) await sleep(100);
// call message producer with time index
await api.produceMessages(data);
});
export const streamConsumer = new Corva().stream(async (event: StreamTimeEvent) => {
// data from the producer - same that was published
expect(event.records.map((record) => record.data)).toEqual([{ answer: 10 }, { answer: 11 }]);
});
export const scheduledConsumer = new Corva().scheduled(async (event: ScheduledDataTimeEvent, context) => {
const searchParams = {
query: { timestamp: { $gte: event.start_time, $lte: event.end_time } },
limit: 10,
sort: { timestamp: 1 },
};
const records: CollectionRecord<{ answer: number }>[] = [];
for await (const record of context.api
.provider('my-provider')
.dataset<{ answer: number }>('quiz-answers')
.search(searchParams)) {
records.push(...record);
}
// data from the producer - same that was published
expect(records.map((record) => record.data)).toEqual([{ answer: 10 }, { answer: 11 }]);
});
Readonly providerReadonly rawMake a request to any URL.
For options' details see got documentation
import { Corva } from '@corva/node-sdk';
type Movie = {
id: number;
};
export const handler = new Corva().scheduled(async (event, { api, secrets }) => {
// Call any URL
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
await api.raw<Movie>('https://api.themoviedb.org/3/movie/76341', {
searchParams: { api_key: (secrets as Record<string, string>).api_key },
});
return { status: 'OK' };
});
Readonly requestMake a request to any Corva URL.
For options' details see got documentation
import { Corva } from '@corva/node-sdk';
export const handler = new Corva().scheduled(async (event, { api }) => {
// Corva API calls
await api.request('/v2/pads', {
searchParams: { param: 'val' },
});
await api.request('/v2/pads', {
method: 'POST',
json: { key: 'val' },
});
await api.request('/v2/pads', {
method: 'PUT',
json: { key: 'val' },
});
await api.request('/v2/pads', {
method: 'DELETE',
});
// Corva Data API calls
await api.request('api/v1/data/provider/dataset/', {
searchParams: { param: 'val' },
});
await api.request('api/v1/data/provider/dataset/', {
method: 'POST',
json: { key: 'val' },
});
await api.request('api/v1/data/provider/dataset/', {
method: 'PUT',
json: { key: 'val' },
});
await api.request('api/v1/data/provider/dataset/', {
method: 'DELETE',
});
return { status: 'OK' };
});
Readonly saveCreate/update one or multiple records.
This method will update existing records or create new ones.
use createOrUpdate instead
Apps might need to communicate with the Corva Platform API and Corva Data API.
This SDK provides an CorvaDataSource class, which is node-api-client and based on got