open-index/open-npm huggingface dataset:
npm package: @madxnl/madhatter-cli
Description: Madhatter CLI
Latest version: 0.5.10

# madhatter-cli

BUGS:
  - (Maybe) we want to return not the Schema but the Model itself. `extended-service.ts.hbs:14 ({{tsResolverReturnType fn}})`

TODO:
	- Required relations
  - Make sure that Query is also supported
  - Named relations
    - bag.activeWorkout
    - bag.workouts
    - workout.bag

Long term TODO's
	- ValidationRules based on InputSchema
	- optional enums

## How to use
Install
```javascript
npm install @madxnl/madhatter-cli
```

Run
```javascript
npm madhatter generate
```

Before running it you need to create a config file in the root of your project.

Example config file:
```yml
modules:
  - name: User
    models:
      - name: User
        fields:
          - "firstName: string"
          - "lastName?: string"
          - "email: @unique string"
          - "lastLoggedIn?: Date"
          - "emailVerified: boolean: false"
          - "icon?: ~File"
          - "teams: *Team[]"
```

The above example would generate a `User` module, with a `user.models.ts`, `user.service.ts`, and `user.resolver.ts` file.

The `User` model would be defined as such:
```typescript
@Entity()
export class User extends BaseModel {
	_modelName = 'user'

	@Column()
	firstName: string

	@Column({ nullable: true })
	lastName: string

	@Column({ unique: true })
	email: string

	@Column({ nullable: true })
	lastLoggedIn: Date

	@Column({ default: false })
	emailVerified: boolean

	@OneToOne(() => File, { nullable: true })
	@JoinColumn()
	icon: File

	@ManyToMany(() => Team, o => o.users)
	@JoinTable()
	teams: Team[]
}
```

The above example demonstrates how to:
- Distinguish between required and optional fields (`?` sign)
- Define a field as unique (`@unique`)
- Define a field with default value (`: false`)
- Define a relation explicitly as `OneToOne` or `ManyToMany` (`@OneToOne` and `@ManyToMany`)

In every other case the CLI will infer the type of relation (`@OneToMany` or `@ManyToOne`).


## New version

```
npm version <nummer>
git push && git push --tags
```


## Usage permission flow.

Convert .ts or .dart files to .graphql files:
```
#.ts
yarn run cli file-to-graphql example.ts
#.dart
yarn run cli file-to-graphql example.dart output/all.graphql
```

Convert directory of GraphQL, ts, and/or .dart files to a single GraphQL file:
```
yarn run cli folder-to-graphql ../goose-windows-app/GraphQLClient/ ./output/windows.graphql [graphql,ts,dart]
```

Convert directory of GraphQL files to a single GraphQL file:
```
yarn run cli folder-to-graphql ../goose-windows-app/GraphQLClient/ ./output/windows.graphql [graphql]
```


Convert Graphql to node permission list:
```
yarn run cli graphql-to-permissions output/all.graphql
```