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

feat: add ok boolean to DWNResponseStatus #959

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/agent/src/types/dwn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ export type DwnResponseStatus = {

/** Descriptive detail about the status or error. */
detail: string;
ok: boolean;
};
};

Expand Down
10 changes: 10 additions & 0 deletions packages/api/src/dwn-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,8 @@ export class DwnApi {

const { reply: { status } } = agentResponse;

status.ok = (200 <= status.code && status.code <= 299);

return { status };
},
/**
Expand Down Expand Up @@ -706,6 +708,8 @@ export class DwnApi {
return record;
});

status.ok = (200 <= status.code && status.code <= 299);

return { records, status, cursor };
},

Expand Down Expand Up @@ -767,6 +771,8 @@ export class DwnApi {

const { reply: { entry, status } } = agentResponse;

status.ok = (200 <= status.code && status.code <= 299);

let record: Record;
if (200 <= status.code && status.code <= 299) {
const recordOptions = {
Expand Down Expand Up @@ -874,6 +880,8 @@ export class DwnApi {
const reply = agentResponse.reply;
const { status, subscription } = reply;

status.ok = (200 <= status.code && status.code <= 299);

return { status, subscription };
},

Expand Down Expand Up @@ -923,6 +931,8 @@ export class DwnApi {

const { message: responseMessage, reply: { status } } = agentResponse;

status.ok = (status.code === 202);

let record: Record;
if (200 <= status.code && status.code <= 299) {
const recordOptions = {
Expand Down
8 changes: 8 additions & 0 deletions packages/api/tests/dwn-api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1735,6 +1735,7 @@ describe('DwnApi', () => {
});

expect(writeResult.status.code).to.equal(202);
expect(writeResult.status.ok).to.equal(true)
expect(writeResult.status.detail).to.equal('Accepted');
expect(writeResult.record).to.exist;

Expand Down Expand Up @@ -1862,6 +1863,7 @@ describe('DwnApi', () => {

// should return both records
expect(result.status.code).to.equal(200);
expect(result.status.ok).to.equal(true)
expect(result.records).to.exist;
expect(result.records!.length).to.equal(2);

Expand Down Expand Up @@ -1921,6 +1923,7 @@ describe('DwnApi', () => {

// Verify the query returns a result.
expect(result.status.code).to.equal(200);
expect(result.status.ok).to.equal(true)
expect(result.records).to.exist;
expect(result.records!.length).to.equal(1);
expect(result.records![0].id).to.equal(record!.id);
Expand All @@ -1938,6 +1941,7 @@ describe('DwnApi', () => {
});
// Confirm that the record does not currently exist on Bob's DWN.
expect(result.status.code).to.equal(200);
expect(result.status.ok).to.equal(true)
expect(result.records).to.exist;
expect(result.records!.length).to.equal(0);
});
Expand Down Expand Up @@ -2017,6 +2021,7 @@ describe('DwnApi', () => {
}
});
expect(status.code).to.equal(202);
expect(status.ok).to.equal(true)
const { status: sendFooBarStatus } = await record.send(aliceDid.uri);
expect(sendFooBarStatus.code).to.equal(202);

Expand Down Expand Up @@ -2053,6 +2058,7 @@ describe('DwnApi', () => {

// should return both records
expect(result.status.code).to.equal(200);
expect(result.status.ok).to.equal(true)
expect(result.records).to.exist;
expect(result.records!.length).to.equal(2);

Expand Down Expand Up @@ -2203,6 +2209,7 @@ describe('DwnApi', () => {
});

expect(writeResult.status.code).to.equal(202);
expect(writeResult.status.ok).to.equal(true)
expect(writeResult.status.detail).to.equal('Accepted');
expect(writeResult.record).to.exist;

Expand All @@ -2215,6 +2222,7 @@ describe('DwnApi', () => {
});

expect(result.status.code).to.equal(200);
expect(result.status.ok).to.equal(true)
expect(result.record.id).to.equal(writeResult.record!.id);
});

Expand Down
Loading