JSPM

flowize

0.0.3
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4
  • Score
    100M100P100Q20596F
  • License MIT

Generate FlowJs Types from Sequelize model definitions

Package Exports

  • flowize

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (flowize) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

flowize

Generate FlowJs Types from Sequelize model definitions

Usage

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;

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 <typePrefix><model name>.js format.

TypeTitle.js

declare type TypeTaskId = number;
declare type TypeTaskTitle = string;

type Title = {|
  id: TypeTaskId,
  title: TypeTaskTitle,
  userId: TypeUserId,
  user: TypeUser,
|};

declare type TypeTitle = $Shape<Title>;

TypeUser.js

declare type TypeUserId = number;

type User = {|
  id: TypeUserId,
  tasks: TypeTitle[],
|};

declare type TypeUser = $Shape<User>;