Skip to content

Commit cfee199

Browse files
committed
refactor: remove now obsolete nullish coalescing
1 parent fdb491e commit cfee199

File tree

9 files changed

+16
-21
lines changed

9 files changed

+16
-21
lines changed

packages/binding-coap/src/coap-client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ export default class CoapClient implements ProtocolClient {
159159
debug(`CoapClient received Content-Format: ${res.headers["Content-Format"]}`);
160160

161161
// FIXME does not work with blockwise because of node-coap
162-
const contentType = res.headers["Content-Format"] ?? form.contentType ?? ContentSerdes.DEFAULT;
162+
const contentType = res.headers["Content-Format"] ?? form.contentType;
163163

164164
res.on("data", (data: Buffer) => {
165165
next(new Content(`${contentType}`, Readable.from(res.payload)));
@@ -253,7 +253,7 @@ export default class CoapClient implements ProtocolClient {
253253
const method = form["cov:method"] ?? defaultMethod;
254254
debug(`CoapClient got Form "method" ${method}`);
255255

256-
const contentFormat = form["cov:contentFormat"] ?? form.contentType ?? "application/json";
256+
const contentFormat = form["cov:contentFormat"] ?? form.contentType;
257257
debug(`"CoapClient got Form 'contentType' ${contentFormat} `);
258258

259259
const accept = form["cov:accept"];

packages/binding-coap/src/coap-server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ export default class CoapServer implements ProtocolServer {
939939
);
940940
}
941941

942-
return contentType ?? ContentSerdes.DEFAULT;
942+
return contentType;
943943
}
944944

945945
private checkContentTypeSupportForInput(method: string, contentType: string): boolean {

packages/binding-coap/src/coaps-client.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export default class CoapsClient implements ProtocolClient {
4747
debug(`CoapsClient received ${res.code} from ${form.href}`);
4848

4949
// FIXME: Add toString conversion for response Content-Format
50-
const contentType = form.contentType ?? ContentSerdes.DEFAULT;
50+
const contentType = form.contentType;
5151
const body = Readable.from(res.payload ?? Buffer.alloc(0));
5252

5353
resolve(new Content(contentType, body));
@@ -79,7 +79,7 @@ export default class CoapsClient implements ProtocolClient {
7979
debug(`CoapsClient received ${res.code} from ${form.href}`);
8080

8181
// FIXME: Add toString conversion for response Content-Format
82-
const contentType = form.contentType ?? ContentSerdes.DEFAULT;
82+
const contentType = form.contentType;
8383
const body = Readable.from(res.payload ?? Buffer.alloc(0));
8484

8585
resolve(new Content(contentType, body));
@@ -118,7 +118,7 @@ export default class CoapsClient implements ProtocolClient {
118118

119119
const callback = (resp: CoapResponse) => {
120120
if (resp.payload != null) {
121-
next(new Content(form?.contentType ?? ContentSerdes.DEFAULT, Readable.from(resp.payload)));
121+
next(new Content(form?.contentType, Readable.from(resp.payload)));
122122
}
123123
};
124124

packages/binding-http/src/subscription-protocols.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,7 @@ export class SSESubscription implements InternalSubscription {
117117
};
118118
this.eventSource.onmessage = (event) => {
119119
debug(`HttpClient received ${JSON.stringify(event)} from ${this.form.href}`);
120-
const output = new Content(
121-
this.form.contentType ?? ContentSerdes.DEFAULT,
122-
Readable.from(JSON.stringify(event))
123-
);
120+
const output = new Content(this.form.contentType, Readable.from(JSON.stringify(event)));
124121
next(output);
125122
};
126123
this.eventSource.onerror = function (event) {

packages/binding-modbus/src/modbus-connection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ export class PropertyOperation {
451451
this.quantity = form["modv:quantity"];
452452
this.function = form["modv:function"] as ModbusFunction;
453453
this.endianness = endianness;
454-
this.contentType = form.contentType ?? ContentSerdes.DEFAULT;
454+
this.contentType = form.contentType;
455455
this.content = content;
456456
this.transaction = null;
457457
}

packages/binding-mqtt/src/mqtt-broker-server.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ export default class MqttBrokerServer implements ProtocolServer {
279279
* https://github.com/mqttjs/MQTT.js/pull/1103
280280
* For further discussion see https://github.com/eclipse-thingweb/node-wot/pull/253
281281
*/
282-
const contentType = packet?.properties?.contentType ?? ContentSerdes.DEFAULT;
282+
const contentType = packet?.properties?.contentType;
283283

284284
const options: InteractionOptions & { formIndex: number } = {
285285
formIndex: ProtocolHelpers.findRequestMatchingFormIndex(
@@ -290,7 +290,7 @@ export default class MqttBrokerServer implements ProtocolServer {
290290
),
291291
};
292292

293-
const formContentType = action.forms[options.formIndex].contentType ?? ContentSerdes.DEFAULT;
293+
const formContentType = action.forms[options.formIndex].contentType;
294294
const inputContent = new Content(formContentType, Readable.from(payload));
295295

296296
thing
@@ -322,7 +322,7 @@ export default class MqttBrokerServer implements ProtocolServer {
322322
) {
323323
const readOnly = property.readOnly ?? false;
324324
if (!readOnly) {
325-
const contentType = packet?.properties?.contentType ?? ContentSerdes.DEFAULT;
325+
const contentType = packet?.properties?.contentType;
326326

327327
const options: InteractionOptions & { formIndex: number } = {
328328
formIndex: ProtocolHelpers.findRequestMatchingFormIndex(
@@ -333,7 +333,7 @@ export default class MqttBrokerServer implements ProtocolServer {
333333
),
334334
};
335335

336-
const formContentType = property.forms[options.formIndex].contentType ?? ContentSerdes.DEFAULT;
336+
const formContentType = property.forms[options.formIndex].contentType;
337337
const inputContent = new Content(formContentType, Readable.from(payload));
338338

339339
try {

packages/binding-mqtt/src/mqtt-client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export default class MqttClient implements ProtocolClient {
5050
error?: (error: Error) => void,
5151
complete?: () => void
5252
): Promise<Subscription> {
53-
const contentType = form.contentType ?? ContentSerdes.DEFAULT;
53+
const contentType = form.contentType;
5454
const requestUri = new url.URL(form.href);
5555
const brokerUri: string = `${this.scheme}://` + requestUri.host;
5656
// Keeping the path as the topic for compatibility reasons.

packages/binding-opcua/src/opcua-protocol-client.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ export class OPCUAProtocolClient implements ProtocolClient {
466466

467467
///
468468
private async _dataValueToContent(form: OPCUAForm, dataValue: DataValue): Promise<Content> {
469-
const contentType = form.contentType ?? "application/json";
469+
const contentType = form.contentType;
470470

471471
// QUESTION: how can we extend the default contentSerDes.valueToContent for application/json,
472472
const contentSerDes = ContentSerdes.get();
@@ -615,13 +615,11 @@ export class OPCUAProtocolClient implements ProtocolClient {
615615
): Promise<Content> {
616616
const outputArguments = (argumentDefinition.outputArguments ?? []) as unknown as Argument[];
617617

618-
const contentType = form.contentType ?? "application/json";
619-
620618
const body: Record<string, unknown> = {};
621619
for (let index = 0; index < outputArguments.length; index++) {
622620
const argument = outputArguments[index];
623621
const { name } = argument;
624-
const element = _variantToJSON(outputVariants[index], contentType);
622+
const element = _variantToJSON(outputVariants[index], form.contentType);
625623
body[name ?? "null"] = element;
626624
}
627625

packages/core/src/exposed-thing.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ export default class ExposedThing extends TD.Thing implements WoT.ExposedThing {
412412
return ContentManager.valueToContent(
413413
result,
414414
this.properties[propertyName],
415-
form?.contentType ?? "application/json"
415+
form.contentType
416416
);
417417
} else {
418418
throw new Error(`ExposedThing '${this.title}' has no readHandler for Property '${propertyName}'`);

0 commit comments

Comments
 (0)