Skip to content

Commit

Permalink
refactor: remove "own" definition of ThingModel
Browse files Browse the repository at this point in the history
use the one from "wot-thing-model-types"
  • Loading branch information
danielpeintner committed Aug 8, 2024
1 parent d608cb5 commit 8c1e059
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
7 changes: 4 additions & 3 deletions packages/core/src/consumed-thing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { ConsumedThing as IConsumedThing, InteractionInput, Subscription } from
import {
Form,
Thing,
ThingModel,
ThingProperty,
BaseSchema,
ThingInteraction,
Expand All @@ -27,6 +26,8 @@ import {
SecurityScheme,
} from "./thing-description";

import { ThingModel } from "wot-thing-model-types";

import Servient from "./servient";
import Helpers from "./helpers";

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

constructor(servient: Servient, thingModel: ThingModel = {}) {
constructor(servient: Servient, thingModel?: ThingModel) {
super();

this.#servient = servient;
Expand All @@ -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();
}
Expand Down
7 changes: 0 additions & 7 deletions packages/core/src/thing-description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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> = T extends Record<string, unknown>
? {
[P in keyof T]?: T[P] extends Array<infer I> ? Array<DeepPartial<I>> : DeepPartial<T[P]>;
}
: T;
export type ThingModel = DeepPartial<Thing>;

/** Implements the Thing Description as software object */
export class Thing implements TDT.ThingDescription {
title: TDT.Title;
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/wot-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -103,7 +104,7 @@ export default class WoTImpl {
async consume(td: WoT.ThingDescription): Promise<ConsumedThing> {
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 ${
Expand Down

0 comments on commit 8c1e059

Please sign in to comment.