Skip to content

Commit 315cd09

Browse files
authored
Use oxfmt (#264)
* chore: use oxfmt * chore: run formatter
1 parent 497f358 commit 315cd09

19 files changed

+192
-321
lines changed

.github/workflows/cla.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
name: "CLA"
3-
on: # yamllint disable-line rule:truthy
3+
on: # yamllint disable-line rule:truthy
44
issue_comment:
55
types:
66
- "created"

.github/workflows/lint.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
with:
2020
useLockFile: false
2121
- name: "Run prettier"
22-
run: "CI=true yarn run prettier src -c"
22+
run: "CI=true yarn run oxfmt --check"
2323
- name: "Run lint"
2424
run: "CI=true yarn lint"
2525
- name: "Run publint"

.github/workflows/publish.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
# yamllint disable rule:line-length
33
name: "Publish to NPM"
4-
on: # yamllint disable-line rule:truthy
4+
on: # yamllint disable-line rule:truthy
55
release:
66
types:
77
- "published"

.oxfmtrc.jsonc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"$schema": "./node_modules/oxfmt/configuration_schema.json",
3+
"ignorePatterns": ["src/authzedapi"],
4+
}

.prettierignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ You can regenerate the code by executing `buf.gen.yaml`:
120120
Releases are published to NPM using a GitHub action.
121121

122122
To create a new release:
123+
123124
1. Use the [yarn version] command to bump the package version.
124125
1. Create a new [release on GitHub] to initiate the release action.
125126

README.md

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,21 @@ Everything required to connect and make API calls is located in a module respect
5757
You will have to provide a your own API Token from the [Authzed dashboard] in place of `t_your_token_here_1234567deadbeef` in the following example:
5858

5959
```js
60-
import { v1 } from '@authzed/authzed-node';
60+
import { v1 } from "@authzed/authzed-node";
6161
// if your endpoint is localhost
6262
// const client = v1.NewClient('t_your_token_here_1234567deadbeef', 'localhost:50051', v1.ClientSecurity.INSECURE_LOCALHOST_ALLOWED);
63-
const client = v1.NewClient('t_your_token_here_1234567deadbeef');
63+
const client = v1.NewClient("t_your_token_here_1234567deadbeef");
6464
```
6565

6666
Or to use a custom certificate authority, load the CA certificate and pass the file reference to `NewClientWithCustomCert`.
67+
6768
```js
68-
import { v1 } from '@authzed/authzed-node';
69-
import fs from 'fs';
69+
import { v1 } from "@authzed/authzed-node";
70+
import fs from "fs";
7071

71-
const endpoint = 'localhost:50051';
72-
const cert = fs.readFileSync('path/to/cert.pem');
73-
const client = v1.NewClientWithCustomCert('t_your_token_here_1234567deadbeef', endpoint, cert);
72+
const endpoint = "localhost:50051";
73+
const cert = fs.readFileSync("path/to/cert.pem");
74+
const client = v1.NewClientWithCustomCert("t_your_token_here_1234567deadbeef", endpoint, cert);
7475
```
7576

7677
### Performing an API call
@@ -80,36 +81,36 @@ Because of the verbosity of these types, we recommend writing your own functions
8081
The `create` method on generated classes takes attributes as input and defaults unspecified attributes to their empty value. This allows you to create request messages, for example, by specifying only relevant fields and leaves optional fields empty.
8182

8283
```js
83-
import { v1 } from '@authzed/authzed-node';
84+
import { v1 } from "@authzed/authzed-node";
8485

85-
const client = v1.NewClient('token')
86+
const client = v1.NewClient("token");
8687

8788
// Create the relationship between the resource and the user.
8889
const firstPost = v1.ObjectReference.create({
89-
objectType: "blog/post",
90-
objectId: "1",
90+
objectType: "blog/post",
91+
objectId: "1",
9192
});
9293

9394
// Create the user reference.
9495
const emilia = v1.ObjectReference.create({
95-
objectType: "blog/user",
96-
objectId: "emilia",
96+
objectType: "blog/user",
97+
objectId: "emilia",
9798
});
9899

99100
// Create the subject reference using the user reference
100101
const subject = v1.SubjectReference.create({
101-
object: emilia,
102+
object: emilia,
102103
});
103104

104105
const checkPermissionRequest = v1.CheckPermissionRequest.create({
105-
resource: firstPost,
106-
permission: "read",
107-
subject,
106+
resource: firstPost,
107+
permission: "read",
108+
subject,
108109
});
109110

110111
client.checkPermission(checkPermissionRequest, (err, response) => {
111-
console.log(response);
112-
console.log(err);
112+
console.log(response);
113+
console.log(err);
113114
});
114115
```
115116

@@ -131,9 +132,9 @@ const result = await promiseClient.checkPermission(checkPermissionRequest);
131132
For stream-returning methods, including `client.readRelationships()`, `client.lookupResources()` and `client.lookupSubjects()`, the promise-style method will result in an array of response objects once the stream has been closed.
132133

133134
```js
134-
import { v1 } from '@authzed/authzed-node';
135+
import { v1 } from "@authzed/authzed-node";
135136

136-
const client = v1.NewClient('token');
137+
const client = v1.NewClient("token");
137138
const { promises: promiseClient } = client; // access client.promises
138139

139140
const results = await promiseClient.readRelationships(/** req **/);
@@ -150,28 +151,28 @@ writing context will fail silently and the relations won't reflect the context.
150151
An example:
151152

152153
```js
153-
import { protobuf } from '@authzed/authzed-node';
154+
import { protobuf } from "@authzed/authzed-node";
154155
const { Struct } = protobuf;
155156

156157
const writeRequest = WriteRelationshipsRequest.create({
157-
updates: [
158-
RelationshipUpdate.create({
159-
relationship: Relationship.create({
160-
resource: resource,
161-
relation: "caveated_viewer",
162-
subject: SubjectReference.create({
163-
object: testUser,
164-
}),
165-
optionalCaveat: ContextualizedCaveat.create({
166-
caveatName: "has_special_attribute",
167-
context: Struct.fromJson({
168-
special: true,
158+
updates: [
159+
RelationshipUpdate.create({
160+
relationship: Relationship.create({
161+
resource: resource,
162+
relation: "caveated_viewer",
163+
subject: SubjectReference.create({
164+
object: testUser,
165+
}),
166+
optionalCaveat: ContextualizedCaveat.create({
167+
caveatName: "has_special_attribute",
168+
context: Struct.fromJson({
169+
special: true,
170+
}),
169171
}),
170172
}),
173+
operation: RelationshipUpdate_Operation.CREATE,
171174
}),
172-
operation: RelationshipUpdate_Operation.CREATE,
173-
}),
174-
],
175+
],
175176
});
176177

177178
const response = await client.writeRelationships(writeRequest);

docker-compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
services:
33
spicedb-servetesting:
44
image: quay.io/authzed/spicedb:latest
5-
ports: ['50051:50051']
5+
ports: ["50051:50051"]
66
command: serve-testing
77
healthcheck:
88
test: ["CMD", "/usr/local/bin/grpc_health_probe", "-addr=:50051"]

eslint.config.mjs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,36 @@ import { FlatCompat } from "@eslint/eslintrc";
99
const __filename = fileURLToPath(import.meta.url);
1010
const __dirname = path.dirname(__filename);
1111
const compat = new FlatCompat({
12-
baseDirectory: __dirname,
13-
recommendedConfig: js.configs.recommended,
14-
allConfig: js.configs.all
12+
baseDirectory: __dirname,
13+
recommendedConfig: js.configs.recommended,
14+
allConfig: js.configs.all,
1515
});
1616

17-
export default [{
17+
export default [
18+
{
1819
ignores: ["src/authzedapi/**/*", "src/*.test.js"],
19-
}, ...compat.extends(
20+
},
21+
...compat.extends(
2022
"eslint:recommended",
2123
"plugin:@typescript-eslint/eslint-recommended",
2224
"plugin:@typescript-eslint/recommended",
23-
), {
25+
),
26+
{
2427
plugins: {
25-
"@typescript-eslint": typescriptEslint,
28+
"@typescript-eslint": typescriptEslint,
2629
},
2730

2831
languageOptions: {
29-
globals: {
30-
...globals.browser,
31-
...globals.commonjs,
32-
},
32+
globals: {
33+
...globals.browser,
34+
...globals.commonjs,
35+
},
3336

34-
parser: tsParser,
35-
ecmaVersion: 12,
36-
sourceType: "script",
37+
parser: tsParser,
38+
ecmaVersion: 12,
39+
sourceType: "script",
3740
},
3841

3942
rules: {},
40-
}];
43+
},
44+
];

examples/v1/example.js

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { v1 } from '@authzed/authzed-node';
1+
import { v1 } from "@authzed/authzed-node";
22
// set up it on localhost like this:
33
// const client = v1.NewClient('mytokenhere', 'localhost:50051', v1.ClientSecurity.INSECURE_LOCALHOST_ALLOWED);
4-
const client = v1.NewClient('mytokenhere');
4+
const client = v1.NewClient("mytokenhere");
55
const { promises: promiseClient } = client; // access client.promises after instantiating client
66

77
const writeRequest = v1.WriteSchemaRequest.create({
@@ -28,14 +28,14 @@ const writeRelationshipRequest = v1.WriteRelationshipsRequest.create({
2828
v1.RelationshipUpdate.create({
2929
relationship: v1.Relationship.create({
3030
resource: v1.ObjectReference.create({
31-
objectType: 'test/document',
32-
objectId: 'somedocument',
31+
objectType: "test/document",
32+
objectId: "somedocument",
3333
}),
34-
relation: 'viewer',
34+
relation: "viewer",
3535
subject: v1.SubjectReference.create({
3636
object: v1.ObjectReference.create({
37-
objectType: 'test/user',
38-
objectId: 'fred',
37+
objectType: "test/user",
38+
objectId: "fred",
3939
}),
4040
}),
4141
}),
@@ -54,19 +54,19 @@ await new Promise((resolve, reject) => {
5454
// Check a permission.
5555
const checkPermissionRequest = v1.CheckPermissionRequest.create({
5656
resource: v1.ObjectReference.create({
57-
objectType: 'test/document',
58-
objectId: 'somedocument',
57+
objectType: "test/document",
58+
objectId: "somedocument",
5959
}),
60-
permission: 'view',
60+
permission: "view",
6161
subject: v1.SubjectReference.create({
6262
object: v1.ObjectReference.create({
63-
objectType: 'test/user',
64-
objectId: 'fred',
63+
objectType: "test/user",
64+
objectId: "fred",
6565
}),
6666
}),
6767
consistency: v1.Consistency.create({
6868
requirement: {
69-
oneofKind: 'fullyConsistent',
69+
oneofKind: "fullyConsistent",
7070
fullyConsistent: true,
7171
},
7272
}),
@@ -80,29 +80,28 @@ const checkResult = await new Promise((resolve, reject) => {
8080
});
8181

8282
console.log(
83-
checkResult.permissionship ===
84-
v1.CheckPermissionResponse_Permissionship.HAS_PERMISSION
83+
checkResult.permissionship === v1.CheckPermissionResponse_Permissionship.HAS_PERMISSION,
8584
);
8685

8786
// Lookup Resources
8887

8988
const lookupResourcesRequest = v1.LookupResourcesRequest.create({
9089
consistency: v1.Consistency.create({
9190
requirement: {
92-
oneofKind: 'fullyConsistent',
91+
oneofKind: "fullyConsistent",
9392
fullyConsistent: true,
9493
},
9594
}),
96-
resourceObjectType: 'test/document',
97-
permission: 'view',
95+
resourceObjectType: "test/document",
96+
permission: "view",
9897
subject: v1.SubjectReference.create({
9998
object: v1.ObjectReference.create({
100-
objectType: 'test/user',
101-
objectId: 'fred',
99+
objectType: "test/user",
100+
objectId: "fred",
102101
}),
103102
}),
104103
});
105104

106-
const results = await promiseClient.lookupResources(lookupResourcesRequest)
105+
const results = await promiseClient.lookupResources(lookupResourcesRequest);
107106

108107
console.log(results);

0 commit comments

Comments
 (0)