Skip to content

Commit c3070e4

Browse files
chore(deps-dev): bump the development group across 1 directory with 7 updates (#837)
* chore(deps-dev): bump the development group across 1 directory with 7 updates Bumps the development group with 7 updates in the / directory: | Package | From | To | | --- | --- | --- | | [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) | `20.19.37` | `20.19.39` | | [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin) | `8.57.1` | `8.58.0` | | [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser) | `8.57.1` | `8.58.0` | | [eslint](https://github.com/eslint/eslint) | `10.1.0` | `10.2.0` | | [tsdown](https://github.com/rolldown/tsdown) | `0.21.4` | `0.21.7` | | [typescript](https://github.com/microsoft/TypeScript) | `5.9.3` | `6.0.2` | | [typescript-eslint](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/typescript-eslint) | `8.57.1` | `8.58.0` | Updates `@types/node` from 20.19.37 to 20.19.39 - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node) Updates `@typescript-eslint/eslint-plugin` from 8.57.1 to 8.58.0 - [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases) - [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/CHANGELOG.md) - [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v8.58.0/packages/eslint-plugin) Updates `@typescript-eslint/parser` from 8.57.1 to 8.58.0 - [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases) - [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/parser/CHANGELOG.md) - [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v8.58.0/packages/parser) Updates `eslint` from 10.1.0 to 10.2.0 - [Release notes](https://github.com/eslint/eslint/releases) - [Commits](eslint/eslint@v10.1.0...v10.2.0) Updates `tsdown` from 0.21.4 to 0.21.7 - [Release notes](https://github.com/rolldown/tsdown/releases) - [Commits](rolldown/tsdown@v0.21.4...v0.21.7) Updates `typescript` from 5.9.3 to 6.0.2 - [Release notes](https://github.com/microsoft/TypeScript/releases) - [Commits](microsoft/TypeScript@v5.9.3...v6.0.2) Updates `typescript-eslint` from 8.57.1 to 8.58.0 - [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases) - [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/typescript-eslint/CHANGELOG.md) - [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v8.58.0/packages/typescript-eslint) --- updated-dependencies: - dependency-name: "@types/node" dependency-version: 20.19.39 dependency-type: direct:development update-type: version-update:semver-patch dependency-group: development - dependency-name: "@typescript-eslint/eslint-plugin" dependency-version: 8.58.0 dependency-type: direct:development update-type: version-update:semver-minor dependency-group: development - dependency-name: "@typescript-eslint/parser" dependency-version: 8.58.0 dependency-type: direct:development update-type: version-update:semver-minor dependency-group: development - dependency-name: eslint dependency-version: 10.2.0 dependency-type: direct:development update-type: version-update:semver-minor dependency-group: development - dependency-name: tsdown dependency-version: 0.21.7 dependency-type: direct:development update-type: version-update:semver-patch dependency-group: development - dependency-name: typescript dependency-version: 6.0.2 dependency-type: direct:development update-type: version-update:semver-major dependency-group: development - dependency-name: typescript-eslint dependency-version: 8.58.0 dependency-type: direct:development update-type: version-update:semver-minor dependency-group: development ... Signed-off-by: dependabot[bot] <support@github.com> * fixup: remove node imports from non-test code * fixup: revert package-lock.json due to wasm dependencies --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Bruce Felt <bruce.felt@gmail.com>
1 parent aeddbf6 commit c3070e4

File tree

10 files changed

+558
-547
lines changed

10 files changed

+558
-547
lines changed

lib/parsed-policy-statement.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { RulesLogic } from "json-logic-js";
2-
import { randomUUID } from "node:crypto";
2+
import { createRandomId } from "./utils/random-id.js";
33
import { PolicyStatement } from "./types.js";
44
import { arrayify } from "./utils/arr.js";
55
import { traverseRulesLogic } from "./utils/logic.js";
@@ -100,7 +100,7 @@ export function parsePolicyStatement(
100100
const { action, constraint, effect } = statement;
101101
const actions = arrayify(action);
102102

103-
const sid = opts.sid ?? statement.sid ?? randomUUID();
103+
const sid = opts.sid ?? statement.sid ?? createRandomId();
104104
const gid = opts.gid;
105105

106106
return {

lib/policy-resolver.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import assert from "node:assert";
2-
import { describe, it, mock } from "node:test";
2+
import { beforeEach, describe, it, mock } from "node:test";
33
import { parsePolicyStatement } from "./parsed-policy-statement.js";
44
import { PolicyResolver } from "./policy-resolver.js";
55
import { IndexedStatementsStore } from "./store/index.js";

lib/policy-resolver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import pathExists from "just-has";
22
import jsonLogic from "json-logic-js";
33
import { LRUCache } from "lru-cache";
4-
import { randomUUID } from "node:crypto";
54
import { CachedStatementsStore } from "./store/cached-statements-store.js";
65
import { PolicyStatementStore } from "./store/types.js";
6+
import { createRandomId } from "./utils/random-id.js";
77
import {
88
ParsedPolicyStatement,
99
parsePolicyStatement,
@@ -58,7 +58,7 @@ export class PolicyResolver {
5858
docs.forEach((doc) => {
5959
validator.validate(doc);
6060

61-
const gid = doc.id ?? randomUUID();
61+
const gid = doc.id ?? createRandomId();
6262

6363
const parsed = arrayify(doc.statement).map((statement) =>
6464
parsePolicyStatement(statement),

lib/store/cached-statements-store.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { LRUCache } from "lru-cache";
2-
import assert from "node:assert";
32
import { ParsedPolicyStatement } from "../parsed-policy-statement.js";
43
import { TypedEmitter } from "../utils/events.js";
54
import { IndexedStatementsStore } from "./indexed-statements-store.js";
@@ -72,7 +71,9 @@ export class CachedStatementsStore
7271
#mustGet(sid: string): ParsedPolicyStatement {
7372
const statement = this.#store.get(sid);
7473

75-
assert.ok(statement, `no statement with sid '${sid}'`);
74+
if (!statement) {
75+
throw new Error(`no statement with sid '${sid}'`);
76+
}
7677

7778
return statement;
7879
}

lib/store/indexed-statements-store.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import uniq from "just-unique";
2-
import assert from "node:assert";
32
import { ParsedPolicyStatement } from "../parsed-policy-statement.js";
43
import { TypedEmitter } from "../utils/events.js";
54
import {
@@ -154,7 +153,9 @@ export class IndexedStatementsStore
154153
#mustGet(sid: string): ParsedPolicyStatement {
155154
const statement = this.#statements.get(sid);
156155

157-
assert.ok(statement, `no statement with sid '${sid}'`);
156+
if (!statement) {
157+
throw new Error(`no statement with sid '${sid}'`);
158+
}
158159

159160
return statement;
160161
}

lib/utils/events.ts

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import EventEmitter from "node:events";
2-
31
type EventMap = Record<string, unknown>;
42

53
type EventKey<T extends EventMap> = string & keyof T;
@@ -12,20 +10,39 @@ export interface Emitter<T extends EventMap> {
1210
}
1311

1412
export class TypedEmitter<T extends EventMap> implements Emitter<T> {
15-
private emitter = new EventEmitter();
13+
private listeners = new Map<string, Set<EventReceiver<unknown>>>();
14+
1615
on<K extends EventKey<T>>(eventName: K, fn: EventReceiver<T[K]>) {
17-
this.emitter.on(eventName, fn);
16+
const listeners =
17+
this.listeners.get(eventName) ?? new Set<EventReceiver<unknown>>();
18+
listeners.add(fn as EventReceiver<unknown>);
19+
this.listeners.set(eventName, listeners);
1820
}
1921

2022
off<K extends EventKey<T>>(eventName: K, fn: EventReceiver<T[K]>) {
21-
this.emitter.off(eventName, fn);
23+
const listeners = this.listeners.get(eventName);
24+
if (!listeners) {
25+
return;
26+
}
27+
28+
listeners.delete(fn as EventReceiver<unknown>);
29+
if (listeners.size === 0) {
30+
this.listeners.delete(eventName);
31+
}
2232
}
2333

2434
emit<K extends EventKey<T>>(eventName: K, params: T[K]) {
25-
this.emitter.emit(eventName, params);
35+
const listeners = this.listeners.get(eventName);
36+
if (!listeners) {
37+
return;
38+
}
39+
40+
for (const listener of listeners) {
41+
listener(params);
42+
}
2643
}
2744

2845
removeAllListeners() {
29-
this.emitter.removeAllListeners();
46+
this.listeners.clear();
3047
}
3148
}

lib/utils/random-id.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export function createRandomId(): string {
2+
const cryptoApi = globalThis.crypto;
3+
if (cryptoApi && typeof cryptoApi.randomUUID === "function") {
4+
return cryptoApi.randomUUID();
5+
}
6+
7+
const timestamp = Date.now().toString(36);
8+
const random = Math.random().toString(36).slice(2, 14);
9+
return `${timestamp}-${random}`;
10+
}

0 commit comments

Comments
 (0)