Skip to content

Commit 097d226

Browse files
committed
chore: run linter; use just-has package
1 parent fd70a0b commit 097d226

17 files changed

+1666
-95
lines changed

.eslintrc.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"es2021": true
5+
},
6+
"extends": [
7+
"eslint:recommended",
8+
"plugin:@typescript-eslint/recommended",
9+
"prettier"
10+
],
11+
"parser": "@typescript-eslint/parser",
12+
"parserOptions": {
13+
"ecmaVersion": "latest",
14+
"sourceType": "module"
15+
},
16+
"plugins": [
17+
"@typescript-eslint"
18+
],
19+
"rules": {
20+
"no-unused-vars": "off",
21+
"@typescript-eslint/no-unused-vars": ["warn", {
22+
"argsIgnorePattern": "^_",
23+
"varsIgnorePattern": "^_"
24+
}]
25+
}
26+
}

lib/__fixtures__/statements.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export const InvalidConstraintStatement = parsePolicyStatement(
8686
{
8787
action: "create",
8888
effect: "allow",
89+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
8990
constraint: { foo: "bar" } as any,
9091
},
9192
"InvalidConstraintStatement"

lib/parsed-policy-statement.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { PolicyStatement } from "./types";
21
import { RulesLogic } from "json-logic-js";
32
import { randomUUID } from "node:crypto";
3+
import { PolicyStatement } from "./types";
44
import { traverseRulesLogic } from "./utils/logic";
55
import {
66
isStringLiteral,

lib/policy-resolver.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
import jsonLogic, { RulesLogic } from "json-logic-js";
1+
import jsonLogic from "json-logic-js";
2+
import pathExists from "just-has";
23
import { PolicyStatementStore } from "./store/types";
34
import { JsonLogicParser, PolicyDocument, PolicyStatement } from "./types";
45
import {
56
ParsedPolicyStatement,
67
parsePolicyStatement,
78
} from "./parsed-policy-statement";
8-
import { pathExists } from "./utils/obj";
99
import { PolicyDocumentValidator } from "./validator";
1010
import { CachedStatementsStore } from "./store/cached-statements-store";
11-
import { IndexedStatementsStore } from "./store/indexed-statements-store";
1211

1312
interface ResourceActionResolverOptions {
1413
parser?: JsonLogicParser;
@@ -27,7 +26,7 @@ function hasAllPaths(statement: ParsedPolicyStatement, ctx: unknown) {
2726
return false;
2827
}
2928
return statement.contextPaths.every((path) =>
30-
pathExists(ctx as Record<string, unknown>, path)
29+
pathExists(ctx, path)
3130
);
3231
}
3332

@@ -78,7 +77,7 @@ export class PolicyResolver {
7877
this.#cache.set(action, this.#compileAction(action));
7978
}
8079

81-
return this.#cache.get(action)!.can(context);
80+
return this.#cache.get(action)?.can(context) ?? false;
8281
}
8382

8483
/**
@@ -94,7 +93,7 @@ export class PolicyResolver {
9493
this.#cache.set(action, this.#compileAction(action));
9594
}
9695

97-
return this.#cache.get(action)!.explain(context);
96+
return this.#cache.get(action)?.explain(context) ?? [];
9897
}
9998

10099
#compileAction<TContext>(action: string): CompiledFns<TContext> {

lib/store/cached-statements-store.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class CachedStatementsStore implements PolicyStatementStore {
4141
);
4242
}
4343

44-
return this.#cache.get(action)!.map((sid) => this.#mustGet(sid));
44+
return this.#cache.get(action)?.map((sid) => this.#mustGet(sid)) ?? [];
4545
}
4646

4747
#mustGet(sid: string): ParsedPolicyStatement {

lib/store/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from "./cached-statements-store";
2+
export * from "./indexed-statements-store";
3+
export * from "./types";

lib/store/indexed-statements-store.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
GlobStartStatement,
66
MultipleActionsStatement,
77
} from "../__fixtures__/statements";
8-
import { parsePolicyStatement } from "../parsed-policy-statement";
98
import { IndexedStatementsStore } from "./indexed-statements-store";
109

1110
describe("IndexedStatementsStore", () => {

lib/store/indexed-statements-store.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
import assert from "node:assert";
2-
import { PolicyStatement } from "../types";
3-
import {
4-
ParsedPolicyStatement,
5-
parsePolicyStatement,
6-
SYM_SID,
7-
} from "../parsed-policy-statement";
8-
import { disjoint } from "../utils/arr";
2+
import { ParsedPolicyStatement, SYM_SID } from "../parsed-policy-statement";
93
import {
104
ParsedStatementsDB,
115
ByActionIndex,
@@ -68,6 +62,7 @@ export class IndexedStatementsStore implements PolicyStatementStore {
6862
const statementIds = [...this.#byAction.globAll];
6963

7064
if (this.#byAction.exact.has(action)) {
65+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
7166
statementIds.push(...this.#byAction.exact.get(action)!);
7267
}
7368
for (const [regexp, sid] of this.#byAction.regex) {

lib/store/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { ParsedPolicyStatement } from "../parsed-policy-statement";
2-
import { PolicyStatement } from "../types";
32

43
export type ParsedStatementsDB = Map<string, ParsedPolicyStatement>;
54

lib/utils/arr.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)