Skip to content

Commit

Permalink
refactor(core/interaction-output): use make all private properties use #
Browse files Browse the repository at this point in the history
  • Loading branch information
relu91 committed Jan 17, 2024
1 parent 1148fab commit c10cdfc
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions packages/core/src/interaction-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ const { debug } = createLoggers("core", "interaction-output");
const ajv = new Ajv({ strict: false });

export class InteractionOutput implements WoT.InteractionOutput {
private content: Content;
#content: Content;
#value: unknown;
private buffer?: ArrayBuffer;
private _stream?: ReadableStream;
#buffer?: ArrayBuffer;
#stream?: ReadableStream;
dataUsed: boolean;
form?: WoT.Form;
schema?: WoT.DataSchema;

public get data(): ReadableStream {
if (this._stream) {
return this._stream;
if (this.#stream) {
return this.#stream;
}

if (this.dataUsed) {
Expand All @@ -51,28 +51,28 @@ export class InteractionOutput implements WoT.InteractionOutput {
// Once the stream is created data might be pulled unpredictably
// therefore we assume that it is going to be used to be safe.
this.dataUsed = true;
return (this._stream = ProtocolHelpers.toWoTStream(this.content.body) as ReadableStream);
return (this.#stream = ProtocolHelpers.toWoTStream(this.#content.body) as ReadableStream);
}

constructor(content: Content, form?: WoT.Form, schema?: WoT.DataSchema) {
this.content = content;
this.#content = content;
this.form = form;
this.schema = schema;
this.dataUsed = false;
}

async arrayBuffer(): Promise<ArrayBuffer> {
if (this.buffer) {
return this.buffer;
if (this.#buffer) {
return this.#buffer;

Check warning on line 66 in packages/core/src/interaction-output.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/interaction-output.ts#L66

Added line #L66 was not covered by tests
}

if (this.dataUsed) {
throw new Error("Can't read the stream once it has been already used");
}

const data = await this.content.toBuffer();
const data = await this.#content.toBuffer();
this.dataUsed = true;
this.buffer = data;
this.#buffer = data;

return data;
}
Expand All @@ -96,17 +96,17 @@ export class InteractionOutput implements WoT.InteractionOutput {
}

// is content type valid?
if (!ContentSerdes.get().isSupported(this.content.type)) {
const message = `Content type ${this.content.type} not supported`;
if (!ContentSerdes.get().isSupported(this.#content.type)) {
const message = `Content type ${this.#content.type} not supported`;

Check warning on line 100 in packages/core/src/interaction-output.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/interaction-output.ts#L100

Added line #L100 was not covered by tests
throw new NotSupportedError(message);
}

// read fully the stream
const bytes = await this.content.toBuffer();
const bytes = await this.#content.toBuffer();
this.dataUsed = true;
this.buffer = bytes;
this.#buffer = bytes;

const json = ContentSerdes.get().contentToValue({ type: this.content.type, body: bytes }, this.schema);
const json = ContentSerdes.get().contentToValue({ type: this.#content.type, body: bytes }, this.schema);

// validate the schema
const validate = ajv.compile<T>(this.schema);
Expand Down

0 comments on commit c10cdfc

Please sign in to comment.