Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
schema-typegen
Advanced tools
Generate TypeScript type definitions from database schema.
npm install schema-typegen
For now only Postgres is supported.
Usage: schema-typegen [opts] connection_string
Example:
schema-typegen -o ./entities.ts postgres://username:password@localhost:5432/database
Available options:
-f/--suffix SUFFIX
Suffix to append to generated table type, e.g. item -> ItemEntity. Default: 'Entity'.
-s/--schema SCHEMA
Schema. Default: 'public'.
-h/--header HEADER
Header content. Default: ''.
-o/--output OUTPUT_PATH
Output path, e.g. './entities.ts'. Default: outputs to stdout.
-e/--exclude EXCLUDE
Excluded tables and enums as comma separated string e.g. knex_migrations,knex_migrations_lock Default: ''.
--types
Use type definitions instead of interfaces in generated output. Default: false.
--no-semicolons
Omit semicolons in generated types. Default: false.
--ssl
Use ssl. Default: false.
--optionals
Use optionals "?" instead of null. Default: false.
--pascal-enums
Transform enum keys to pascal case. Default: false.
--bigint
Use bigint for int8 types instead of strings. Default: false.
-v/--version
Print the version number.
-h/--help
Print this menu.
Given database table
CREATE TYPE user_state AS ENUM (
'asleep',
'awake'
);
CREATE TABLE users (
id int4 NOT NULL,
name varchar(255),
state user_state,
is_enabled bool NOT NULL DEFAULT FALSE
);
Running schema-typegen -o ./entities.ts postgres://username:password@localhost:5432/database
Will generate the following type definitions
enum UserState {
asleep = 'asleep',
awake = 'awake'
}
interface UserEntity {
id: number;
name: string | null;
state: UserState | null;
is_enabled: boolean;
}
import { join } from 'path'
import generate from 'schema-typegen'
;(async () => {
const output = join(__dirname, 'entities.ts')
await generate({ connection: 'postgres://username:password@localhost:5432/database', output })
})()
export $(grep -v '^#' .env | xargs) && schema-typegen -o ./entities.ts postgres://$DB_USERNAME:$DB_PASSWORD@$DB_HOST:$DB_PORT/$DB_NAME
schema-typegen -o ./entities.ts postgres://$(jq -r '.DB.USERNAME' config.json):$(jq -r '.DB.PASSWORD' config.json)@$(jq -r '.DB.HOST' config.json):$(jq -r '.DB.PORT' config.json)/$(jq -r '.DB.NAME' config.json)
docker-compose up -d
npm test
Contributions, issues and feature requests are welcome!
Copyright © 2020 Aldis Ameriks.
This project is MIT licensed.
FAQs
Generate TypeScript type definitions from database schema
The npm package schema-typegen receives a total of 2 weekly downloads. As such, schema-typegen popularity was classified as not popular.
We found that schema-typegen demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.