{"name":"nice-grpc-client-middleware-deadline","version":"2.0.16","author":"Daniel Lytkin <aikoven@deeplay.io>","license":"MIT","_id":"nice-grpc-client-middleware-deadline@2.0.16","maintainers":[{"name":"aikoven","email":"dan.lytkin@gmail.com"}],"dist":{"shasum":"71bf46d807039a13648c02a177b79b1c76896137","tarball":"http://registry-npm.ywwl.com/nice-grpc-client-middleware-deadline/download/nice-grpc-client-middleware-deadline-2.0.16.tgz","fileCount":7,"integrity":"sha512-tIIuuTqRxzHkI5ivvmf1rsiw3kF24puLWJq53Wm+DZsmSovHgcMkVxxvQblnxalwzdQrQYgKH0cLYqR1U+KTIA==","signatures":[{"sig":"MEQCIG3aITFGAYlJwa1l782SEHQcIH5K9KySoHO6GNMv2MUYAiBIjYNLXs7JpCVKRn5lZEoLRLmNRpiM/eCgWOMVvv+NVw==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":9247,"size":3490,"noattachment":false,"key":"/nice-grpc-client-middleware-deadline/-/nice-grpc-client-middleware-deadline-2.0.16.tgz"},"main":"lib/index.js","gitHead":"dd503076181fc33b0cfd6ff373cd8b281fb6995b","scripts":{"test":"jest","build":"tsc -P tsconfig.build.json","clean":"rimraf lib","prepare":"npm run build:proto","build:proto":"grpc_tools_node_protoc --plugin=protoc-gen-grpc=./node_modules/.bin/grpc_tools_node_protoc_plugin --plugin=protoc-gen-ts=./node_modules/.bin/protoc-gen-ts --js_out=import_style=commonjs,binary:./fixtures --ts_out=grpc_js:./fixtures --grpc_out=grpc_js:./fixtures -I fixtures fixtures/*.proto","prepublishOnly":"npm run clean && npm run build && npm test"},"typings":"lib/index.d.ts","_npmUser":{"name":"aikoven","email":"dan.lytkin@gmail.com"},"repository":"deeplay-io/nice-grpc","_npmVersion":"lerna/8.2.2/node@v20.19.5+arm64 (darwin)","description":"Deadline client middleware for nice-grpc","directories":{},"_nodeVersion":"20.19.5","dependencies":{"nice-grpc-common":"^2.0.2"},"_hasShrinkwrap":false,"devDependencies":{"nice-grpc":"^2.1.13","grpc-tools":"^1.12.4","google-protobuf":"^3.14.0","abort-controller-x":"^0.4.0","@tsconfig/recommended":"^1.0.1","@types/google-protobuf":"^3.7.4","grpc_tools_node_protoc_ts":"^5.0.1"},"_npmOperationalInternal":{"tmp":"tmp/nice-grpc-client-middleware-deadline_2.0.16_1759309603172_0.3836625410236194","host":"s3://npm-registry-packages-npm-production"},"readme":"# nice-grpc-client-middleware-deadline [![npm version][npm-image]][npm-url]\n\nClient middleware for [nice-grpc](https://github.com/deeplay-io/nice-grpc) that\nadds support for setting deadline for a call, after which the call will get\ncancelled, and a `ClientError` with status code `DEADLINE_EXCEEDED` will be\nthrown.\n\n## Installation\n\n```\nnpm install nice-grpc-client-middleware-deadline\n```\n\n## Usage\n\n```ts\nimport {\n  createClientFactory,\n  createChannel,\n  ClientError,\n  Status,\n} from 'nice-grpc';\nimport {deadlineMiddleware} from 'nice-grpc-client-middleware-deadline';\nimport {addSeconds} from 'date-fns';\n\nconst clientFactory = createClientFactory().use(deadlineMiddleware);\n\nconst channel = createChannel(address);\nconst client = clientFactory.create(ExampleService, channel);\n\ntry {\n  const response = await client.exampleMethod(request, {\n    deadline: addSeconds(new Date(), 15),\n  });\n} catch (error: unknown) {\n  if (error instanceof ClientError && error.code === Status.DEADLINE_EXCEEDED) {\n    // timed out\n  } else {\n    throw error;\n  }\n}\n```\n\nAlternatively, you can specify deadline as a relative offset in milliseconds:\n\n```ts\nimport ms from 'ms';\n\nconst response = await client.exampleMethod(request, {\n  deadline: ms('15s'),\n});\n```\n\n[npm-image]: https://badge.fury.io/js/nice-grpc-client-middleware-deadline.svg\n[npm-url]: https://badge.fury.io/js/nice-grpc-client-middleware-deadline\n","publish_time":1759309603344,"_cnpm_publish_time":1759309603344,"dist-tags":{"latest":"2.0.21"}}