Using the TypeScript Client
To perform data management operations, initialize a HydroServer client once at app startup.
import hs, { createHydroServer } from "@hydroserver/client";
await createHydroServer({
host: "https://playground.hydroserver.org",
});If your frontend is served from the same domain as HydroServer, set host: "" to use same-origin requests.
await createHydroServer({ host: "" });The TypeScript client exposes these services:
| Area | Services |
|---|---|
| Authentication and account | session, user |
| Data management | workspaces, monitoringSites, datastreams, methods, units, processingLevels, observedProperties, resultQualifiers |
| Controlled vocabularies | monitoringSiteTypes, methodTypes, observedPropertyTypes, unitTypes, sampledMediums, aggregationStatistics, datastreamStatuses, linkedResourceTypes |
| Ingestion and orchestration | dataConnections, tasks, etlMappings, monitoringTasks, monitoringRules, dataProductTasks, dataProductTransformations, ratingCurves |
| Quality control | qualityControlHistories, qualityControlSessions, qualityControlOperations |
Services are created lazily, so reading a service property does not make a request.
Responses and errors
Most methods return an ApiResponse<T> discriminated union:
ok: request success flagdata: response payload whenokistruestatus: HTTP statusmessage: best-available status/error textmeta: optional metadata
const res = await hs.workspaces.list();
if (!res.ok) {
console.error(res.message);
} else {
console.log(res.data);
}Always check ok before reading data; TypeScript then narrows the response to the success shape.
Collections and CRUD helpers
Model-backed collection services support:
list(params): returnsApiResponse<T[]>listItems(params): returnsT[](or[]on error)listAllItems(params): fetches and merges all pages
They also provide get/getItem, create/createItem, update/updateItem, and delete. Methods ending in Item return the payload directly, with null or [] on failure; use the methods returning ApiResponse when the caller needs status or error details.
QC sessions and operations use similar helpers but also require their parent history and session IDs. Authentication and linked resource methods expose purpose-specific methods instead.
Most collection endpoints support query params such as:
limitandoffsetfor pagingsortbyproperties, to return only some properties of each iteminclude, to add related resources to the response'sincludedsectionq,bboxanddatetime, where a collection supports them- Resource-specific filters
f selects the response format (for example geojson on workspaces, monitoring sites, datastreams, and observations), and observations also accept a profile (see Get observations).
Example: Access collection items
const workspaces = await hs.workspaces.listItems();
for (const workspace of workspaces) {
console.log(workspace.name);
}Example: Collection pagination
// Fetch the second page of 5 only
const page2 = await hs.workspaces.list({
offset: 5,
limit: 5,
});
// Fetch all pages
const allWorkspaces = await hs.workspaces.listAllItems({
isAssociated: true,
});Example: Collection ordering
const ordered = await hs.workspaces.list({
sortby: ["name"],
});
const multiOrdered = await hs.workspaces.list({
sortby: ["-name", "isPrivate"],
});Example: Collection filtering
const publicWorkspaces = await hs.workspaces.listAllItems({
isPrivate: false,
});
const yourPrivateWorkspaces = await hs.workspaces.listAllItems({
isPrivate: true,
isAssociated: true,
});Authentication and session
HydroServer provides pages for signing in, signing up, and editing account details. Your app can open these pages using the client methods below.
Sign in and sign out
Call hs.session.login() when the user clicks your app's sign-in button. This opens HydroServer's sign-in page. The user enters their email and password there.
async function signIn() {
await hs.session.login("/");
}
async function signOut() {
await hs.session.logout("/");
}The "/" tells HydroServer to send the user back to your app's home page afterwards. You can replace it with another path in your app, such as "/workspaces". If you leave it out, signing in returns to the current page and signing out returns to the home page.
Check who is signed in
After setting up the client with await createHydroServer(...), you can check whether the user is signed in. Check again when the user returns from the sign-in page:
if (hs.session.isAuthenticated) {
console.log("You are signed in.");
} else {
console.log("Please sign in.");
}Use hs.user.get() to read the signed-in user's details. Check ok before using the returned data:
const accountRes = await hs.user.get();
if (accountRes.ok) {
console.log(accountRes.data.firstName);
} else {
console.log(accountRes.message);
}Edit an account or sign up
To let the user edit their profile, open HydroServer's account page:
window.location.assign(hs.session.getAccountProfileUrl("/"));Here, getAccountProfileUrl() builds the account page's address, and window.location.assign() opens it in the browser. Use getAccountSignupUrl() in the same way to open the sign-up page. The "/" sets the return page, just as it does for signing in. If you leave it out, the return page is your current page.
See Managing Your Account for the changes a user can make on the account page.
If your app uses OpenID Connect (OIDC)
If you set the client's oidc option, your app needs a page to handle the user's return from signing in. On that page, call await hs.session.completeLogin() to finish signing in. It returns the path your app should open next.
Tokens managed by your app
If your app already holds HydroServer access tokens, for example because its backend signs users in through HydroServer, pass an accessTokenProvider so the client uses those tokens instead of signing the user in itself:
await createHydroServer({
host: "https://playground.hydroserver.org",
accessTokenProvider: async () => {
const res = await fetch("/my-app/hydroserver-token/");
return res.ok ? (await res.json()).access_token : null;
},
onUnauthorized: () => window.location.assign("/login/"),
});- The provider is called before each request, so cache the token until shortly before it expires. Return
nullwhen the user isn't signed in. - When a request is rejected with a
401, the client calls the provider again and retries once. If the retry is also rejected, it callsonUnauthorizedand emitssession:expired. hs.session.isAuthenticatedreflects whether the provider returned a token.hs.user.get()reads the user from the OIDC UserInfo endpoint, so the token needs theopenid,profile, andemailscopes.- Your app handles sign-in and sign-out:
hs.session.login()andhs.session.logout()throw in this mode. accessTokenProvidercan't be combined with theoidcoption.
The endpoint that returns the token should require your app's own sign-in, reject cross-origin requests, and send Cache-Control: no-store. The browser can use the token for everything its scopes allow, so request only the scopes your frontend needs.
Workspaces
Workspaces are the top-level access-control boundary for HydroServer data.
Example: Get workspaces
const publicWorkspaces = await hs.workspaces.listAllItems();
const yourWorkspaces = await hs.workspaces.listAllItems({
isAssociated: true,
});
const workspace = await hs.workspaces.getItem(
"00000000-0000-0000-0000-000000000000"
);Example: Create a workspace
import { Workspace } from "@hydroserver/client";
const workspace = new Workspace();
workspace.name = "New Workspace";
workspace.isPrivate = false;
const created = await hs.workspaces.create(workspace);Example: Modify a workspace
const workspace = await hs.workspaces.getItem(
"00000000-0000-0000-0000-000000000000"
);
if (!workspace) throw new Error("Workspace not found");
workspace.name = "Updated Workspace Name";
workspace.isPrivate = true;
await hs.workspaces.update(workspace);Example: Manage collaborators and ownership transfer
const workspaceId = "00000000-0000-0000-0000-000000000000";
const userEmail = "user@example.com";
const roleId = "11111111-1111-1111-1111-111111111111";
await hs.workspaces.addCollaborator(workspaceId, userEmail, roleId);
await hs.workspaces.updateCollaboratorRole(workspaceId, userEmail, roleId);
await hs.workspaces.removeCollaborator(workspaceId, userEmail);
await hs.workspaces.transferOwnership(workspaceId, "new-owner@example.com");
await hs.workspaces.acceptOwnershipTransfer(workspaceId);
await hs.workspaces.rejectOwnershipTransfer(workspaceId);Monitoring Sites
Monitoring sites represent physical monitoring locations.
Example: Get monitoringSites
const publicMonitoringSites = await hs.monitoringSites.listAllItems();
const workspaceMonitoringSites = await hs.monitoringSites.listAllItems({
workspaceId: ["00000000-0000-0000-0000-000000000000"],
});
const boundedMonitoringSites = await hs.monitoringSites.listAllItems({
bbox: ["-112.166,41.369,-111.402,42.999"],
});
const filteredMonitoringSites = await hs.monitoringSites.listAllItems({
tag: ["Region:A"],
});Example: Create a monitoringSite
import { MonitoringSite } from "@hydroserver/client";
const monitoringSite = new MonitoringSite();
monitoringSite.workspaceId = "00000000-0000-0000-0000-000000000000";
monitoringSite.name = "My Site";
monitoringSite.description = "This site records environmental observations.";
monitoringSite.code = "OBSERVATION_SITE";
monitoringSite.type = "Atmosphere";
monitoringSite.latitude = 41.739;
monitoringSite.longitude = -111.7957;
monitoringSite.elevationM = 1414;
monitoringSite.elevationDatum = "EGM96";
monitoringSite.adminArea1 = "UT";
monitoringSite.adminArea2 = "Cache";
monitoringSite.country = "US";
monitoringSite.dataDisclaimer = "Data may be provisional and subject to revision.";
monitoringSite.isPrivate = false;
await hs.monitoringSites.create(monitoringSite);Example: Modify monitoringSite metadata and privacy
const monitoringSite = await hs.monitoringSites.getItem("00000000-0000-0000-0000-000000000000");
if (!monitoringSite) throw new Error("MonitoringSite not found");
monitoringSite.name = "Updated Site Name";
monitoringSite.description = "Updated site metadata";
await hs.monitoringSites.update(monitoringSite);
await hs.monitoringSites.updatePrivacy(monitoringSite.id, true);Example: Manage monitoringSite tags
const monitoringSiteId = "00000000-0000-0000-0000-000000000000";
await hs.monitoringSites.setTag(monitoringSiteId, "Region", "A");
await hs.monitoringSites.deleteTag(monitoringSiteId, "Region");Example: Manage monitoringSite linked resources
const monitoringSiteId = "00000000-0000-0000-0000-000000000000";
const hostedData = new FormData();
hostedData.append("name", "site-photo.png");
hostedData.append("type", "Photo");
hostedData.append("file", fileInput.files![0]);
const created = await hs.monitoringSites.createLinkedResource(monitoringSiteId, hostedData);
const externalData = new FormData();
externalData.append("name", "Site report");
externalData.append("type", "Document");
externalData.append("link", "https://example.com/report.pdf");
await hs.monitoringSites.createLinkedResource(monitoringSiteId, externalData);
await hs.monitoringSites.getLinkedResources(monitoringSiteId);
const renameData = new FormData();
renameData.append("name", "Updated site photo");
await hs.monitoringSites.updateLinkedResource(monitoringSiteId, created.data!.id, renameData);
await hs.monitoringSites.deleteLinkedResource(monitoringSiteId, created.data!.id);Example: Get datastreams for a monitoringSite
const monitoringSiteDatastreams = await hs.datastreams.listAllItems({
monitoringSiteId: ["00000000-0000-0000-0000-000000000000"],
});Example: Delete a monitoringSite
await hs.monitoringSites.delete("00000000-0000-0000-0000-000000000000");Observed Properties
Example: Get observed properties
const observedProperties = await hs.observedProperties.listAllItems();
const workspaceObservedProperties = await hs.observedProperties.listAllItems({
workspaceId: ["00000000-0000-0000-0000-000000000000"],
});Example: Create and modify an observed property
import { ObservedProperty } from "@hydroserver/client";
const observedProperty = new ObservedProperty();
observedProperty.workspaceId = "00000000-0000-0000-0000-000000000000";
observedProperty.name = "Temperature";
observedProperty.definition =
"http://vocabulary.odm2.org/variablename/airTemperature/";
observedProperty.description = "Near-surface air temperature";
observedProperty.type = "Climate";
observedProperty.code = "AirTemp";
const created = await hs.observedProperties.createItem(observedProperty);
if (!created) throw new Error("Unable to create observed property");
created.name = "Air Temperature";
await hs.observedProperties.update(created);Example: Delete an observed property
await hs.observedProperties.delete("00000000-0000-0000-0000-000000000000");Units
Example: Create and modify a unit
import { Unit } from "@hydroserver/client";
const unit = new Unit();
unit.workspaceId = "00000000-0000-0000-0000-000000000000";
unit.name = "Degree Celsius";
unit.symbol = "C";
unit.definition = "https://qudt.org/vocab/unit/DEG_C";
unit.type = "Temperature";
const created = await hs.units.createItem(unit);
if (!created) throw new Error("Unable to create unit");
created.name = "Celsius";
await hs.units.update(created);Example: Delete a unit
await hs.units.delete("00000000-0000-0000-0000-000000000000");Methods
Example: Create and modify a method
import { Method } from "@hydroserver/client";
const method = new Method();
method.workspaceId = "00000000-0000-0000-0000-000000000000";
method.name = "Environmental Instrument";
method.description = "Records environmental observations.";
method.type = "Instrument Deployment";
method.code = "SENSOR_A";
method.definition = "https://example.com/methods/sensor";
method.sensorModel = "A";
method.sensorModelManufacturer = "Campbell Scientific";
method.sensorModelDefinition = "https://example.com/sensors/A";
const created = await hs.methods.createItem(method);
if (!created) throw new Error("Unable to create method");
created.name = "Environmental Instrument - Updated";
await hs.methods.update(created);Example: Delete a method
await hs.methods.delete("00000000-0000-0000-0000-000000000000");Processing Levels
Example: Create and modify a processing level
import { ProcessingLevel } from "@hydroserver/client";
const processingLevel = new ProcessingLevel();
processingLevel.workspaceId = "00000000-0000-0000-0000-000000000000";
processingLevel.code = "0";
processingLevel.name = "Raw";
processingLevel.description =
"Data have not been processed or quality controlled.";
const created = await hs.processingLevels.createItem(processingLevel);
if (!created) throw new Error("Unable to create processing level");
created.code = "1";
await hs.processingLevels.update(created);Example: Delete a processing level
await hs.processingLevels.delete("00000000-0000-0000-0000-000000000000");Result Qualifiers
Example: Create and modify a result qualifier
import { ResultQualifier } from "@hydroserver/client";
const resultQualifier = new ResultQualifier();
resultQualifier.workspaceId = "00000000-0000-0000-0000-000000000000";
resultQualifier.name = "PF";
resultQualifier.description = "Power Failure";
const created = await hs.resultQualifiers.createItem(resultQualifier);
if (!created) throw new Error("Unable to create result qualifier");
created.name = "PF2";
await hs.resultQualifiers.update(created);Example: Delete a result qualifier
await hs.resultQualifiers.delete("00000000-0000-0000-0000-000000000000");Controlled Vocabularies
Metadata forms choose some values from controlled vocabularies: monitoring site types, method types, observed property types, unit types, sampled mediums, aggregation statistics, datastream statuses, and linked resource types. Each vocabulary has its own service with the standard collection helpers. Every term has an id, a name, and an optional description. Monitoring sites, datastreams, and other records store the term's name.
Example: List vocabulary terms
const siteTypes = await hs.monitoringSiteTypes.listAllItems();
const siteTypeNames = siteTypes.map((term) => term.name);
const statuses = await hs.datastreamStatuses.listAllItems({ q: "complete" });Anyone can read vocabulary terms. Only HydroServer administrators can create, update, or delete them, using the same create, update, and delete helpers as other services.
Datastreams
Datastreams group observations for one observed property, produced by one method, at one monitoring site.
Example: Get datastreams
const datastreams = await hs.datastreams.listAllItems();
const workspaceDatastreams = await hs.datastreams.listAllItems({
workspaceId: ["00000000-0000-0000-0000-000000000000"],
});
const monitoringSiteDatastreams = await hs.datastreams.listAllItems({
monitoringSiteId: ["00000000-0000-0000-0000-000000000000"],
});
const datastream = await hs.datastreams.getItem(
"00000000-0000-0000-0000-000000000000"
);Example: Create and modify a datastream
import { Datastream } from "@hydroserver/client";
const datastream = new Datastream();
datastream.workspaceId = "00000000-0000-0000-0000-000000000000";
datastream.monitoringSiteId = "11111111-1111-1111-1111-111111111111";
datastream.methodId = "22222222-2222-2222-2222-222222222222";
datastream.observedPropertyId = "33333333-3333-3333-3333-333333333333";
datastream.processingLevelId = "44444444-4444-4444-4444-444444444444";
datastream.unitId = "55555555-5555-5555-5555-555555555555";
datastream.name = "Air Temperature";
datastream.description = "15-minute air temperature";
datastream.sampledMedium = "Air";
datastream.aggregationStatistic = "Continuous";
datastream.noDataValue = -9999;
datastream.timeAggregationInterval = 15;
datastream.timeAggregationIntervalUnit = "minutes";
datastream.intendedTimeSpacing = 15;
datastream.intendedTimeSpacingUnit = "minutes";
datastream.isPrivate = false;
datastream.isRestricted = false;
const created = await hs.datastreams.createItem(datastream);
if (!created) throw new Error("Unable to create datastream");
created.name = "Air Temperature (Updated)";
await hs.datastreams.update(created);Example: Manage datastream tags
const datastreamId = "00000000-0000-0000-0000-000000000000";
await hs.datastreams.setTag(datastreamId, "MaxAllowableResult", "100");
await hs.datastreams.deleteTag(datastreamId, "MaxAllowableResult");Example: Manage datastream linked resources
const datastreamId = "00000000-0000-0000-0000-000000000000";
const data = new FormData();
data.append("name", "rating-curve.csv");
data.append("type", "Rating Curve");
data.append("file", fileInput.files![0]);
const created = await hs.datastreams.createLinkedResource(datastreamId, data);
await hs.datastreams.getLinkedResources(datastreamId);
await hs.datastreams.deleteLinkedResource(datastreamId, created.data!.id);Example: Get related metadata for a datastream
The datastream service accepts expand_related, which requests the datastream's related resources with include and nests them in the datastream it returns.
import type { DatastreamExtended } from "@hydroserver/client";
const res = await hs.datastreams.get(
"00000000-0000-0000-0000-000000000000",
{ expand_related: true }
);
if (res.ok) {
const datastream = res.data as unknown as DatastreamExtended;
console.log(datastream.monitoringSite);
console.log(datastream.method);
console.log(datastream.observedProperty);
console.log(datastream.unit);
console.log(datastream.processingLevel);
}Example: Get observations
Without a profile, getObservations returns observation records. The row and column profiles return the same properties grouped by datastream: each group has datastreamId and either fields and rows, or columns with one array per property. Use properties to request only the properties you need.
import { ObservationProfile } from "@hydroserver/client";
const observations = await hs.datastreams.getObservations(
"00000000-0000-0000-0000-000000000000",
{
profile: [ObservationProfile.Column],
properties: ["phenomenonTime", "result"],
sortby: ["phenomenonTime"],
datetime: "2025-01-01T00:00:00Z/2025-12-31T23:59:59Z",
limit: 1000,
}
);
if (observations.ok) {
const [group] = observations.data;
if (group && "columns" in group) {
console.log(group.columns.phenomenonTime, group.columns.result);
}
}Example: Upload observations
await hs.datastreams.createObservations(
"00000000-0000-0000-0000-000000000000",
{
fields: ["phenomenonTime", "result"],
data: [
["2025-01-26T00:00:00Z", 40.0],
["2025-01-27T00:00:00Z", 41.0],
["2025-01-28T00:00:00Z", 42.0],
],
}
);Example: Replace observations in a date range
await hs.datastreams.createObservations(
"00000000-0000-0000-0000-000000000000",
{
fields: ["phenomenonTime", "result"],
data: [
["2025-01-26T00:00:00Z", 40.0],
["2025-01-27T00:00:00Z", 41.0],
["2025-01-28T00:00:00Z", 42.0],
],
},
{ mode: "replace" }
);Example: Delete observations
const datastreamId = "00000000-0000-0000-0000-000000000000";
// Delete observations in a time range
await hs.datastreams.deleteObservations(datastreamId, {
phenomenonTimeStart: "2025-01-01T00:00:00Z",
phenomenonTimeEnd: "2025-12-31T23:59:59Z",
});
// Delete all observations in a datastream
await hs.datastreams.deleteObservations(datastreamId);Example: Fetch observations as CSV
fetchCsvBlob returns the server response without prescribing how an application saves or displays the file.
const csvRes = await hs.datastreams.fetchCsvBlob(
"00000000-0000-0000-0000-000000000000"
);
if (csvRes.ok) {
const url = URL.createObjectURL(csvRes.data);
const link = document.createElement("a");
link.href = url;
link.download = "observations.csv";
link.click();
URL.revokeObjectURL(url);
}Example: Delete a datastream
await hs.datastreams.delete("00000000-0000-0000-0000-000000000000");Data Connections
Data connections define the source, payload format, timestamp handling, placeholders, and optional notifications used by ETL tasks.
Example: Get data connections
const dataConnections = await hs.dataConnections.listAllItems({
workspaceId: ["00000000-0000-0000-0000-000000000000"],
});Example: Create and modify a data connection
import { DataConnection } from "@hydroserver/client";
const dataConnection = Object.assign(
new DataConnection({
name: "Example Data Connection",
sourceUrl: "https://example.com/data.csv",
timezoneType: "iana",
timezone: "Etc/UTC",
payload: {
type: "CSV",
timestampKey: "timestamp",
timestampFormat: "%Y-%m-%dT%H:%M:%SZ",
delimiter: ",",
},
placeholderVariables: [],
}),
{ workspaceId: "00000000-0000-0000-0000-000000000000" }
);
const created = await hs.dataConnections.createItem(dataConnection);
if (!created) throw new Error("Unable to create data connection");
await hs.dataConnections.update({
id: created.id,
name: "Updated Data Connection",
});Example: Delete a data connection
await hs.dataConnections.delete("00000000-0000-0000-0000-000000000000");Tasks
ETL tasks bind a data connection to source-to-datastream mappings.
Example: Get tasks
const tasks = await hs.tasks.listAllItems({
workspaceId: ["00000000-0000-0000-0000-000000000000"],
});Example: Create and modify a task
import { Task } from "@hydroserver/client";
const task = new Task({
name: "Example Task",
dataConnectionId: "11111111-1111-1111-1111-111111111111",
taskVariables: {},
mappings: [
{
sourceIdentifier: "temperature",
targetDatastreamId: "33333333-3333-3333-3333-333333333333",
},
],
});
const created = await hs.tasks.createItem(task);
if (!created) throw new Error("Unable to create task");
created.name = "Updated Task";
await hs.tasks.update(created);Example: Manage a task's mappings
A task's mappings are also available as a top-level resource through hs.etlMappings, which is useful when you need to find which tasks load a datastream or change one mapping without updating the whole task.
const mappings = await hs.etlMappings.listAllItems({
targetDatastreamId: ["33333333-3333-3333-3333-333333333333"],
include: ["targetDatastream"],
});
await hs.etlMappings.create({
etlTaskId: "00000000-0000-0000-0000-000000000000",
sourceIdentifier: "humidity",
targetDatastreamId: "44444444-4444-4444-4444-444444444444",
});Example: Trigger a task run
await hs.tasks.runTask("00000000-0000-0000-0000-000000000000");Example: Delete a task
await hs.tasks.delete("00000000-0000-0000-0000-000000000000");Task Runs
HydroServer stores task run history for ETL execution.
Example: Get task runs
const taskId = "00000000-0000-0000-0000-000000000000";
const runs = await hs.tasks.getTaskRuns(taskId, {
limit: 50,
sortby: ["-startedAt"],
});
const run = await hs.tasks.getTaskRun(
taskId,
"11111111-1111-1111-1111-111111111111"
);The same runTask, getTaskRuns, and getTaskRun helpers are available on monitoringTasks and dataProductTasks.
Monitoring Tasks
Monitoring tasks run data-quality rules for the datastreams at a MonitoringSite and can notify a list of recipients.
import { MonitoringTask } from "@hydroserver/client";
const task = await hs.monitoringTasks.createItem(
new MonitoringTask({
name: "Daily range checks",
monitoringSiteId: "00000000-0000-0000-0000-000000000000",
recipients: ["alerts@example.com"],
schedule: null,
})
);
if (!task) throw new Error("Unable to create monitoring task");
await hs.monitoringRules.create({
id: "",
taskId: task.id,
datastreamId: "11111111-1111-1111-1111-111111111111",
ruleType: "range",
minValue: -40,
maxValue: 60,
});
await hs.monitoringTasks.runTask(task.id);Monitoring rules are a top-level resource: use hs.monitoringRules' list (filtered with { taskId: task.id }), get, create, update, and delete methods to manage a monitoring task's rules.
Data Product Tasks and Rating Curves
Data product tasks create derived datastreams through derivation, rating-curve, or aggregation transformations.
import { DataProductTask } from "@hydroserver/client";
const task = await hs.dataProductTasks.createItem(
new DataProductTask({
name: "Convert temperature",
monitoringSiteId: "00000000-0000-0000-0000-000000000000",
schedule: null,
})
);
if (!task) throw new Error("Unable to create data product task");
await hs.dataProductTransformations.create({
taskId: task.id,
transformationType: "derivation",
outputDatastreamId: "22222222-2222-2222-2222-222222222222",
inputDatastreams: [
{
datastreamId: "11111111-1111-1111-1111-111111111111",
variableName: "temperature",
},
],
formula: "temperature * 9 / 5 + 32",
});Transformations are a top-level resource: use hs.dataProductTransformations' list (filtered with { taskId: task.id }), get, create, update, and delete methods for every transformation type. Set transformationType to derivation, rating_curve, or aggregation and supply that type's fields. Rating curves themselves are managed through hs.ratingCurves:
import { RatingCurve } from "@hydroserver/client";
const curve = await hs.ratingCurves.createItem(
new RatingCurve({
name: "Stage to discharge",
monitoringSiteId: "00000000-0000-0000-0000-000000000000",
fittingMethod: "power_law",
points: [
[0.1, 0.3],
[0.5, 2.4],
[1.0, 7.8],
],
})
);Use listItemsForMonitoringSite(monitoringSiteId) to retrieve all curves for one MonitoringSite.
Quality Control Histories
A QC history links an immutable source datastream to the managed datastream that receives quality-controlled observations. Sessions record a time-bounded QC pass, and ordered operations record what changed.
Create and query histories
const historyRes = await hs.qualityControlHistories.create({
sourceDatastreamId: "00000000-0000-0000-0000-000000000000",
managedDatastreamId: "11111111-1111-1111-1111-111111111111",
});
if (!historyRes.ok) throw new Error(historyRes.message);
const history = await hs.qualityControlHistories.getItem(historyRes.data.id);
if (!history) throw new Error("Quality control history not found");
const historiesRes = await hs.qualityControlHistories.list({
managedDatastreamId: [history.managedDatastreamId],
include: ["sourceDatastream", "managedDatastream"],
});History responses contain sourceDatastreamId and managedDatastreamId. With include, the datastreams themselves come back in the response's included section, as sourceDatastreams and managedDatastreams.
Example: Correct observations in a range
This example corrects source values that were recorded at ten times their actual value. The app records the range selection and multiplication as QC operations, applies the same change locally, writes the corrected range to the managed datastream, and then commits the session.
const rangeStart = "2026-01-01T00:00:00Z";
const rangeEnd = "2026-01-02T00:00:00Z";
const sessionRes = await hs.qualityControlSessions.create(history.id, {
phenomenonTimeStart: rangeStart,
phenomenonTimeEnd: rangeEnd,
description: "Correct values recorded at ten times their actual value",
});
if (!sessionRes.ok) throw new Error(sessionRes.message);
const session = sessionRes.data;
const sourceRes = await hs.datastreams.getObservations(
history.sourceDatastreamId,
{
sortby: ["phenomenonTime"],
datetime: `${rangeStart}/${rangeEnd}`,
}
);
if (!sourceRes.ok) throw new Error(sourceRes.message);
if (!Array.isArray(sourceRes.data) || sourceRes.data.length === 0) {
throw new Error("No source observations found in the QC range");
}
const sourceObservations = sourceRes.data as Array<{
phenomenonTime: string;
result: number;
resultQualifiers: string[];
}>;
const correctedRows = sourceObservations.map((observation) => [
observation.phenomenonTime,
observation.result * 0.1,
observation.resultQualifiers,
]);
const operationsRes = await hs.qualityControlOperations.create(
history.id,
session.id,
[
{
operationType: "DATETIME_RANGE",
order: 1,
comment: "Selected the affected period",
arguments: [Date.parse(rangeStart), Date.parse(rangeEnd)],
},
{
operationType: "CHANGE_VALUES",
order: 2,
comment: "Converted values to the correct scale",
arguments: ["MULT", 0.1],
},
]
);
if (!operationsRes.ok) throw new Error(operationsRes.message);
const writeRes = await hs.datastreams.createObservations(
history.managedDatastreamId,
{
fields: ["phenomenonTime", "result", "resultQualifiers"],
data: correctedRows,
},
{ mode: "replace" }
);
if (!writeRes.ok) throw new Error(writeRes.message);
const commitRes = await hs.qualityControlSessions.commit(
history.id,
session.id
);
if (!commitRes.ok) throw new Error(commitRes.message);Operation arguments are specific to the selected operationType. Timestamps in QC operation arguments use epoch milliseconds. The client records the operations but does not execute them, so the application must apply those same operations before writing the managed observations. A production QC app can use a dedicated processing layer for more complex filters and edits.
Query session ancestry
const sessions = await hs.qualityControlSessions.listAllItems(history.id, {
status: "committed",
rangeStart: "2026-01-01T00:00:00Z",
rangeEnd: "2026-02-01T00:00:00Z",
includeAncestors: true,
});
const ancestors = await hs.qualityControlSessions.listAllItems(history.id, {
ancestorOf: session.id,
});History methods are list, listItems, listAllItems, get, getItem, create, createItem, and delete. Session methods add update and commit; operation methods provide list/get, bulk create, update, and delete helpers.
