@kubun/hub 0.16.0 → 0.17.1

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.
@@ -1,7 +1,7 @@
1
1
  import type { Identity } from '@kokuin/token';
2
2
  import type { Adapter } from '@kubun/db-adapter';
3
3
  import { type AdapterInput } from '@kubun/db-provider';
4
- import type { AuthorizeHook } from '@kumiai/hub-server';
4
+ import type { AuthorizeHook, HubRateLimits } from '@kumiai/hub-server';
5
5
  import { Kysely } from 'kysely';
6
6
  import { type HubDatabase, type KubunHubStore } from './hub-store.js';
7
7
  import { type RelayObservers } from './observers.js';
@@ -29,6 +29,15 @@ export type CreateRelayOptions = {
29
29
  */
30
30
  authorize?: AuthorizeHook;
31
31
  allowedOrigin?: string | Array<string>;
32
+ /**
33
+ * Per-DID / per-topic rate limits, forwarded verbatim to `@kumiai/hub-server`
34
+ * `createHub`. Merged per-field over its `DEFAULT_RATE_LIMITS`
35
+ * (`perDID: { rate: 20, burst: 50 }`, `perTopic: { rate: 100, burst: 200 }`),
36
+ * so a partial override touches only the fields it sets. Omitted, the hub
37
+ * keeps those defaults. An embedded/loopback relay can raise or effectively
38
+ * disable the limit for high-op-rate use.
39
+ */
40
+ rateLimits?: Partial<HubRateLimits>;
32
41
  retention?: RelayRetentionConfig;
33
42
  defaultRetention?: number;
34
43
  maxRetention?: number;
@@ -54,6 +63,7 @@ export type RelayInternalOptions = {
54
63
  */
55
64
  authorize?: AuthorizeHook;
56
65
  allowedOrigin?: string | Array<string>;
66
+ rateLimits?: Partial<HubRateLimits>;
57
67
  retention?: RelayRetentionConfig;
58
68
  defaultRetention?: number;
59
69
  maxRetention?: number;
@@ -98,6 +98,9 @@ export async function createRelayInternal(options) {
98
98
  identity: options.identity,
99
99
  accessRules,
100
100
  authorize: options.authorize,
101
+ ...options.rateLimits != null ? {
102
+ rateLimits: options.rateLimits
103
+ } : {},
101
104
  purge: false
102
105
  });
103
106
  if (observers?.onAuthRejected != null) {
@@ -225,6 +228,7 @@ export async function createRelay(options) {
225
228
  auth: options.auth,
226
229
  authorize: options.authorize,
227
230
  allowedOrigin: options.allowedOrigin,
231
+ rateLimits: options.rateLimits,
228
232
  retention: options.retention,
229
233
  defaultRetention: options.defaultRetention,
230
234
  maxRetention: options.maxRetention,
package/lib/hub-store.js CHANGED
@@ -226,7 +226,7 @@ export function createHubStore(params) {
226
226
  logPosition: row.sequence_id
227
227
  } : {}
228
228
  }));
229
- const cursor = messages.length > 0 ? messages[messages.length - 1].sequenceID : null;
229
+ const cursor = messages.at(-1)?.sequenceID ?? null;
230
230
  return {
231
231
  messages,
232
232
  cursor,
package/lib/index.d.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  import type { Identity } from '@kokuin/token';
2
2
  import type { Adapter } from '@kubun/db-adapter';
3
+ import type { HubRateLimits } from '@kumiai/hub-server';
3
4
  import type { Kysely } from 'kysely';
4
5
  import { type HubAuthConfig, type RelayRetentionConfig } from './create-relay.js';
5
6
  import type { HubDatabase } from './hub-store.js';
6
7
  import type { RelayObservers } from './observers.js';
7
- export type { AuthorizeDecision, AuthorizeHook, AuthorizeRequest } from '@kumiai/hub-server';
8
+ export type { AuthorizeDecision, AuthorizeHook, AuthorizeRequest, HubRateLimits, RateLimitConfig, } from '@kumiai/hub-server';
8
9
  export { type CreateRelayOptions, createRelay, createRelayInternal, type HubAuthConfig, type Relay, type RelayRetentionConfig, } from './create-relay.js';
9
10
  export { type CreateHubStoreParams, createHubStore, type HubDatabase, type KubunHubStore, type PurgedSubscription, type PurgeSubscriptionsParams, } from './hub-store.js';
10
11
  export { type JoinLaneAuthorizeConfig, joinLaneAuthorize } from './join-lane-authorize.js';
@@ -30,6 +31,11 @@ export type HubOptions = {
30
31
  * omitted, no access rules are configured beyond signature verification.
31
32
  */
32
33
  auth?: HubAuthConfig;
34
+ /**
35
+ * Per-DID / per-topic rate limits, forwarded verbatim to `@kumiai/hub-server`.
36
+ * Omitted, its defaults apply. See `CreateRelayOptions.rateLimits`.
37
+ */
38
+ rateLimits?: Partial<HubRateLimits>;
33
39
  /** Optional retention scheduler. */
34
40
  retention?: RelayRetentionConfig;
35
41
  /** Optional observers for counters / diagnostics. */
package/lib/index.js CHANGED
@@ -14,6 +14,7 @@ export async function createHub(options) {
14
14
  identity: options.identity,
15
15
  auth: options.auth,
16
16
  allowedOrigin: options.allowedOrigin,
17
+ rateLimits: options.rateLimits,
17
18
  retention: options.retention,
18
19
  observers: options.observers,
19
20
  ownsKysely: false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubun/hub",
3
- "version": "0.16.0",
3
+ "version": "0.17.1",
4
4
  "license": "see LICENSE.md",
5
5
  "sideEffects": false,
6
6
  "type": "module",
@@ -18,14 +18,14 @@
18
18
  "@enkaku/server": "^0.21.2",
19
19
  "@hono/node-server": "^2.1.1",
20
20
  "@kokuin/token": "^0.5.0",
21
- "@kubun/db-adapter": "^0.16.0",
22
- "@kubun/db-provider": "^0.16.0",
23
- "@kubun/http-util": "^0.16.0",
21
+ "@kubun/db-adapter": "^0.17.0",
22
+ "@kubun/db-provider": "^0.17.0",
23
+ "@kubun/http-util": "^0.17.0",
24
24
  "@kumiai/hub-protocol": "^0.9.0",
25
25
  "@kumiai/hub-server": "^0.9.0",
26
26
  "@sozai/event": "^0.1.3",
27
27
  "get-port": "^7.2.0",
28
- "hono": "^4.13.5",
28
+ "hono": "^4.13.7",
29
29
  "kysely": "^0.29.5"
30
30
  },
31
31
  "devDependencies": {
@@ -33,9 +33,9 @@
33
33
  "@enkaku/http-fetch": "^0.21.0",
34
34
  "@enkaku/protocol": "^0.21.1",
35
35
  "@enkaku/transport": "^0.21.0",
36
- "@kubun/db-better-sqlite": "^0.16.0",
37
- "@kubun/db-node-sqlite": "^0.16.0",
38
- "@kubun/db-postgres": "^0.16.0",
36
+ "@kubun/db-better-sqlite": "^0.17.0",
37
+ "@kubun/db-node-sqlite": "^0.17.0",
38
+ "@kubun/db-postgres": "^0.17.0",
39
39
  "@kumiai/hub-conformance": "^0.9.0",
40
40
  "@kumiai/mls": "^0.9.0",
41
41
  "@sozai/async": "^0.2.1",
@@ -47,8 +47,8 @@
47
47
  "scripts": {
48
48
  "build": "pnpm run build:clean && pnpm run build:js && pnpm run build:types",
49
49
  "build:clean": "del lib",
50
- "build:js": "swc src -d ./lib --config-file ../../node_modules/@kigu/dev/swc.json --strip-leading-paths",
51
- "build:types": "tsc --emitDeclarationOnly --skipLibCheck",
50
+ "build:js": "del 'lib/**/*.js' && swc src -d ./lib --config-file ../../node_modules/@kigu/dev/swc.json --strip-leading-paths",
51
+ "build:types": "del 'lib/**/*.d.ts' 'lib/**/*.d.ts.map' && tsc --emitDeclarationOnly --skipLibCheck",
52
52
  "test:types": "tsc --noEmit -p tsconfig.test.json"
53
53
  }
54
54
  }