From 8c1e0598f4c45cb42e60b292013db3cf2e31516a Mon Sep 17 00:00:00 2001 From: danielpeintner Date: Thu, 8 Aug 2024 10:04:46 +0200 Subject: [PATCH] refactor: remove "own" definition of ThingModel use the one from "wot-thing-model-types" --- packages/core/src/consumed-thing.ts | 7 ++++--- packages/core/src/thing-description.ts | 7 ------- packages/core/src/wot-impl.ts | 3 ++- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/packages/core/src/consumed-thing.ts b/packages/core/src/consumed-thing.ts index 8b5796d36..3f976d614 100644 --- a/packages/core/src/consumed-thing.ts +++ b/packages/core/src/consumed-thing.ts @@ -18,7 +18,6 @@ import { ConsumedThing as IConsumedThing, InteractionInput, Subscription } from import { Form, Thing, - ThingModel, ThingProperty, BaseSchema, ThingInteraction, @@ -27,6 +26,8 @@ import { SecurityScheme, } from "./thing-description"; +import { ThingModel } from "wot-thing-model-types"; + import Servient from "./servient"; import Helpers from "./helpers"; @@ -366,7 +367,7 @@ export default class ConsumedThing extends Thing implements IConsumedThing { private subscribedEvents: Map = new Map(); private observedProperties: Map = new Map(); - constructor(servient: Servient, thingModel: ThingModel = {}) { + constructor(servient: Servient, thingModel?: ThingModel) { super(); this.#servient = servient; @@ -376,7 +377,7 @@ export default class ConsumedThing extends Thing implements IConsumedThing { this.actions = {}; this.events = {}; - const deepClonedModel = Helpers.structuredClone(thingModel); + const deepClonedModel = Helpers.structuredClone(thingModel ?? {}); Object.assign(this, deepClonedModel); this.extendInteractions(); } diff --git a/packages/core/src/thing-description.ts b/packages/core/src/thing-description.ts index 3c93d2a56..61fc2433e 100644 --- a/packages/core/src/thing-description.ts +++ b/packages/core/src/thing-description.ts @@ -22,13 +22,6 @@ export const DEFAULT_CONTEXT_V11 = "https://www.w3.org/2022/wot/td/v1.1"; export const DEFAULT_CONTEXT_LANGUAGE = "en"; export const DEFAULT_THING_TYPE = "Thing"; -type DeepPartial = T extends Record - ? { - [P in keyof T]?: T[P] extends Array ? Array> : DeepPartial; - } - : T; -export type ThingModel = DeepPartial; - /** Implements the Thing Description as software object */ export class Thing implements TDT.ThingDescription { title: TDT.Title; diff --git a/packages/core/src/wot-impl.ts b/packages/core/src/wot-impl.ts index 2a2411417..2228bad35 100644 --- a/packages/core/src/wot-impl.ts +++ b/packages/core/src/wot-impl.ts @@ -14,6 +14,7 @@ ********************************************************************************/ import * as WoT from "wot-typescript-definitions"; +import { ThingModel } from "wot-thing-model-types"; import { parseTD } from "./serdes"; import Servient from "./servient"; import ExposedThing from "./exposed-thing"; @@ -103,7 +104,7 @@ export default class WoTImpl { async consume(td: WoT.ThingDescription): Promise { try { const thing = parseTD(JSON.stringify(td), true); - const newThing: ConsumedThing = new ConsumedThing(this.srv, thing); + const newThing: ConsumedThing = new ConsumedThing(this.srv, thing as ThingModel); debug( `WoTImpl consuming TD ${