Skip to content

Instantly share code, notes, and snippets.

@olafwrieden
Created January 7, 2025 06:40
Show Gist options
  • Save olafwrieden/d2d7bc52b93e733fbfb6adf599caadae to your computer and use it in GitHub Desktop.
Save olafwrieden/d2d7bc52b93e733fbfb6adf599caadae to your computer and use it in GitHub Desktop.
Digital Twin Definition Language (DTDL) v4 TypeScript Types
type DTMI = string;
interface Interface {
"@context": string;
"@type": "Interface";
"@id": DTMI;
comment?: string;
contents?: (Command | Component | Property | Relationship | Telemetry)[];
description?: string;
displayName?: string;
extends?: DTMI[];
schemas?: (ArraySchema | EnumSchema | MapSchema | ObjectSchema)[];
}
interface Telemetry {
"@type": "Telemetry";
"@id"?: DTMI;
comment?: string;
description?: string;
displayName?: string;
name: string;
schema: Schema;
}
interface Property {
"@type": "Property";
"@id"?: DTMI;
comment?: string;
description?: string;
displayName?: string;
name: string;
schema: Schema;
writable?: boolean;
}
interface Command {
"@type": "Command";
"@id"?: DTMI;
comment?: string;
description?: string;
displayName?: string;
name: string;
request?: CommandRequest;
response?: CommandResponse;
}
interface CommandRequest {
"@type"?: "CommandRequest";
"@id"?: DTMI;
comment?: string;
description?: string;
displayName?: string;
name: string;
nullable?: boolean;
schema: Schema;
}
interface CommandResponse {
"@type"?: "CommandResponse";
"@id"?: DTMI;
comment?: string;
description?: string;
displayName?: string;
name: string;
nullable?: boolean;
schema: Schema;
}
interface Relationship {
"@type": "Relationship";
"@id"?: DTMI;
comment?: string;
description?: string;
displayName?: string;
maxMultiplicity?: number;
minMultiplicity?: number;
name: string;
properties?: Property[];
target?: DTMI;
writable?: boolean;
}
interface Component {
"@type": "Component";
"@id"?: DTMI;
comment?: string;
description?: string;
displayName?: string;
name: string;
schema: DTMI;
}
type Schema = PrimitiveSchema | ArraySchema | EnumSchema | MapSchema | ObjectSchema;
type PrimitiveSchema = "boolean" | "byte" | "bytes" | "date" | "dateTime" | "decimal" | "double" | "duration" | "float" | "integer" | "long" | "short" | "string" | "time" | "unsignedByte" | "unsignedInteger" | "unsignedLong" | "unsignedShort" | "uuid";
interface ArraySchema {
"@type": "Array";
"@id"?: DTMI;
comment?: string;
description?: string;
displayName?: string;
elementSchema: Schema;
}
interface EnumSchema {
"@type": "Enum";
"@id"?: DTMI;
comment?: string;
description?: string;
displayName?: string;
enumValues?: EnumValue[];
valueSchema: "integer" | "string";
}
interface EnumValue {
"@type"?: "EnumValue";
"@id"?: DTMI;
comment?: string;
description?: string;
displayName?: string;
enumValue: number | string;
name: string;
}
interface MapSchema {
"@type": "Map";
"@id"?: DTMI;
comment?: string;
description?: string;
displayName?: string;
mapKey: MapKey;
mapValue: MapValue;
}
interface MapKey {
"@type"?: "MapKey";
"@id"?: DTMI;
comment?: string;
description?: string;
displayName?: string;
name: string;
schema: "string";
}
interface MapValue {
"@type"?: "MapValue";
"@id"?: DTMI;
comment?: string;
description?: string;
displayName?: string;
name: string;
schema: Schema;
}
interface ObjectSchema {
"@type": "Object";
"@id"?: DTMI;
comment?: string;
description?: string;
displayName?: string;
fields?: Field[];
}
interface Field {
"@type"?: "Field";
"@id"?: DTMI;
comment?: string;
description?: string;
displayName?: string;
name: string;
schema: Schema;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment