Skip to content

Commit 47ced02

Browse files
authored
Merge pull request #223 from authzed/add-prettier-to-repo
Add prettier to repo
2 parents fdf7660 + 0cb6d80 commit 47ced02

File tree

13 files changed

+840
-802
lines changed

13 files changed

+840
-802
lines changed

.github/workflows/test.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,11 @@ jobs:
4747
with:
4848
useLockFile: false
4949
- name: Run lint
50-
run: CI=true yarn lint
50+
run: "CI=true yarn lint"
51+
- name: Run prettier
52+
run: "CI=true yarn run prettier src -c"
5153
- name: Run Yarn tests
52-
run: CI=true yarn only-run-tests
54+
run: "CI=true yarn only-run-tests"
5355
build-js-client:
5456
name: Build and Test JS client
5557
runs-on: "depot-ubuntu-24.04-small"

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
src/authzedapi

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"@typescript-eslint/parser": "^8.29.1",
5757
"eslint": "^9.24.0",
5858
"grpc-tools": "^1.13.0",
59+
"prettier": "^3.5.3",
5960
"rollup": "^4.40.0",
6061
"tsc-esm-fix": "^3.1.2",
6162
"typescript": "^5.8",

src/__utils__/helpers.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/**
22
* Generates a random token with a prefix to support
33
* unique, idempotent local testing.
4-
* @param prefix
5-
* @returns
4+
* @param prefix
5+
* @returns
66
*/
77
export function generateTestToken(prefix: string): string {
8-
return `${prefix}-${Date.now().toString()}`
9-
}
8+
return `${prefix}-${Date.now().toString()}`;
9+
}

src/full-promises.test.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
import { ClientSecurity } from "./util.js";
22
import * as v1 from "./v1.js";
33
import { Consistency } from "./v1.js";
4-
import { generateTestToken } from './__utils__/helpers.js'
5-
import { describe, it, expect } from 'vitest'
4+
import { generateTestToken } from "./__utils__/helpers.js";
5+
import { describe, it, expect } from "vitest";
66

77
describe("a check following a write of schema and relationships", () => {
88
it("should succeed", async () => {
99
// Write the schema.
10-
const token = generateTestToken('full-promises')
11-
const { promises: v1client } = v1.NewClient(token, "localhost:50051", ClientSecurity.INSECURE_LOCALHOST_ALLOWED);
10+
const token = generateTestToken("full-promises");
11+
const { promises: v1client } = v1.NewClient(
12+
token,
13+
"localhost:50051",
14+
ClientSecurity.INSECURE_LOCALHOST_ALLOWED,
15+
);
1216

1317
const writeSchemaRequest = v1.WriteSchemaRequest.create({
1418
schema: `
@@ -21,7 +25,7 @@ describe("a check following a write of schema and relationships", () => {
2125
`,
2226
});
2327

24-
await v1client.writeSchema(writeSchemaRequest)
28+
await v1client.writeSchema(writeSchemaRequest);
2529
// Create the relationship between the resource and the user.
2630
const resource = v1.ObjectReference.create({
2731
objectType: "test/resource",
@@ -54,7 +58,7 @@ describe("a check following a write of schema and relationships", () => {
5458
updates: [update],
5559
});
5660

57-
const response = await v1client.writeRelationships(writeRequest)
61+
const response = await v1client.writeRelationships(writeRequest);
5862
expect(response).toBeTruthy();
5963

6064
const checkPermissionRequest = v1.CheckPermissionRequest.create({
@@ -66,12 +70,14 @@ describe("a check following a write of schema and relationships", () => {
6670
oneofKind: "fullyConsistent",
6771
fullyConsistent: true,
6872
},
69-
})
73+
}),
7074
});
7175

72-
const permissionResponse = await v1client.checkPermission(checkPermissionRequest)
76+
const permissionResponse = await v1client.checkPermission(
77+
checkPermissionRequest,
78+
);
7379
expect(permissionResponse?.permissionship).toBe(
74-
v1.CheckPermissionResponse_Permissionship.HAS_PERMISSION
80+
v1.CheckPermissionResponse_Permissionship.HAS_PERMISSION,
7581
);
7682
});
7783
});

src/full.test.ts

Lines changed: 63 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,90 @@
11
import { ClientSecurity } from "./util.js";
22
import * as v1 from "./v1.js";
33
import { Consistency } from "./v1.js";
4-
import { generateTestToken } from './__utils__/helpers.js'
5-
import { describe, it, expect } from 'vitest'
4+
import { generateTestToken } from "./__utils__/helpers.js";
5+
import { describe, it, expect } from "vitest";
66

77
describe("a check following a write of schema and relationships", () => {
8-
it("should succeed", () => new Promise<void>((done) => {
9-
// Write the schema.
10-
const token = generateTestToken('full-test')
11-
const v1client = v1.NewClient(token, "localhost:50051", ClientSecurity.INSECURE_LOCALHOST_ALLOWED);
8+
it("should succeed", () =>
9+
new Promise<void>((done) => {
10+
// Write the schema.
11+
const token = generateTestToken("full-test");
12+
const v1client = v1.NewClient(
13+
token,
14+
"localhost:50051",
15+
ClientSecurity.INSECURE_LOCALHOST_ALLOWED,
16+
);
1217

13-
const writeSchemaRequest = v1.WriteSchemaRequest.create({
14-
schema: `
18+
const writeSchemaRequest = v1.WriteSchemaRequest.create({
19+
schema: `
1520
definition test/user {}
1621
1722
definition test/resource {
1823
relation viewer: test/user
1924
permission view = viewer
2025
}
2126
`,
22-
});
23-
24-
v1client.writeSchema(writeSchemaRequest, function (err) {
25-
expect(err).toBe(null);
26-
27-
// Create the relationship between the resource and the user.
28-
const resource = v1.ObjectReference.create({
29-
objectType: "test/resource",
30-
objectId: "someresource",
31-
});
32-
33-
// Create the user reference.
34-
const userref = v1.ObjectReference.create({
35-
objectType: "test/user",
36-
objectId: "someuser",
37-
});
38-
39-
const user = v1.SubjectReference.create({
40-
object: userref,
4127
});
4228

43-
const relationship = v1.Relationship.create({
44-
resource,
45-
relation: "viewer",
46-
subject: user,
47-
});
29+
v1client.writeSchema(writeSchemaRequest, function (err) {
30+
expect(err).toBe(null);
4831

49-
const update = v1.RelationshipUpdate.create({
50-
operation: v1.RelationshipUpdate_Operation.CREATE,
51-
relationship: relationship,
52-
});
32+
// Create the relationship between the resource and the user.
33+
const resource = v1.ObjectReference.create({
34+
objectType: "test/resource",
35+
objectId: "someresource",
36+
});
5337

54-
// Write the relationship.
55-
const writeRequest = v1.WriteRelationshipsRequest.create({
56-
updates: [update],
57-
});
38+
// Create the user reference.
39+
const userref = v1.ObjectReference.create({
40+
objectType: "test/user",
41+
objectId: "someuser",
42+
});
5843

59-
v1client.writeRelationships(writeRequest, function (err, response) {
60-
expect(err).toBe(null);
61-
expect(response).toBeTruthy();
44+
const user = v1.SubjectReference.create({
45+
object: userref,
46+
});
6247

63-
const checkPermissionRequest = v1.CheckPermissionRequest.create({
48+
const relationship = v1.Relationship.create({
6449
resource,
65-
permission: "view",
50+
relation: "viewer",
6651
subject: user,
67-
consistency: Consistency.create({
68-
requirement: {
69-
oneofKind: "fullyConsistent",
70-
fullyConsistent: true,
71-
},
72-
})
7352
});
7453

75-
v1client.checkPermission(checkPermissionRequest, (err, response) => {
54+
const update = v1.RelationshipUpdate.create({
55+
operation: v1.RelationshipUpdate_Operation.CREATE,
56+
relationship: relationship,
57+
});
58+
59+
// Write the relationship.
60+
const writeRequest = v1.WriteRelationshipsRequest.create({
61+
updates: [update],
62+
});
63+
64+
v1client.writeRelationships(writeRequest, function (err, response) {
7665
expect(err).toBe(null);
77-
expect(response?.permissionship).toBe(
78-
v1.CheckPermissionResponse_Permissionship.HAS_PERMISSION
79-
);
80-
done();
66+
expect(response).toBeTruthy();
67+
68+
const checkPermissionRequest = v1.CheckPermissionRequest.create({
69+
resource,
70+
permission: "view",
71+
subject: user,
72+
consistency: Consistency.create({
73+
requirement: {
74+
oneofKind: "fullyConsistent",
75+
fullyConsistent: true,
76+
},
77+
}),
78+
});
79+
80+
v1client.checkPermission(checkPermissionRequest, (err, response) => {
81+
expect(err).toBe(null);
82+
expect(response?.permissionship).toBe(
83+
v1.CheckPermissionResponse_Permissionship.HAS_PERMISSION,
84+
);
85+
done();
86+
});
8187
});
8288
});
83-
});
84-
}));
89+
}));
8590
});

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
"use strict";
22

3-
export * as protobuf from './protobuf.js';
4-
export * as v1 from './v1.js';
3+
export * as protobuf from "./protobuf.js";
4+
export * as v1 from "./v1.js";

src/protobuf.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export * from './authzedapi/google/protobuf/descriptor.js';
2-
export * from './authzedapi/google/protobuf/duration.js';
3-
export * from './authzedapi/google/protobuf/struct.js';
4-
export * from './authzedapi/google/protobuf/timestamp.js';
1+
export * from "./authzedapi/google/protobuf/descriptor.js";
2+
export * from "./authzedapi/google/protobuf/duration.js";
3+
export * from "./authzedapi/google/protobuf/struct.js";
4+
export * from "./authzedapi/google/protobuf/timestamp.js";

src/types.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
ClientWritableStream,
77
Metadata,
88
ServiceError,
9-
} from '@grpc/grpc-js';
9+
} from "@grpc/grpc-js";
1010

1111
/**
1212
* Picks all function properties of a type that except for those with a specific return type
@@ -37,7 +37,7 @@ export type OmitBaseMethods<C extends B, B> = {
3737
export type StreamCall<T, U> = (
3838
request: T,
3939
metadata?: Metadata | CallOptions,
40-
options?: CallOptions
40+
options?: CallOptions,
4141
) => ClientReadableStream<U>;
4242

4343
/**
@@ -54,8 +54,8 @@ export type WritableStreamCall<T, U> = (
5454
| undefined,
5555
callback?: (
5656
err: ServiceError | null,
57-
value?: U | undefined
58-
) => void | undefined
57+
value?: U | undefined,
58+
) => void | undefined,
5959
) => ClientWritableStream<T>;
6060

6161
/**
@@ -65,7 +65,7 @@ export type UnaryCall<T, U> = (
6565
request: T,
6666
metadata: Metadata | CallOptions,
6767
options: Partial<CallOptions>,
68-
callback: (err: ServiceError | null, res?: U) => void
68+
callback: (err: ServiceError | null, res?: U) => void,
6969
) => ClientUnaryCall;
7070

7171
/**
@@ -74,7 +74,7 @@ export type UnaryCall<T, U> = (
7474
export type PromisifiedCall<T, U> = (
7575
request: T,
7676
metadata?: Metadata,
77-
options?: Partial<CallOptions>
77+
options?: Partial<CallOptions>,
7878
) => Promise<U>;
7979

8080
/**

0 commit comments

Comments
 (0)