@ihazz/bitrix24 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,52 @@
1
+ import { describe, it, expect, afterEach } from 'vitest';
2
+ import { RateLimiter } from '../src/rate-limiter.js';
3
+
4
+ describe('RateLimiter', () => {
5
+ let limiter: RateLimiter;
6
+
7
+ afterEach(() => {
8
+ limiter?.destroy();
9
+ });
10
+
11
+ it('allows immediate requests within budget', async () => {
12
+ limiter = new RateLimiter({ maxPerSecond: 2 });
13
+ // First two should be immediate
14
+ const start = Date.now();
15
+ await limiter.acquire();
16
+ await limiter.acquire();
17
+ const elapsed = Date.now() - start;
18
+ expect(elapsed).toBeLessThan(50);
19
+ });
20
+
21
+ it('queues requests when budget exhausted', async () => {
22
+ limiter = new RateLimiter({ maxPerSecond: 2 });
23
+ // Exhaust budget
24
+ await limiter.acquire();
25
+ await limiter.acquire();
26
+ // Third should be delayed
27
+ const start = Date.now();
28
+ await limiter.acquire();
29
+ const elapsed = Date.now() - start;
30
+ expect(elapsed).toBeGreaterThanOrEqual(400); // ~500ms for 1 token at 2/sec
31
+ });
32
+
33
+ it('tracks pending count', async () => {
34
+ limiter = new RateLimiter({ maxPerSecond: 1 });
35
+ await limiter.acquire();
36
+ expect(limiter.pending).toBe(0);
37
+
38
+ // Start a pending acquire
39
+ const p = limiter.acquire();
40
+ expect(limiter.pending).toBe(1);
41
+ await p;
42
+ expect(limiter.pending).toBe(0);
43
+ });
44
+
45
+ it('resolves pending on destroy', async () => {
46
+ limiter = new RateLimiter({ maxPerSecond: 1 });
47
+ await limiter.acquire();
48
+ const p = limiter.acquire();
49
+ limiter.destroy();
50
+ await p; // Should resolve without hanging
51
+ });
52
+ });
package/tsconfig.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "lib": ["ES2022"],
7
+ "types": ["node"],
8
+ "outDir": "./dist",
9
+ "rootDir": ".",
10
+ "declaration": true,
11
+ "declarationMap": true,
12
+ "sourceMap": true,
13
+ "strict": true,
14
+ "esModuleInterop": true,
15
+ "skipLibCheck": true,
16
+ "forceConsistentCasingInFileNames": true,
17
+ "resolveJsonModule": true,
18
+ "isolatedModules": true
19
+ },
20
+ "include": ["index.ts", "src/**/*.ts"],
21
+ "exclude": ["node_modules", "dist", "tests"]
22
+ }
@@ -0,0 +1,9 @@
1
+ import { defineConfig } from 'vitest/config';
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ globals: true,
6
+ environment: 'node',
7
+ include: ['tests/**/*.test.ts'],
8
+ },
9
+ });