@bavenir/spade-node-js-client
Version:
A client-side JavaScript library that can be used to iteract with Data Broker's API.
235 lines (234 loc) • 7.91 kB
TypeScript
/**
* Copyright (C) 2024 bAvenir
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*/
/**
* Represents a Web of Things (WoT) Thing Description (TD) for an Item.
* For more information, visit the official W3C Thing Description specification:
* {@link https://www.w3.org/TR/wot-thing-description11/}.
*
* @interface ItemTD
*
* @property {string} id - The unique identifier of the Thing.
* @property {string} oid - The object identifier of the Thing.
* @property {string} base - The base URI of the Thing.
* @property {string} title - The title of the Thing.
* @property {Array<ContextClassTD | string>} '@context' - The context of the Thing, which could be an array of ContextClassTD or string.
* @property {string[]} security - An array of security methods used by the Thing.
* @property {SecurityDefinitionsTD} securityDefinitions - The security definitions for the Thing.
* @property {string | string[]} ['@type'] - Optional types of the Thing.
* @property {string} [adapterId] - Optional adapter ID of the Thing.
* @property {SPADEIdentityTD} ['SPADE:node'] - Optional SPADE node identity of the Thing.
* @property {SPADEIdentityTD} ['SPADE:organisation'] - Optional SPADE organisation identity of the Thing.
* @property {SPADEPrivacyTD} ['SPADE:Privacy'] - Optional privacy details of the Thing.
* @property {PropertiesTD} [properties] - Optional properties of the Thing.
* @property {string} [description] - Optional description of the Thing.
* @property {GeoLocationTD} ['geo:location'] - Optional geolocation of the Thing.
* @property {RegistrationTD} [registration] - Optional registration details of the Thing.
* @property {string} ['dct:license'] - Optional license of the Thing.
* @property {string} ['dct:licenseHolder'] - Optional license holder of the Thing.
*/
export interface ItemTD {
id: string;
oid: string;
base: string;
title: string;
'@context': Array<ContextClassTD | string>;
security: string[];
securityDefinitions: SecurityDefinitionsTD;
'@type'?: string | string[];
adapterId?: string;
'SPADE:node'?: SPADEIdentityTD;
'SPADE:organisation'?: SPADEIdentityTD;
'SPADE:Privacy'?: SPADEPrivacyTD;
properties?: PropertiesTD;
description?: string;
'geo:location'?: GeoLocationTD;
registration?: RegistrationTD;
'dct:license'?: string;
'dct:licenseHolder'?: string;
}
/**
* Represents a mapping of key-value pairs for the context of a Thing Description.
*
* @interface ContextClassTD
*
* @property {string} [key: string] - A key-value pair representing the context.
*/
export interface ContextClassTD {
[key: string]: string;
}
/**
* Defines the security methods available for a Thing Description.
*
* @interface SecurityDefinitionsTD
*
* @property {NosecScTD} nosec_sc - The "no security" scheme definition.
*/
export interface SecurityDefinitionsTD {
nosec_sc?: NosecScTD;
Bearer?: BearerTD;
}
/**
* Represents a "no security" scheme for a Thing Description.
*
* @interface NosecScTD
*
* @property {string} scheme - The scheme identifier, typically "nosec" to indicate no security.
*/
export interface NosecScTD {
scheme: string;
}
/**
* Represents a "Bearer" scheme for a Thing Description.
*
* @interface BearerTD
*
* @property {string} in - The location of the bearer token.
* @property {string} alg - The algorithm used for the bearer token.
* @property {string} name - The name of the bearer token.
* @property {string} format - The format of the bearer token.
* @property {string} scheme - The scheme identifier, typically "Bearer".
*/
export interface BearerTD {
in: string;
alg: string;
name: string;
format: string;
scheme: string;
}
/**
* Represents a SPADE identity (node or organisation) in a Thing Description.
*
* @interface SPADEIdentityTD
*
* @property {string} '@id' - The unique identifier of the SPADE entity.
*/
export interface SPADEIdentityTD {
'@id': string;
}
/**
* Defines the privacy details for a Thing Description.
*
* @interface SPADEPrivacyTD
*
* @property {number} Level - The privacy level of the Thing.
* @property {string} Caption - A description or caption related to the privacy level.
*/
export interface SPADEPrivacyTD {
Level: number;
Caption: string;
}
/**
* Represents the properties of a Thing Description.
*
* @interface PropertiesTD
*
* @property {PropertyTD} [key: string] - A key-value pair representing a property of the Thing.
*/
export interface PropertiesTD {
[key: string]: PropertyTD | undefined;
}
/**
* Describes an individual property in a Thing Description.
*
* @interface PropertyTD
*
* @property {string} title - The title of the property.
* @property {string} [description] - Optional description of the property.
* @property {string} ['@type'] - Optional type of the property.
* @property {string} [unit] - Optional unit of the property.
* @property {string} ['om:hasUnit'] - Optional unit following the OM (Ontology of Units of Measure) standard.
* @property {boolean} [readOnly] - Optional flag indicating if the property is read-only.
* @property {string} type - The data type of the property.
* @property {FormTD[]} [forms] - Optional forms that describe how to interact with the property.
* @property {UriVariableTD} [uriVariables] - Optional URI variables for the property.
*/
export interface PropertyTD {
title: string;
description?: string;
'@type'?: string;
unit?: string;
'om:hasUnit'?: string;
readOnly?: boolean;
type: string;
forms?: FormTD[];
uriVariables?: UriVariableTD;
}
/**
* Represents a form for interacting with a Thing property.
*
* @interface FormTD
*
* @property {string} op - The operation type (e.g., read, write).
* @property {string} href - The URL or URI where the operation is performed.
* @property {string} ['htv:methodName'] - Optional HTTP method for the operation (e.g., GET, POST).
* @property {string} [contentType] - Optional content type of the operation.
* @property {PropertyResponseTD} [response] - Optional response information.
*/
export interface FormTD {
op: string;
href: string;
'htv:methodName'?: string;
contentType?: string;
response?: PropertyResponseTD;
}
/**
* Represents URI variables used in a Thing Description property.
*
* @interface UriVariableTD
*
* @property {string} [key: string] - A key-value pair representing a URI variable.
*/
export interface UriVariableTD {
[key: string]: UriVariableContentTD | string | undefined;
}
/**
* Represents URI variables content used in a Thing Description property.
*
* @interface UriVariableContentTD
*
* @property {string} [key: string] - A key-value pair representing a URI variable content.
*/
export interface UriVariableContentTD {
[key: string]: any;
}
/**
* Represents the response details for a property in a Thing Description.
*
* @interface PropertyResponseTD
*
* @property {string} [contentType] - Optional content type of the response.
*/
export interface PropertyResponseTD {
contentType?: string;
}
/**
* Represents the geographical location of a Thing.
*
* @interface GeoLocationTD
*
* @property {string} 'geo:lat' - The latitude of the Thing.
* @property {string} 'geo:long' - The longitude of the Thing.
*/
export interface GeoLocationTD {
'geo:lat': string;
'geo:long': string;
}
/**
* Contains the registration details for a Thing.
*
* @interface RegistrationTD
*
* @property {string} created - The creation date of the Thing registration.
* @property {string} modified - The last modification date of the Thing registration.
*/
export interface RegistrationTD {
created: string;
modified: string;
}