Skip to content

Commit

Permalink
fiuxp! chore(binding-http): enable eslint/strict-boolean-expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRhb committed Sep 30, 2023
1 parent e0e9452 commit 500bf0e
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions packages/binding-http/src/http-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,19 +333,21 @@ export default class HttpServer implements ProtocolServer {

public addEndpoint(thing: ExposedThing, tdTemplate: WoT.ExposedThingInit, base: string): void {
for (const type of ContentSerdes.get().getOfferedMediaTypes()) {
const properties = Object.values(thing.properties);

let allReadOnly = true;
let allWriteOnly = true;
let anyProperties = false;
for (const property of Object.values(thing.properties)) {
anyProperties = true;

for (const property of properties) {
if (property.readOnly ?? false) {
allReadOnly = false;
}
if (property.writeOnly ?? false) {
allWriteOnly = false;
}
}
if (anyProperties) {

if (properties.length > 0) {
const href = base + "/" + this.PROPERTY_DIR;
const form = new TD.Form(href, type);
if (allReadOnly && !allWriteOnly) {
Expand All @@ -367,10 +369,10 @@ export default class HttpServer implements ProtocolServer {
this.addUrlRewriteEndpoints(form, thing.forms);
}

for (const propertyName in thing.properties) {
for (const [propertyName, property] of Object.entries(thing.properties)) {
const propertyNamePattern = Helpers.updateInteractionNameWithUriVariablePattern(
propertyName,
thing.properties[propertyName].uriVariables,
property.uriVariables,
thing.uriVariables
);
const href = base + "/" + this.PROPERTY_DIR + "/" + propertyNamePattern;
Expand All @@ -379,28 +381,24 @@ export default class HttpServer implements ProtocolServer {
form,
(tdTemplate.properties?.[propertyName] ?? {}) as PropertyElement
);
if (thing.properties[propertyName].readOnly ?? false) {
if (property.readOnly ?? false) {
form.op = ["readproperty"];
const hform: HttpForm = form;
if (hform["htv:methodName"] === undefined) {
hform["htv:methodName"] = "GET";
}
} else if (thing.properties[propertyName].writeOnly ?? false) {
hform["htv:methodName"] ??= "GET";
} else if (property.writeOnly ?? false) {
form.op = ["writeproperty"];
const hform: HttpForm = form;
if (hform["htv:methodName"] === undefined) {
hform["htv:methodName"] = "PUT";
}
hform["htv:methodName"] ??= "PUT";
} else {
form.op = ["readproperty", "writeproperty"];
}

thing.properties[propertyName].forms.push(form);
property.forms.push(form);
debug(`HttpServer on port ${this.getPort()} assigns '${href}' to Property '${propertyName}'`);
this.addUrlRewriteEndpoints(form, thing.properties[propertyName].forms);
this.addUrlRewriteEndpoints(form, property.forms);

// if property is observable add an additional form with a observable href
if (thing.properties[propertyName].observable === true) {
if (property.observable === true) {
const href =
base +
"/" +
Expand All @@ -412,11 +410,11 @@ export default class HttpServer implements ProtocolServer {
const form = new TD.Form(href, type);
form.op = ["observeproperty", "unobserveproperty"];
form.subprotocol = "longpoll";
thing.properties[propertyName].forms.push(form);
property.forms.push(form);
debug(
`HttpServer on port ${this.getPort()} assigns '${href}' to observable Property '${propertyName}'`
);
this.addUrlRewriteEndpoints(form, thing.properties[propertyName].forms);
this.addUrlRewriteEndpoints(form, property.forms);
}
}

Expand Down

0 comments on commit 500bf0e

Please sign in to comment.