{"_id":"kanel-enum-tables","_rev":"2-5748cf072aaa5116c69f26a7d91134ef","name":"kanel-enum-tables","dist-tags":{"latest":"4.0.0"},"versions":{"1.0.0":{"name":"kanel-enum-tables","version":"1.0.0","keywords":["enum","postgresql","schema","typescript"],"author":{"url":"http://github.com/zimme","name":"Simon Fridlund"},"license":"MIT","_id":"kanel-enum-tables@1.0.0","maintainers":[{"name":"kristiandupont","email":"kristian@kristiandupont.com"}],"homepage":"https://kristiandupont.github.io/kanel","bugs":{"url":"https://github.com/kristiandupont/kanel/issues"},"dist":{"shasum":"85738db8afdc329faf4150ef382584184dbdb0cb","tarball":"https://registry.npmjs.org/kanel-enum-tables/-/kanel-enum-tables-1.0.0.tgz","fileCount":8,"integrity":"sha512-4/bv2LkpCokgpDUY6GEvEjrDLaJNjfk6HzEC7Dfa2sH0RunzQMM3Nw+qxQJtJbMRVShSnjrBNQsRO0aITWA7pA==","signatures":[{"sig":"MEQCIBWreT+Ckt88B0kpXVDMILACNtM3a4a5/tuScvjYHWOyAiBlUsz92VxvtQ/UoeZW7kSZdwNPLZ+cZO2qnuWJUnlO2g==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":31710},"main":"build/index.js","types":"build/index.d.ts","gitHead":"5d7b462d2d244f0d72ba5338e2e6bcfaf8918c0c","scripts":{"test":"vitest run","build":"rm -rf ./build && tsc"},"_npmUser":{"name":"kristiandupont","email":"kristian@kristiandupont.com"},"repository":{"url":"git+https://github.com/kristiandupont/kanel.git","type":"git"},"_npmVersion":"10.7.0","description":"Kanel extension for generating enums from table values","directories":{},"_nodeVersion":"24.11.1","dependencies":{"knex":"^3.0.0","tagged-comment-parser":"^1.3.8"},"_hasShrinkwrap":false,"devDependencies":{"kanel":"*","vitest":"^4.0.0","extract-pg-schema":"^5.8.1"},"_npmOperationalInternal":{"tmp":"tmp/kanel-enum-tables_1.0.0_1771080163671_0.6640174812117137","host":"s3://npm-registry-packages-npm-production"}},"4.0.0":{"name":"kanel-enum-tables","version":"4.0.0","keywords":["enum","postgresql","schema","typescript"],"repository":{"type":"git","url":"git+https://github.com/kristiandupont/kanel.git"},"description":"Kanel extension for generating enums from table values","homepage":"https://kristiandupont.github.io/kanel","author":{"name":"Simon Fridlund","url":"http://github.com/zimme"},"main":"build/index.js","types":"build/index.d.ts","license":"MIT","scripts":{"build":"rm -rf ./build && tsc","test":"vitest run"},"dependencies":{"knex":"^3.0.0","tagged-comment-parser":"^1.3.8"},"devDependencies":{"extract-pg-schema":"^5.8.1","kanel":"*","vitest":"^4.0.0"},"_id":"kanel-enum-tables@4.0.0","gitHead":"a5b3df3f61ad0a159f38a04426d4929234173284","bugs":{"url":"https://github.com/kristiandupont/kanel/issues"},"_nodeVersion":"24.11.1","_npmVersion":"10.7.0","dist":{"integrity":"sha512-mxifAFckNrKz+nb8lhBE0UkWNIi47RA5V/tlUGiGAIHZ0wZ04fhauLfrVobH3PInvru6KtwH9zYxMIwzZi2LFA==","shasum":"b4936728ee797aaa1adaef71ee05438b94ed065a","tarball":"https://registry.npmjs.org/kanel-enum-tables/-/kanel-enum-tables-4.0.0.tgz","fileCount":8,"unpackedSize":31778,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDmPgSnpqL14WfB3JsZRjn/YZgT/jN9ec7VxVEwtHFWCAIhALoxq7chZ1+ZmTofahCRnku1+vck0POriUm5QaU+Supj"}]},"_npmUser":{"name":"kristiandupont","email":"kristian@kristiandupont.com"},"directories":{},"maintainers":[{"name":"kristiandupont","email":"kristian@kristiandupont.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/kanel-enum-tables_4.0.0_1775056808444_0.750450198645781"},"_hasShrinkwrap":false}},"time":{"created":"2026-02-14T14:42:43.670Z","modified":"2026-04-01T15:20:08.734Z","1.0.0":"2026-02-14T14:42:43.812Z","4.0.0":"2026-04-01T15:20:08.597Z"},"bugs":{"url":"https://github.com/kristiandupont/kanel/issues"},"author":{"name":"Simon Fridlund","url":"http://github.com/zimme"},"license":"MIT","homepage":"https://kristiandupont.github.io/kanel","keywords":["enum","postgresql","schema","typescript"],"repository":{"type":"git","url":"git+https://github.com/kristiandupont/kanel.git"},"description":"Kanel extension for generating enums from table values","maintainers":[{"name":"kristiandupont","email":"kristian@kristiandupont.com"}],"readme":"# Kanel extension to generate enum types from table values\n\nThis package extends [Kanel](https://github.com/kristiandupont/kanel) with the ability to generate enum types from table values.\n\nIt uses the [Postgraphile](https://www.graphile.org/postgraphile) concept of [enum tables](https://www.graphile.org/postgraphile/enums/#with-enum-tables).\n\n## Smart Comments\n\nMark a table as an enum table by adding a `@enum` tag to its comment:\n\n```sql\nCOMMENT ON TABLE animal_type IS '@enum';\n```\n\nYou can optionally rename the generated type with `@enumName`:\n\n```sql\nCOMMENT ON TABLE animal_type IS E'@enum\\n@enumName TypeOfAnimal';\n```\n\nBoth Postgraphile's space format and the colon format used by other Kanel extensions are supported:\n\n- `@enumName TypeOfAnimal` (Postgraphile convention)\n- `@enumName:TypeOfAnimal` (tagged-comment-parser convention)\n\n### `@enumDescription`\n\nYou can add per-value descriptions to your enum by tagging a column with `@enumDescription`. The values in that column will be rendered as JSDoc comments on each enum member.\n\n```sql\nCREATE TABLE animal_type (\n  type text PRIMARY KEY,\n  description text NOT NULL\n);\n\nCOMMENT ON TABLE animal_type IS '@enum';\nCOMMENT ON COLUMN animal_type.description IS '@enumDescription';\n\nINSERT INTO animal_type VALUES\n  ('cat', 'A small domesticated feline'),\n  ('dog', 'A loyal canine companion');\n```\n\nWith `enumStyle: \"enum\"` this generates:\n\n```typescript\nexport enum AnimalType {\n  /** A small domesticated feline */\n  cat = \"cat\",\n  /** A loyal canine companion */\n  dog = \"dog\",\n}\n```\n\nWith `enumStyle: \"type\"` (the default) this generates:\n\n```typescript\nexport type AnimalType =\n  /** A small domesticated feline */\n  | \"cat\"\n  /** A loyal canine companion */\n  | \"dog\";\n```\n\n## Installation\n\nAssuming you already have Kanel installed, add this with\n\n```bash\nnpm i -D kanel-enum-tables\n```\n\n## Usage\n\nAdd the hook to your `.kanelrc.js` file:\n\n```javascript\nconst { enumTablesPreRenderHook } = require(\"kanel-enum-tables\");\n\nmodule.exports = {\n  // ... your config here.\n\n  preRenderHooks: [enumTablesPreRenderHook],\n};\n```\n\n### With kanel-kysely\n\nWhen using [kanel-kysely](https://github.com/kristiandupont/kanel/tree/main/packages/kanel-kysely), place `enumTablesPreRenderHook` **before** the kysely hook for best results:\n\n```javascript\nconst { enumTablesPreRenderHook } = require(\"kanel-enum-tables\");\nconst { makeKyselyHook } = require(\"kanel-kysely\");\n\nmodule.exports = {\n  // ... your config here.\n\n  preRenderHooks: [enumTablesPreRenderHook, makeKyselyHook()],\n};\n```\n\nThe hook also works if placed after the kysely hook — it will detect the `ColumnType<>` wrappers and update them accordingly.\n","readmeFilename":"README.md"}