{"_id":"@ws-kit/memory","_rev":"7-1a0b53145df3076bedd921babc783fea","name":"@ws-kit/memory","dist-tags":{"latest":"0.10.1"},"versions":{"0.7.0":{"name":"@ws-kit/memory","version":"0.7.0","keywords":["websocket","adapter","memory","rate-limiting","rate-limiter","token-bucket","pub-sub","type-safe","typescript"],"author":"Konstantin Tarkus","license":"MIT","_id":"@ws-kit/memory@0.7.0","maintainers":[{"name":"koistya","email":"hello@tarkus.me"},{"name":"kriasoft-bot","email":"kriasoft@gmail.com"}],"homepage":"https://kriasoft.com/ws-kit/","bugs":"https://github.com/kriasoft/ws-kit/issues","dist":{"shasum":"cc92a71042b07d79e927312acf3895a419940c32","tarball":"https://registry.npmjs.org/@ws-kit/memory/-/memory-0.7.0.tgz","fileCount":29,"integrity":"sha512-f0Aaubzo2ARx0oXKa/xqwk1ORUnxmmGYDJjOXrpEqaAC6lx1AFDWoL9u8QYnxZ4cscVFm1CkRtkgU3M5q0TixA==","signatures":[{"sig":"MEQCIG/943KDxMAIGujTUDXbQpYeByZ6PDHEHVUO9Gznek8EAiAfAcoQVgNpBrtDJy8pzyTxNeJhndQAozKTNmXCNGUCGQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":169028},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","shasum":"cc92a71042b07d79e927312acf3895a419940c32","engines":{"node":">=22"},"exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.js"}},"funding":{"url":"https://github.com/sponsors/koistya","type":"github"},"_npmUser":{"name":"koistya","email":"hello@tarkus.me"},"_integrity":"sha512-f0Aaubzo2ARx0oXKa/xqwk1ORUnxmmGYDJjOXrpEqaAC6lx1AFDWoL9u8QYnxZ4cscVFm1CkRtkgU3M5q0TixA==","repository":{"url":"https://github.com/kriasoft/ws-kit.git","type":"git","directory":"packages/memory"},"_npmVersion":"10.8.3","description":"In-memory rate limiter and pub/sub adapter for WS-Kit","directories":{},"sideEffects":false,"_nodeVersion":"24.3.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"@types/bun":"^1.3.3","@ws-kit/core":"^0.7.0","@ws-kit/rate-limit":"^0.7.0"},"peerDependencies":{"@ws-kit/core":"^0.7.0","@ws-kit/rate-limit":"^0.7.0"},"_npmOperationalInternal":{"tmp":"tmp/memory_0.7.0_1764543802927_0.7034614173714835","host":"s3://npm-registry-packages-npm-production"}},"0.8.0":{"name":"@ws-kit/memory","version":"0.8.0","keywords":["websocket","adapter","memory","rate-limiting","rate-limiter","token-bucket","pub-sub","type-safe","typescript"],"author":{"name":"Konstantin Tarkus"},"license":"MIT","_id":"@ws-kit/memory@0.8.0","maintainers":[{"name":"koistya","email":"hello@tarkus.me"},{"name":"kriasoft-bot","email":"kriasoft@gmail.com"}],"homepage":"https://kriasoft.com/ws-kit/","bugs":{"url":"https://github.com/kriasoft/ws-kit/issues"},"dist":{"shasum":"a535e4e6de33d4f99f5642d98ff4324f94dd0db2","tarball":"https://registry.npmjs.org/@ws-kit/memory/-/memory-0.8.0.tgz","fileCount":16,"integrity":"sha512-FTYwupSDbio6TEbxmuteFgwCVaaWTCZHMdAsL2h1sbaJlmuPSH8hPBKwEg9kUwJAcEk8dKxP94rA4RNn048fEQ==","signatures":[{"sig":"MEQCIHIfxJshE56Yc34USAtwkwVsWfFz+9+ulK+rqMXpv8eeAiAP0eepM6y1nDjQ700VCQgrvFKPa08+sRb6cvvNd31LOQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@ws-kit%2fmemory@0.8.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":87687},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","engines":{"node":">=22"},"exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.js"}},"funding":{"url":"https://github.com/sponsors/koistya","type":"github"},"gitHead":"b1d18ca9b170c34c784ff4b4d5b03d44e13148b3","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:eb14a5f2-82f8-4276-8ae5-de0e84ac8235"}},"repository":{"url":"git+https://github.com/kriasoft/ws-kit.git","type":"git","directory":"packages/memory"},"_npmVersion":"11.6.2","description":"In-memory rate limiter and pub/sub adapter for WS-Kit","directories":{},"sideEffects":false,"_nodeVersion":"24.11.1","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"@types/bun":"^1.3.3","@ws-kit/core":"^0.8.0","@ws-kit/rate-limit":"^0.8.0"},"peerDependencies":{"@ws-kit/core":"^0.8.0","@ws-kit/rate-limit":"^0.8.0"},"_npmOperationalInternal":{"tmp":"tmp/memory_0.8.0_1764547610346_0.014409338666028448","host":"s3://npm-registry-packages-npm-production"}},"0.9.0":{"name":"@ws-kit/memory","version":"0.9.0","keywords":["websocket","adapter","memory","rate-limiting","rate-limiter","token-bucket","pub-sub","type-safe","typescript"],"author":{"name":"Konstantin Tarkus"},"license":"MIT","_id":"@ws-kit/memory@0.9.0","maintainers":[{"name":"koistya","email":"hello@tarkus.me"},{"name":"kriasoft-bot","email":"kriasoft@gmail.com"}],"homepage":"https://kriasoft.com/ws-kit/","bugs":{"url":"https://github.com/kriasoft/ws-kit/issues"},"dist":{"shasum":"dfd43becc6e1da2c034d9e0ceab20a51b14f320b","tarball":"https://registry.npmjs.org/@ws-kit/memory/-/memory-0.9.0.tgz","fileCount":16,"integrity":"sha512-gHrfXQB2Y143r1u/0EosH5SPcs4YAxoG4rQfBhfUc3dPFhOPxp/425Y3xwuK/F41rboRPKDb90BCBIqpnqgMgw==","signatures":[{"sig":"MEYCIQDXCeSKi+NoxeztLfMlvocM1Jaajw9LZX5wQO0LTHI5swIhAIq2/LLvPK3wYXF5woS62nUPml5HRHEVdqgNVxtBE/p1","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@ws-kit%2fmemory@0.9.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":89417},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","engines":{"node":">=22"},"exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.js"}},"funding":{"url":"https://github.com/sponsors/koistya","type":"github"},"gitHead":"7f41d1c07b55142e2f575372066b7db0a6cc5362","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:eb14a5f2-82f8-4276-8ae5-de0e84ac8235"}},"repository":{"url":"git+https://github.com/kriasoft/ws-kit.git","type":"git","directory":"packages/memory"},"_npmVersion":"11.6.2","description":"In-memory rate limiter and pub/sub adapter for WS-Kit","directories":{},"sideEffects":false,"_nodeVersion":"24.11.1","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"@types/bun":"^1.3.3","@ws-kit/core":"^0.9.0","@ws-kit/rate-limit":"^0.9.0"},"peerDependencies":{"@ws-kit/core":"^0.9.0","@ws-kit/rate-limit":"^0.9.0"},"_npmOperationalInternal":{"tmp":"tmp/memory_0.9.0_1764885621773_0.24186383888986085","host":"s3://npm-registry-packages-npm-production"}},"0.10.0":{"name":"@ws-kit/memory","version":"0.10.0","keywords":["websocket","adapter","memory","rate-limiting","rate-limiter","token-bucket","pub-sub","type-safe","typescript"],"author":{"name":"Konstantin Tarkus"},"license":"MIT","_id":"@ws-kit/memory@0.10.0","maintainers":[{"name":"koistya","email":"hello@tarkus.me"},{"name":"kriasoft-bot","email":"kriasoft@gmail.com"}],"homepage":"https://kriasoft.com/ws-kit/","bugs":{"url":"https://github.com/kriasoft/ws-kit/issues"},"dist":{"shasum":"e23c135bfe04a66c9128e5f4c87d9900448aaf89","tarball":"https://registry.npmjs.org/@ws-kit/memory/-/memory-0.10.0.tgz","fileCount":16,"integrity":"sha512-9eEUnDh36HdPCGr7x+2fpEtpbLmAEOCkdt3Zywxm1wkQfwDUPbd4BjUVimiPZazo7+weImwOD/xopJeemkOV3A==","signatures":[{"sig":"MEQCIETPeqfGkuU1Za4vFU1s42iMzZccv6KMK6BLgZT/W0zAAiArfpwtD7hzmAjWUUCdVFgKdvNamLekXOoxWuu8CUZhCw==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@ws-kit%2fmemory@0.10.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":89501},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","engines":{"node":">=22"},"exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.js"}},"funding":{"url":"https://github.com/sponsors/koistya","type":"github"},"gitHead":"b0a32263ddc6a0b9a54084519304f0bbb478538f","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:eb14a5f2-82f8-4276-8ae5-de0e84ac8235"}},"repository":{"url":"git+https://github.com/kriasoft/ws-kit.git","type":"git","directory":"packages/memory"},"_npmVersion":"11.6.2","description":"In-memory rate limiter and pub/sub adapter for WS-Kit","directories":{},"sideEffects":false,"_nodeVersion":"24.11.1","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"@types/bun":"^1.3.3","@ws-kit/core":"^0.10.0","@ws-kit/rate-limit":"^0.10.0"},"peerDependencies":{"@ws-kit/core":"^0.10.0","@ws-kit/rate-limit":"^0.10.0"},"_npmOperationalInternal":{"tmp":"tmp/memory_0.10.0_1764943200733_0.6487286084738313","host":"s3://npm-registry-packages-npm-production"}},"0.10.1":{"name":"@ws-kit/memory","version":"0.10.1","description":"In-memory rate limiter and pub/sub adapter for WS-Kit","type":"module","sideEffects":false,"license":"MIT","author":{"name":"Konstantin Tarkus"},"homepage":"https://kriasoft.com/ws-kit/","bugs":{"url":"https://github.com/kriasoft/ws-kit/issues"},"repository":{"type":"git","url":"git+https://github.com/kriasoft/ws-kit.git","directory":"packages/memory"},"funding":{"type":"github","url":"https://github.com/sponsors/koistya"},"keywords":["websocket","adapter","memory","rate-limiting","rate-limiter","token-bucket","pub-sub","type-safe","typescript"],"exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.js"}},"main":"./dist/index.js","types":"./dist/index.d.ts","peerDependencies":{"@ws-kit/core":"^0.10.1","@ws-kit/rate-limit":"^0.10.0"},"devDependencies":{"@types/bun":"^1.3.6","@ws-kit/core":"^0.10.1","@ws-kit/rate-limit":"^0.10.0"},"engines":{"node":">=22"},"publishConfig":{"access":"public"},"gitHead":"aaa14caf31960392a54c7475fbf458811407a7f9","_id":"@ws-kit/memory@0.10.1","_nodeVersion":"24.12.0","_npmVersion":"11.6.2","dist":{"integrity":"sha512-y1Gk49lGZLPBBI5j2FtBWqI5xEFOgPL25atjxVrwgEGt38agqaMptuOLeIi98F/ShsnvZAINi9DLQoEbGTUZVQ==","shasum":"5edd6e5171c3ee86fbce87ef33bf246754bde9c1","tarball":"https://registry.npmjs.org/@ws-kit/memory/-/memory-0.10.1.tgz","fileCount":16,"unpackedSize":95385,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@ws-kit%2fmemory@0.10.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDYqxolvyu8aGVhmg4SpeM5u57lgzUOl3IKeFBmP8b5EAIgLBprOAEwriDnoEOxmOqRbUs2v3U1qUS71xhwdHC5ViE="}]},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:eb14a5f2-82f8-4276-8ae5-de0e84ac8235"}},"directories":{},"maintainers":[{"name":"koistya","email":"hello@tarkus.me"},{"name":"kriasoft-bot","email":"kriasoft@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/memory_0.10.1_1768870685086_0.6634687349256578"},"_hasShrinkwrap":false}},"time":{"created":"2025-11-30T23:03:22.835Z","modified":"2026-01-20T00:58:05.521Z","1.0.0":"2025-11-30T22:29:49.431Z","0.7.0":"2025-11-30T23:03:23.126Z","0.8.0":"2025-12-01T00:06:50.528Z","0.9.0":"2025-12-04T22:00:21.926Z","0.10.0":"2025-12-05T14:00:00.872Z","0.10.1":"2026-01-20T00:58:05.223Z"},"bugs":{"url":"https://github.com/kriasoft/ws-kit/issues"},"author":{"name":"Konstantin Tarkus"},"license":"MIT","homepage":"https://kriasoft.com/ws-kit/","keywords":["websocket","adapter","memory","rate-limiting","rate-limiter","token-bucket","pub-sub","type-safe","typescript"],"repository":{"type":"git","url":"git+https://github.com/kriasoft/ws-kit.git","directory":"packages/memory"},"description":"In-memory rate limiter and pub/sub adapter for WS-Kit","maintainers":[{"name":"koistya","email":"hello@tarkus.me"},{"name":"kriasoft-bot","email":"kriasoft@gmail.com"}],"readme":"# @ws-kit/memory\n\nIn-memory adapters for WS-Kit. Provides a zero-dependency pub/sub registry and token-bucket rate limiter for single-instance development and tests (Bun/Node.js).\n\n## When to use\n\n- Local development, unit tests, or single-server deployments\n- Exact subscriber counts without external brokers\n- Deterministic rate-limit testing via injectable clocks\n- ⚠️ Not distributed — no cross-process/state persistence\n\n## What you get\n\n- `memoryPubSub()` — In-memory topic index (`Map<topic, Set<clientId>>`). Implements `publish`, `subscribe`, `unsubscribe`, `getSubscribers`, `listTopics`, `hasTopic`, and `replace` for bulk topic swaps. `excludeSelf` filtering is handled by the pubsub plugin layer.\n- `memoryRateLimiter(policy, opts?)` — Token-bucket limiter with per-key mutex to prevent double spending. Supports `prefix` isolation, `getPolicy()`, `dispose()`, and optional `clock` injection for deterministic tests.\n- Types: `MemoryPubSubAdapter`, `MemoryRateLimiterOptions`, `Clock`.\n\n## Installation\n\n```bash\nbun add @ws-kit/memory\n```\n\n## Quick start: pub/sub (development)\n\n```typescript\nimport { createRouter, withZod, message } from \"@ws-kit/zod\";\nimport { withPubSub } from \"@ws-kit/plugins\";\nimport { memoryPubSub } from \"@ws-kit/memory\";\nimport { z } from \"zod\";\n\nconst Notify = message(\"NOTIFY\", { text: z.string() });\n\nconst router = createRouter()\n  .plugin(withZod())\n  .plugin(withPubSub({ adapter: memoryPubSub() })); // exact local fan-out\n\nrouter.on(Notify, async (ctx) => {\n  await ctx.topics.subscribe(\"room:lobby\");\n  await ctx.publish(\"room:lobby\", Notify, { text: \"Hi!\" });\n});\n```\n\n## Quick start: rate limiting\n\n```typescript\nimport { createRouter } from \"@ws-kit/core\";\nimport { rateLimit, keyPerUserPerType } from \"@ws-kit/rate-limit\";\nimport { memoryRateLimiter } from \"@ws-kit/memory\";\n\nconst limiter = memoryRateLimiter({\n  capacity: 100, // bucket size\n  tokensPerSecond: 10, // refill rate\n  prefix: \"api:\", // optional isolation when sharing a backend\n});\n\nconst router = createRouter().use(\n  rateLimit({\n    limiter,\n    key: keyPerUserPerType,\n    cost: () => 1,\n  }),\n);\n```\n\n## Notes\n\n- Pub/sub is process-local only; restart clears subscriptions.\n- Rate limiter is process-local; use `@ws-kit/redis` or a Durable Objects adapter for shared limits.\n- For deterministic tests, pass `{ clock: { now: () => number } }` to `memoryRateLimiter()`.\n","readmeFilename":"README.md"}