Skip to content

Commit

Permalink
Merge pull request #1312 from danielpeintner/issue-1311
Browse files Browse the repository at this point in the history
Remove dependencies from td-tool package
  • Loading branch information
relu91 authored Aug 8, 2024
2 parents 274bf4a + 8c1e059 commit 915c111
Show file tree
Hide file tree
Showing 68 changed files with 1,752 additions and 222 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
> A fast and extensible framework to connect any device with your application
[![Default CI Pipeline](https://github.com/eclipse-thingweb/node-wot/actions/workflows/ci.yaml/badge.svg)](https://github.com/eclipse-thingweb/node-wot/actions/workflows/ci.yaml)
[<img alt="npm" src="https://img.shields.io/npm/dw/@node-wot/td-tools">](https://npm-stat.com/charts.html?package=%40node-wot%2Ftd-tools)
[<img alt="npm" src="https://img.shields.io/npm/dw/@node-wot/core">](https://npm-stat.com/charts.html?package=%40node-wot%2Fcore)
[![codecov](https://codecov.io/gh/eclipse-thingweb/node-wot/branch/master/graph/badge.svg)](https://codecov.io/gh/eclipse-thingweb/node-wot)
[![Telegram Group](https://img.shields.io/endpoint?color=neon&url=https%3A%2F%2Ftg.sumanjay.workers.dev%2Fnodewot)](https://t.me/nodewot)
[![Discord](https://img.shields.io/badge/Discord-7289DA?logo=discord&logoColor=white&label=node-wot)](https://discord.gg/JXY2Jzefz3)
Expand Down Expand Up @@ -59,7 +59,7 @@ The framework can be used in two ways: as a library or as a CLI tool. In this se

### As a library

The framework is composed by different packages that users can use as they please. The core package is `@node-wot/core` and it is the only mandatory package to install. The other packages are bindings that allow the framework to communicate with different protocols and optionally we offer a set of tools in the `@node-wot/td-tools` package.
The framework is composed by different packages that users can use as they please. The core package is `@node-wot/core` and it is the only mandatory package to install. The other packages are bindings that allow the framework to communicate with different protocols.

#### Node.js

Expand Down
56 changes: 41 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion packages/binding-coap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"types": "dist/coap.d.ts",
"dependencies": {
"@node-wot/core": "0.8.15",
"@node-wot/td-tools": "0.8.15",
"@types/node": "16.18.35",
"coap": "^1.4.0",
"multicast-dns": "^7.2.5",
Expand Down
7 changes: 2 additions & 5 deletions packages/binding-coap/src/coap-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ import * as net from "net";

import { Subscription } from "rxjs/Subscription";

// for Security definition
import * as TD from "@node-wot/td-tools";

import { ProtocolClient, Content, ContentSerdes, createLoggers } from "@node-wot/core";
import { ProtocolClient, Content, ContentSerdes, SecurityScheme, createLoggers } from "@node-wot/core";
import { BlockSize, blockSizeToOptionValue, CoapForm, CoapMethodName } from "./coap";
import CoapServer from "./coap-server";
import { Readable } from "stream";
Expand Down Expand Up @@ -209,7 +206,7 @@ export default class CoapClient implements ProtocolClient {
this.agent.close();
}

public setSecurity = (metadata: Array<TD.SecurityScheme>): boolean => true;
public setSecurity = (metadata: Array<SecurityScheme>): boolean => true;

private uriToOptions(uri: string): CoapRequestParams {
// eslint-disable-next-line n/no-deprecated-api
Expand Down
14 changes: 7 additions & 7 deletions packages/binding-coap/src/coap-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
* CoAP Server based on coap by mcollina
*/

import * as TD from "@node-wot/td-tools";
import Servient, {
ProtocolServer,
ContentSerdes,
Expand All @@ -26,6 +25,7 @@ import Servient, {
ProtocolHelpers,
Content,
createLoggers,
Form,
} from "@node-wot/core";
import { Socket } from "dgram";
import { Server, createServer, registerFormat, IncomingMessage, OutgoingMessage } from "coap";
Expand Down Expand Up @@ -231,7 +231,7 @@ export default class CoapServer implements ProtocolServer {
return opValues;
}

private addFormToAffordance(form: TD.Form, affordance: AffordanceElement): void {
private addFormToAffordance(form: Form, affordance: AffordanceElement): void {
const affordanceForms = affordance.forms;
if (affordanceForms == null) {
affordance.forms = [form];
Expand Down Expand Up @@ -317,7 +317,7 @@ export default class CoapServer implements ProtocolServer {
affordanceName?: string,
affordanceUriVariables?: PropertyElement["uriVariables"],
subprotocol?: string
): TD.Form {
): Form {
const affordanceNamePattern = Helpers.updateInteractionNameWithUriVariablePattern(
affordanceName ?? "",
affordanceUriVariables,
Expand All @@ -330,14 +330,14 @@ export default class CoapServer implements ProtocolServer {
href += `/${encodeURIComponent(affordanceNamePattern)}`;
}

const form = new TD.Form(href, offeredMediaType);
const form = new Form(href, offeredMediaType);
form.op = opValues;
form.subprotocol = subprotocol;

return form;
}

private logHrefAssignment(form: TD.Form, affordanceType: string, affordanceName: string) {
private logHrefAssignment(form: Form, affordanceType: string, affordanceName: string) {
debug(`CoapServer on port ${this.port} assigns '${form.href}' to ${affordanceType} '${affordanceName}'`);
}

Expand Down Expand Up @@ -610,7 +610,7 @@ export default class CoapServer implements ProtocolServer {
}

private async handleReadMultipleProperties(
forms: TD.Form[],
forms: Form[],
req: IncomingMessage,
contentType: string,
thing: ExposedThing,
Expand Down Expand Up @@ -817,7 +817,7 @@ export default class CoapServer implements ProtocolServer {
}

private createInteractionOptions(
forms: TD.Form[],
forms: Form[],
thing: ExposedThing,
req: IncomingMessage,
contentType: string,
Expand Down
2 changes: 1 addition & 1 deletion packages/binding-coap/src/coap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* SPDX-License-Identifier: EPL-2.0 OR W3C-20150513
********************************************************************************/

import { Form } from "@node-wot/td-tools";
import { Form } from "@node-wot/core";

export { default as CoapServer } from "./coap-server";
export { default as CoapClientFactory } from "./coap-client-factory";
Expand Down
8 changes: 3 additions & 5 deletions packages/binding-coap/src/coaps-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@
* CoAPS client based on node-coap-client by AlCalzone
*/

import * as TD from "@node-wot/td-tools";

import { Subscription } from "rxjs/Subscription";

import { ProtocolClient, Content, createLoggers, ContentSerdes } from "@node-wot/core";
import { ProtocolClient, Content, createLoggers, ContentSerdes, SecurityScheme } from "@node-wot/core";
import { CoapForm, CoapMethodName, isValidCoapMethod, isSupportedCoapMethod } from "./coap";
import { CoapClient as coaps, CoapResponse, RequestMethod, SecurityParameters } from "node-coap-client";
import { Readable } from "stream";
Expand Down Expand Up @@ -164,13 +162,13 @@ export default class CoapsClient implements ProtocolClient {
// FIXME coap does not provide proper API to close Agent
}

public setSecurity(metadata: Array<TD.SecurityScheme>, credentials?: pskSecurityParameters): boolean {
public setSecurity(metadata: Array<SecurityScheme>, credentials?: pskSecurityParameters): boolean {
if (metadata === undefined || !Array.isArray(metadata) || metadata.length === 0) {
warn(`CoapsClient received empty security metadata`);
return false;
}

const security: TD.SecurityScheme = metadata[0];
const security: SecurityScheme = metadata[0];

if (security.scheme === "psk" && credentials != null) {
this.authorization = { psk: {} };
Expand Down
Loading

0 comments on commit 915c111

Please sign in to comment.