{"_id":"@c11/pgmq-nestjs","_rev":"3-d806dffc598584a45c4a4306e2a534a7","name":"@c11/pgmq-nestjs","dist-tags":{"latest":"1.0.3"},"versions":{"1.0.0":{"name":"@c11/pgmq-nestjs","version":"1.0.0","license":"PRIVATE","_id":"@c11/pgmq-nestjs@1.0.0","maintainers":[{"name":"code11-dev","email":"platform-ops@code11.com"}],"dist":{"shasum":"9e6465080bc1a30db1e1e9d75bf9d91d64ac641f","tarball":"https://registry.npmjs.org/@c11/pgmq-nestjs/-/pgmq-nestjs-1.0.0.tgz","fileCount":24,"integrity":"sha512-h4Fr5m2DWMZKQn3UctyI/tdZrUZ58EWott8cqJsoC8klDbCaA+5a5vJLkzAOHawbASYF8a+Zx4nDs4uL7Kskig==","signatures":[{"sig":"MEQCIEsxGbvQKKj1q1gAlc7gjOwtpn8+VyQYZQe9qg10d69GAiB/6yGu8mTiEmLlflC/puZgjc7Ta0ya9O7CZHVfHrK4Gg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":43573},"main":"dist/index.js","type":"module","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","default":"./dist/index.js"}},"gitHead":"6edfed5e0b065c4d119b35252b08487e29f04229","scripts":{"build":"tsc","prepublishOnly":"npm run build"},"_npmUser":{"name":"code11-dev","email":"platform-ops@code11.com"},"_npmVersion":"10.8.2","description":"NestJS microservice transport using [pgmq](https://github.com/tembo-io/pgmq) (PostgreSQL message queues). Exposes a custom transport strategy so you can run a hybrid app with `connectMicroservice({ strategy, options: {} })`.","directories":{},"_nodeVersion":"20.20.0","dependencies":{"pg":"^8.11.0","rxjs":"^7.8.0","@nestjs/core":"^10.0.0","@nestjs/common":"^10.0.0","@nestjs/microservices":"^10.0.0"},"publishConfig":{"registry":"https://registry.npmjs.org"},"_hasShrinkwrap":false,"devDependencies":{"@types/pg":"^8.10.0","typescript":"^5.0.0","@types/node":"^20.0.0"},"peerDependencies":{"typeorm":"^0.3.0"},"_npmOperationalInternal":{"tmp":"tmp/pgmq-nestjs_1.0.0_1772202147838_0.3686655756483519","host":"s3://npm-registry-packages-npm-production"}},"1.0.2":{"name":"@c11/pgmq-nestjs","version":"1.0.2","license":"PRIVATE","_id":"@c11/pgmq-nestjs@1.0.2","maintainers":[{"name":"code11-dev","email":"platform-ops@code11.com"}],"dist":{"shasum":"eb74f4925d778374b96007bf585d89463d5a0877","tarball":"https://registry.npmjs.org/@c11/pgmq-nestjs/-/pgmq-nestjs-1.0.2.tgz","fileCount":24,"integrity":"sha512-wkacTRLXdCXNBKzpvpjrEEAeYZzKRpMU+uau9RlMOsfSZPtGgS/LBHNRyu9P0um6EkVqh/OMPwCGZVvmJrGr4w==","signatures":[{"sig":"MEYCIQD6vBh5Yd6c8hdW/KkFxNDUqZXya0NgjBB8dEvOxqoeXgIhAPEeg91aDEP2ppN7hbANkh8q2+8F9c7khmbMATLUeTTJ","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":43647},"main":"dist/index.js","type":"module","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","default":"./dist/index.js"}},"gitHead":"d96d4aed5ba77fe979dab753b9b05d5a3f31064b","scripts":{"build":"tsc","prepublishOnly":"npm run build"},"_npmUser":{"name":"code11-dev","email":"platform-ops@code11.com"},"_npmVersion":"10.8.2","description":"NestJS microservice transport using [pgmq](https://github.com/tembo-io/pgmq) (PostgreSQL message queues). Exposes a custom transport strategy so you can run a hybrid app with `connectMicroservice({ strategy, options: {} })`.","directories":{},"_nodeVersion":"20.20.0","dependencies":{},"publishConfig":{"registry":"https://registry.npmjs.org"},"_hasShrinkwrap":false,"devDependencies":{"pg":"^8.11.0","rxjs":"^7.8.0","@types/pg":"^8.10.0","typescript":"^5.0.0","@types/node":"^20.0.0","@nestjs/core":"^11.1.14","@nestjs/common":"^11.1.14","@nestjs/microservices":"^11.1.14"},"peerDependencies":{"pg":"^8.11.0","rxjs":"^7.8.0","typeorm":"^0.3.0","@nestjs/core":"^11","@nestjs/common":"^11","@nestjs/microservices":"^11"},"_npmOperationalInternal":{"tmp":"tmp/pgmq-nestjs_1.0.2_1772203615460_0.9868518890469338","host":"s3://npm-registry-packages-npm-production"}},"1.0.3":{"name":"@c11/pgmq-nestjs","version":"1.0.3","type":"module","main":"dist/index.js","types":"dist/index.d.ts","private":false,"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","default":"./dist/index.js"}},"scripts":{"build":"tsc","prepublishOnly":"npm run build"},"dependencies":{},"peerDependencies":{"@nestjs/common":"^11","@nestjs/core":"^11","@nestjs/microservices":"^11","pg":"^8.11.0","rxjs":"^7.8.0"},"devDependencies":{"@types/node":"^20.0.0","@types/pg":"^8.10.0","typescript":"^5.0.0","@nestjs/common":"^11.1.14","@nestjs/core":"^11.1.14","@nestjs/microservices":"^11.1.14","pg":"^8.11.0","rxjs":"^7.8.0"},"license":"MIT","publishConfig":{"registry":"https://registry.npmjs.org"},"_id":"@c11/pgmq-nestjs@1.0.3","gitHead":"b10f97c27a34d24fbe4165d65f27fab01f32ff1e","description":"NestJS microservice transport using [pgmq](https://github.com/tembo-io/pgmq) (PostgreSQL message queues). Exposes a custom transport strategy so you can run a hybrid app with `connectMicroservice({ strategy, options: {} })`.","_nodeVersion":"20.20.2","_npmVersion":"10.8.2","dist":{"integrity":"sha512-9luAx+Uq8BbrumGejI1U5phLWU8Iq1PlrrAPi1XPQyLb1JbWBs4sKe2GrywYRbhGjudQX3BMJUCxkHTdHQOyxw==","shasum":"eed38c7230eb729948022c9452592a134d0c0e04","tarball":"https://registry.npmjs.org/@c11/pgmq-nestjs/-/pgmq-nestjs-1.0.3.tgz","fileCount":24,"unpackedSize":43542,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIBbSufD/K2JzGTlGUQ/4TLf9WQxtJNM5UD8Bt4V10ScZAiEAiQ+LNfAU/KYsh+AG+hR/TZYqtNV9LQPwh3Ry3hBxJis="}]},"_npmUser":{"name":"code11-dev","email":"platform-ops@code11.com"},"directories":{},"maintainers":[{"name":"code11-dev","email":"platform-ops@code11.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/pgmq-nestjs_1.0.3_1777023908154_0.6480630217820491"},"_hasShrinkwrap":false}},"time":{"created":"2026-02-27T14:22:27.735Z","modified":"2026-04-24T09:45:08.892Z","1.0.0":"2026-02-27T14:22:28.020Z","1.0.2":"2026-02-27T14:46:55.601Z","1.0.3":"2026-04-24T09:45:08.291Z"},"license":"MIT","description":"NestJS microservice transport using [pgmq](https://github.com/tembo-io/pgmq) (PostgreSQL message queues). Exposes a custom transport strategy so you can run a hybrid app with `connectMicroservice({ strategy, options: {} })`.","maintainers":[{"name":"code11-dev","email":"platform-ops@code11.com"}],"readme":"# @c11/pgmq-nestjs\n\nNestJS microservice transport using [pgmq](https://github.com/tembo-io/pgmq) (PostgreSQL message queues). Exposes a custom transport strategy so you can run a hybrid app with `connectMicroservice({ strategy, options: {} })`.\n\n## Install\n\n```bash\nnpm install @c11/pgmq-nestjs pg\n# or\nyarn add @c11/pgmq-nestjs pg\n# or\npnpm add @c11/pgmq-nestjs pg\n```\n\n**Peer dependency (optional):** Install `typeorm` if you use `PgMqTransportStrategy.fromDataSource()` in `forRootAsync`:\n\n```bash\nnpm install typeorm\n```\n\n**Requirements:**\n\n- Node.js 18+\n- PostgreSQL with the [pgmq extension](https://github.com/tembo-io/pgmq) installed (create extension in your database if needed).\n\n## Usage\n\n### 1. Register the module\n\n**Synchronous config (`forRoot`):**\n\n```ts\n// app.module.ts\nimport { Module } from \"@nestjs/common\";\nimport { PgmqModule } from \"@c11/pgmq-nestjs\";\n\n@Module({\n  imports: [\n    PgmqModule.forRoot({\n      connection: {\n        host: \"localhost\",\n        port: 5432,\n        user: \"postgres\",\n        password: \"postgres\",\n        database: \"mydb\",\n      },\n      queuePrefix: \"nestjs_\",\n    }),\n  ],\n})\nexport class AppModule {}\n```\n\n**Async config (`forRootAsync`):**\n\n```ts\nimport { Module } from \"@nestjs/common\";\nimport { ConfigModule, ConfigService } from \"@nestjs/config\";\nimport { PgmqModule } from \"@c11/pgmq-nestjs\";\nimport { PgMqTransportStrategy } from \"@c11/pgmq-nestjs\";\n\n@Module({\n  imports: [\n    PgmqModule.forRootAsync({\n      imports: [ConfigModule],\n      inject: [ConfigService],\n      useFactory: (config: ConfigService) => {\n        return new PgMqTransportStrategy({\n          connection: {\n            host: config.get(\"DB_HOST\", \"localhost\"),\n            port: config.get(\"DB_PORT\", 5432),\n            user: config.get(\"DB_USER\", \"postgres\"),\n            password: config.get(\"DB_PASSWORD\", \"\"),\n            database: config.get(\"DB_NAME\", \"postgres\"),\n          },\n        });\n      },\n    }),\n  ],\n})\nexport class AppModule {}\n```\n\nWith TypeORM `DataSource` (requires `typeorm` installed):\n\n```ts\nimport { PgmqModule } from \"@c11/pgmq-nestjs\";\nimport { PgMqTransportStrategy } from \"@c11/pgmq-nestjs\";\n\nPgmqModule.forRootAsync({\n  inject: [DataSource],\n  useFactory: (ds: DataSource) => PgMqTransportStrategy.fromDataSource(ds, { queuePrefix: \"app_\" }),\n})\n```\n\n### 2. Connect the microservice in bootstrap\n\n```ts\n// main.ts\nimport { NestFactory } from \"@nestjs/core\";\nimport { AppModule } from \"./app.module.js\";\nimport { PGMQ_STRATEGY, CustomStrategy } from \"@c11/pgmq-nestjs\";\n\nconst app = await NestFactory.create(AppModule);\nconst strategy = app.get(PGMQ_STRATEGY);\napp.connectMicroservice<CustomStrategy>(\n  { strategy, options: {} },\n  { inheritAppConfig: true },\n);\nawait app.startAllMicroservices();\nawait app.listen(3000);\n```\n\n### 3. Use event handlers\n\nUse `@EventPattern()` (and optional `MessagePattern()`) as with any NestJS microservice. The transport uses pgmq queues; event handler groups map to queue names (see Configuration).\n\n## Configuration\n\n| Option | Type | Default | Description |\n|--------|------|---------|-------------|\n| `connection` | `object` | required | Postgres connection: `host`, `port`, `user`, `password`, `database`, optional `ssl`. |\n| `queuePrefix` | `string` | `\"nestjs_\"` | Prefix for all queue names. |\n| `visibilityTimeoutSeconds` | `number` | `30` | Visibility timeout when reading messages. |\n| `replyQueueName` | `string` | `\"nestjs_reply\"` | Queue used for request-response. |\n| `pollIntervalMs` | `number` | `500` | Poll interval in milliseconds. |\n\nQueue names are derived from event handler patterns (or `extras.group`) and sanitized to alphanumeric + underscore; length is capped at **47 characters** (pgmq limit). Longer names are truncated and suffixed with a short hash.\n\n## Caveats\n\n- **pgmq extension:** PostgreSQL must have the pgmq extension available. Create it with `CREATE EXTENSION IF NOT EXISTS pgmq;` (or your provider’s equivalent) if the extension is installed but not yet enabled in the database.\n- **Queue name length:** pgmq limits queue names to 47 characters. Patterns or group names are sanitized and truncated with a hash suffix when longer.\n- **ESM:** This package is published as ESM (`\"type\": \"module\"`). Use `import` and, if needed, `.js` extensions in your own ESM resolution.\n- **One strategy per app:** The module provides a single strategy instance. For multiple distinct connections or configs, use multiple Nest apps or a single strategy with one pool.\n- **Request-response:** Reply queue and correlation are supported; ensure `replyQueueName` does not clash with other queues.\n\n## API\n\n- `PgmqModule.forRoot(options)` / `PgmqModule.forRootAsync(options)` – register the transport.\n- `PGMQ_STRATEGY` – injection token for the strategy (use with `app.get(PGMQ_STRATEGY)` or `@Inject(PGMQ_STRATEGY)`).\n- `CustomStrategy` – type for `connectMicroservice<CustomStrategy>({ strategy, options: {} })`.\n- `PgMqTransportStrategy`, `PgMqTransportStrategyOptions`, `PgmqHandlerExtras`, `PgmqContext` – exported for typing and advanced use.\n- `PgMqTransportStrategy.fromDataSource(ds, overrides?)` – build options from a TypeORM `DataSource` (requires `typeorm`).\n\n## License\n\nPRIVATE\n","readmeFilename":"README.md"}