https://github.com/ridakk/flowize
generate FlowJS Types from Sequelize model definitions
https://github.com/ridakk/flowize
flow flowjs flowtype sequelize types
Last synced: about 1 year ago
JSON representation
generate FlowJS Types from Sequelize model definitions
- Host: GitHub
- URL: https://github.com/ridakk/flowize
- Owner: ridakk
- License: mit
- Created: 2021-01-17T16:49:49.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-01-19T18:51:41.000Z (over 5 years ago)
- Last Synced: 2025-03-30T04:01:38.195Z (about 1 year ago)
- Topics: flow, flowjs, flowtype, sequelize, types
- Language: JavaScript
- Homepage:
- Size: 85.9 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# flowize
Generate FlowJs Types from Sequelize model definitions
## Usage
```js
const flowize = require('flowize');
const sequelize = require('sequelize');
(async () => {
// make sure sequelize models are initialized and associated
await flowize(sequelize, {
outputPath: `${__dirname}/flow-typed`,
typePrefix: 'Type',
excludedModelNames: ['audit'],
typePerField: true,
});
process.exit();
})();
```
For below sequelize models;
```js
class Task extends Model {}
Task.init({
title: Sequelize.STRING,
},
{ sequelize, modelName: 'task' });
class User extends Model {}
User.init({
username: Sequelize.STRING
},
{ sequelize, modelName: 'user' });
User.hasMany(Task);
Task.belongsTo(User);
```
below FlowJs definitions will be created under `outputPath` option with in `.js` format.
TypeTitle.js
```js
declare type TypeTaskId = number;
declare type TypeTaskTitle = string;
type Title = {|
id: TypeTaskId,
title: TypeTaskTitle,
userId: TypeUserId,
user: TypeUser,
|};
declare type TypeTitle = $Shape;
```
TypeUser.js
```js
declare type TypeUserId = number;
type User = {|
id: TypeUserId,
tasks: TypeTitle[],
|};
declare type TypeUser = $Shape;
```