Skip to content
This repository was archived by the owner on Jul 1, 2024. It is now read-only.

Commit 90a2248

Browse files
committed
rename: highlevel -> porcelain, OPA -> OPAClient
Signed-off-by: Stephan Renatus <stephan@styra.com>
1 parent 4a8bb1f commit 90a2248

File tree

8 files changed

+21
-18
lines changed

8 files changed

+21
-18
lines changed

.genignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
LICENSE
22
/src/helpers
3-
/src/highlevel
3+
/src/porcelain
44
/src/index.ts
55
/.eslintrc.js

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
/cjs
99
/node_modules
1010
/.tsbuildinfo
11-
/highlevel
11+
/porcelain

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ For supported JavaScript runtimes, please consult [RUNTIMES.md](RUNTIMES.md).
2929
All the code examples that follow assume that the high-level SDK module has been imported, and that an `OPA` instance was created:
3030

3131
```ts
32-
import { OPA } from "opa/highlevel";
32+
import { OPAClient } from "@styra/opa";
3333

3434
const serverURL = "http://opa-host:8181";
3535
const path = "authz/allow";
36-
const opa = new OPA(serverURL);
36+
const opa = new OPAClient(serverURL);
3737
```
3838

3939
### Simple query
@@ -70,7 +70,7 @@ Input is provided as a second (optional) argument to `authorize`:
7070

7171
```ts
7272
const input = { user: "alice" };
73-
const allowed = await new OPA(serverURL).authorize(path, input);
73+
const allowed = await opa.authorize(path, input);
7474
console.log(allowed ? "allowed!" : "denied!");
7575
```
7676

src/highlevel/index.ts

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

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
*/
44

55
export * from "./lib/config";
6-
export * from "./highlevel";
6+
export * from "./porcelain";

src/porcelain/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./porcelain";

src/highlevel/highlevel.ts renamed to src/porcelain/porcelain.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ function implementsToInput(object: any): object is ToInput {
2020
return u.toInput !== undefined && typeof u.toInput == "function";
2121
}
2222

23-
/** OPA is the starting point for using the high-level API.
23+
/** OPAClient is the starting point for using the high-level API.
2424
*
2525
* Use {@link Opa} if you need some low-level customization.
2626
*/
27-
export class OPA {
27+
export class OPAClient {
2828
private opa: Opa;
2929

3030
constructor(serverURL: string) {

tests/authorizer.test.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { describe, before, after, it } from "node:test";
22
import assert from "node:assert";
33
import { GenericContainer, StartedTestContainer, Wait } from "testcontainers";
4-
import { OPA, ToInput, Input, Result } from "../src/highlevel";
4+
import { OPAClient, ToInput, Input, Result } from "../src/porcelain";
55

66
// Run these locally, with debug output from testcontainers, like this:
77
// DEBUG='testcontainers*' node --require ts-node/register --test tests/**/*.ts
@@ -54,17 +54,20 @@ it_is := true
5454
});
5555

5656
it("can be called without types, without input", async () => {
57-
const res = await new OPA(serverURL).authorize("test/p_bool");
57+
const res = await new OPAClient(serverURL).authorize("test/p_bool");
5858
assert.strictEqual(res, true);
5959
});
6060

6161
it("can be called with input==false", async () => {
62-
const res = await new OPA(serverURL).authorize("test/p_bool_false", false);
62+
const res = await new OPAClient(serverURL).authorize(
63+
"test/p_bool_false",
64+
false,
65+
);
6366
assert.strictEqual(res, true);
6467
});
6568

6669
it("supports rules with slashes", async () => {
67-
const res = await new OPA(serverURL).authorize(
70+
const res = await new OPAClient(serverURL).authorize(
6871
"has/weird%2fpackage/but/it_is",
6972
);
7073
assert.strictEqual(res, true);
@@ -79,7 +82,7 @@ it_is := true
7982
foo: string;
8083
}
8184
const inp: myInput = { name: "alice", list: [1, 2, true] };
82-
const res = await new OPA(serverURL).authorize<myInput, myResult>(
85+
const res = await new OPAClient(serverURL).authorize<myInput, myResult>(
8386
"test/compound_input",
8487
inp,
8588
);
@@ -91,7 +94,7 @@ it_is := true
9194
type: string;
9295
}
9396
const inp = true;
94-
const res = await new OPA(serverURL).authorize<boolean, typeResult>(
97+
const res = await new OPAClient(serverURL).authorize<boolean, typeResult>(
9598
"test/has_type",
9699
inp,
97100
);
@@ -114,7 +117,7 @@ it_is := true
114117
interface myResult {
115118
foo: string;
116119
}
117-
const res = await new OPA(serverURL).authorize<A, myResult>(
120+
const res = await new OPAClient(serverURL).authorize<A, myResult>(
118121
"test/compound_input",
119122
inp,
120123
);
@@ -141,15 +144,15 @@ it_is := true
141144
interface myResult {
142145
foo: string;
143146
}
144-
const res = await new OPA(serverURL).authorize<A, myResult>(
147+
const res = await new OPAClient(serverURL).authorize<A, myResult>(
145148
"test/compound_input",
146149
inp,
147150
);
148151
assert.deepStrictEqual(res, { foo: "bar" });
149152
});
150153

151154
it("supports result class implementing FromResult", async () => {
152-
const res = await new OPA(serverURL).authorize<any, boolean>(
155+
const res = await new OPAClient(serverURL).authorize<any, boolean>(
153156
"test/compound_result",
154157
undefined, // input
155158
(r?: Result) => (r as Record<string, any>)["allowed"] ?? false,

0 commit comments

Comments
 (0)