Skip to content

Commit 7f2ca49

Browse files
committed
Merge remote-tracking branch 'origin/feat/migrate-index-js-to-typescript' into beta
2 parents 44c9f61 + 1d54bf7 commit 7f2ca49

18 files changed

+559
-391
lines changed

.eslintrc.js

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,7 @@ module.exports = {
88
'plugin:react/recommended',
99
'plugin:@typescript-eslint/recommended',
1010
],
11-
ignorePatterns: [
12-
'*/build/**/*',
13-
'*.json',
14-
'*.txt',
15-
'yarn.lock',
16-
'*.yaml',
17-
],
11+
ignorePatterns: ['*/build/**/*', '*.json', '*.txt', 'yarn.lock', '*.yaml'],
1812
parser: '@typescript-eslint/parser',
1913
parserOptions: {
2014
ecmaFeatures: {
@@ -23,38 +17,35 @@ module.exports = {
2317
ecmaVersion: 11,
2418
sourceType: 'module',
2519
},
26-
plugins: [
27-
'react',
28-
'@typescript-eslint',
29-
],
20+
plugins: ['react', '@typescript-eslint'],
3021
rules: {
31-
semi: ['error', 'never'],
22+
semi: ['error', 'always'],
3223
'no-unused-vars': 'off',
3324
'import/extensions': 'off',
3425
'import/no-unresolved': 'off',
3526
'react/jsx-filename-extension': 'off',
36-
indent: [
37-
'error',
38-
2,
39-
],
27+
indent: ['error', 2],
4028
'linebreak-style': ['error', 'unix'],
4129
'object-curly-newline': 'off',
4230
'@typescript-eslint/no-explicit-any': 'off',
4331
},
44-
overrides: [{
45-
files: ['*.tsx'],
46-
rules: {
47-
'react/prop-types': 'off',
48-
'react/jsx-props-no-spreading': 'off',
49-
'import/no-extraneous-dependencies': 'off',
32+
overrides: [
33+
{
34+
files: ['*.tsx'],
35+
rules: {
36+
'react/prop-types': 'off',
37+
'react/jsx-props-no-spreading': 'off',
38+
'import/no-extraneous-dependencies': 'off',
39+
},
5040
},
51-
}, {
52-
files: ['./src/**/*.spec.ts', 'spec/*.ts'],
53-
rules: {
54-
'no-unused-expressions': 'off',
55-
'prefer-arrow-callback': 'off',
56-
'func-names': 'off',
57-
'import/no-extraneous-dependencies': 'off',
41+
{
42+
files: ['./src/**/*.spec.ts', 'spec/*.ts'],
43+
rules: {
44+
'no-unused-expressions': 'off',
45+
'prefer-arrow-callback': 'off',
46+
'func-names': 'off',
47+
'import/no-extraneous-dependencies': 'off',
48+
},
5849
},
59-
}],
60-
}
50+
],
51+
};

config/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ module.exports = {
66
database: process.env.POSTGRES_DATABASE || 'database_test',
77
host: process.env.POSTGRES_HOST || 'localhost',
88
dialect: 'postgres',
9+
logging: false,
910
},
1011
}

example-app/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"build": "tsc",
88
"start": "yarn build && node build/index.js",
9-
"start:dev": "concurrently \"yarn build --watch\" \"nodemon --ext '.js' --watch ../build --watch ./build --ignore 'cypress/**/*.js' node build/src/index.js\"",
9+
"dev": "SKIP_SYNC=true concurrently \"wait-on build/src/index.js && nodemon --ext '.js' --watch ../build --watch ./build --ignore 'cypress/**/*.js' node build/src/index.js\" \"yarn build --watch\"",
1010
"cypress:open": "cypress open",
1111
"cypress:run": "cypress run"
1212
},
@@ -16,7 +16,8 @@
1616
"cypress": "^4.11.0",
1717
"nodemon": "^2.0.4",
1818
"ts-node": "^8.10.2",
19-
"typescript": "^3.9.7"
19+
"typescript": "^3.9.7",
20+
"wait-on": "^5.2.0"
2021
},
2122
"dependencies": {
2223
"@admin-bro/express": "^3.0.0",

example-app/src/connect.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ const connect = async (): Promise<Sequelize> => {
2727
console.error('Unable to connect to the database:', error)
2828
}
2929

30-
await sequelize.sync({ force: true })
30+
if (!process.env.SKIP_SYNC) {
31+
await sequelize.sync({ force: true })
32+
}
3133
return sequelize
3234
}
3335

example-app/yarn.lock

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,6 +1119,35 @@
11191119
resolved "https://registry.yarnpkg.com/@emotion/utils/-/utils-0.8.2.tgz#576ff7fb1230185b619a75d258cbc98f0867a8dc"
11201120
integrity sha512-rLu3wcBWH4P5q1CGoSSH/i9hrXs7SlbRLkoq9IGuoPYNGQvDJ3pt/wmOM+XgYjIDRMVIdkUWt0RsfzF50JfnCw==
11211121

1122+
"@hapi/address@^4.1.0":
1123+
version "4.1.0"
1124+
resolved "https://registry.yarnpkg.com/@hapi/address/-/address-4.1.0.tgz#d60c5c0d930e77456fdcde2598e77302e2955e1d"
1125+
integrity sha512-SkszZf13HVgGmChdHo/PxchnSaCJ6cetVqLzyciudzZRT0jcOouIF/Q93mgjw8cce+D+4F4C1Z/WrfFN+O3VHQ==
1126+
dependencies:
1127+
"@hapi/hoek" "^9.0.0"
1128+
1129+
"@hapi/formula@^2.0.0":
1130+
version "2.0.0"
1131+
resolved "https://registry.yarnpkg.com/@hapi/formula/-/formula-2.0.0.tgz#edade0619ed58c8e4f164f233cda70211e787128"
1132+
integrity sha512-V87P8fv7PI0LH7LiVi8Lkf3x+KCO7pQozXRssAHNXXL9L1K+uyu4XypLXwxqVDKgyQai6qj3/KteNlrqDx4W5A==
1133+
1134+
"@hapi/hoek@^9.0.0":
1135+
version "9.1.0"
1136+
resolved "https://registry.yarnpkg.com/@hapi/hoek/-/hoek-9.1.0.tgz#6c9eafc78c1529248f8f4d92b0799a712b6052c6"
1137+
integrity sha512-i9YbZPN3QgfighY/1X1Pu118VUz2Fmmhd6b2n0/O8YVgGGfw0FbUYoA97k7FkpGJ+pLCFEDLUmAPPV4D1kpeFw==
1138+
1139+
"@hapi/pinpoint@^2.0.0":
1140+
version "2.0.0"
1141+
resolved "https://registry.yarnpkg.com/@hapi/pinpoint/-/pinpoint-2.0.0.tgz#805b40d4dbec04fc116a73089494e00f073de8df"
1142+
integrity sha512-vzXR5MY7n4XeIvLpfl3HtE3coZYO4raKXW766R6DZw/6aLqR26iuZ109K7a0NtF2Db0jxqh7xz2AxkUwpUFybw==
1143+
1144+
"@hapi/topo@^5.0.0":
1145+
version "5.0.0"
1146+
resolved "https://registry.yarnpkg.com/@hapi/topo/-/topo-5.0.0.tgz#c19af8577fa393a06e9c77b60995af959be721e7"
1147+
integrity sha512-tFJlT47db0kMqVm3H4nQYgn6Pwg10GTZHb1pwmSiv1K4ks6drQOtfEF5ZnPjkvC+y4/bUPHK+bc87QvLcL+WMw==
1148+
dependencies:
1149+
"@hapi/hoek" "^9.0.0"
1150+
11221151
"@samverschueren/stream-to-observable@^0.3.0":
11231152
version "0.3.0"
11241153
resolved "https://registry.yarnpkg.com/@samverschueren/stream-to-observable/-/stream-to-observable-0.3.0.tgz#ecdf48d532c58ea477acfcab80348424f8d0662f"
@@ -3129,6 +3158,17 @@ jest-worker@^26.0.0:
31293158
merge-stream "^2.0.0"
31303159
supports-color "^7.0.0"
31313160

3161+
joi@^17.1.1:
3162+
version "17.2.1"
3163+
resolved "https://registry.yarnpkg.com/joi/-/joi-17.2.1.tgz#e5140fdf07e8fecf9bc977c2832d1bdb1e3f2a0a"
3164+
integrity sha512-YT3/4Ln+5YRpacdmfEfrrKh50/kkgX3LgBltjqnlMPIYiZ4hxXZuVJcxmsvxsdeHg9soZfE3qXxHC2tMpCCBOA==
3165+
dependencies:
3166+
"@hapi/address" "^4.1.0"
3167+
"@hapi/formula" "^2.0.0"
3168+
"@hapi/hoek" "^9.0.0"
3169+
"@hapi/pinpoint" "^2.0.0"
3170+
"@hapi/topo" "^5.0.0"
3171+
31323172
"js-tokens@^3.0.0 || ^4.0.0", js-tokens@^4.0.0:
31333173
version "4.0.0"
31343174
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
@@ -4441,6 +4481,13 @@ rxjs@^6.3.3, rxjs@^6.5.2:
44414481
dependencies:
44424482
tslib "^1.9.0"
44434483

4484+
rxjs@^6.5.5:
4485+
version "6.6.3"
4486+
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-6.6.3.tgz#8ca84635c4daa900c0d3967a6ee7ac60271ee552"
4487+
integrity sha512-trsQc+xYYXZ3urjOiJOuCOa5N3jAZ3eiSpQB5hIT8zGlL2QfnHLJ2r7GMkBGuIausdJN1OneaI6gQlsqNHHmZQ==
4488+
dependencies:
4489+
tslib "^1.9.0"
4490+
44444491
safe-buffer@5.1.2, safe-buffer@~5.1.0, safe-buffer@~5.1.1:
44454492
version "5.1.2"
44464493
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d"
@@ -5176,6 +5223,17 @@ void-elements@^2.0.1:
51765223
resolved "https://registry.yarnpkg.com/void-elements/-/void-elements-2.0.1.tgz#c066afb582bb1cb4128d60ea92392e94d5e9dbec"
51775224
integrity sha1-wGavtYK7HLQSjWDqkjkulNXp2+w=
51785225

5226+
wait-on@^5.2.0:
5227+
version "5.2.0"
5228+
resolved "https://registry.yarnpkg.com/wait-on/-/wait-on-5.2.0.tgz#6711e74422523279714a36d52cf49fb47c9d9597"
5229+
integrity sha512-U1D9PBgGw2XFc6iZqn45VBubw02VsLwnZWteQ1au4hUVHasTZuFSKRzlTB2dqgLhji16YVI8fgpEpwUdCr8B6g==
5230+
dependencies:
5231+
axios "^0.19.2"
5232+
joi "^17.1.1"
5233+
lodash "^4.17.19"
5234+
minimist "^1.2.5"
5235+
rxjs "^6.5.5"
5236+
51795237
warning@^4.0.2, warning@^4.0.3:
51805238
version "4.0.3"
51815239
resolved "https://registry.yarnpkg.com/warning/-/warning-4.0.3.tgz#16e9e077eb8a86d6af7d64aa1e05fd85b4678ca3"

index.d.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

index.js renamed to index.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable @typescript-eslint/no-var-requires */
21
/**
32
* @module @admin-bro/sequelize
43
* @subcategory Adapters
@@ -79,7 +78,8 @@
7978
* @type {typeof BaseDatabase}
8079
* @static
8180
*/
82-
const Database = require('./build/database').default
81+
import type { BaseDatabase, BaseResource } from 'admin-bro';
82+
import Database from './src/database';
8383

8484
/**
8585
* Implementation of {@link BaseResource} for Sequelize Adapter
@@ -88,6 +88,10 @@ const Database = require('./build/database').default
8888
* @type {typeof BaseResource}
8989
* @static
9090
*/
91-
const Resource = require('./build/resource').default
91+
import Resource from './src/resource';
9292

93-
module.exports = { Database, Resource }
93+
module.exports = { Database, Resource };
94+
95+
const SequelizeAdapter = { Database, Resource };
96+
97+
export default SequelizeAdapter;

models/comment.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module.exports = (sequelize, DataTypes) => {
2+
const Comment = sequelize.define('Comment', {
3+
id: {
4+
primaryKey: true,
5+
type: DataTypes.UUID,
6+
defaultValue: sequelize.UUIDV4,
7+
},
8+
title: DataTypes.STRING,
9+
description: DataTypes.STRING,
10+
publishedAt: DataTypes.DATE,
11+
}, {})
12+
return Comment
13+
}

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
{
22
"name": "@admin-bro/sequelize",
3-
"version": "1.1.0-beta.1",
3+
"version": "1.2.1",
44
"description": "Sequelize adapter for AdminBro",
55
"main": "build/index.js",
66
"types": "index.d.ts",
77
"scripts": {
88
"build": "tsc",
9+
"dev": "tsc --watch",
910
"test": "mocha -r ts-node/register src/*.spec.ts",
11+
"check:all": "yarn build && yarn test && yarn lint",
1012
"cover": "NODE_ENV=test ./node_modules/nyc/bin/nyc.js --reporter=html -x=spec -x=coverage --all=true npm test",
1113
"sequelize": "sequelize",
1214
"lint": "eslint ./src/**/*.ts",
@@ -37,7 +39,7 @@
3739
"@types/sinon-chai": "^3.2.4",
3840
"@typescript-eslint/eslint-plugin": "^3.7.0",
3941
"@typescript-eslint/parser": "^3.7.0",
40-
"admin-bro": "^3.2.3",
42+
"admin-bro": "^3.4.0",
4143
"chai": "^4.2.0",
4244
"eslint": "^7.5.0",
4345
"eslint-config-airbnb": "^18.2.0",

src/database.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe('Database', () => {
3535
describe('#resources', () => {
3636
it('fetches all resources when entire db is given', () => {
3737
const database = new Database(db)
38-
expect(database.resources()).to.have.lengthOf(2)
38+
expect(database.resources()).to.have.lengthOf(Object.keys(db.sequelize.models).length)
3939
expect(database.resources()[0]).to.be.an.instanceof(Resource)
4040
})
4141

0 commit comments

Comments
 (0)