Skip to content

Commit 45ff471

Browse files
authored
Merge pull request #106 from aserto-dev/protobuf_helpers
Facilitate json serialization, export bufbuild helpers
2 parents 867a835 + 5a26fec commit 45ff471

File tree

11 files changed

+1392
-83
lines changed

11 files changed

+1392
-83
lines changed

MIGRATING.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ m
106106
Response Messages no longer implement the magic toJSON method, which serializes a message with the Protobuf JSON format when it's passed to `JSON.stringify`. Make sure to always serializes to JSON with the toJson or toJsonString function.
107107

108108
```ts
109-
import { GetObjectsResponseSchema } from '@aserto/aserto-node'
110-
import { toJson } from "@bufbuild/protobuf";
109+
import { GetObjectsResponseSchema, toJson } from '@aserto/aserto-node'
111110

112111
const response = await directoryClient.objects({
113112
objectType: "user",
@@ -150,8 +149,7 @@ TypeError: Do not know how to serialize a BigInt
150149
This requires [data serialization](#serialization-and-deserialization-of-data):
151150

152151
```ts
153-
import { GetObjectsResponseSchema } from '@aserto/aserto-node'
154-
import { toJson } from "@bufbuild/protobuf";
152+
import { GetObjectsResponseSchema, toJson } from '@aserto/aserto-node'
155153

156154
app.get("/api/users/:id", async (req, res) => {
157155
const id = req.params.id;

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -811,8 +811,7 @@ Use [Protocol Buffers](https://github.com/bufbuild/protobuf-es) to serialize dat
811811
812812
813813
```ts
814-
import { GetObjectsResponseSchema } from "@aserto/aserto-node";
815-
import { toJson } from "@bufbuild/protobuf";
814+
import { GetObjectsResponseSchema, toJson } from "@aserto/aserto-node";
816815

817816
const objects = await directoryClient.objects({objectType: "user"});
818817
const json = toJson(GetObjectsResponseSchema, objects)

__tests__/authorizer/index.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { create } from "@bufbuild/protobuf";
21
import { Code, ConnectError } from "@connectrpc/connect";
32

43
import {
4+
create,
55
decisionTreeOptions,
66
DecisionTreeResponseSchema,
77
IsResponseSchema,
@@ -391,7 +391,6 @@ describe("ListPolicies", () => {
391391
const result = await authorizer.ListPolicies({});
392392
expect(result).toEqual([
393393
{
394-
$typeName: "aserto.authorizer.v2.api.Module",
395394
id: "1",
396395
packagePath: "a.b.c",
397396
},

__tests__/directory/v3/index.test.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import * as fs from "fs";
22
import { describe } from "node:test";
3-
import { create } from "@bufbuild/protobuf";
43
import { Code, ConnectError } from "@connectrpc/connect";
54
import { createAsyncIterable } from "@connectrpc/connect/protocol";
65
import * as connectNode from "@connectrpc/connect-node";
76

87
import {
98
CheckResponseSchema,
109
ConfigError,
10+
create,
1111
createImportRequest,
1212
DeleteManifestResponseSchema,
1313
DeleteObjectResponseSchema,
@@ -29,7 +29,7 @@ import {
2929
SetManifestResponseSchema,
3030
SetObjectResponseSchema,
3131
SetRelationResponseSchema,
32-
} from "../../../lib/index";
32+
} from "../../../lib";
3333
jest.mock("fs");
3434

3535
describe("DirectoryV3", () => {
@@ -466,6 +466,7 @@ describe("DirectoryV3", () => {
466466
$typeName: "aserto.directory.reader.v3.CheckResponse",
467467
check: true,
468468
trace: [],
469+
toJSON: expect.any(Function),
469470
});
470471

471472
mockCheck.mockReset();
@@ -516,6 +517,7 @@ describe("DirectoryV3", () => {
516517
id: "123",
517518
type: "",
518519
},
520+
toJSON: expect.any(Function),
519521
});
520522

521523
mockGetObject.mockReset();
@@ -576,6 +578,7 @@ describe("DirectoryV3", () => {
576578
expect(result).toEqual({
577579
$typeName: "aserto.directory.reader.v3.GetObjectsResponse",
578580
results: [],
581+
toJSON: expect.any(Function),
579582
});
580583

581584
mockGetObjects.mockReset();
@@ -612,6 +615,7 @@ describe("DirectoryV3", () => {
612615
expect(result).toEqual({
613616
$typeName: "aserto.directory.reader.v3.GetObjectsResponse",
614617
results: [],
618+
toJSON: expect.any(Function),
615619
});
616620

617621
mockGetObjects.mockReset();
@@ -648,6 +652,7 @@ describe("DirectoryV3", () => {
648652
expect(result).toEqual({
649653
$typeName: "aserto.directory.reader.v3.GetObjectsResponse",
650654
results: [],
655+
toJSON: expect.any(Function),
651656
});
652657

653658
mockGetObjects.mockReset();
@@ -685,6 +690,7 @@ describe("DirectoryV3", () => {
685690
expect(result).toEqual({
686691
$typeName: "aserto.directory.reader.v3.GetObjectsResponse",
687692
results: [],
693+
toJSON: expect.any(Function),
688694
});
689695

690696
mockGetObjects.mockReset();
@@ -833,6 +839,7 @@ describe("DirectoryV3", () => {
833839
expect(result).toEqual({
834840
$typeName: "aserto.directory.reader.v3.GetObjectManyResponse",
835841
results: [],
842+
toJSON: expect.any(Function),
836843
});
837844

838845
mockGetObjectMany.mockReset();
@@ -881,6 +888,7 @@ describe("DirectoryV3", () => {
881888
$typeName: "aserto.directory.reader.v3.GetGraphResponse",
882889
results: [],
883890
trace: [],
891+
toJSON: expect.any(Function),
884892
});
885893

886894
mockGetGraph.mockReset();
@@ -977,6 +985,7 @@ describe("DirectoryV3", () => {
977985
etag: "",
978986
},
979987
objects: {},
988+
toJSON: expect.any(Function),
980989
});
981990

982991
mockGetRelation.mockReset();
@@ -1033,6 +1042,7 @@ describe("DirectoryV3", () => {
10331042
$typeName: "aserto.directory.reader.v3.GetRelationsResponse",
10341043
results: [],
10351044
objects: {},
1045+
toJSON: expect.any(Function),
10361046
});
10371047

10381048
mockGetRelations.mockReset();
@@ -1145,6 +1155,7 @@ describe("DirectoryV3", () => {
11451155
expect(result).toEqual({
11461156
$typeName: "aserto.directory.writer.v3.DeleteRelationResponse",
11471157
result: { $typeName: "google.protobuf.Empty" },
1158+
toJSON: expect.any(Function),
11481159
});
11491160

11501161
mockDeleteRelation.mockReset();
@@ -1198,6 +1209,7 @@ describe("DirectoryV3", () => {
11981209
body: "test",
11991210
etag: "",
12001211
updatedAt: undefined,
1212+
toJSON: expect.any(Function),
12011213
});
12021214

12031215
getManifestMock.mockReset();
@@ -1228,6 +1240,7 @@ describe("DirectoryV3", () => {
12281240
expect(result).toEqual({
12291241
$typeName: "aserto.directory.model.v3.SetManifestResponse",
12301242
result: { $typeName: "google.protobuf.Empty" },
1243+
toJSON: expect.any(Function),
12311244
});
12321245

12331246
mockSetManifest.mockReset();
@@ -1255,6 +1268,7 @@ describe("DirectoryV3", () => {
12551268
const result = await directory.deleteManifest();
12561269
expect(result).toEqual({
12571270
$typeName: "aserto.directory.model.v3.DeleteManifestResponse",
1271+
toJSON: expect.any(Function),
12581272
});
12591273

12601274
mockDeleteManifest.mockReset();

0 commit comments

Comments
 (0)