Skip to content

Commit 8c1e059

Browse files
refactor: remove "own" definition of ThingModel
use the one from "wot-thing-model-types"
1 parent d608cb5 commit 8c1e059

3 files changed

Lines changed: 6 additions & 11 deletions

File tree

packages/core/src/consumed-thing.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { ConsumedThing as IConsumedThing, InteractionInput, Subscription } from
1818
import {
1919
Form,
2020
Thing,
21-
ThingModel,
2221
ThingProperty,
2322
BaseSchema,
2423
ThingInteraction,
@@ -27,6 +26,8 @@ import {
2726
SecurityScheme,
2827
} from "./thing-description";
2928

29+
import { ThingModel } from "wot-thing-model-types";
30+
3031
import Servient from "./servient";
3132
import Helpers from "./helpers";
3233

@@ -366,7 +367,7 @@ export default class ConsumedThing extends Thing implements IConsumedThing {
366367
private subscribedEvents: Map<string, Subscription> = new Map<string, Subscription>();
367368
private observedProperties: Map<string, Subscription> = new Map<string, Subscription>();
368369

369-
constructor(servient: Servient, thingModel: ThingModel = {}) {
370+
constructor(servient: Servient, thingModel?: ThingModel) {
370371
super();
371372

372373
this.#servient = servient;
@@ -376,7 +377,7 @@ export default class ConsumedThing extends Thing implements IConsumedThing {
376377
this.actions = {};
377378
this.events = {};
378379

379-
const deepClonedModel = Helpers.structuredClone(thingModel);
380+
const deepClonedModel = Helpers.structuredClone(thingModel ?? {});
380381
Object.assign(this, deepClonedModel);
381382
this.extendInteractions();
382383
}

packages/core/src/thing-description.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,6 @@ export const DEFAULT_CONTEXT_V11 = "https://www.w3.org/2022/wot/td/v1.1";
2222
export const DEFAULT_CONTEXT_LANGUAGE = "en";
2323
export const DEFAULT_THING_TYPE = "Thing";
2424

25-
type DeepPartial<T> = T extends Record<string, unknown>
26-
? {
27-
[P in keyof T]?: T[P] extends Array<infer I> ? Array<DeepPartial<I>> : DeepPartial<T[P]>;
28-
}
29-
: T;
30-
export type ThingModel = DeepPartial<Thing>;
31-
3225
/** Implements the Thing Description as software object */
3326
export class Thing implements TDT.ThingDescription {
3427
title: TDT.Title;

packages/core/src/wot-impl.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
********************************************************************************/
1515

1616
import * as WoT from "wot-typescript-definitions";
17+
import { ThingModel } from "wot-thing-model-types";
1718
import { parseTD } from "./serdes";
1819
import Servient from "./servient";
1920
import ExposedThing from "./exposed-thing";
@@ -103,7 +104,7 @@ export default class WoTImpl {
103104
async consume(td: WoT.ThingDescription): Promise<ConsumedThing> {
104105
try {
105106
const thing = parseTD(JSON.stringify(td), true);
106-
const newThing: ConsumedThing = new ConsumedThing(this.srv, thing);
107+
const newThing: ConsumedThing = new ConsumedThing(this.srv, thing as ThingModel);
107108

108109
debug(
109110
`WoTImpl consuming TD ${

0 commit comments

Comments
 (0)