Skip to content

Commit 0d36543

Browse files
committed
Update response for batchCheck and clientBatchCheck
1 parent b68e18e commit 0d36543

File tree

4 files changed

+21
-21
lines changed

4 files changed

+21
-21
lines changed

client.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export type ClientBatchCheckSingleClientResponse = {
145145
});
146146

147147
export interface ClientBatchCheckClientResponse {
148-
responses: ClientBatchCheckSingleClientResponse[];
148+
result: ClientBatchCheckSingleClientResponse[];
149149
}
150150

151151
export interface ClientBatchCheckClientRequestOpts {
@@ -183,7 +183,7 @@ export type ClientBatchCheckSingleResponse = {
183183
}
184184

185185
export interface ClientBatchCheckResponse {
186-
responses: ClientBatchCheckSingleResponse[];
186+
result: ClientBatchCheckSingleResponse[];
187187
}
188188

189189
export interface ClientWriteRequestOpts {
@@ -643,7 +643,7 @@ export class OpenFgaClient extends BaseAPI {
643643
setHeaderIfNotSet(headers, CLIENT_METHOD_HEADER, "ClientBatchCheck");
644644
setHeaderIfNotSet(headers, CLIENT_BULK_REQUEST_ID_HEADER, generateRandomIdWithNonUniqueFallback());
645645

646-
const responses: ClientBatchCheckSingleClientResponse[] = [];
646+
const result: ClientBatchCheckSingleClientResponse[] = [];
647647
for await (const singleCheckResponse of asyncPool(maxParallelRequests, body, (tuple) => this.check(tuple, { ...options, headers })
648648
.then(response => {
649649
(response as ClientBatchCheckSingleClientResponse)._request = tuple;
@@ -661,9 +661,9 @@ export class OpenFgaClient extends BaseAPI {
661661
};
662662
})
663663
)) {
664-
responses.push(singleCheckResponse);
664+
result.push(singleCheckResponse);
665665
}
666-
return { responses };
666+
return { result };
667667
}
668668

669669

@@ -761,7 +761,7 @@ export class OpenFgaClient extends BaseAPI {
761761
}
762762
}
763763

764-
return { responses: results };
764+
return { result: results };
765765
}
766766

767767
/**
@@ -836,12 +836,12 @@ export class OpenFgaClient extends BaseAPI {
836836
context,
837837
})), { ...options, headers, maxParallelRequests });
838838

839-
const firstErrorResponse = batchCheckResults.responses.find(response => (response as any).error);
839+
const firstErrorResponse = batchCheckResults.result.find(response => (response as any).error);
840840
if (firstErrorResponse) {
841841
throw (firstErrorResponse as any).error;
842842
}
843843

844-
return { relations: batchCheckResults.responses.filter(result => result.allowed).map(result => result._request.relation) };
844+
return { relations: batchCheckResults.result.filter(result => result.allowed).map(result => result._request.relation) };
845845
}
846846

847847
/**

example/example1/example1.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ async function main () {
188188

189189
// execute a batch check
190190
const anneCorrelationId = randomUUID();
191-
const { responses } = await fgaClient.batchCheck({
191+
const { result } = await fgaClient.batchCheck({
192192
checks: [
193193
{
194194
// should have access
@@ -209,7 +209,7 @@ async function main () {
209209
]
210210
});
211211

212-
const anneAllowed = responses.filter(r => r.correlationId === anneCorrelationId);
212+
const anneAllowed = result.filter(r => r.correlationId === anneCorrelationId);
213213
console.log(`Anne is allowed access to ${anneAllowed.length} documents`);
214214
anneAllowed.forEach(item => {
215215
console.log(`Anne is allowed access to ${item.request.object}`);

example/opentelemetry/opentelemetry.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ async function main () {
101101
}
102102

103103
console.log("Calling BatcCheck")
104-
const { responses } = await fgaClient.batchCheck({
104+
await fgaClient.batchCheck({
105105
checks: [
106106
{
107107
object: "doc:roadmap",

tests/client.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -549,8 +549,8 @@ describe("OpenFGA Client", () => {
549549
expect(scope1.isDone()).toBe(true);
550550
expect(scope2.isDone()).toBe(true);
551551
expect(scope3.isDone()).toBe(false);
552-
expect(response.responses.length).toBe(3);
553-
expect(response.responses.sort((a, b) => String(a._request.object).localeCompare(b._request.object)))
552+
expect(response.result.length).toBe(3);
553+
expect(response.result.sort((a, b) => String(a._request.object).localeCompare(b._request.object)))
554554
.toMatchObject(expect.arrayContaining([
555555
{ _request: tuples[0], allowed: true, },
556556
{ _request: tuples[1], allowed: false },
@@ -585,7 +585,7 @@ describe("OpenFGA Client", () => {
585585
const response = await fgaClient.batchCheck({
586586
checks: [],
587587
});
588-
expect(response.responses.length).toBe(0);
588+
expect(response.result.length).toBe(0);
589589
});
590590
it("should handle single batch successfully", async () => {
591591
const mockedResponse = {
@@ -635,9 +635,9 @@ describe("OpenFGA Client", () => {
635635
});
636636

637637
expect(scope.isDone()).toBe(true);
638-
expect(response.responses).toHaveLength(2);
639-
expect(response.responses[0].allowed).toBe(true);
640-
expect(response.responses[1].allowed).toBe(false);
638+
expect(response.result).toHaveLength(2);
639+
expect(response.result[0].allowed).toBe(true);
640+
expect(response.result[1].allowed).toBe(false);
641641
});
642642
it("should split batches successfully", async () => {
643643
const mockedResponse0 = {
@@ -709,11 +709,11 @@ describe("OpenFGA Client", () => {
709709

710710
expect(scope0.isDone()).toBe(true);
711711
expect(scope1.isDone()).toBe(true);
712-
expect(response.responses).toHaveLength(3);
712+
expect(response.result).toHaveLength(3);
713713

714-
const resp0 = response.responses.find(r => r.correlationId === "cor-1");
715-
const resp1 = response.responses.find(r => r.correlationId === "cor-2");
716-
const resp2 = response.responses.find(r => r.correlationId === "cor-3");
714+
const resp0 = response.result.find(r => r.correlationId === "cor-1");
715+
const resp1 = response.result.find(r => r.correlationId === "cor-2");
716+
const resp2 = response.result.find(r => r.correlationId === "cor-3");
717717

718718
expect(resp0?.allowed).toBe(true);
719719
expect(resp0?.request.user).toBe("user:81684243-9356-4421-8fbf-a4f8d36aa31b");

0 commit comments

Comments
 (0)