{"_id":"@blackrock-oss/micro-batcher","_rev":"3-d6cf4f2fe34da3c24f49cd0b026888c9","name":"@blackrock-oss/micro-batcher","dist-tags":{"latest":"1.2.0"},"versions":{"1.0.0":{"name":"@blackrock-oss/micro-batcher","version":"1.0.0","keywords":["micro","batch","processing","decorator"],"author":{"url":"https://github.com/JaysonGCS","name":"Jayson Goh"},"license":"MIT","_id":"@blackrock-oss/micro-batcher@1.0.0","maintainers":[{"name":"jaysongcs","email":"goh.chung.sern@gmail.com"}],"homepage":"https://github.com/blackrock/micro-batcher#readme","bugs":{"url":"https://github.com/blackrock/micro-batcher/issues"},"dist":{"shasum":"30438399010f192cb487196e7540acf39b9d543c","tarball":"https://registry.npmjs.org/@blackrock-oss/micro-batcher/-/micro-batcher-1.0.0.tgz","fileCount":9,"integrity":"sha512-s25azhg+Ug+OtroEpoq7ic66rqj6Xf9oDMCSLSDH6R0bREllGA/8JzNjErhW7urL7pdXYT/dmL84+ctC8X+qRw==","signatures":[{"sig":"MEUCICKUyISKIVrhznJ8yS2DR8MxVllj38laI5JC6qEmDohyAiEA4rVwLo0uDTNLg1lJIos2/62Wm7w51byS58sY2EHGdSo=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":108529},"main":"dist/index.js","types":"dist/index.d.ts","engines":{"node":">=22"},"gitHead":"90d89f526ffa74e2d5701000a0d96af60ac0c099","scripts":{"doc":"typedoc","lint":"eslint src/**","test":"vitest run","build":"tsup","format":"prettier --write './**/*.{js,jsx,ts,tsx,css,md,json}' --config ./.prettierrc","prepare":"husky || true","lint:fix":"eslint src/** --fix","test:dev":"vitest watch","build:demo":"pnpm run clean:dist && pnpm run build && pnpm pack && pnpm run move:webapp","clean:dist":"rimraf dist","lint:debug":"eslint src/** --debug","move:webapp":"mv $(find . -depth 1  -type f -name blackrock-oss-micro-batcher-*.tgz) ./examples/webapp/micro-batcher.tgz","test:coverage":"vitest run --coverage","semantic-release":"semantic-release"},"_npmUser":{"name":"jaysongcs","email":"goh.chung.sern@gmail.com"},"repository":{"url":"git+https://github.com/blackrock/micro-batcher.git","type":"git"},"_npmVersion":"11.6.2","description":"Interval-based micro batching library for TypeScript/JavaScript","directories":{},"lint-staged":{"*.{js,ts}":["eslint src/** --max-warnings=0 --ext .ts,.tsx","prettier --write --ignore-unknown"],"*.{json,html}":["prettier --write --ignore-unknown"]},"_nodeVersion":"24.12.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.4.0","vite":"^5.4.18","husky":"^9.0.11","eslint":"^8.57.1","rimraf":"^6.0.1","vitest":"^3.1.1","typedoc":"^0.27.9","prettier":"^3.5.3","@swc/core":"^1.11.21","typescript":"^5.8.3","@types/node":"^22.14.0","lint-staged":"^15.2.7","semantic-release":"^25.0.2","@vitest/coverage-v8":"^3.1.1","eslint-plugin-import":"^2.30.0","eslint-config-prettier":"^9.1.0","eslint-plugin-prettier":"^5.2.1","@typescript-eslint/parser":"7.18.0","eslint-plugin-perfectionist":"2.10.0","typedoc-plugin-missing-exports":"^3.1.0"},"_npmOperationalInternal":{"tmp":"tmp/micro-batcher_1.0.0_1766194923233_0.9266381214903172","host":"s3://npm-registry-packages-npm-production"}},"1.1.0":{"name":"@blackrock-oss/micro-batcher","version":"1.1.0","keywords":["micro","batch","processing","decorator"],"author":{"url":"https://github.com/JaysonGCS","name":"Jayson Goh"},"license":"MIT","_id":"@blackrock-oss/micro-batcher@1.1.0","maintainers":[{"name":"jaysongcs","email":"goh.chung.sern@gmail.com"}],"homepage":"https://github.com/blackrock/micro-batcher#readme","bugs":{"url":"https://github.com/blackrock/micro-batcher/issues"},"dist":{"shasum":"1a3e39a780115f5970cd8b258bdb5fcecb246368","tarball":"https://registry.npmjs.org/@blackrock-oss/micro-batcher/-/micro-batcher-1.1.0.tgz","fileCount":9,"integrity":"sha512-yCZQRPNaJ84ckP0Mk2Qgg6o36ZFZX+kX1HkSyA2NZbRw//FV+Ezx7pG6WPfV/H33gUFt1lj6HeTC7gQAEwp2nQ==","signatures":[{"sig":"MEUCIB2cgCRI/srqAZBkbFwFzIg421YBrdQMcPBvQkjMaGQPAiEA/IrXx/XMWzj43gVgWbDWlOCEgOUWCc1gQ+fForFny8k=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@blackrock-oss%2fmicro-batcher@1.1.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":109669},"main":"dist/index.js","types":"dist/index.d.ts","engines":{"node":">=22"},"gitHead":"21ef2d029499a9f649919046bd64e1f717b2b0c6","scripts":{"doc":"typedoc","lint":"eslint src/**","test":"vitest run","build":"tsup","format":"prettier --write './**/*.{js,jsx,ts,tsx,css,md,json}' --config ./.prettierrc","prepare":"husky || true","lint:fix":"eslint src/** --fix","test:dev":"vitest watch","typecheck":"tsc --noEmit --skipLibCheck","build:demo":"pnpm run clean:dist && pnpm run build && pnpm pack && pnpm run move:webapp","clean:dist":"rimraf dist","lint:debug":"eslint src/** --debug","move:webapp":"mv $(find . -depth 1  -type f -name blackrock-oss-micro-batcher-*.tgz) ./examples/webapp/micro-batcher.tgz","format:check":"prettier --check './**/*.{js,jsx,ts,tsx,css,md,json}' --config ./.prettierrc","test:coverage":"vitest run --coverage","semantic-release":"semantic-release"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:a71b46f7-0ba0-4e8b-80e6-9385b5d7501a"}},"repository":{"url":"git+https://github.com/blackrock/micro-batcher.git","type":"git"},"_npmVersion":"11.12.1","description":"Interval-based micro batching library for TypeScript/JavaScript","directories":{},"lint-staged":{"*.{js,ts}":["eslint src/** --max-warnings=0 --ext .ts,.tsx","prettier --write --ignore-unknown"],"*.{json,html}":["prettier --write --ignore-unknown"]},"_nodeVersion":"24.15.0","publishConfig":{"access":"public","provenance":true},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.5.1","vite":"^8.0.10","husky":"^9.0.11","eslint":"^8.57.1","rimraf":"^6.0.1","vitest":"^4.1.6","typedoc":"^0.28.19","prettier":"^3.5.3","@swc/core":"^1.15.33","typescript":"^6.0.3","@types/node":"^22.14.0","lint-staged":"^15.2.7","semantic-release":"^25.0.2","@vitest/coverage-v8":"^4.1.6","eslint-plugin-import":"^2.30.0","eslint-config-prettier":"^9.1.0","eslint-plugin-prettier":"^5.2.1","@typescript-eslint/parser":"7.18.0","eslint-plugin-perfectionist":"2.10.0","typedoc-plugin-missing-exports":"^4.1.3"},"_npmOperationalInternal":{"tmp":"tmp/micro-batcher_1.1.0_1778859776368_0.9409403651029444","host":"s3://npm-registry-packages-npm-production"}},"1.2.0":{"name":"@blackrock-oss/micro-batcher","version":"1.2.0","description":"Interval-based micro batching library for TypeScript/JavaScript","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"clean:dist":"rimraf dist","test":"vitest run","test:coverage":"vitest run --coverage","test:dev":"vitest watch","move:webapp":"mv $(find . -depth 1  -type f -name blackrock-oss-micro-batcher-*.tgz) ./examples/webapp/micro-batcher.tgz","build":"tsup","build:demo":"pnpm run clean:dist && pnpm run build && pnpm pack && pnpm run move:webapp","format":"prettier --write './**/*.{js,jsx,ts,tsx,css,md,json}' --config ./.prettierrc","format:check":"prettier --check './**/*.{js,jsx,ts,tsx,css,md,json}' --config ./.prettierrc","typecheck":"tsc --noEmit --skipLibCheck","lint":"eslint src/**","lint:fix":"eslint src/** --fix","lint:debug":"eslint src/** --debug","prepare":"husky || true","doc":"typedoc","semantic-release":"semantic-release"},"lint-staged":{"*.{js,ts}":["eslint src/** --max-warnings=0 --ext .ts,.tsx","prettier --write --ignore-unknown"],"*.{json,html}":["prettier --write --ignore-unknown"]},"publishConfig":{"access":"public","provenance":true},"repository":{"type":"git","url":"git+https://github.com/blackrock/micro-batcher.git"},"keywords":["micro","batch","processing","decorator"],"author":{"name":"Jayson Goh","url":"https://github.com/JaysonGCS"},"bugs":{"url":"https://github.com/blackrock/micro-batcher/issues"},"license":"MIT","devDependencies":{"@swc/core":"^1.15.33","@types/node":"^22.14.0","@typescript-eslint/parser":"7.18.0","@vitest/coverage-v8":"^4.1.6","eslint":"^8.57.1","eslint-config-prettier":"^9.1.0","eslint-plugin-import":"^2.30.0","eslint-plugin-perfectionist":"2.10.0","eslint-plugin-prettier":"^5.2.1","husky":"^9.0.11","lint-staged":"^15.2.7","prettier":"^3.5.3","rimraf":"^6.0.1","semantic-release":"^25.0.2","tsup":"^8.5.1","typedoc":"^0.28.19","typedoc-plugin-missing-exports":"^4.1.3","typescript":"^6.0.3","vite":"^8.0.10","vitest":"^4.1.6"},"engines":{"node":">=22"},"gitHead":"4b1ae9431e619787efd7099922adc6a311638285","_id":"@blackrock-oss/micro-batcher@1.2.0","homepage":"https://github.com/blackrock/micro-batcher#readme","_nodeVersion":"24.16.0","_npmVersion":"11.13.0","dist":{"integrity":"sha512-dDMNnzrVKBcqAW5gj4KGnXLSbLJg0hzwLxkTj7kbc/tz76NRDBmLgybEMyNtmQb1Z1adCWa1xs9KaHRsMX95LQ==","shasum":"151491d713c32b03567dd18361df70163158927b","tarball":"https://registry.npmjs.org/@blackrock-oss/micro-batcher/-/micro-batcher-1.2.0.tgz","fileCount":9,"unpackedSize":128048,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@blackrock-oss%2fmicro-batcher@1.2.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIEbyYkoO/ijvABIlccAbHEgSyU1Y6Il/fbGhlsn3l3xjAiAaGis2hzBMr67bAX4TtjZiwIuV0zT7ef+Bg1Y/KZh2kg=="}]},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:a71b46f7-0ba0-4e8b-80e6-9385b5d7501a"}},"directories":{},"maintainers":[{"name":"jaysongcs","email":"goh.chung.sern@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/micro-batcher_1.2.0_1780155054474_0.6436643244071765"},"_hasShrinkwrap":false}},"time":{"created":"2025-12-20T01:42:03.132Z","modified":"2026-05-30T15:30:54.988Z","1.0.0":"2025-12-20T01:42:03.387Z","1.1.0":"2026-05-15T15:42:56.512Z","1.2.0":"2026-05-30T15:30:54.621Z"},"bugs":{"url":"https://github.com/blackrock/micro-batcher/issues"},"author":{"name":"Jayson Goh","url":"https://github.com/JaysonGCS"},"license":"MIT","homepage":"https://github.com/blackrock/micro-batcher#readme","keywords":["micro","batch","processing","decorator"],"repository":{"type":"git","url":"git+https://github.com/blackrock/micro-batcher.git"},"description":"Interval-based micro batching library for TypeScript/JavaScript","maintainers":[{"name":"jaysongcs","email":"goh.chung.sern@gmail.com"}],"readme":"# Micro Batcher\n\nMicro Batcher is a lightweight, zero-dependency, and experimental interval-based micro-batching library for TypeScript/JavaScript.\n\n## Table of Contents\n\n- [Micro Batcher](#micro-batcher)\n  - [Table of Contents](#table-of-contents)\n  - [Installation](#installation)\n  - [Examples](#examples)\n  - [Usage](#usage)\n  - [Development](#development)\n  - [Roadmap](#roadmap)\n  - [Contributing](#contributing)\n  - [License](#license)\n  - [Contact](#contact)\n\n## Installation\n\n```shell\nnpm install @blackrock-oss/micro-batcher\nyarn add @blackrock-oss/micro-batcher\npnpm add @blackrock-oss/micro-batcher\n```\n\n## Examples\n\nThe [Examples Directory](./examples) is a great resource for learning how to setup Micro Batcher.\n\n[Web Application](./examples/webapp) is a playground application which provides examples on how to configure and integrate Micro Batcher, including error handling scenarios and batch resilience demonstrations.\n\n## Usage\n\n### Micro Batcher in a nutshell\n\nMicro Batcher is a decorator utility that enhances the input function with additional functionalities such as batching, throttling, and more.\n\nBy decorating the original function with Micro Batcher, it produces an enhanced function with the same function signature, allowing developers to seamlessly replace the original function with the enhanced version.\n\nIf a batching function is provided to Micro Batcher, calls to the decorated function within a short interval are intercepted, their payloads are accumulated, then forwarded to the batching or original function for processing, and the results are distributed back to the respective callers.\n\n![micro batcher demo](./gif/micro-batcher-demo.gif)\n\n### API Examples\n\nBelow code snippets are taken from the [Example Web Application](./examples/webapp). Micro Batcher is used to generate a decorated function that is being used by data fetching workflow.\n\n```typescript\nexport const fetchSingleSecurity = async (cusip: string): Promise<Security> => {\n  // Data Fetching Implementation\n};\n\nconst batchFetchSecurities = async (cusips: string[]): Promise<Security[]> => {\n  // Data Fetching Implementation\n};\n\nexport const decoratedFetchSecurity = MicroBatcher(fetchSingleSecurity)\n  .batchResolver(batchFetchSecurities, {\n    payloadWindowSizeLimit: 4,\n    batchingIntervalInMs: 50\n  })\n  .build();\n```\n\nThe decorated function has the same signature as the original, so it can be used as a drop-in replacement:\n\n```typescript\n// With Micro Batcher enabled\nconst result = await decoratedFetchSecurity('AAPL');\n\n// Without Micro Batcher — same signature, same result\nconst result = await fetchSingleSecurity('AAPL');\n```\n\n#### Other Examples\n\n##### Example 1: Single Parameter Function\n\n```typescript\n// Original function\nconst multiplyByTwo = (input: number): Promise<number> => {...};\n\n// Batch resolver function for \"multiplyByTwo\" function\nconst batchMultiplyByTwo = (inputs: number[]): Promise<number[]> => {...};\n\nconst multiplyByTwoBatcher: (input: number) => Promise<number> =\n  MicroBatcher<number, number>(multiplyByTwo)\n    .batchResolver(batchMultiplyByTwo)\n    .build();\n```\n\n##### Example 2: Multiple Parameters Function\n\n```typescript\n// Original function\nconst multiply = (input1: number, input2: number): Promise<number> => {...};\n\n// Batch resolver function for \"multiply\" function\nconst batchMultiply = (inputs: [number, number][]): Promise<number[]> => {...};\n\nconst multiplyBatcher: (input1: number, input2: number) => Promise<number> =\n  MicroBatcher<[number, number], number>(multiply)\n    .batchResolver(batchMultiply)\n    .build();\n```\n\n##### Example 3: Override Default Batching Interval\n\nThe default batching interval is 50ms, which can be overridden using `batchingIntervalInMs` in the batch options.\n\n```typescript\nconst multiplyBatcher: (input1: number, input2: number) => Promise<number> = MicroBatcher<\n  [number, number],\n  number\n>(multiply)\n  .batchResolver(batchMultiply, {\n    batchingIntervalInMs: 100\n  })\n  .build();\n```\n\n##### Example 4: Specify Payload Window Size Limit\n\nBy default, Micro Batcher accumulates all caller payloads based on the batching interval.\n\nHowever, an optional batch option `payloadWindowSizeLimit` can specify the upper limit of the accumulation size.\n\nUpon reaching the limit, the payloads are immediately delegated to the batch resolver.\n\n```typescript\nconst multiplyBatcher: (input1: number, input2: number) => Promise<number> = MicroBatcher<\n  [number, number],\n  number\n>(multiply)\n  .batchResolver(batchMultiply, {\n    payloadWindowSizeLimit: 5\n  })\n  .build();\n```\n\n##### Example 5: Error Strategy\n\nBy default, Micro Batcher uses the `broadcast` error strategy — if the batch resolver throws, all callers in the batch receive the same error.\n\nThe `isolate` error strategy enables per-item error handling. The batch resolver returns `Promise<TReturnType>[]` (an array of independent promises), allowing each caller to settle independently. A failed or cancelled caller bails immediately without waiting for or affecting the rest of the batch.\n\n```typescript\n// Broadcast (default) — batch resolver error rejects all callers\nconst decoratedFn = MicroBatcher(fetchSingle)\n  .batchResolver(batchFetch) // errorStrategy defaults to { type: 'broadcast' }\n  .build();\n\n// Isolate — per-item promises, each caller settles independently\nconst batchFetchIsolated = (cusips: string[]): Promise<Security>[] => {\n  return cusips.map((cusip) => fetchSingle(cusip)); // each item is an independent promise\n};\n\nconst decoratedFn = MicroBatcher(fetchSingle)\n  .batchResolver(batchFetchIsolated, {\n    errorStrategy: { type: 'isolate' }\n  })\n  .build();\n```\n\nIn `isolate` mode, if a caller's underlying API call is cancelled or fails, that caller receives the error immediately while other callers in the same batch continue processing. If the batch resolver itself throws synchronously, all callers are rejected (broadcast fallback).\n\n## Development\n\n### Local Development\n\n```shell\npnpm install\n```\n\n### Build\n\n```shell\npnpm run build\n```\n\n### Test\n\n```shell\n# Run tests\npnpm run test\n\n# Run tests with coverage report\npnpm run test:coverage\n\n# Watch mode\npnpm run test:dev\n```\n\n## Roadmap\n\n### Features\n\n- [ ] Concurrent Batcher Limit Support\n- [ ] Rate Limiting and Throttling Policies Support\n\n## Contributing\n\n### [Contributing](./CONTRIBUTING.md)\n\n### [Code of Conduct](./CODE_OF_CONDUCT.md)\n\n### [Support](./SUPPORT.md)\n\n## License\n\nMicro Batcher is [Apache Licensed](./LICENSE).\n\n## Contact\n\nGitHub Issues: https://github.com/blackrock/micro-batcher/issues\n","readmeFilename":"README.md"}