wot-typescript-definitions
Advanced tools
Comparing version
437
index.d.ts
@@ -0,10 +1,9 @@ | ||
import { Observable } from 'rxjs/Observable'; | ||
export as namespace WoT; | ||
export default WoT; | ||
declare let WoT: WoTFactory; | ||
import { Observable } from 'rxjs/Observable'; | ||
/** The WoT object is the main API entry point and it is exposed by an implementation of the WoT Runtime. */ | ||
/** | ||
* The WoTFactory (usually instantiated as "WoT" object) is the main API entry point | ||
* and it is exposed by an implementation of the WoT Runtime. | ||
*/ | ||
export interface WoTFactory { | ||
@@ -37,51 +36,12 @@ /** | ||
/** | ||
* Make a request to register td to the given WoT Thing Directory.. | ||
*/ | ||
register(directory: USVString, thing: ExposedThing): Promise<void> | ||
register(directory: USVString, thing: ExposedThing): Promise<void>; | ||
/** | ||
* Makes a request to unregister the thing from the given WoT Thing Directory. */ | ||
unregister(directory: USVString, thing: ExposedThing): Promise<void> | ||
unregister(directory: USVString, thing: ExposedThing): Promise<void>; | ||
} | ||
/** WoT provides a unified representation for data exchange between Things, standardized in the Wot Things Description specification. | ||
* In this version of the API, Thing Descriptions are represented as opaque strings, denoting a serialized form, for instance JSON or JSON-LD | ||
*/ | ||
export declare type ThingDescription = USVString; | ||
/** The ThingTemplate dictionary contains properties to initialize a Thing */ | ||
export interface ThingTemplate | ||
// extends SemanticAnnotations | ||
{ | ||
/** The name attribute represents the user given name of the Thing */ | ||
name?: string; | ||
id?: string; | ||
description?: string; | ||
support?: string; | ||
security?: Security; | ||
properties?: Array<PropertyInit>; // Set? | ||
actions?: Array<ActionInit>; // Set? | ||
events?: Array<EventInit>; // Set? | ||
links?: Array<WebLink> | ||
// @context | ||
// @type | ||
} | ||
/** A Thing model is used for producing a new ExposedThing and can be either a ThingTemplate, or a ThingDescription. */ | ||
export declare type ThingModel = (ThingDescription | ThingTemplate); | ||
/** | ||
@@ -92,17 +52,17 @@ * Dictionary that represents the constraints for discovering Things as key-value pairs. | ||
/** | ||
* The method property represents the discovery type that should be used in the discovery process. The possible values are defined by the DiscoveryMethod enumeration that can be extended by string values defined by solutions (with no guarantee of interoperability). | ||
* The method field represents the discovery type that should be used in the discovery process. The possible values are defined by the DiscoveryMethod enumeration that can be extended by string values defined by solutions (with no guarantee of interoperability). | ||
*/ | ||
method?: DiscoveryMethod | string; // default value "any", DOMString | ||
method?: DiscoveryMethod | string; // default value "any", DOMString | ||
/** | ||
* The url property represents additional information for the discovery method, such as the URL of the target entity serving the discovery request, such as a Thing Directory or a Thing. | ||
* The url field represents additional information for the discovery method, such as the URL of the target entity serving the discovery request, such as a Thing Directory or a Thing. | ||
*/ | ||
url?: USVString; | ||
/** | ||
* The query property represents a query string accepted by the implementation, for instance a SPARQL query. | ||
* The query field represents a query string accepted by the implementation, for instance a SPARQL query. | ||
*/ | ||
query?: USVString; | ||
/** | ||
* The template property represents a ThingTemplate dictionary used for matching against discovered Things. | ||
* The fragment field represents a ThingFragment dictionary used for matching against discovered Things. | ||
*/ | ||
template?: ThingTemplate; | ||
fragment?: ThingFragment; | ||
} | ||
@@ -112,197 +72,129 @@ | ||
export declare enum DiscoveryMethod { | ||
/** does not provide any restriction */ | ||
/** does not restrict */ | ||
"any", | ||
/** for discovering Things defined in the same device */ | ||
/** for discovering Things defined in the same Servient */ | ||
"local", | ||
/** for discovery based on a service provided by a directory or repository of Things */ | ||
/** for discovery based on a service provided by a Thing Directory */ | ||
"directory", | ||
/** for discovering Things in the device's network by using a supported multicast protocol */ | ||
/** for discovering Things in the same/reachable network by using a supported multicast protocol */ | ||
"multicast" | ||
} | ||
export interface Security { | ||
scheme: string; | ||
in?: any; | ||
} | ||
/** | ||
* WoT provides a unified representation for data exchange between Things, standardized in the Wot Things Description specification. | ||
* In this version of the API, Thing Descriptions are represented as opaque strings, denoting a serialized form, for instance JSON or JSON-LD | ||
*/ | ||
export declare type ThingDescription = USVString; | ||
export interface Link { | ||
href: USVString; | ||
mediaType?: USVString; | ||
rel?: USVString; | ||
/** | ||
* The ThingFragment dictionary contains fields to initialize a Thing or to match during discovery | ||
*/ | ||
export interface ThingFragment { | ||
/** A hint to gernerate the identifier for the Thing */ | ||
id?: string; | ||
/** The name attribute represents the user given name of the Thing */ | ||
name?: string; | ||
} | ||
/** A human-readable description of the Thing */ | ||
description?: string; | ||
export interface WebLink extends Link { | ||
anchor?: USVString; | ||
/** Information about the Thing maintainer, e.g., author or contact URI */ | ||
support?: string; | ||
/** A list of security schemas used by the Thing */ | ||
security?: Array<Security>; | ||
/** A map of PropertyFragments with decriptions only */ | ||
properties?: { [key: string]: PropertyFragment } | ||
/** A map of ActionFragments with decriptions only */ | ||
actions?: { [key: string]: ActionFragment } | ||
/** A map of EventFragments with decriptions only */ | ||
events?: { [key: string]: EventFragment } | ||
/** A list of Web links to other Things or metadata */ | ||
links?: Array<WebLink>; | ||
/** | ||
* A collection of predicate terms that reference values of any type, | ||
* e.g., @context, @type, or other terms from the vocabulary defined in @context. | ||
*/ | ||
[key: string]: any; | ||
} | ||
export interface Form extends Link { | ||
security?: Security; | ||
} | ||
/** A Thing model is used for producing a new ExposedThing and can be either a ThingTemplate, or a ThingDescription. */ | ||
export declare type ThingModel = (ThingDescription | ThingFragment); | ||
export declare enum DataType { | ||
boolean = "boolean", | ||
number = "number", | ||
integer = "integer", | ||
string = "string", | ||
object = "object", | ||
array = "array", | ||
null = "null" | ||
} | ||
export interface DataSchema { | ||
type: DataType; | ||
// required?: boolean; | ||
/** Base for representing Thing Interaction descriptions */ | ||
export interface InteractionFragment { | ||
label?: string; | ||
description?: string; | ||
const?: boolean; | ||
[key: string]: any; | ||
} | ||
export class NumberSchema implements DataSchema { | ||
type: DataType.number; | ||
minimium?: number; | ||
maximimum?: number; | ||
/** Represents a Thing Property description */ | ||
export interface PropertyFragment extends InteractionFragment { | ||
writable?: boolean; | ||
observable?: boolean; | ||
} | ||
export class BooleanSchema implements DataSchema { | ||
type: DataType.boolean; | ||
/** Represents a Thing Action description */ | ||
export interface ActionFragment extends InteractionFragment { | ||
input?: DataSchema; | ||
output?: DataSchema; | ||
} | ||
export class StringSchema implements DataSchema { | ||
type: DataType.string; | ||
enum?: Array<string>; | ||
/** Represents a Thing Event description */ | ||
export interface EventFragment extends InteractionFragment { | ||
} | ||
export class ObjectSchema implements DataSchema { | ||
type: DataType.object; | ||
properties?: Map<string, DataSchema>; | ||
required?: Array<string>; | ||
} | ||
/** | ||
* A Thing instance must have an id and a name and its Interactions do have forms and | ||
* functions to interact (get/set/run/subscribe/emit). | ||
*/ | ||
export interface ThingInstance extends ThingFragment { | ||
id: string; | ||
name: string; | ||
base?: string; | ||
export class ArraySchema implements DataSchema { | ||
type: DataType.array; | ||
items?: DataSchema; | ||
minItems?: number; | ||
maxItems?: number; | ||
properties: { [key: string]: ThingProperty }; | ||
actions: { [key: string]: ThingAction }; | ||
events: { [key: string]: ThingEvent }; | ||
} | ||
// export class NullValueType implements ValueType { | ||
// type: JSONType.null; | ||
// } | ||
/** | ||
* The Interaction interface is an abstract class to represent Thing interactions: Properties, Actions and Events. | ||
*/ | ||
export interface Interaction | ||
// implements Observable | ||
{ | ||
label?: string; | ||
forms?: Array<Form>; | ||
links?: Array<Link>; | ||
export interface ThingInteraction extends InteractionFragment { | ||
forms: Array<Form>; | ||
} | ||
// XXX could we inherit Interaction (Typescript difference of FrozenArray and sequence) | ||
export interface InteractionInit { | ||
label?: string; | ||
// forms?: Array<Form>; | ||
// links?: Array<Link>; | ||
} | ||
/** Represents the Thing Property description. */ | ||
export interface ThingProperty extends Interaction, PropertyInit | ||
// Observable | ||
/** Represents an interactable Thing Property */ | ||
export interface ThingProperty extends ThingInteraction, PropertyFragment //, Observable<any> | ||
{ | ||
// getter for PropertyInit properties | ||
// XXX causes conflicts with "other" get | ||
// get(name: string): any; | ||
// get and set interface for the Property | ||
get(): Promise<any>; | ||
set(value: any): Promise<void>; | ||
} | ||
export interface PropertyInit extends InteractionInit, DataSchema { | ||
writable?: boolean; | ||
observable?: boolean; | ||
value?: any; | ||
} | ||
export interface ThingAction extends Interaction { | ||
input?: DataSchema; | ||
output?: DataSchema; | ||
description?: string; | ||
/** Represents an interactable Thing Action */ | ||
export interface ThingAction extends ThingInteraction, ActionFragment { | ||
run(parameter?: any): Promise<any>; | ||
} | ||
export interface ActionInit extends InteractionInit { | ||
input?: DataSchema; | ||
output?: DataSchema; | ||
description?: string; | ||
/** Represents an interactable Thing Event */ | ||
// FIXME: Events are different on ConsumendThing and ExposedThing | ||
export interface ThingEvent extends ThingInteraction, EventFragment { | ||
emit(data?: any): void; | ||
} | ||
export interface ThingEvent extends ThingProperty { | ||
/** Represents a client API object to consume Things and their Properties, Actions, and Events */ | ||
export interface ConsumedThing extends ThingInstance { | ||
// TODO: subscribe | ||
} | ||
export declare type EventInit = PropertyInit; | ||
/** Represents a server API object to expose Things and their Properties, Actions, and Events */ | ||
export interface ExposedThing extends ThingInstance { | ||
export interface Thing { | ||
/** collection of string-based keys that reference values of any type */ | ||
[key: string]: any; /* e.g., @context besides the one that are explitecly defined below */ | ||
id: string; | ||
name: string; | ||
description: string; | ||
base?: string; | ||
// properties: Map<string, ThingProperty>; | ||
properties: { | ||
[key: string]: ThingProperty | ||
}; | ||
// actions: Map<string, ThingAction>; | ||
actions: { | ||
[key: string]: ThingAction; | ||
} | ||
// events: Map<string, ThingEvent>; | ||
events: { | ||
[key: string]: ThingEvent; | ||
} | ||
links: Array<WebLink>; | ||
} | ||
/** The ConsumedThing interface is a client API for sending requests to servers in order to retrieve or update properties, invoke Actions, and observe properties, Actions and Events. */ | ||
export interface ConsumedThing extends Thing | ||
// extends/implements Observable | ||
{ | ||
// getter for ThingTemplate properties | ||
get(name: string): any; | ||
} | ||
export interface ExposedThing extends ConsumedThing { | ||
// setter for ThingTemplate properties | ||
set(name: string, value: any): void; | ||
// define how to expose and run the Thing | ||
/** Start serving external requests for the Thing. */ | ||
expose(): Promise<void> | ||
expose(): Promise<void>; | ||
/** Stop serving external requests for the Thing. */ | ||
destroy(): Promise<void> | ||
destroy(): Promise<void>; | ||
/** Emits an the event initialized with the event name specified by the eventName argument and data specified by the payload argument. */ | ||
emitEvent(eventName: string, payload: any): Promise<void> | ||
// define Thing Description modifiers | ||
@@ -313,3 +205,3 @@ | ||
*/ | ||
addProperty(name: string, property: PropertyInit): ExposedThing | ||
addProperty(name: string, property: PropertyFragment, init?: any): ExposedThing; | ||
@@ -319,3 +211,3 @@ /** | ||
*/ | ||
removeProperty(name: string): ExposedThing | ||
removeProperty(name: string): ExposedThing; | ||
@@ -325,3 +217,3 @@ /** | ||
*/ | ||
addAction(name: string, action: ActionInit): ExposedThing | ||
addAction(name: string, action: ActionFragment): ExposedThing; | ||
@@ -331,3 +223,3 @@ /** | ||
*/ | ||
removeAction(name: string): ExposedThing | ||
removeAction(name: string): ExposedThing; | ||
@@ -337,3 +229,3 @@ /** | ||
*/ | ||
addEvent(name: string, event: EventInit): ExposedThing | ||
addEvent(name: string, event: EventFragment): ExposedThing; | ||
@@ -343,3 +235,3 @@ /** | ||
*/ | ||
removeEvent(name: string): ExposedThing | ||
removeEvent(name: string): ExposedThing; | ||
@@ -370,9 +262,124 @@ // define request handlers | ||
*/ | ||
setActionHandler(actionName: string, action: ActionHandler, ): ExposedThing; | ||
setActionHandler(actionName: string, action: ActionHandler): ExposedThing; | ||
} | ||
export declare type PropertyReadHandler = () => Promise<any>; | ||
// TODO: Decide if decorator (with 'internal') or replacement (without 'internal') for get() | ||
// For now decorator in node-wot | ||
export declare type PropertyReadHandler = (internal?: any) => Promise<any>; | ||
export declare type PropertyWriteHandler = (value: any) => Promise<void>; | ||
// TODO: Decide if decorator (return any) or replacement (return void) for set() | ||
// For now decorator in node-wot | ||
export declare type PropertyWriteHandler = (value: any) => Promise<any>; | ||
export declare type ActionHandler = (parameters: any) => Promise<any>; | ||
export declare type ActionHandler = (parameters: any) => Promise<any>; | ||
export interface Link { | ||
href: USVString; | ||
mediaType?: USVString; | ||
rel?: USVString; | ||
} | ||
export interface WebLink extends Link { | ||
anchor?: USVString; | ||
} | ||
export interface Form extends Link { | ||
security?: Security; | ||
} | ||
export type DataSchema = BooleanSchema | IntegerSchema | NumberSchema | StringSchema | ObjectSchema | ArraySchema | NullSchema; | ||
export interface BaseSchema { | ||
type: string; | ||
const?: any; | ||
enum?: Array<any>; | ||
} | ||
export interface BooleanSchema extends BaseSchema { | ||
type: "boolean"; | ||
} | ||
export interface IntegerSchema extends BaseSchema { | ||
type: "integer"; | ||
minimum?: number; | ||
maximum?: number; | ||
} | ||
export interface NumberSchema extends BaseSchema { | ||
type: "number"; | ||
minimum?: number; | ||
maximum?: number; | ||
} | ||
export interface StringSchema extends BaseSchema { | ||
type: "string"; | ||
} | ||
export interface ObjectSchema extends BaseSchema { | ||
type: "object"; | ||
properties: { [key:string]: DataSchema }; | ||
required?: Array<string>; | ||
} | ||
export interface ArraySchema extends BaseSchema { | ||
type: "array"; | ||
items: DataSchema; | ||
minItems?: number; | ||
maxItems?: number; | ||
} | ||
export interface NullSchema extends BaseSchema { | ||
type: "null"; | ||
} | ||
export type Security = BasicSecurityScheme | DigestSecurityScheme | BearerSecurityScheme | PopSecurityScheme | ApikeySecurityScheme | OAuth2SecurityScheme; | ||
export interface SecurityScheme { | ||
scheme: string; | ||
description?: string; | ||
proxyURI?: any; | ||
} | ||
export interface BasicSecurityScheme extends SecurityScheme { | ||
scheme: "basic"; | ||
in: string; | ||
pname?: string; | ||
} | ||
export interface DigestSecurityScheme extends SecurityScheme { | ||
scheme: "digest"; | ||
in: string; | ||
qop: string; | ||
pname?: string; | ||
} | ||
export interface BearerSecurityScheme extends SecurityScheme { | ||
scheme: "bearer"; | ||
alg: string; | ||
format: string; | ||
in: string; | ||
pname?: string; | ||
} | ||
export interface PopSecurityScheme extends SecurityScheme { | ||
scheme: "pop"; | ||
alg: string; | ||
format: string; | ||
in: string; | ||
pname?: string; | ||
} | ||
export interface ApikeySecurityScheme extends SecurityScheme { | ||
scheme: "apikey"; | ||
in: string; | ||
pname?: string; | ||
} | ||
export interface OAuth2SecurityScheme extends SecurityScheme { | ||
scheme: "oauth2"; | ||
authorizationUrl: string; | ||
scopes?: Array<string>; | ||
// one of implicit, password, client, or code | ||
flow: string; | ||
} |
{ | ||
"name": "wot-typescript-definitions", | ||
"version": "0.5.0-SNAPSHOT.1", | ||
"version": "0.5.0-SNAPSHOT.4", | ||
"description": "TypeScript definitions for the W3C WoT Scripting API", | ||
@@ -21,3 +21,2 @@ "author": "the thingweb community", | ||
}, | ||
"main": "index.d.ts", | ||
"types": "index.d.ts", | ||
@@ -24,0 +23,0 @@ "dependencies": { |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
15275
10.34%331
10.33%1
Infinity%