Skip to content

Commit 345e086

Browse files
committed
fix: individual exported database and resource
1 parent 49a2c27 commit 345e086

File tree

7 files changed

+122
-107
lines changed

7 files changed

+122
-107
lines changed

.eslintrc.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
module.exports = {
22
env: {
3-
browser: true,
43
es2020: true,
54
},
65
extends: [
76
'airbnb',
87
'plugin:react/recommended',
98
'plugin:@typescript-eslint/recommended',
109
],
11-
ignorePatterns: ['*/build/**/*', '*.json', '*.txt', 'yarn.lock', '*.yaml'],
1210
parser: '@typescript-eslint/parser',
1311
parserOptions: {
1412
ecmaFeatures: {

src/index.ts renamed to index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
* @type {typeof BaseDatabase}
7979
* @static
8080
*/
81-
import Database from './database';
81+
import Database from './src/database';
8282

8383
/**
8484
* Implementation of {@link BaseResource} for Sequelize Adapter
@@ -87,7 +87,10 @@ import Database from './database';
8787
* @type {typeof BaseResource}
8888
* @static
8989
*/
90-
import Resource from './resource';
90+
import Resource from './src/resource';
91+
92+
export { default as Resource } from './src/resource';
93+
export { default as Database } from './src/database';
9194

9295
module.exports = { Database, Resource };
9396

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"@semantic-release/git": "^9.0.0",
3636
"@types/chai": "^4.2.12",
3737
"@types/mocha": "^8.0.3",
38+
"@types/node": "^14.14.37",
3839
"@types/sinon": "^9.0.5",
3940
"@types/sinon-chai": "^3.2.4",
4041
"@typescript-eslint/eslint-plugin": "^3.7.0",

src/property.ts

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable no-underscore-dangle */
2-
import { BaseProperty, PropertyType } from 'admin-bro'
3-
import { ModelAttributeColumnOptions } from 'sequelize/types'
2+
import { BaseProperty, PropertyType } from 'admin-bro';
3+
import { ModelAttributeColumnOptions } from 'sequelize/types';
44

55
const TYPES_MAPPING = [
66
['STRING', 'string'],
@@ -25,99 +25,98 @@ const TYPES_MAPPING = [
2525
['RANGE', 'string'],
2626
['GEOMETRY', 'string'],
2727
['BOOLEAN', 'boolean'],
28-
]
28+
];
2929

3030
class Property extends BaseProperty {
3131
private sequelizePath: ModelAttributeColumnOptions
3232

3333
private fieldName: string
3434

3535
constructor(sequelizePath: ModelAttributeColumnOptions) {
36-
const { fieldName } = sequelizePath as any
37-
super({ path: fieldName })
38-
this.fieldName = fieldName
39-
this.sequelizePath = sequelizePath
36+
const { fieldName } = sequelizePath as any;
37+
super({ path: fieldName });
38+
this.fieldName = fieldName;
39+
this.sequelizePath = sequelizePath;
4040
}
4141

4242
name(): string {
43-
return this.fieldName
43+
return this.fieldName;
4444
}
4545

4646
isEditable(): boolean {
4747
if ((this.sequelizePath as any)._autoGenerated) {
48-
return false
48+
return false;
4949
}
5050
if (this.sequelizePath.autoIncrement) {
51-
return false
51+
return false;
5252
}
5353
if (this.isId()) {
54-
return false
54+
return false;
5555
}
56-
return true
56+
return true;
5757
}
5858

5959
isVisible(): boolean {
6060
// fields containing password are hidden by default
61-
return !this.name().match('password')
61+
return !this.name().match('password');
6262
}
6363

6464
isId(): boolean {
65-
return !!this.sequelizePath.primaryKey
65+
return !!this.sequelizePath.primaryKey;
6666
}
6767

6868
reference(): string | null {
6969
if (this.isArray()) {
70-
return null
70+
return null;
7171
}
7272

7373
if (this.sequelizePath.references === 'string') {
74-
return this.sequelizePath.references as string
74+
return this.sequelizePath.references as string;
7575
} if (this.sequelizePath.references && typeof this.sequelizePath.references !== 'string') {
76-
return this.sequelizePath.references?.model as string
76+
return this.sequelizePath.references?.model as string;
7777
}
78-
return null
78+
return null;
7979
}
8080

8181
availableValues(): Array<string> | null {
8282
return this.sequelizePath.values && this.sequelizePath.values.length
8383
? this.sequelizePath.values as Array<string>
84-
: null
84+
: null;
8585
}
8686

8787
isArray(): boolean {
88-
return this.sequelizePath.type.constructor.name === 'ARRAY'
88+
return this.sequelizePath.type.constructor.name === 'ARRAY';
8989
}
9090

9191
/**
9292
* @returns {PropertyType}
9393
*/
9494
type(): PropertyType {
95-
let sequelizeType = this.sequelizePath.type
95+
let sequelizeType = this.sequelizePath.type;
9696

9797
if (this.isArray()) {
98-
sequelizeType = (sequelizeType as any).type
98+
sequelizeType = (sequelizeType as any).type;
9999
}
100100

101101
const key = TYPES_MAPPING.find((element) => (
102102
sequelizeType.constructor.name === element[0]
103-
))
103+
));
104104

105105
if (this.reference()) {
106-
return 'reference' as PropertyType
106+
return 'reference' as PropertyType;
107107
}
108108

109-
const type = key && key[1]
110-
return (type || 'string') as PropertyType
109+
const type = key && key[1];
110+
return (type || 'string') as PropertyType;
111111
}
112112

113113
isSortable(): boolean {
114-
return this.type() !== 'mixed' && !this.isArray()
114+
return this.type() !== 'mixed' && !this.isArray();
115115
}
116116

117117
isRequired(): boolean {
118-
return !(typeof this.sequelizePath.allowNull === 'undefined'
119-
|| this.sequelizePath.allowNull === true)
118+
return !(typeof this.sequelizePath.allowNull === 'undefined' || this.sequelizePath.allowNull);
120119
}
121120
}
122121

123-
export default Property
122+
export default Property;

0 commit comments

Comments
 (0)