├── .eslintrc.cjs ├── .github └── workflows │ └── push.yml ├── .gitignore ├── .npmignore ├── .npmrc ├── .releaserc ├── LICENSE ├── README.md ├── commitlint.config.cjs ├── package.json ├── src ├── Adapter.ts ├── Database.ts ├── Property.ts ├── Resource.ts ├── dialects │ ├── base-database.parser.ts │ ├── index.ts │ ├── mysql.parser.ts │ ├── postgres.parser.ts │ └── types │ │ └── index.ts ├── index.ts └── metadata │ ├── DatabaseMetadata.ts │ ├── ResourceMetadata.ts │ └── index.ts ├── tsconfig.json └── yarn.lock /.eslintrc.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parser: '@typescript-eslint/parser', 3 | plugins: ['@typescript-eslint'], 4 | env: { 5 | es6: true, 6 | node: true, 7 | }, 8 | extends: ['airbnb', 'plugin:@typescript-eslint/recommended'], 9 | parserOptions: { 10 | ecmaVersion: 20, 11 | sourceType: 'module', 12 | }, 13 | rules: { 14 | 'react/jsx-filename-extension': 'off', 15 | '@typescript-eslint/no-explicit-any': 'off', 16 | indent: ['error', 2], 17 | 'max-len': ['error', 120], 18 | '@typescript-eslint/explicit-function-return-type': 'off', 19 | '@typescript-eslint/no-non-null-assertion': 'off', 20 | '@typescript-eslint/ban-ts-ignore': 'off', 21 | 'import/prefer-default-export': 'off', 22 | 'linebreak-style': ['error', 'unix'], 23 | quotes: ['error', 'single'], 24 | semi: ['error', 'always'], 25 | 'import/no-unresolved': 'off', 26 | 'func-names': 'off', 27 | 'no-underscore-dangle': 'off', 28 | 'guard-for-in': 'off', 29 | 'no-restricted-syntax': 'off', 30 | 'no-await-in-loop': 'off', 31 | 'object-curly-newline': 'off', 32 | 'import/extensions': 'off', 33 | 'no-param-reassign': 'off', 34 | 'default-param-last': 'off', 35 | 'no-use-before-define': 'off', 36 | 'no-restricted-exports': 'off', 37 | 'react/require-default-props': 'off', 38 | 'react/jsx-props-no-spreading': 'off', 39 | 'react/function-component-definition': 'off', 40 | 'max-classes-per-file': 'off', 41 | '@typescript-eslint/ban-ts-comment': 'off', 42 | 'import/no-import-module-exports': 'off', 43 | 'no-shadow': 'off', 44 | 'import/no-extraneous-dependencies': 'off', 45 | 'consistent-return': 'off', 46 | 'import/order': [ 47 | 'error', 48 | { 49 | groups: ['builtin', 'external', 'parent', 'sibling', 'index'], 50 | 'newlines-between': 'always', 51 | }, 52 | ], 53 | }, 54 | }; 55 | -------------------------------------------------------------------------------- /.github/workflows/push.yml: -------------------------------------------------------------------------------- 1 | name: CI/CD 2 | on: [push, pull_request] 3 | jobs: 4 | setup: 5 | name: setup 6 | runs-on: ubuntu-latest 7 | steps: 8 | - name: Checkout 9 | uses: actions/checkout@v2 10 | - name: Setup 11 | uses: actions/setup-node@v2 12 | with: 13 | node-version: '18' 14 | - uses: actions/cache@v2 15 | id: yarn-cache 16 | with: 17 | path: node_modules 18 | key: ${{ runner.os }}-node_modules-${{ hashFiles('**/yarn.lock') }} 19 | restore-keys: | 20 | ${{ runner.os }}-node_modules- 21 | - name: Install 22 | if: steps.yarn-cache.outputs.cache-hit != 'true' 23 | run: yarn install 24 | 25 | test: 26 | name: Test 27 | runs-on: ubuntu-latest 28 | needs: setup 29 | steps: 30 | - name: Checkout 31 | uses: actions/checkout@v2 32 | - name: Setup 33 | uses: actions/setup-node@v2 34 | with: 35 | node-version: '18' 36 | - uses: actions/cache@v2 37 | id: yarn-cache 38 | with: 39 | path: node_modules 40 | key: ${{ runner.os }}-node_modules-${{ hashFiles('**/yarn.lock') }} 41 | restore-keys: | 42 | ${{ runner.os }}-node_modules- 43 | - name: Install 44 | if: steps.yarn-cache.outputs.cache-hit != 'true' 45 | run: yarn install 46 | - name: Lint 47 | run: yarn lint 48 | 49 | publish: 50 | name: Publish 51 | needs: test 52 | runs-on: ubuntu-latest 53 | steps: 54 | - name: Checkout 55 | uses: actions/checkout@v2 56 | - name: Setup 57 | uses: actions/setup-node@v2 58 | with: 59 | node-version: '18' 60 | - uses: actions/cache@v2 61 | id: yarn-cache 62 | with: 63 | path: node_modules 64 | key: ${{ runner.os }}-node_modules-${{ hashFiles('**/yarn.lock') }} 65 | restore-keys: | 66 | ${{ runner.os }}-node_modules- 67 | - name: Install 68 | if: steps.yarn-cache.outputs.cache-hit != 'true' 69 | run: yarn install 70 | - name: build 71 | run: yarn build 72 | - name: Release 73 | env: 74 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }} 75 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 76 | SLACK_WEBHOOK: ${{ secrets.ADMIN_SLACK_WEBHOOK }} 77 | run: yarn release -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | 106 | lib 107 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | \.idea/ 2 | node_modules/ 3 | spec/ 4 | example-app/ 5 | src/ 6 | package-lock\.json 7 | *.db 8 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | access=public 2 | -------------------------------------------------------------------------------- /.releaserc: -------------------------------------------------------------------------------- 1 | { 2 | "branches": [ 3 | "main", 4 | { "name": "beta", "channel": "beta", "prerelease": true } 5 | ], 6 | "plugins": [ 7 | "@semantic-release/commit-analyzer", 8 | "@semantic-release/release-notes-generator", 9 | "@semantic-release/npm", 10 | "@semantic-release/github", 11 | "@semantic-release/git", 12 | [ 13 | "semantic-release-slack-bot", 14 | { 15 | "notifyOnSuccess": true, 16 | "notifyOnFail": false 17 | } 18 | ] 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 AdminJS 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # @adminjs/sql 2 | 3 | This is an official AdminJS adapter for SQL databases. It does not require you to use any ORMs, instead you just provide database connection and you model the data sources using AdminJS configuration. 4 | 5 | Supported databases: 6 | - PostgreSQL 7 | - MySQL 8 | - more coming soon 9 | 10 | This adapter is heavily inspired by [wirekang's adminjs-sql](https://github.com/wirekang/adminjs-sql) which is an unofficial adapter for a MySQL database. 11 | 12 | # Installation 13 | 14 | ```bash 15 | $ yarn add @adminjs/sql 16 | ``` 17 | 18 | # Usage with Express 19 | 20 | The example below shows usage with `@adminjs/express`. The usage of `Adapter` class is required to parse your database's schema. 21 | 22 | ```typescript 23 | import AdminJS from 'adminjs' 24 | import express from 'express' 25 | import Plugin from '@adminjs/express' 26 | import Adapter, { Database, Resource } from '@adminjs/sql' 27 | 28 | AdminJS.registerAdapter({ 29 | Database, 30 | Resource, 31 | }) 32 | 33 | const start = async () => { 34 | const app = express() 35 | 36 | const db = await new Adapter('postgresql', { 37 | connectionString: '', // postgresql://[user]:[password]@[netloc]:[port]/[dbname] 38 | database: '', 39 | }).init(); 40 | 41 | const admin = new AdminJS({ 42 | resources: [ 43 | { 44 | resource: db.table('users'), 45 | options: { /* any resource options, rbac, etc */ }, 46 | }, 47 | ], 48 | // databases: [db] <- you can also provide the DB connection to register all tables at once 49 | }); 50 | 51 | admin.watch() 52 | 53 | const router = Plugin.buildRouter(admin) 54 | 55 | app.use(admin.options.rootPath, router) 56 | 57 | app.listen(8080, () => { 58 | console.log('app started') 59 | }) 60 | } 61 | 62 | start() 63 | ``` 64 | 65 | # Database Relations 66 | 67 | Currently only `many-to-one` relation works out of the box if you specify foreign key constraints in your database. Other relations will require you to make UI/backend customizations. Please see our [documentation](https://docs.adminjs.co) to learn more. 68 | 69 | # Enums 70 | 71 | As of version `1.0.0` database enums aren't automatically detected and loaded. You can assign them manually in your resource options: 72 | 73 | ```typescript 74 | // ... 75 | const admin = new AdminJS({ 76 | resources: [{ 77 | resource: db.table('users'), 78 | options: { 79 | properties: { 80 | role: { 81 | availableValues: [ 82 | { label: 'Admin', value: 'ADMIN' }, 83 | { label: 'Client', value: 'CLIENT' }, 84 | ], 85 | }, 86 | }, 87 | }, 88 | }], 89 | }) 90 | // ... 91 | ``` 92 | 93 | # Timestamps 94 | 95 | If your database tables have automatically default-set timestamps (`created_at`, `updated_at`, etc) they will be visible in create/edit forms by default. You can hide them in resource options: 96 | 97 | ```typescript 98 | // ... 99 | const admin = new AdminJS({ 100 | resources: [{ 101 | resource: db.table('users'), 102 | options: { 103 | properties: { 104 | created_at: { isVisible: false }, 105 | }, 106 | }, 107 | }], 108 | }) 109 | // ... 110 | ``` 111 | 112 | ## License 113 | 114 | AdminJS is copyrighted © 2023 rst.software. It is a free software, and may be redistributed under the terms specified in the [LICENSE](LICENSE.md) file. 115 | 116 | ## About rst.software 117 | 118 | 119 | 120 | We’re an open, friendly team that helps clients from all over the world to transform their businesses and create astonishing products. 121 | 122 | * We are available for [hire](https://www.rst.software/estimate-your-project). 123 | * If you want to work for us - check out the [career page](https://www.rst.software/join-us). 124 | -------------------------------------------------------------------------------- /commitlint.config.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: [ 3 | '@commitlint/config-conventional', 4 | ], 5 | }; 6 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@adminjs/sql", 3 | "version": "2.2.6", 4 | "type": "module", 5 | "exports": { 6 | ".": { 7 | "import": "./lib/index.js", 8 | "types": "./lib/index.d.ts" 9 | } 10 | }, 11 | "repository": "git@github.com:SoftwareBrothers/adminjs-sql.git", 12 | "author": "Rafal Dziegielewski ", 13 | "license": "MIT", 14 | "keywords": [ 15 | "sql", 16 | "postgres", 17 | "adminjs", 18 | "admin panel", 19 | "database", 20 | "adapter" 21 | ], 22 | "description": "An official AdminJS adapter for SQL databases.", 23 | "scripts": { 24 | "clean": "rimraf lib", 25 | "build": "tsc", 26 | "lint": "eslint './src/**/*.{ts,js}' --ignore-pattern 'build' --ignore-pattern 'yarn.lock'", 27 | "release": "semantic-release" 28 | }, 29 | "devDependencies": { 30 | "@commitlint/cli": "^17.4.4", 31 | "@commitlint/config-conventional": "^17.4.4", 32 | "@semantic-release/git": "^10.0.1", 33 | "@typescript-eslint/eslint-plugin": "^5.55.0", 34 | "@typescript-eslint/parser": "^5.55.0", 35 | "adminjs": "^7.0.0", 36 | "eslint": "^8.36.0", 37 | "eslint-config-airbnb": "^19.0.4", 38 | "eslint-plugin-import": "^2.27.5", 39 | "eslint-plugin-jsx-a11y": "^6.7.1", 40 | "eslint-plugin-react": "^7.32.2", 41 | "eslint-plugin-react-hooks": "^4.6.0", 42 | "husky": "^4.2.5", 43 | "rimraf": "^4.4.0", 44 | "semantic-release": "^20.1.3", 45 | "semantic-release-slack-bot": "^4.0.0", 46 | "ts-node": "^10.9.1", 47 | "typescript": "^4.9.5" 48 | }, 49 | "dependencies": { 50 | "knex": "^2.4.2", 51 | "mysql2": "^3.3.3", 52 | "pg": "^8.10.0" 53 | }, 54 | "peerDependencies": { 55 | "adminjs": "^7.0.0" 56 | }, 57 | "husky": { 58 | "hooks": { 59 | "commit-msg": "commitlint -E HUSKY_GIT_PARAMS" 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Adapter.ts: -------------------------------------------------------------------------------- 1 | import { Database as SqlDatabase } from './Database.js'; 2 | import { DatabaseDialect, parse } from './dialects/index.js'; 3 | import { ConnectionOptions } from './dialects/types/index.js'; 4 | import { Property as SqlProperty } from './Property.js'; 5 | import { Resource as SqlResource } from './Resource.js'; 6 | 7 | export class Adapter { 8 | public static Resource: SqlResource; 9 | 10 | public static Database: SqlDatabase; 11 | 12 | public static Property: SqlProperty; 13 | 14 | private dialect: DatabaseDialect; 15 | 16 | private connection: ConnectionOptions; 17 | 18 | constructor(dialect: DatabaseDialect, connection: ConnectionOptions) { 19 | this.dialect = dialect; 20 | this.connection = connection; 21 | } 22 | 23 | public async init() { 24 | return parse(this.dialect, this.connection); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Database.ts: -------------------------------------------------------------------------------- 1 | import { BaseDatabase } from 'adminjs'; 2 | 3 | import { DatabaseMetadata } from './metadata/index.js'; 4 | import { Resource } from './Resource.js'; 5 | 6 | export class Database extends BaseDatabase { 7 | public static override isAdapterFor(info: any): boolean { 8 | return info instanceof DatabaseMetadata; 9 | } 10 | 11 | constructor(private readonly info: DatabaseMetadata) { 12 | super(info.database); 13 | } 14 | 15 | override resources(): Resource[] { 16 | const tables = this.info.tables(); 17 | 18 | return tables.map((metadata) => new Resource(metadata)); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Property.ts: -------------------------------------------------------------------------------- 1 | import { BaseProperty, PropertyType } from 'adminjs'; 2 | 3 | export type ColumnInfo = { 4 | name: string; 5 | isId: boolean; 6 | position: number; 7 | defaultValue?: string | number | boolean; 8 | isNullable: boolean; 9 | isEditable: boolean; 10 | type: PropertyType; 11 | referencedTable: string | null; 12 | availableValues?: string[] | null; 13 | } 14 | 15 | export class Property extends BaseProperty { 16 | private readonly _isPrimary: boolean; 17 | 18 | private readonly _isNullable: boolean; 19 | 20 | private readonly _isEditable: boolean; 21 | 22 | private readonly _referencedTable: string | null; 23 | 24 | private readonly _name: string; 25 | 26 | private readonly _availableValues?: string[] | null; 27 | 28 | constructor(column: ColumnInfo) { 29 | const { 30 | name, 31 | isId, 32 | position, 33 | isNullable, 34 | isEditable, 35 | type, 36 | referencedTable, 37 | availableValues, 38 | } = column; 39 | 40 | super({ 41 | path: name, 42 | isId, 43 | position, 44 | type, 45 | }); 46 | 47 | this._name = name; 48 | this._isPrimary = isId; 49 | this._isNullable = isNullable; 50 | this._isEditable = isEditable; 51 | this._referencedTable = referencedTable; 52 | this._availableValues = availableValues; 53 | } 54 | 55 | override isId(): boolean { 56 | return this._isPrimary; 57 | } 58 | 59 | override name(): string { 60 | return this._name; 61 | } 62 | 63 | override path(): string { 64 | return this._name; 65 | } 66 | 67 | override isEditable(): boolean { 68 | return this._isEditable && !this.isId(); 69 | } 70 | 71 | override reference(): string | null { 72 | return this._referencedTable; 73 | } 74 | 75 | // eslint-disable-next-line class-methods-use-this 76 | override availableValues(): Array | null { 77 | if (this._availableValues) return this._availableValues; 78 | 79 | return null; 80 | } 81 | 82 | // eslint-disable-next-line class-methods-use-this 83 | override subProperties(): BaseProperty[] { 84 | return []; 85 | } 86 | 87 | override isRequired(): boolean { 88 | return !this._isNullable; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/Resource.ts: -------------------------------------------------------------------------------- 1 | import { 2 | BaseRecord, 3 | BaseResource, 4 | Filter, 5 | ParamsType, 6 | SupportedDatabasesType, 7 | } from 'adminjs'; 8 | import type { Knex } from 'knex'; 9 | 10 | import { ResourceMetadata } from './metadata/index.js'; 11 | import { Property } from './Property.js'; 12 | import { DatabaseDialect } from './dialects/index.js'; 13 | 14 | export class Resource extends BaseResource { 15 | static override isAdapterFor(resource: any): boolean { 16 | return resource instanceof ResourceMetadata; 17 | } 18 | 19 | private knex: Knex; 20 | 21 | private dialect: DatabaseDialect; 22 | 23 | private propertyMap = new Map(); 24 | 25 | private tableName: string; 26 | 27 | private schemaName: string | null; 28 | 29 | private _database: string; 30 | 31 | private _properties: Property[]; 32 | 33 | private idColumn: string; 34 | 35 | constructor(info: ResourceMetadata) { 36 | super(info.tableName); 37 | this.knex = info.knex; 38 | this.schemaName = info.schemaName; 39 | this.tableName = info.tableName; 40 | this._database = info.database; 41 | this._properties = info.properties; 42 | this._properties.forEach((p) => { 43 | this.propertyMap.set(p.path(), p); 44 | }); 45 | this.idColumn = info.idProperty.path(); 46 | this.dialect = info.dialect; 47 | } 48 | 49 | override databaseName(): string { 50 | return this._database; 51 | } 52 | 53 | // eslint-disable-next-line class-methods-use-this 54 | override databaseType(): SupportedDatabasesType | string { 55 | return 'Postgres'; 56 | } 57 | 58 | override id(): string { 59 | return this.tableName; 60 | } 61 | 62 | override properties(): Property[] { 63 | return this._properties; 64 | } 65 | 66 | override property(path: string): Property | null { 67 | return this.propertyMap.get(path) ?? null; 68 | } 69 | 70 | override async count(filter: Filter): Promise { 71 | const [r] = await this.filterQuery(filter).count('* as cnt'); 72 | return r.cnt; 73 | } 74 | 75 | override async find( 76 | filter: Filter, 77 | options: { 78 | limit?: number; 79 | offset?: number; 80 | sort?: { 81 | sortBy?: string; 82 | direction?: 'asc' | 'desc'; 83 | }; 84 | }, 85 | ): Promise { 86 | const query = this.filterQuery(filter); 87 | if (options.limit) { 88 | query.limit(options.limit); 89 | } 90 | if (options.offset) { 91 | query.offset(options.offset); 92 | } 93 | if (options.sort?.sortBy) { 94 | query.orderBy(options.sort.sortBy, options.sort.direction); 95 | } 96 | const rows: any[] = await query; 97 | return rows.map((row) => new BaseRecord(row, this)); 98 | } 99 | 100 | override async findOne(id: string): Promise { 101 | const knex = this.schemaName 102 | ? this.knex(this.tableName).withSchema(this.schemaName) 103 | : this.knex(this.tableName); 104 | const res = await knex.where(this.idColumn, id); 105 | return res[0] ? this.build(res[0]) : null; 106 | } 107 | 108 | override async findMany(ids: (string | number)[]): Promise { 109 | const knex = this.schemaName 110 | ? this.knex(this.tableName).withSchema(this.schemaName) 111 | : this.knex(this.tableName); 112 | const res = await knex.whereIn(this.idColumn, ids); 113 | return res.map((r) => this.build(r)); 114 | } 115 | 116 | override build(params: Record): BaseRecord { 117 | return new BaseRecord(params, this); 118 | } 119 | 120 | override async create(params: Record): Promise { 121 | const knex = this.schemaName 122 | ? this.knex(this.tableName).withSchema(this.schemaName) 123 | : this.knex(this.tableName); 124 | await knex.insert(params); 125 | 126 | return params; 127 | } 128 | 129 | override async update( 130 | id: string, 131 | params: Record, 132 | ): Promise { 133 | const knex = this.schemaName 134 | ? this.knex.withSchema(this.schemaName) 135 | : this.knex; 136 | 137 | await knex.from(this.tableName).update(params).where(this.idColumn, id); 138 | 139 | const knexQb = this.schemaName 140 | ? this.knex(this.tableName).withSchema(this.schemaName) 141 | : this.knex(this.tableName); 142 | const [row] = await knexQb.where(this.idColumn, id); 143 | return row; 144 | } 145 | 146 | override async delete(id: string): Promise { 147 | const knex = this.schemaName 148 | ? this.knex.withSchema(this.schemaName) 149 | : this.knex; 150 | await knex.from(this.tableName).delete().where(this.idColumn, id); 151 | } 152 | 153 | private filterQuery(filter: Filter | undefined): Knex.QueryBuilder { 154 | const knex = this.schemaName 155 | ? this.knex(this.tableName).withSchema(this.schemaName) 156 | : this.knex(this.tableName); 157 | const q = knex; 158 | 159 | if (!filter) { 160 | return q; 161 | } 162 | 163 | const { filters } = filter; 164 | 165 | Object.entries(filters ?? {}).forEach(([key, filter]) => { 166 | if ( 167 | typeof filter.value === 'object' 168 | && ['date', 'datetime'].includes(filter.property.type()) 169 | ) { 170 | q.whereBetween(key, [filter.value.from, filter.value.to]); 171 | } else if (filter.property.type() === 'string' && !filter.property.availableValues()) { 172 | if (this.dialect === 'postgresql') { 173 | q.whereILike(key, `%${filter.value}%`); 174 | } else { 175 | q.whereLike(key, `%${filter.value}%`); 176 | } 177 | } else { 178 | q.where(key, filter.value); 179 | } 180 | }); 181 | 182 | return q; 183 | } 184 | } 185 | -------------------------------------------------------------------------------- /src/dialects/base-database.parser.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-unused-vars */ 2 | /* eslint-disable class-methods-use-this */ 3 | import type { Knex } from 'knex'; 4 | import KnexModule from 'knex'; 5 | 6 | import { DatabaseMetadata, ResourceMetadata } from '../metadata/index.js'; 7 | 8 | import { ConnectionOptions, DatabaseDialect } from './types/index.js'; 9 | 10 | const KnexConnection = KnexModule.knex; 11 | 12 | export class BaseDatabaseParser { 13 | protected knex: Knex; 14 | 15 | protected dialect: DatabaseDialect; 16 | 17 | protected connectionOptions: ConnectionOptions; 18 | 19 | public static dialects: DatabaseDialect[]; 20 | 21 | constructor( 22 | dialect: DatabaseDialect, 23 | connection: ConnectionOptions, 24 | ) { 25 | if (!connection.database) { 26 | throw new Error('Please provide your database'); 27 | } 28 | 29 | const knex = KnexConnection({ 30 | client: dialect, 31 | connection, 32 | }); 33 | 34 | this.dialect = dialect; 35 | this.connectionOptions = connection; 36 | this.knex = knex; 37 | } 38 | 39 | public async parse(): Promise { 40 | throw new Error('Implement "parse" method for your database parser!'); 41 | } 42 | 43 | public async getSchema(): Promise { 44 | throw new Error('Implement "getSchema" method for your database parser!'); 45 | } 46 | 47 | public async getTables(schemaName: string): Promise { 48 | throw new Error('Implement "getTables" method for your database parser!'); 49 | } 50 | 51 | public async getResources(tables: string[], schemaName: string): Promise { 52 | throw new Error('Implement "getResources" method for your database parser!'); 53 | } 54 | 55 | public async getProperties(table: string, schemaName: string): Promise { 56 | throw new Error('Implement "getProperties" method for your database parser!'); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/dialects/index.ts: -------------------------------------------------------------------------------- 1 | import { BaseDatabaseParser } from './base-database.parser.js'; 2 | import { MysqlParser } from './mysql.parser.js'; 3 | import { PostgresParser } from './postgres.parser.js'; 4 | import { ConnectionOptions, DatabaseDialect } from './types/index.js'; 5 | 6 | export * from './types/index.js'; 7 | 8 | const parsers: (typeof BaseDatabaseParser)[] = [PostgresParser, MysqlParser]; 9 | 10 | export function parse(dialect: DatabaseDialect, connection: ConnectionOptions) { 11 | const Parser = parsers.find((p) => p.dialects.includes(dialect)); 12 | 13 | if (!Parser) { 14 | throw new Error(`${dialect} is not supported.`); 15 | } 16 | 17 | return new Parser(dialect, connection).parse(); 18 | } 19 | -------------------------------------------------------------------------------- /src/dialects/mysql.parser.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * MySQL parser originally authored by https://github.com/wirekang 3 | * Source: https://github.com/wirekang/adminjs-sql/blob/main/src/parser/mysql.ts 4 | */ 5 | import { PropertyType } from 'adminjs'; 6 | 7 | import { DatabaseMetadata, ResourceMetadata } from '../metadata/index.js'; 8 | import { ColumnInfo, Property } from '../Property.js'; 9 | 10 | import { BaseDatabaseParser } from './base-database.parser.js'; 11 | 12 | const getColumnInfo = (column: Record): ColumnInfo => { 13 | const type = column.DATA_TYPE.toLowerCase(); 14 | const columnType = column.COLUMN_TYPE.toLowerCase(); 15 | 16 | let availableValues: string[] | null = null; 17 | if (type === 'set' || type === 'enum') { 18 | if (!columnType.startsWith(type)) { 19 | throw new Error(`Unknown column type: ${type}`); 20 | } 21 | availableValues = columnType 22 | .split(type)[1] 23 | .replace(/^\('/, '') 24 | .replace(/'\)$/, '') 25 | .split('\',\''); 26 | } 27 | const reference = column.REFERENCED_TABLE_NAME; 28 | const isId = column.COLUMN_KEY.toLowerCase() === 'pri'; 29 | const isNullable = column.IS_NULLABLE.toLowerCase() !== 'no'; 30 | 31 | return { 32 | name: column.COLUMN_NAME, 33 | isId, 34 | position: column.ORDINAL_POSITION, 35 | defaultValue: column.COLUMN_DEFAULT, 36 | isNullable, 37 | isEditable: !isId, 38 | type: reference ? 'reference' : ensureType(type, columnType), 39 | referencedTable: reference ?? null, 40 | availableValues, 41 | }; 42 | }; 43 | 44 | const ensureType = (dataType: string, columnType: string): PropertyType => { 45 | switch (dataType) { 46 | case 'char': 47 | case 'varchar': 48 | case 'binary': 49 | case 'varbinary': 50 | case 'tinyblob': 51 | case 'blob': 52 | case 'mediumblob': 53 | case 'longblob': 54 | case 'enum': 55 | case 'set': 56 | case 'time': 57 | case 'year': 58 | return 'string'; 59 | 60 | case 'tinytext': 61 | case 'text': 62 | case 'mediumtext': 63 | case 'longtext': 64 | return 'textarea'; 65 | 66 | case 'bit': 67 | case 'smallint': 68 | case 'mediumint': 69 | case 'int': 70 | case 'integer': 71 | case 'bigint': 72 | return 'number'; 73 | 74 | case 'float': 75 | case 'double': 76 | case 'decimal': 77 | case 'dec': 78 | return 'float'; 79 | 80 | case 'tinyint': 81 | if (columnType === 'tinyint(1)') { 82 | return 'boolean'; 83 | } 84 | return 'number'; 85 | 86 | case 'bool': 87 | case 'boolean': 88 | return 'boolean'; 89 | 90 | case 'date': 91 | return 'date'; 92 | 93 | case 'datetime': 94 | case 'timestamp': 95 | return 'datetime'; 96 | 97 | default: 98 | // eslint-disable-next-line no-console 99 | console.warn( 100 | `Unexpected type: ${dataType} ${columnType} fallback to string`, 101 | ); 102 | return 'string'; 103 | } 104 | }; 105 | 106 | export class MysqlParser extends BaseDatabaseParser { 107 | public static dialects = ['mysql' as const, 'mysql2' as const]; 108 | 109 | public async parse() { 110 | const tableNames = await this.getTables(); 111 | const resources = await this.getResources(tableNames); 112 | const resourceMap = new Map(); 113 | resources.forEach((r) => { 114 | resourceMap.set(r.tableName, r); 115 | }); 116 | 117 | return new DatabaseMetadata(this.connectionOptions.database, resourceMap); 118 | } 119 | 120 | public async getTables() { 121 | const query = await this.knex.raw(` 122 | SHOW FULL TABLES FROM \`${this.connectionOptions.database}\` WHERE Table_type = 'BASE TABLE' 123 | `); 124 | 125 | const result = await query; 126 | const tables = result?.[0]; 127 | 128 | if (!tables?.length) { 129 | // eslint-disable-next-line no-console 130 | console.warn(`No tables in database ${this.connectionOptions.database}`); 131 | 132 | return []; 133 | } 134 | 135 | return tables.reduce((memo, info) => { 136 | // eslint-disable-next-line @typescript-eslint/no-unused-vars, camelcase 137 | const { Table_type, ...nameInfo } = info; 138 | 139 | const tableName = Object.values(nameInfo ?? {})[0]; 140 | 141 | memo.push(tableName); 142 | 143 | return memo; 144 | }, []); 145 | } 146 | 147 | public async getResources(tables: string[]) { 148 | const resources = await Promise.all( 149 | tables.map(async (tableName) => { 150 | try { 151 | const resourceMetadata = new ResourceMetadata( 152 | this.dialect, 153 | this.knex, 154 | this.connectionOptions.database, 155 | null, 156 | tableName, 157 | await this.getProperties(tableName), 158 | ); 159 | 160 | return resourceMetadata; 161 | } catch (error) { 162 | // eslint-disable-next-line no-console 163 | console.error(error); 164 | 165 | return false; 166 | } 167 | }), 168 | ); 169 | 170 | return resources.filter(Boolean) as ResourceMetadata[]; 171 | } 172 | 173 | public async getProperties(table: string) { 174 | const query = this.knex 175 | .from('information_schema.COLUMNS as col') 176 | .select( 177 | 'col.COLUMN_NAME as COLUMN_NAME', 178 | 'col.ORDINAL_POSITION as ORDINAL_POSITION', 179 | 'col.COLUMN_DEFAULT as COLUMN_DEFAULT', 180 | 'col.IS_NULLABLE as IS_NULLABLE', 181 | 'col.DATA_TYPE as DATA_TYPE', 182 | 'col.COLUMN_TYPE as COLUMN_TYPE', 183 | 'col.COLUMN_KEY as COLUMN_KEY', 184 | 'col.EXTRA as EXTRA', 185 | 'col.COLUMN_COMMENT as COLUMN_COMMENT', 186 | 'key.REFERENCED_TABLE_NAME as REFERENCED_TABLE_NAME', 187 | 'key.REFERENCED_COLUMN_NAME as REFERENCED_COLUMN_NAME', 188 | ) 189 | .leftJoin('information_schema.KEY_COLUMN_USAGE as key', (c) => c 190 | .on('key.TABLE_SCHEMA', 'col.TABLE_SCHEMA') 191 | .on('key.TABLE_NAME', 'col.TABLE_NAME') 192 | .on('key.COLUMN_NAME', 'col.COLUMN_NAME') 193 | .on('key.REFERENCED_TABLE_SCHEMA', 'col.TABLE_SCHEMA')) 194 | .where('col.TABLE_SCHEMA', this.connectionOptions.database) 195 | .where('col.TABLE_NAME', table); 196 | 197 | const columns = await query; 198 | 199 | return columns.map((col) => new Property(getColumnInfo(col))); 200 | } 201 | } 202 | -------------------------------------------------------------------------------- /src/dialects/postgres.parser.ts: -------------------------------------------------------------------------------- 1 | import { PropertyType } from 'adminjs'; 2 | 3 | import { DatabaseMetadata, ResourceMetadata } from '../metadata/index.js'; 4 | import { ColumnInfo, Property } from '../Property.js'; 5 | 6 | import { BaseDatabaseParser } from './base-database.parser.js'; 7 | 8 | const pgArrayAggToArray = (agg: string) => agg.replace(/{/g, '').replace(/}/g, '').split(','); 9 | 10 | const getColumnType = (dbType: string): PropertyType => { 11 | switch (dbType) { 12 | case 'uuid': return 'uuid'; 13 | case 'bigint': 14 | case 'int8': 15 | case 'bigserial': 16 | case 'serial8': 17 | case 'integer': 18 | case 'int': 19 | case 'int4': 20 | case 'smallint': 21 | case 'int2': 22 | case 'serial': 23 | case 'serial4': 24 | case 'smallserial': 25 | case 'serial2': 26 | return 'number'; 27 | case 'double precision': 28 | case 'float8': 29 | case 'numeric': 30 | case 'decimal': 31 | case 'real': 32 | case 'float4': 33 | return 'float'; 34 | case 'money': 35 | return 'currency'; 36 | case 'boolean': 37 | return 'boolean'; 38 | case 'time': 39 | case 'time with time zone': 40 | case 'timetz': 41 | case 'time without time zone': 42 | case 'timestamp': 43 | case 'timestamp with time zone': 44 | case 'timestamptz': 45 | case 'timestamp without time zone': 46 | return 'datetime'; 47 | case 'date': 48 | return 'date'; 49 | case 'json': 50 | case 'jsonb': 51 | return 'key-value'; 52 | case 'text': 53 | case 'character varying': 54 | case 'char': 55 | case 'varchar': 56 | default: 57 | return 'string'; 58 | } 59 | }; 60 | 61 | const getColumnInfo = (column: Record): ColumnInfo => ({ 62 | name: column.column_name as string, 63 | isId: column.key_type === 'PRIMARY KEY', 64 | position: column.ordinal_position as number, 65 | defaultValue: column.column_default, 66 | isNullable: column.is_nullable === 'YES', 67 | isEditable: column.is_updatable === 'YES', 68 | type: column.referenced_table ? 'reference' : getColumnType(column.data_type as string), 69 | referencedTable: (column.referenced_table ?? null) as string | null, 70 | }); 71 | 72 | export class PostgresParser extends BaseDatabaseParser { 73 | public static dialects = ['postgresql' as const]; 74 | 75 | public async parse() { 76 | const schemaName = await this.getSchema(); 77 | const tableNames = await this.getTables(schemaName); 78 | const resources = await this.getResources(tableNames, schemaName); 79 | const resourceMap = new Map(); 80 | resources.forEach((r) => { 81 | resourceMap.set(r.tableName, r); 82 | }); 83 | 84 | return new DatabaseMetadata(this.connectionOptions.database, resourceMap); 85 | } 86 | 87 | public async getSchema() { 88 | if (this.connectionOptions.schema) { 89 | return this.connectionOptions.schema; 90 | } 91 | const query = await this.knex.raw('SELECT current_schema() AS schema_name'); 92 | const result = await query; 93 | 94 | return result.rows?.[0]?.schema_name?.toString() ?? 'public'; 95 | } 96 | 97 | public async getTables(schemaName: string) { 98 | const query = await this.knex.raw(` 99 | SELECT table_name 100 | FROM information_schema.tables 101 | WHERE table_type='BASE TABLE' 102 | AND table_schema='${schemaName}' 103 | `); 104 | 105 | const result = await query; 106 | 107 | if (!result?.rows?.length) { 108 | // eslint-disable-next-line no-console 109 | console.warn(`No tables in database ${this.connectionOptions.database}`); 110 | 111 | return []; 112 | } 113 | 114 | return result.rows.map(({ table_name: table }) => table); 115 | } 116 | 117 | public async getResources(tables: string[], schemaName: string) { 118 | const resources = await Promise.all( 119 | tables.map(async (tableName) => { 120 | try { 121 | const resourceMetadata = new ResourceMetadata( 122 | this.dialect, 123 | this.knex, 124 | this.connectionOptions.database, 125 | schemaName, 126 | tableName, 127 | await this.getProperties(tableName, schemaName), 128 | ); 129 | 130 | return resourceMetadata; 131 | } catch (error) { 132 | // eslint-disable-next-line no-console 133 | console.error(error); 134 | 135 | return false; 136 | } 137 | }), 138 | ); 139 | 140 | return resources.filter(Boolean) as ResourceMetadata[]; 141 | } 142 | 143 | public async getProperties(table: string, schemaName: string) { 144 | const query = this.knex 145 | .from('information_schema.columns as col') 146 | .select( 147 | 'col.column_name', 148 | 'col.ordinal_position', 149 | 'col.column_default', 150 | 'col.is_nullable', 151 | 'col.is_updatable', 152 | 'col.data_type', 153 | 'tco.constraint_type as key_type', 154 | ) 155 | .leftJoin('information_schema.key_column_usage as kcu', (c) => c 156 | .on('kcu.column_name', 'col.column_name') 157 | .on('kcu.table_name', 'col.table_name')) 158 | .leftJoin('information_schema.table_constraints as tco', (c) => c 159 | .on('tco.constraint_name', 'kcu.constraint_name') 160 | .on('tco.constraint_schema', 'kcu.constraint_schema') 161 | .onVal('tco.constraint_type', 'PRIMARY KEY')) 162 | .where('col.table_schema', schemaName) 163 | .where('col.table_name', table); 164 | 165 | const columns = await query; 166 | 167 | const relQuery = this.knex.raw(` 168 | select 169 | (select r.relname from pg_class r where r.oid = c.conrelid) as table, 170 | (select array_agg(attname) from pg_attribute 171 | where attrelid = c.conrelid and ARRAY[attnum] <@ c.conkey) as col, 172 | (select r.relname from pg_class r where r.oid = c.confrelid) as referenced_table 173 | from pg_constraint c 174 | where c.conrelid = (select oid from pg_class where relname = '${table}') 175 | and (select r.relname from pg_class r where r.oid = c.confrelid) is not null 176 | `); 177 | 178 | const relations = await relQuery; 179 | 180 | return columns.map((col) => { 181 | const rel = relations.rows.find((r) => { 182 | const cols = pgArrayAggToArray(r.col); 183 | if (cols.length > 1) return null; // AdminJS doesn't support multiple foreign keys 184 | 185 | return cols.find((c) => c === col.column_name); 186 | }); 187 | 188 | if (rel) { 189 | col.referenced_table = rel.referenced_table; 190 | } 191 | 192 | return new Property(getColumnInfo(col)); 193 | }); 194 | } 195 | } 196 | -------------------------------------------------------------------------------- /src/dialects/types/index.ts: -------------------------------------------------------------------------------- 1 | import stream from 'stream'; 2 | 3 | export type DatabaseDialect = 'postgresql' | 'mysql' | 'mysql2' 4 | 5 | export type PgGetTypeParser = (oid: number, format: string) => any; 6 | 7 | export interface PgCustomTypesConfig { 8 | getTypeParser: PgGetTypeParser; 9 | } 10 | 11 | // Config object for pg: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/pg/index.d.ts 12 | export interface PostgresConnectionConfig { 13 | user?: string; 14 | database?: string; 15 | password?: string | (() => string | Promise); 16 | port?: number; 17 | host?: string; 18 | connectionString?: string; 19 | keepAlive?: boolean; 20 | stream?: stream.Duplex; 21 | statement_timeout?: false | number; 22 | parseInputDatesAsUTC?: boolean; 23 | ssl?: boolean | ConnectionOptions; 24 | query_timeout?: number; 25 | keepAliveInitialDelayMillis?: number; 26 | idle_in_transaction_session_timeout?: number; 27 | application_name?: string; 28 | connectionTimeoutMillis?: number; 29 | types?: PgCustomTypesConfig; 30 | options?: string; 31 | } 32 | 33 | export interface MysqlSslConfiguration { 34 | key?: string; 35 | cert?: string; 36 | ca?: string; 37 | capath?: string; 38 | cipher?: string; 39 | rejectUnauthorized?: boolean; 40 | expirationChecker?(): boolean; 41 | } 42 | 43 | // Config object for mysql: https://github.com/mysqljs/mysql#connection-options 44 | export interface MysqlConnectionConfig { 45 | host?: string; 46 | port?: number; 47 | localAddress?: string; 48 | socketPath?: string; 49 | user?: string; 50 | password?: string; 51 | charset?: string; 52 | timezone?: string; 53 | connectTimeout?: number; 54 | stringifyObjects?: boolean; 55 | insecureAuth?: boolean; 56 | typeCast?: any; 57 | queryFormat?: (query: string, values: any) => string; 58 | supportBigNumbers?: boolean; 59 | bigNumberStrings?: boolean; 60 | dateStrings?: boolean; 61 | debug?: boolean; 62 | trace?: boolean; 63 | multipleStatements?: boolean; 64 | flags?: string; 65 | ssl?: string | MysqlSslConfiguration; 66 | decimalNumbers?: boolean; 67 | expirationChecker?(): boolean; 68 | } 69 | 70 | export interface BaseConnectionConfig { 71 | database: string; 72 | schema?: string; 73 | } 74 | 75 | export type ConnectionOptions = (PostgresConnectionConfig | MysqlConnectionConfig) & BaseConnectionConfig; 76 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import { Adapter } from './Adapter.js'; 2 | 3 | export { Database } from './Database.js'; 4 | export * from './dialects/index.js'; 5 | export * from './metadata/index.js'; 6 | export { Property } from './Property.js'; 7 | export { Resource } from './Resource.js'; 8 | export { Adapter }; 9 | 10 | export default Adapter; 11 | -------------------------------------------------------------------------------- /src/metadata/DatabaseMetadata.ts: -------------------------------------------------------------------------------- 1 | import { ResourceMetadata } from './ResourceMetadata.js'; 2 | 3 | export class DatabaseMetadata { 4 | public readonly database: string; 5 | 6 | protected resourceMap: Map; 7 | 8 | constructor( 9 | database: string, 10 | resourceMap: Map, 11 | ) { 12 | this.database = database; 13 | this.resourceMap = resourceMap; 14 | } 15 | 16 | public tables(): ResourceMetadata[] { 17 | return Array.from(this.resourceMap.values()); 18 | } 19 | 20 | public table(tableName: string): ResourceMetadata { 21 | const resource = this.resourceMap.get(tableName); 22 | 23 | if (!resource) { 24 | throw new Error(`Table does not exist: "${this.database}.${tableName}"`); 25 | } 26 | 27 | return resource; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/metadata/ResourceMetadata.ts: -------------------------------------------------------------------------------- 1 | import type { Knex } from 'knex'; 2 | 3 | import { DatabaseDialect } from '../dialects/index.js'; 4 | import { Property } from '../Property.js'; 5 | 6 | export class ResourceMetadata { 7 | public idProperty: Property; 8 | 9 | constructor( 10 | public dialect: DatabaseDialect, 11 | public readonly knex: Knex, 12 | public readonly database: string, 13 | public readonly schemaName: string | null, 14 | public readonly tableName: string, 15 | public readonly properties: Property[], 16 | ) { 17 | const idProperty = properties.find((p) => p?.isId?.()); 18 | if (!idProperty) { 19 | throw new Error(`Table "${tableName}" has no primary key`); 20 | } 21 | 22 | this.idProperty = idProperty; 23 | this.dialect = dialect; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/metadata/index.ts: -------------------------------------------------------------------------------- 1 | export { DatabaseMetadata } from './DatabaseMetadata.js'; 2 | export { ResourceMetadata } from './ResourceMetadata.js'; 3 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "moduleResolution": "nodenext", 4 | "module": "nodenext", 5 | "target": "esnext", 6 | "lib": ["esnext", "DOM"], 7 | "skipLibCheck": true, 8 | "sourceMap": true, 9 | "noImplicitAny": false, 10 | "strictNullChecks": true, 11 | "esModuleInterop": true, 12 | "declaration": true, 13 | "declarationDir": "./lib", 14 | "outDir": "./lib", 15 | "emitDecoratorMetadata": true, 16 | "experimentalDecorators": true, 17 | "baseUrl": "." 18 | }, 19 | "include": ["./src/**/*.ts"], 20 | "exclude": ["node_modules", "lib"] 21 | } 22 | --------------------------------------------------------------------------------