Skip to content
This repository was archived by the owner on Sep 1, 2022. It is now read-only.

Commit 535cdc9

Browse files
committed
Converted the project to TypeScript
1 parent b866e1e commit 535cdc9

18 files changed

+211
-120
lines changed

.eslintignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build
2+
node_modules

.eslintrc

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"root": true,
3+
"parser": "@typescript-eslint/parser",
4+
"env": {
5+
"browser": true,
6+
"amd": true,
7+
"node": true
8+
},
9+
"plugins": [
10+
"@typescript-eslint"
11+
],
12+
"extends": [
13+
"eslint:recommended",
14+
"plugin:@typescript-eslint/eslint-recommended",
15+
"plugin:@typescript-eslint/recommended"
16+
],
17+
"rules": {}
18+
}

.github/workflows/ci.yml

+9-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- name: Setup Node.js
1818
uses: actions/setup-node@v1
1919
with:
20-
node-version: '12.x'
20+
node-version: '14.x'
2121

2222
- name: Checkout the code
2323
uses: actions/checkout@v2
@@ -27,19 +27,23 @@ jobs:
2727
run: |
2828
echo "::set-output name=date::$(date +'%y.%-m').$GITHUB_RUN_NUMBER"
2929
30+
- name: Compile the binaries
31+
run: |
32+
yarn
33+
yarn build
34+
3035
- name: Build and run the Docker image
3136
run: |
3237
docker build -t $IMAGE_NAME .
3338
docker tag $IMAGE_NAME:latest $IMAGE_NAME:${{ steps.calver.outputs.date }}
34-
docker-compose up -d
3539
3640
- name: Test the build
3741
run: |
42+
docker-compose up -d
3843
sleep 10
39-
yarn --cwd $GITHUB_WORKSPACE/test
40-
yarn --cwd $GITHUB_WORKSPACE/test test
44+
yarn test
4145
42-
- name: Creating release
46+
- name: Create release
4347
id: create_release
4448
uses: actions/create-release@v1
4549
env:

.github/workflows/cron.yml

+9-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- name: Setup Node.js
1616
uses: actions/setup-node@v1
1717
with:
18-
node-version: '12.x'
18+
node-version: '14.x'
1919

2020
- name: Checkout the code
2121
uses: actions/checkout@v2
@@ -25,17 +25,21 @@ jobs:
2525
run: |
2626
echo "::set-output name=date::$(date +'%y.%-m')"
2727
28-
- name: Build and run the Docker image
28+
- name: Compile the binaries
29+
run: |
30+
yarn
31+
yarn build
32+
33+
- name: Build the Docker image
2934
run: |
3035
docker build -t $IMAGE_NAME .
3136
docker tag $IMAGE_NAME:latest $IMAGE_NAME:${{ steps.calver.outputs.date }}
32-
docker-compose up -d
3337
3438
- name: Test the build
3539
run: |
40+
docker-compose up -d
3641
sleep 10
37-
yarn --cwd $GITHUB_WORKSPACE/test
38-
yarn --cwd $GITHUB_WORKSPACE/test test
42+
yarn test
3943
4044
- name: Creating release
4145
id: create_release

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
# User-specific stuff:
66
.idea/
7+
build/
78

89
## File-based project format:
910
*.iws

Dockerfile

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
FROM node:alpine
22
LABEL maintainer="Vinicius Egidio <[email protected]>"
33

4-
# Installing build dependencies
5-
RUN apk --no-cache --virtual .build-deps add python build-base
6-
7-
ADD express /usr/local/parse
4+
# Pulling dependencies
5+
ADD build /usr/local/parse
86
WORKDIR /usr/local/parse
9-
RUN yarn
10-
11-
# Removing build dependencies
12-
RUN apk del .build-deps
7+
RUN yarn --production
138

14-
CMD yarn start
9+
CMD node server.js

express/package.json

-14
This file was deleted.

jest.config.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
preset: 'ts-jest',
3+
testEnvironment: 'node',
4+
modulePathIgnorePatterns: ['<rootDir>/build']
5+
};

package.json

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"name": "parse-server",
3+
"version": "1.0.0",
4+
"license": "Apache-2.0",
5+
"main": "src/index.ts",
6+
"dependencies": {
7+
"@types/express": "latest",
8+
"express": "latest",
9+
"parse-server": "latest",
10+
"parse-dashboard": "latest"
11+
},
12+
"devDependencies": {
13+
"@types/copy-webpack-plugin": "latest",
14+
"@types/jest": "latest",
15+
"@types/node": "latest",
16+
"@types/parse": "latest",
17+
"@types/webpack": "latest",
18+
"@types/webpack-node-externals": "latest",
19+
"@typescript-eslint/eslint-plugin": "latest",
20+
"@typescript-eslint/parser": "latest",
21+
"axios": "latest",
22+
"copy-webpack-plugin": "latest",
23+
"eslint": "latest",
24+
"jest": "latest",
25+
"moment": "latest",
26+
"parse": "latest",
27+
"ts-jest": "latest",
28+
"ts-loader": "latest",
29+
"ts-node": "latest",
30+
"typescript": "latest",
31+
"webpack": "latest",
32+
"webpack-cli": "latest",
33+
"webpack-node-externals": "latest"
34+
},
35+
"scripts": {
36+
"build": "webpack",
37+
"lint": "eslint src --ext .ts",
38+
"start": "ts-node src/index.ts",
39+
"test": "jest"
40+
}
41+
}
+7-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
module.exports =
2-
{
3-
buildConnectionUrl: (env, appId) =>
1+
import ProcessEnv = NodeJS.ProcessEnv;
2+
3+
export default {
4+
buildConnectionUrl: (env: ProcessEnv, appId: string): string =>
45
{
56
let url = env.DB_HOST;
67

78
// Add username & password
89
if (typeof env.DB_USERNAME !== 'undefined' && typeof env.DB_PASSWORD !== 'undefined') {
9-
let creds = env.DB_USERNAME + ':' + env.DB_PASSWORD + '@';
10-
let pos = url.indexOf('://') + 3;
10+
const creds = env.DB_USERNAME + ':' + env.DB_PASSWORD + '@';
11+
const pos = url.indexOf('://') + 3;
1112
url = url.substring(0, pos) + creds + url.substring(pos);
1213
}
1314

@@ -16,4 +17,4 @@ module.exports =
1617

1718
return url;
1819
}
19-
};
20+
}

express/index.js src/index.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
const express = require('express');
2-
const { default: ParseServer, ParseGraphQLServer } = require('parse-server');
3-
const ParseDashboard = require('parse-dashboard');
4-
const db = require("./database");
1+
import * as express from 'express';
2+
import ParseServer, { ParseGraphQLServer } from 'parse-server';
3+
import * as ParseDashboard from 'parse-dashboard';
4+
import db from './database';
55

6-
let app = express();
7-
let parseArray = process.env.APP_IDS.split(',');
8-
let liveQueryArray = process.env.LIVE_QUERIES.split('|');
9-
let dashboardArray = [];
6+
const app = express();
7+
const parseArray = process.env.APP_IDS ? process.env.APP_IDS.split(',') : [];
8+
const liveQueryArray = process.env.LIVE_QUERIES ? process.env.LIVE_QUERIES.split('|') : [];
9+
const dashboardArray: unknown[] = [];
1010

1111
// Parse Server
1212
parseArray.forEach(appId => {
@@ -19,8 +19,8 @@ parseArray.forEach(appId => {
1919
});
2020

2121
// Live Query configuration
22-
let liveQueryClasses = liveQueryArray.reduce((res, value) => {
23-
let prefix = `${appId}:`;
22+
const liveQueryClasses = liveQueryArray.reduce((res, value) => {
23+
const prefix = `${appId}:`;
2424
if(value.startsWith(prefix)) res = res.concat(value.replace(prefix, '').split(','));
2525
return res;
2626
}, []);
@@ -45,7 +45,7 @@ parseArray.forEach(appId => {
4545
});
4646

4747
// Parse Dashboard
48-
let dashboard = new ParseDashboard({
48+
const dashboard = new ParseDashboard({
4949
'apps': dashboardArray,
5050
'users': [{
5151
'user': process.env.DASHBOARD_USERNAME,
@@ -60,5 +60,5 @@ app.use('/dashboard/', dashboard);
6060
// Parse Server plays nicely with the rest of your web routes
6161
app.get('/', (req, res) => res.status(200).send('Welcome to the Parse Server'));
6262

63-
let port = process.env.PORT || 1337;
64-
app.listen(port, () => console.log(`Parse Server is running on port ${port}.`));
63+
const port = process.env.PORT || 1337;
64+
app.listen(port, () => console.log(`Parse Server is running on port ${port}.`));

test/package.json

-19
This file was deleted.

test/rest.test.js test/rest.test.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
const axios = require('axios');
1+
import axios from 'axios';
2+
import * as moment from 'moment';
23

3-
let client = axios.create({
4+
const client = axios.create({
45
baseURL: 'http://localhost:1337/app/app2/',
56
headers: {
67
'X-Parse-Application-Id': 'app2',
@@ -16,14 +17,14 @@ beforeAll(() => {
1617
describe('Test the REST API', () =>
1718
{
1819
test('Create Parse object', () => {
19-
let body = {
20+
const body = {
2021
'name': 'Indiana Jones',
21-
'releaseDate': new Date(Date.UTC(1981, 5, 12)),
22+
'releaseDate': moment.utc([1981, 5, 12]).toDate(),
2223
'rating': 8.5
2324
};
2425

2526
return client.post('classes/Movie', body)
26-
.then((res) => {
27+
.then(res => {
2728
expect(res.status).toBe(201);
2829
expect(res.data).toHaveProperty('objectId');
2930
expect(res.data).toHaveProperty('createdAt');
@@ -32,8 +33,8 @@ describe('Test the REST API', () =>
3233

3334
test('Query Parse object', () => {
3435
return client.get('classes/Movie')
35-
.then((res) => {
36-
let obj = res.data.results[0];
36+
.then(res => {
37+
const obj = res.data.results[0];
3738
expect(res.status).toBe(200);
3839
expect(obj.name).toBe('Indiana Jones');
3940
expect(obj.rating).toBe(8.5);

test/sdk.test.js

-42
This file was deleted.

0 commit comments

Comments
 (0)