Lucid Parser
Parse Lucid models to retrieve properties types information
Lucid Parser is a tool to retrieve Lucid models properties information by parsing the AST Tree.
This become usefull when types information provided by Typescript metadatas are not sufficient as Lucid Parser is able to retrieve type information for nullable, optional and array properties.
Installation
npm install @foadonis/lucid-parserUsage
import { parseModel } from '@foadonis/lucid-parser'
const { columns, computed } = parseModel(import.meta.resolve('#models/user'))import { BaseModel, column, computed } from '@adonisjs/lucid/orm'
export default class User extends BaseModel {
@column({ isPrimary: true })
declare id: number
@column()
declare title: string | null
@column()
declare roles: string[]
@computed()
get isAdmin(): boolean {
return roles.includes('admin')
}
}{
"columns": [
{
"key": "id",
"type": "number",
"isOptional": false,
"isNullable": false,
"isArray": false
},
{
"key": "title",
"type": "string",
"isOptional": false,
"isNullable": true,
"isArray": false
},
{
"key": "roles",
"type": "string",
"isOptional": false,
"isNullable": false,
"isArray": true
}
],
"computed": [
{
"key": "isAdmin",
"type": "boolean",
"isOptional": false,
"isNullable": false
"isArray": false
}
]
}