Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: report undefined for no expected value() #1230

Merged
merged 8 commits into from
Feb 22, 2024
11 changes: 9 additions & 2 deletions packages/core/src/interaction-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ export class InteractionOutput implements WoT.InteractionOutput {
}

async arrayBuffer(): Promise<ArrayBuffer> {
// TODO check for this.schema == null also and return empty array?
danielpeintner marked this conversation as resolved.
Show resolved Hide resolved

if (this.#buffer) {
return this.#buffer;
}
Expand All @@ -78,6 +80,11 @@ export class InteractionOutput implements WoT.InteractionOutput {
}

async value<T extends WoT.DataSchemaValue>(): Promise<T> {
// is there any value expected at all?
if (this.schema == null) {
return this.#value as T;
danielpeintner marked this conversation as resolved.
Show resolved Hide resolved
}

// the value has been already read?
if (this.#value !== undefined) {
return this.#value as T;
Expand All @@ -91,8 +98,8 @@ export class InteractionOutput implements WoT.InteractionOutput {
throw new NotReadableError("No form defined");
}

if (this.schema == null || this.schema.type == null) {
throw new NotReadableError("No schema defined");
if (this.schema.type == null) {
throw new NotReadableError("No schema type defined");
}

// is content type valid?
Expand Down
Loading