Skip to content

Commit f5f1210

Browse files
committed
refactor: remove now obsolete nullish coalescing
1 parent 0b96413 commit f5f1210

10 files changed

Lines changed: 19 additions & 26 deletions

File tree

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
@@ -901,7 +901,7 @@ export default class CoapServer implements ProtocolServer {
901901
);
902902
}
903903

904-
return contentType ?? ContentSerdes.DEFAULT;
904+
return contentType;
905905
}
906906

907907
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
@@ -449,7 +449,7 @@ export class PropertyOperation {
449449
this.quantity = form["modbus:quantity"];
450450
this.function = form["modbus:function"] as ModbusFunction;
451451
this.endianness = endianness;
452-
this.contentType = form.contentType ?? ContentSerdes.DEFAULT;
452+
this.contentType = form.contentType;
453453
this.content = content;
454454
this.transaction = null;
455455
}

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

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

282282
const options: InteractionOptions & { formIndex: number } = {
283283
formIndex: ProtocolHelpers.findRequestMatchingFormIndex(
@@ -288,7 +288,7 @@ export default class MqttBrokerServer implements ProtocolServer {
288288
),
289289
};
290290

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

294294
thing
@@ -320,7 +320,7 @@ export default class MqttBrokerServer implements ProtocolServer {
320320
) {
321321
const readOnly = property.readOnly ?? false;
322322
if (!readOnly) {
323-
const contentType = packet?.properties?.contentType ?? ContentSerdes.DEFAULT;
323+
const contentType = packet?.properties?.contentType;
324324

325325
const options: InteractionOptions & { formIndex: number } = {
326326
formIndex: ProtocolHelpers.findRequestMatchingFormIndex(
@@ -331,7 +331,7 @@ export default class MqttBrokerServer implements ProtocolServer {
331331
),
332332
};
333333

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

337337
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
): Promise<Subscription> {
5151
return new Promise<Subscription>((resolve, reject) => {
5252
// get MQTT-based metadata
53-
const contentType = form.contentType ?? ContentSerdes.DEFAULT;
53+
const contentType = form.contentType;
5454
const requestUri = new url.URL(form.href);
5555
const topic = requestUri.pathname.slice(1);
5656
const brokerUri: string = `${this.scheme}://` + requestUri.host;

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/consumed-thing.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ export default class ConsumedThing extends TD.Thing implements IConsumedThing {
675675

676676
const content = await client.invokeResource(form, input);
677677
// infer media type from form if not in response metadata
678-
if (!content.type) content.type = form.contentType ?? "application/json";
678+
content.type ??= form.contentType;
679679

680680
// check if returned media type is the same as expected media type (from TD)
681681
if (form.response != null) {
@@ -725,8 +725,7 @@ export default class ConsumedThing extends TD.Thing implements IConsumedThing {
725725
formWithoutURITemplates,
726726
// next
727727
(content) => {
728-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- tsc get confused when nullables are to listeners lambdas
729-
if (!content.type) content.type = form!.contentType ?? "application/json";
728+
content.type ??= form.contentType;
730729
try {
731730
listener(new InteractionOutput(content, form, tp));
732731
} catch (e) {
@@ -782,8 +781,7 @@ export default class ConsumedThing extends TD.Thing implements IConsumedThing {
782781
await client.subscribeResource(
783782
formWithoutURITemplates,
784783
(content) => {
785-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- tsc get confused when nullables are to listeners lambdas
786-
if (!content.type) content.type = form!.contentType ?? "application/json";
784+
content.type ??= form.contentType;
787785
try {
788786
listener(new InteractionOutput(content, form, te.data));
789787
} catch (e) {

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)