-
Notifications
You must be signed in to change notification settings - Fork 0
Rewrite encode/decode logic to use BigInt and bitwise operators. #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a7156ee
Refactors permission logic using BigInt
PoOwAa 6e99969
Updates target to ES2020 and adds a test case
PoOwAa a46a172
Adds performance tests for Aclatraz
PoOwAa 0887b84
Updates dev dependencies
PoOwAa 34d8db9
Updates Node.js versions for testing
PoOwAa 827c458
Update src/Aclatraz.ts
PoOwAa df72307
Adds ruleset encode/decode integration test
PoOwAa 9f4c69d
Adds node engine requirement
PoOwAa 6e57802
Validates chunkSize option
PoOwAa 0e48b06
Supports different encoding formats
PoOwAa 8daae96
Adds edge case and coverage tests
PoOwAa 3205e0e
Improves Aclatraz encoding and decoding
PoOwAa 83d64da
Updates codecov action to v5
PoOwAa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| import { performance } from 'perf_hooks'; | ||
| import { Aclatraz } from './Aclatraz'; | ||
|
|
||
| describe('Aclatraz performance test', () => { | ||
| test('generate permission code for 10,000 rules', () => { | ||
| const rules = []; | ||
| for (let i = 1; i <= 10000; i++) { | ||
| rules.push({ id: i, slug: `rule${i}` }); | ||
| } | ||
| const acl = new Aclatraz(rules); | ||
|
|
||
| const ruleIds = Array.from({ length: 10000 }, (_, i) => i + 1); | ||
|
|
||
| const start = performance.now(); | ||
| const code = acl.generateAclCode(ruleIds); | ||
| const end = performance.now(); | ||
|
|
||
| console.log(`Generated code length: ${code.length}`); | ||
| console.log(`Time taken: ${(end - start).toFixed(2)} ms`); | ||
|
|
||
| expect(typeof code).toBe('string'); | ||
| }); | ||
|
|
||
| test('grantPermission 100,000 times', () => { | ||
| const rules = []; | ||
| for (let i = 1; i <= 100; i++) { | ||
| rules.push({ id: i, slug: `rule${i}` }); | ||
| } | ||
| const acl = new Aclatraz(rules); | ||
| const ruleIds = Array.from({ length: 100 }, (_, i) => i + 1); | ||
|
|
||
| const start = performance.now(); | ||
| for (let i = 0; i < 100000; i++) { | ||
| acl.grantPermission('', ruleIds); | ||
| } | ||
| const end = performance.now(); | ||
| console.log( | ||
| `grantPermission 100,000 times took: ${(end - start).toFixed(2)} ms` | ||
| ); | ||
| expect(true).toBe(true); | ||
| }); | ||
|
|
||
| test('verify (decode) 100,000 times', () => { | ||
| const rules = []; | ||
| for (let i = 1; i <= 100; i++) { | ||
| rules.push({ id: i, slug: `rule${i}` }); | ||
| } | ||
| const acl = new Aclatraz(rules); | ||
| const ruleIds = Array.from({ length: 100 }, (_, i) => i + 1); | ||
| const permission = acl.grantPermission('', ruleIds); | ||
|
|
||
| const start = performance.now(); | ||
| for (let i = 0; i < 100000; i++) { | ||
| acl.verify(permission, 50); // Arbitrary ruleId in the middle | ||
| } | ||
| const end = performance.now(); | ||
| console.log( | ||
| `verify (decode) 100,000 times took: ${(end - start).toFixed(2)} ms` | ||
| ); | ||
| expect(true).toBe(true); | ||
| }); | ||
|
|
||
| test('revokePermission 100,000 times', () => { | ||
| const rules = []; | ||
| for (let i = 1; i <= 100; i++) { | ||
| rules.push({ id: i, slug: `rule${i}` }); | ||
| } | ||
| const acl = new Aclatraz(rules); | ||
| const ruleIds = Array.from({ length: 100 }, (_, i) => i + 1); | ||
| const permission = acl.grantPermission('', ruleIds); | ||
|
|
||
| const start = performance.now(); | ||
| for (let i = 0; i < 100000; i++) { | ||
| acl.revokePermission(permission, [50]); // Arbitrary ruleId | ||
| } | ||
| const end = performance.now(); | ||
| console.log( | ||
| `revokePermission 100,000 times took: ${(end - start).toFixed(2)} ms` | ||
| ); | ||
| expect(true).toBe(true); | ||
| }); | ||
|
|
||
| test('grantPermission with 100,000 rules', () => { | ||
| const rules = []; | ||
| for (let i = 1; i <= 100000; i++) { | ||
| rules.push({ id: i, slug: `rule${i}` }); | ||
| } | ||
| const acl = new Aclatraz(rules); | ||
| const ruleIds = Array.from({ length: 100000 }, (_, i) => i + 1); | ||
|
|
||
| const start = performance.now(); | ||
| const permission = acl.grantPermission('', ruleIds); | ||
| const end = performance.now(); | ||
| console.log( | ||
| `grantPermission with 100,000 rules took: ${(end - start).toFixed( | ||
| 2 | ||
| )} ms, token length: ${permission.length}` | ||
| ); | ||
| expect(typeof permission).toBe('string'); | ||
| }); | ||
|
|
||
| test('verify (decode) with 100,000 rules', () => { | ||
| const rules = []; | ||
| for (let i = 1; i <= 100000; i++) { | ||
| rules.push({ id: i, slug: `rule${i}` }); | ||
| } | ||
| const acl = new Aclatraz(rules); | ||
| const ruleIds = Array.from({ length: 100000 }, (_, i) => i + 1); | ||
| const permission = acl.grantPermission('', ruleIds); | ||
|
|
||
| const start = performance.now(); | ||
| let count = 0; | ||
| for (let i = 1; i <= 100000; i += 10000) { | ||
| if (acl.verify(permission, i)) count++; | ||
| } | ||
| const end = performance.now(); | ||
| console.log( | ||
| `verify (decode) with 100,000 rules (checked every 10,000th): ${( | ||
| end - start | ||
| ).toFixed(2)} ms, found: ${count}` | ||
| ); | ||
| expect(count).toBe(10); | ||
| }); | ||
|
|
||
| test('revokePermission with 100,000 rules', () => { | ||
| const rules = []; | ||
| for (let i = 1; i <= 100000; i++) { | ||
| rules.push({ id: i, slug: `rule${i}` }); | ||
| } | ||
| const acl = new Aclatraz(rules); | ||
| const ruleIds = Array.from({ length: 100000 }, (_, i) => i + 1); | ||
| const permission = acl.grantPermission('', ruleIds); | ||
|
|
||
| const start = performance.now(); | ||
| const revoked = acl.revokePermission(permission, [50000, 99999, 100000]); | ||
| const end = performance.now(); | ||
| console.log( | ||
| `revokePermission with 100,000 rules took: ${(end - start).toFixed( | ||
| 2 | ||
| )} ms, token length: ${revoked.length}` | ||
| ); | ||
| expect(typeof revoked).toBe('string'); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Verify npm compatibility with major dependency upgrades.
The significant version bumps across all development dependencies are necessary to support ES2020 features like BigInt, but may require adjustments to CI/CD workflows or developer environments.
🏁 Script executed:
Length of output: 315
🏁 Script executed:
Length of output: 522
Add a Node.js engines field and update CI Node versions
To ensure developers and CI use a compatible Node.js version for these upgraded dev dependencies:
• In
package.json, add an"engines"section (e.g."node": ">=16") to lock the minimum Node.js version.• In
.github/workflows/test.yml, bump thenode-versionmatrix to current LTS releases (e.g.16.x,18.x,20.x), replacing the old10.x, 12.x, 14.x, 15.xentries.• Verify local environments are running Node.js ≥16 before installing.
These changes will align your CI/CD and developer machines with the requirements of TypeScript 5.4+, ESLint 8.x, and other modern tooling.