@shivaedev/rate-limit 0.3.3 → 0.5.0

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.5.0 - 2026-11-04
4
+
5
+ ### Added
6
+
7
+ - The PostgreSQL story fixture exposes `elapseWindows(duration)` to age stored reservations without waiting on wall time.
8
+
9
+ ## 0.4.0 - 2026-11-04
10
+
11
+ ### Breaking
12
+
13
+ - TypeScript source exports now use `@shivaedev/source` instead of `source`. Replace `source` with `@shivaedev/source` in Node `--conditions`, TypeScript `customConditions`, and Vite/Vitest `resolve.conditions`. Bare `source` selects built JavaScript; no compatibility alias is provided.
14
+
3
15
  ## 0.3.3 - 2026-11-04
4
16
 
5
17
  ### Changed
package/README.md CHANGED
@@ -46,7 +46,7 @@ A custom store implements `Store.consume` from `@shivaedev/rate-limit/Store.ts`,
46
46
 
47
47
  ### PostgreSQL story fixtures
48
48
 
49
- `postgresTestDatabase` from `@shivaedev/rate-limit/postgresTestDatabase.ts` provides `expireWindows`, an Effect that expires all stored windows in an isolated test database. Use it to establish expired windows before exercising the production limiter; it does not advance the PostgreSQL clock.
49
+ `postgresTestDatabase` from `@shivaedev/rate-limit/postgresTestDatabase.ts` provides `expireWindows`, an Effect that expires all stored windows in an isolated test database, and `elapseWindows(duration)`, which subtracts an Effect duration from every stored expiry. Use them to establish expired or partially elapsed windows before exercising the production limiter; neither advances the PostgreSQL clock. A story kit advances its controlled clock by the same duration when aging reservations.
50
50
 
51
51
  ### Install
52
52
 
@@ -1,6 +1,7 @@
1
- import { Effect } from "effect";
1
+ import { Duration, Effect } from "effect";
2
2
  import { SqlClient } from "effect/sql";
3
3
  export declare const postgresTestDatabase: Effect.Effect<{
4
+ elapseWindows: (duration: Duration.Input) => Effect.Effect<void, import("effect/sql/SqlError").SqlError, never>;
4
5
  expireWindows: Effect.Effect<void, import("effect/sql/SqlError").SqlError, never>;
5
6
  }, never, SqlClient.SqlClient>;
6
7
  //# sourceMappingURL=postgresTestDatabase.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"postgresTestDatabase.d.ts","sourceRoot":"","sources":["../src/postgresTestDatabase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,eAAO,MAAM,oBAAoB;;8BAK/B,CAAC"}
1
+ {"version":3,"file":"postgresTestDatabase.d.ts","sourceRoot":"","sources":["../src/postgresTestDatabase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,eAAO,MAAM,oBAAoB;8BAGL,QAAQ,CAAC,KAAK;;8BAIxC,CAAC"}
@@ -1,8 +1,9 @@
1
- import { Effect } from "effect";
1
+ import { Duration, Effect } from "effect";
2
2
  import { SqlClient } from "effect/sql";
3
3
  export const postgresTestDatabase = Effect.gen(function* () {
4
4
  const sql = (yield* SqlClient.SqlClient).withoutTransforms();
5
5
  return {
6
+ elapseWindows: (duration) => sql `update rate_limit_windows set expires_at = expires_at - ${Duration.toMillis(Duration.fromInputUnsafe(duration))}`.pipe(Effect.asVoid),
6
7
  expireWindows: sql `update rate_limit_windows set expires_at = 0`.pipe(Effect.asVoid),
7
8
  };
8
9
  });
@@ -1 +1 @@
1
- {"version":3,"file":"postgresTestDatabase.js","sourceRoot":"","sources":["../src/postgresTestDatabase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IACvD,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,iBAAiB,EAAE,CAAC;IAC7D,OAAO;QACN,aAAa,EAAE,GAAG,CAAA,8CAA8C,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;KACpF,CAAC;AACH,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"postgresTestDatabase.js","sourceRoot":"","sources":["../src/postgresTestDatabase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IACvD,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,iBAAiB,EAAE,CAAC;IAC7D,OAAO;QACN,aAAa,EAAE,CAAC,QAAwB,EAAE,EAAE,CAC3C,GAAG,CAAA,2DAA2D,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;QAC1I,aAAa,EAAE,GAAG,CAAA,8CAA8C,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;KACpF,CAAC;AACH,CAAC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shivaedev/rate-limit",
3
- "version": "0.3.3",
3
+ "version": "0.5.0",
4
4
  "description": "Per-key rate limits with memory and PostgreSQL stores for Effect applications",
5
5
  "keywords": [
6
6
  "effect"
@@ -20,14 +20,14 @@
20
20
  "imports": {
21
21
  "#test/*": "./src/test-support/*",
22
22
  "#*.ts": {
23
- "source": "./src/*.ts",
23
+ "@shivaedev/source": "./src/*.ts",
24
24
  "types": "./dist/*.d.ts",
25
25
  "default": "./dist/*.js"
26
26
  }
27
27
  },
28
28
  "exports": {
29
29
  "./*.ts": {
30
- "source": "./src/*.ts",
30
+ "@shivaedev/source": "./src/*.ts",
31
31
  "types": "./dist/*.d.ts",
32
32
  "default": "./dist/*.js"
33
33
  },
@@ -45,20 +45,20 @@
45
45
  "README.md"
46
46
  ],
47
47
  "dependencies": {
48
- "@shivaedev/errors": "0.8.0"
48
+ "@shivaedev/errors": "0.9.0"
49
49
  },
50
50
  "devDependencies": {
51
- "@shivaedev/quality": "0.58.0",
52
- "@shivaedev/sql": "0.36.1",
53
- "@shivaedev/test-sql": "0.18.2",
54
- "@shivaedev/test-story": "0.37.0",
51
+ "@shivaedev/quality": "0.61.0",
52
+ "@shivaedev/sql": "0.38.0",
53
+ "@shivaedev/test-sql": "0.21.0",
54
+ "@shivaedev/test-story": "0.39.0",
55
55
  "@types/node": "24.19.2",
56
56
  "effect": "4.0.6",
57
57
  "typescript": "7.0.2",
58
58
  "vitest": "5.0.5"
59
59
  },
60
60
  "peerDependencies": {
61
- "@shivaedev/sql": "0.36.1",
61
+ "@shivaedev/sql": "0.38.0",
62
62
  "effect": "4.0.6"
63
63
  },
64
64
  "peerDependenciesMeta": {
@@ -1,9 +1,11 @@
1
- import { Effect } from "effect";
1
+ import { Duration, Effect } from "effect";
2
2
  import { SqlClient } from "effect/sql";
3
3
 
4
4
  export const postgresTestDatabase = Effect.gen(function* () {
5
5
  const sql = (yield* SqlClient.SqlClient).withoutTransforms();
6
6
  return {
7
+ elapseWindows: (duration: Duration.Input) =>
8
+ sql`update rate_limit_windows set expires_at = expires_at - ${Duration.toMillis(Duration.fromInputUnsafe(duration))}`.pipe(Effect.asVoid),
7
9
  expireWindows: sql`update rate_limit_windows set expires_at = 0`.pipe(Effect.asVoid),
8
10
  };
9
11
  });