npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@naiv/codegen-nodejs-typeorm

v0.0.1

Published

0. Build project (on this project) ```bash npm run build ```

Readme

How to test

  1. Build project (on this project)
npm run build

build action will create codegen-nodejs-typeorm binary and accessible from terminal.

  1. Create testing folder
mkdir naiv-test-server
cd naiv-test-server
  1. Init Typescript Project
npm init -y
npm install --save-dev typescript
  1. Modify package.json script
  "scripts": {
    "typeorm": "typeorm-ts-node-commonjs",
    "generate-migration": "npm run typeorm migration:generate -- $1 -d ./data-source.ts",
    "migrate": "npm run typeorm migration:run -- -d ./data-source.ts",
    "codegen": "codegen-nodejs-typeorm -d design -o types",
    "codegen-init": "npx ts-node ./generate-initial-api.ts",
    "build": "rm -rf dist && tsc",
    "start": "node dist",
    "dev": "npm run build && npm start"
  },
  1. Create TS-Config file
{
  // Visit https://aka.ms/tsconfig to read more about this file
  "compilerOptions": {

    // Environment Settings
    // See also https://aka.ms/tsconfig/module
    "module": "nodenext",
    "target": "esnext",
    "types": ["node"],

    // Stricter Typechecking Options
    "noUncheckedIndexedAccess": true,
    "exactOptionalPropertyTypes": true,

    // Recommended Options
    "strict": true,
    "jsx": "react-jsx",
    "verbatimModuleSyntax": false,
    "isolatedModules": true,
    "noUncheckedSideEffectImports": true,
    "moduleDetection": "force",
    "skipLibCheck": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "outDir": "dist"
  }
}
  1. Install dependency
npm install --save express cors class-validator class-transformer
npm install --save-dev @types/express @types/cors
  1. Create generate-initial-api.ts
import * as fs from 'fs';
import * as path from 'path';

function getAllTsFiles(dir: string): string[] {
  const files = fs.readdirSync(dir, { withFileTypes: true });
  const tsFiles: string[] = [];

  for (const file of files) {
    if (file.isFile() && file.name.endsWith('.ts')) {
      tsFiles.push(file.name);
      const filePath = path.resolve(`./implementation/${file.name}`);
      if (fs.existsSync(filePath)) {
        console.log(`✅ File already exists: ${filePath}`);
      } else {
        const [fn] = file.name.split('.');
        const prefix = fn?.slice(0, 2);
        const only_name = fn?.slice(2);
        const is_streaming = prefix == 'S_';
        fs.writeFileSync(filePath, `\
import { ${prefix}${only_name} } from "../types/api/${prefix}${only_name}";

export const ${prefix?.toLowerCase()}${only_name}: ${prefix}${only_name} = async ${is_streaming ? '(req, stream, res)' : '(req, res)'} => {
  throw new Error('Implement this');
}
`, 'utf8');
        console.log(`📝 File created: ${filePath}`);
      }
    }
  }

  return tsFiles;
}

console.log(getAllTsFiles('./types/api'));
  1. Create simple api design design/api.naiv
schema Z {
  data string required
}

api get /test-streaming {
  alias testX
  query {
    q string
  }
  return stream of string required
}

api get /common-api {
  alias getY
  query {
    limit number
    offset number
  }
  return array string required
}
  1. Generate code
npm run codegen
  1. Generate code-stub
npm run codegen-init
  1. Copy server.ts from this project to naiv-test-server project

  2. Create index.ts

import path from 'path';
import { Server } from './server';

const server = new Server();
server.run({
  port: +(process.env.PORT ?? 9415),
  types_path: path.resolve(__dirname, 'types'),
  implementation_path: path.resolve(__dirname, 'implementation'),
  async beforeStart() {
    console.log('before start script.')
  }
});
  1. Implement logic
import { S_testX } from "../types/api/S_testX";

export const s_testX: S_testX = async (req, stream, res) => {
  stream(req.query.q ?? 'no query');
  stream('\n');
  stream('aaa\n');
  await new Promise(resolve => setTimeout(resolve, 1000));
  stream('ccc\n');
  await new Promise(resolve => setTimeout(resolve, 1000));
  stream('bbb\n');
  await new Promise(resolve => setTimeout(resolve, 1000));
  stream('eee\n');
  await new Promise(resolve => setTimeout(resolve, 1000));
  stream('ddd\n');
  await new Promise(resolve => setTimeout(resolve, 1000));
  stream('fff\n');
  await new Promise(resolve => setTimeout(resolve, 1000));
}
import { T_getY } from "../types/api/T_getY";

export const t_getY: T_getY = async (req, res) => {
  return ['nice'];
}
  1. curl testing
curl localhost:9415/test-streaming?q=lorem-ipsum -N
curl localhost:9415/common-api