Skip to content
This repository was archived by the owner on Jul 11, 2024. It is now read-only.

Commit d0476c2

Browse files
authored
Merge pull request #344 from Uconnect-Technologies/remove-v1
Remove v1 process
2 parents 728f422 + 4c6dd05 commit d0476c2

File tree

116 files changed

+503
-4254
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+503
-4254
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ npm install wertik-js
3434
To start wertik-js server you need to import wertik and start it:
3535

3636
```js
37-
import wertik from "wertik-js/lib/next"
37+
import wertik from "wertik-js/lib/"
3838

3939
weritk({
4040
port: 1200,

changelog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,10 @@
55
- When sending emails fails, also throws errors in console
66
- When taking backup and provides invalid table/module name, the backup process failes with an error.
77
- Added `extendFields` to `useModule` to extend `sequelize.model` table fields.
8+
9+
### 3.3.1
10+
11+
- Removed support old legacy wertik framework.
12+
- Now wertik can be import from `wertik-js/lib` instead of `wertik-js/lib/ndex`
13+
- Added more types support.
14+
- Change the way mysql is initalized so that it can open doors for postgres and mongoose in future.

docs/v3/cronJobs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Wertik JS allows you to creating Cron Jobs that runs on interval. To use a Cron JOB you need to use `useCronJob`.
44

55
```js
6-
import wertik, { useCronJob } from "wertik-js/lib/next";
6+
import wertik, { useCronJob } from "wertik-js/lib/";
77

88
wertik({
99
port: 1200,

docs/v3/database.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
As of today 28 November 2021, Wertik-js only supports MySQL database. Wertik JS provides a function called `useMysqlDatabase` you can use to connect to a database.
44

55
```js
6-
import wertik, { useMysqlDatabase } from "wertik-js/lib/next";
6+
import wertik, { useMysqlDatabase } from "wertik-js/lib/";
77
weritk({
88
port: 1200,
99
database: {

docs/v3/graphql.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
For GraphQL, Wertik JS uses Apollo GraphQL under the hood. We choose Apollo GraphQL because it is well managed and bug-free. To set up Graphql Wertik JS provides a function called `useGraphql` to use Graphql in your app.
44

55
```javascript
6-
import wertik, { useGraphql } from "wertik-js/lib/next";
6+
import wertik, { useGraphql } from "wertik-js/lib/";
77
wertik({
88
port: 1200,
99
graphql: useGraphql(useGraphqlProps),

docs/v3/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ npm install wertik-js
3333
To start wertik-js server you need to import wertik and start it:
3434

3535
```js
36-
import wertik from "wertik-js/lib/next";
36+
import wertik from "wertik-js/lib/";
3737

3838
weritk({
3939
port: 1200,

docs/v3/logger.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Wertik JS allows using logger for logging purpose. Wertik JS uses `winston` for logging purpose. We choose `winston` because of its popularity. To setup logger, you need to import `useLogger`and `useWinstonTransport` from wertik.
44

55
```javascript
6-
import wertik, { useLogger, useWinstonTransport } from "wertik-js/lib/next"
6+
import wertik, { useLogger, useWinstonTransport } from "wertik-js/lib/"
77
const devIlyas = async () => {
88
wertik({
99
port: 1200,
@@ -32,7 +32,7 @@ import wertik, {
3232
useModule,
3333
useLogger,
3434
useWinstonTransport,
35-
} from "wertik-js/lib/next"
35+
} from "wertik-js/lib/"
3636

3737
const devIlyas = async () => {
3838
wertik({

docs/v3/mailer.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
To send emails. Wertik-js uses Node Mailer for sending emails. To setup emails Wertik JS provides a function called `useMailer` as argument you need to pass Node Mailer Configuration.
44

55
```js
6-
import wertik, { useMysqlDatabase, useMailer } from "wertik-js/lib/next";
6+
import wertik, { useMysqlDatabase, useMailer } from "wertik-js/lib/"
77
weritk({
88
port: 1200,
99
database: {
@@ -18,7 +18,7 @@ weritk({
1818
mailer: {
1919
default: useMailer(),
2020
},
21-
});
21+
})
2222
```
2323

2424
`useMailer` will ask for node mailer configuration. The configuration passed through `useMailer` will be used here:
@@ -27,17 +27,17 @@ weritk({
2727

2828
### Sending Emails
2929

30-
Once you set up at least one mail. In context, wertik will pass `sendEmail(mailer: string, options: emailSendProps)` method that will send email using a different email. Send Email API: `sendEmail(mailer: string, options: emailSendProps)`. The mailer will be `default` here. And the options include:
30+
Once you set up at least one mail. In context, wertik will pass `sendEmail(mailer: string, options: SendEmailProps)` method that will send email using a different email. Send Email API: `sendEmail(mailer: string, options: SendEmailProps)`. The mailer will be `default` here. And the options include:
3131

3232
```typescript
33-
export interface emailSendProps {
34-
template: string;
33+
export interface SendEmailProps {
34+
template: string
3535
variables: {
36-
[key: string]: any;
37-
};
38-
from: string;
39-
to: string;
40-
subject: string;
36+
[key: string]: any
37+
}
38+
from: string
39+
to: string
40+
subject: string
4141
}
4242
```
4343

docs/v3/modules.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import wertik, {
88
useMailer,
99
useModule,
1010
useGraphql,
11-
} from "wertik-js/lib/next";
11+
} from "wertik-js/lib/";
1212

1313
weritk({
1414
port: 1200,
@@ -48,7 +48,7 @@ When you provide `useMysqlDatabase: true`, `table` and `database`, Wertik JS aut
4848
You have to initialize its module in this way:
4949

5050
```js
51-
import wertik, { useModule, useMysqlDatabase, useGraphql } from "wertik-js/lib/next";
51+
import wertik, { useModule, useMysqlDatabase, useGraphql } from "wertik-js/lib/";
5252
wertik({
5353
port: 1200,
5454
graphql: useGraphql(),
@@ -219,7 +219,7 @@ When events are running you get access to Apollo GraphQL Resolver arguments wher
219219
Example:
220220

221221
```js
222-
import wertik, { useMysqlDatabase, useModule } from "wertik-js/lib/next";
222+
import wertik, { useMysqlDatabase, useModule } from "wertik-js/lib/";
223223

224224
wertik({
225225
port: 1200,
@@ -271,7 +271,7 @@ When using Wertik JS modules. `useModule` has a function called `on` which can b
271271
Example:
272272

273273
```js
274-
import wertik, { useModule } from "wertik-js/lib/next";
274+
import wertik, { useModule } from "wertik-js/lib/";
275275
wertik({
276276
port: 1200,
277277
modules: {

docs/v3/queue.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ When handling requests from API clients, We might run into a situation where a r
99
It is considered the elegant way of scaling and solving performance challenges in common applications.
1010

1111
```js
12-
import wertik, { useQueue } from "wertik-js/lib/next"
12+
import wertik, { useQueue } from "wertik-js/lib/"
1313

1414
wertik({
1515
port: 1200,
@@ -77,7 +77,7 @@ export interface useQueueProps {
7777
As of today(Friday 7 Jan 2022), Wertik JS provides [Bull Board UI](https://github.com/felixmosh/bull-board) for monitoring Jobs.
7878

7979
```javascript
80-
import wertik, { useQueue } from "wertik-js/lib/next"
80+
import wertik, { useQueue } from "wertik-js/lib/"
8181
wertik({
8282
port: 1200,
8383
queue: {

docs/v3/redis.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Where rest of the options will be part of redis `createClient` options. For `cre
1515

1616

1717
```javascript
18-
import wertik, { useRedis } from "wertik-js/lib/next";
18+
import wertik, { useRedis } from "wertik-js/lib/";
1919
wertik({
2020
port: 1200,
2121
redis: {

docs/v3/sockets.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Wertik JS allows using both Socket.IO and WebSockets on the same HTTP server as
77
useWebSockets allows you to creating a websockets server on current http server.
88

99
```js
10-
import wertik, { useWebSockets } from "wertik-js/lib/next";
10+
import wertik, { useWebSockets } from "wertik-js/lib/";
1111

1212
wertik({
1313
port: 1200,
@@ -33,7 +33,7 @@ Your Web Sockets server is up an running at ws://localhost:1200/websockets.
3333
useIndependentWebSocketsServer allows you creating a websockets server that runs on different port.
3434

3535
```js
36-
import wertik, { useIndependentWebSocketsServer } from "wertik-js/lib/next";
36+
import wertik, { useIndependentWebSocketsServer } from "wertik-js/lib/";
3737

3838
wertik({
3939
port: 1200,
@@ -57,7 +57,7 @@ Wertik JS app listening at http://localhost:1200
5757
useSocketIO allows you creating a Socket IO server that runs on same http server.
5858

5959
```js
60-
import wertik, { useSocketIO } from "wertik-js/lib/next";
60+
import wertik, { useSocketIO } from "wertik-js/lib/";
6161

6262
wertik({
6363
port: 1200,

docs/v3/storage.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Wertik JS allows adding support for third party Storage services to your app. As of today 28 November 2021, Wertik JS supports `digitalocean` and `dropbox`. To use storage services you need to use `useStorage` function from wertik-js.
44

55
```js
6-
import wertik, { useStorage } from "wertik-js/lib/next";
6+
import wertik, { useStorage } from "wertik-js/lib/";
77

88
wertik({
99
port: 1200,
@@ -49,7 +49,7 @@ Wertik JS provides a builtin module to take backups of your database called Back
4949
To use it You can import it from Wertik JS:
5050

5151
```js
52-
import wertik, { WertikBackupModule } from "wertik-js/lib/next";
52+
import wertik, { WertikBackupModule } from "wertik-js/lib/";
5353
wertik({
5454
port: 1200,
5555
modules: {

package.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "wertik-js",
3-
"version": "3.3.0",
3+
"version": "3.3.1",
44
"main": "lib/main.js",
55
"types": "lib/types.d.ts",
66
"repository": "https://github.com/Uconnect-Technologies/wertik-js.git",
@@ -25,11 +25,8 @@
2525
"author": "Ilyas Karim <ilyas.datoo@gmail.com> ",
2626
"license": "MIT",
2727
"scripts": {
28-
"dev-old": "concurrently -n TS,DevServer \"npm run watch-ts\" \"nodemon lib/devServer.js\" ",
29-
"dev": "concurrently -n TS,DevServer \"npm run watch-ts\" \"nodemon lib/next/devServer.js\" ",
28+
"dev": "tsc-watch --onSuccess \"node lib/devServer.js\"",
3029
"build": "yarn prettier && yarn tsc && yarn test",
31-
"production": "node lib/devServer.js",
32-
"watch-ts": "tsc -w",
3330
"prettier": "prettier --write src package.json index.js",
3431
"test": "cross-env TEST_MODE=true jest --runInBand --forceExit --detectOpenHandles"
3532
},
@@ -64,6 +61,7 @@
6461
"redis": "^4.0.1",
6562
"sequelize": "^6.3.5",
6663
"socket.io": "^4.1.3",
64+
"tsc-watch": "^5.0.3",
6765
"winston": "^3.1.0",
6866
"ws": "^8.0.0"
6967
},
File renamed without changes.

src/next/crud/index.ts renamed to src/crud/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { get } from "lodash"
2-
import convertFiltersIntoSequalizeObject from "./../../framework/database/helpers/convertFiltersIntoSequalizeObject"
2+
import convertFiltersIntoSequalizeObject from "../utils/convertFiltersIntoSequalizeObject"
33

44
export const paginate = async (arg, tableInstance) => {
55
let page = get(arg, "pagination.page", 1)

src/next/database.ts renamed to src/database/database.ts

Lines changed: 3 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,7 @@
1-
import { Sequelize } from "sequelize"
2-
import { databaseDefaultOptions } from "../framework/defaults/options"
31
import { get } from "lodash"
4-
import { paginate } from "./crud/index"
5-
import { Store } from "./types"
6-
import { WertikApp } from "./types"
7-
import { useDatabaseProps } from "./types/database"
8-
9-
export const getAllRelationships = (dbName: String) => {
10-
return `
11-
SELECT *
12-
FROM information_schema.KEY_COLUMN_USAGE
13-
WHERE CONSTRAINT_SCHEMA = '${dbName}'
14-
AND REFERENCED_TABLE_SCHEMA IS NOT NULL
15-
AND REFERENCED_TABLE_NAME IS NOT NULL
16-
AND REFERENCED_COLUMN_NAME IS NOT NULL
17-
`
18-
}
19-
20-
export const useMysqlDatabase = function (obj: useDatabaseProps) {
21-
return async () => {
22-
try {
23-
let sequelize = new Sequelize(obj.name, obj.username, obj.password, {
24-
host: obj.host,
25-
dialect: "mysql",
26-
logging: false,
27-
...get(obj, "options", {}),
28-
...(databaseDefaultOptions as any).sql.dbInitializeOptions,
29-
})
30-
await sequelize.authenticate()
31-
console.log(`[DB] Succcessfully connected to database ${obj.name}`)
32-
;(sequelize as any).relationships = await sequelize.query(
33-
getAllRelationships(obj.name)
34-
)
35-
return {
36-
credentials: obj,
37-
instance: sequelize,
38-
}
39-
} catch (e) {
40-
console.log(`[DB] Connecting failed to datbase ${obj.name}`)
41-
console.log(e.message)
42-
}
43-
}
44-
}
45-
46-
/**
47-
* @deprecated use useMysqlDatabase, useDatabase is deprecated and will be removed in 3.5.0 version.
48-
*/
49-
export const useDatabase = useMysqlDatabase
2+
import { paginate } from "../crud/index"
3+
import { Store } from "../types"
4+
import { WertikApp } from "../types"
505

516
export const applyRelationshipsFromStoreToDatabase = async (
527
store: Store,

src/database/helpers.ts

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import { MysqlColumnInfoDescribeTable } from "src/types/database"
2+
import { capitalizeFirstLetter } from "../utils/capitalizeFirstLetter"
3+
import {
4+
numberTypes,
5+
dateTypes,
6+
stringTypes,
7+
enumTypes,
8+
jsonTypes,
9+
} from "./mysql/getTableInfo"
10+
11+
export const convertDatabaseTypeIntoGraphqlType = (
12+
columnInfo: MysqlColumnInfoDescribeTable,
13+
tableName: string
14+
) => {
15+
var isPrimary = columnInfo.Key === "PRI"
16+
var limit = columnInfo.Type.match(/\d+/g)
17+
var isRequiredIndicator = columnInfo.Null === "NO" ? "!" : ""
18+
if (limit) limit[0]
19+
20+
if (columnInfo.Type.toLowerCase() === "tinyint(1)") {
21+
return {
22+
graphqlType: `Boolean`,
23+
graphqlCreateInputType: `Boolean${isRequiredIndicator}`,
24+
graphqlUpdateInputType: `Boolean${isRequiredIndicator}`,
25+
databaseType: "INTEGER",
26+
}
27+
} else if (numberTypes.find((c) => columnInfo.Type.includes(c))) {
28+
return {
29+
graphqlType: `Int`,
30+
graphqlCreateInputType: `Int`,
31+
graphqlUpdateInputType: `Int${isPrimary ? "!" : ""}`,
32+
databaseType: "INTEGER",
33+
}
34+
} else if (jsonTypes.find((c) => columnInfo.Type.includes(c))) {
35+
return {
36+
graphqlType: `JSON`,
37+
graphqlCreateInputType: `String${isRequiredIndicator}`,
38+
graphqlUpdateInputType: `String${isRequiredIndicator}`,
39+
databaseType: "STRING",
40+
}
41+
} else if (stringTypes.find((c) => columnInfo.Type.includes(c))) {
42+
return {
43+
graphqlType: `String`,
44+
graphqlCreateInputType: `String${isRequiredIndicator}`,
45+
graphqlUpdateInputType: `String${isRequiredIndicator}`,
46+
databaseType: "STRING",
47+
}
48+
} else if (dateTypes.find((c) => columnInfo.Type.includes(c))) {
49+
return {
50+
graphqlType: `String`,
51+
graphqlCreateInputType: `String${isRequiredIndicator}`,
52+
graphqlUpdateInputType: `String${isRequiredIndicator}`,
53+
databaseType: "STRING",
54+
isDateColumn: true,
55+
}
56+
} else if (enumTypes.find((c) => columnInfo.Type.includes(c))) {
57+
return {
58+
graphqlType: `${capitalizeFirstLetter(tableName)}${capitalizeFirstLetter(
59+
columnInfo.Field
60+
)}Enum`,
61+
graphqlCreateInputType: `${capitalizeFirstLetter(
62+
tableName
63+
)}${capitalizeFirstLetter(columnInfo.Field)}Enum${isRequiredIndicator}`,
64+
graphqlUpdateInputType: `${capitalizeFirstLetter(
65+
tableName
66+
)}${capitalizeFirstLetter(columnInfo.Field)}Enum${isRequiredIndicator}`,
67+
databaseType: "ENUM",
68+
isEnum: true,
69+
enumValues: columnInfo.Type.replace("enum(", "")
70+
.replace("ENUM(", "")
71+
.replace(")", "")
72+
.replace(/'/g, "")
73+
.split(","),
74+
}
75+
}
76+
}

0 commit comments

Comments
 (0)