Skip to content

Commit 4e8416e

Browse files
committed
feat: jsdoc type generation
1 parent 616c4d6 commit 4e8416e

File tree

9 files changed

+65
-19
lines changed

9 files changed

+65
-19
lines changed

angular-app/angular.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
22
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3+
"cli": {
4+
"analytics": false
5+
},
36
"version": 1,
47
"newProjectRoot": "projects",
58
"projects": {

angular-app/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
"scripts": {
55
"postinstall": "cd ../backend/ && npm install",
66
"ng": "ng",
7+
"prestart": "warp project select && cd ../backend/ && npm run ts-build",
8+
"start:ts-watch": "cd ../backend/ && npm run ts-watch",
79
"start:client": "ng serve",
810
"start:server": "warp dev ../backend/",
911
"start": "run-p start:*",
12+
"ts-build": "cd ../backend/ && npm run ts-build",
1013
"build:client": "ng build",
1114
"build:server": "warp build ../backend/",
1215
"build": "run-s build:server build:client",
13-
"predeploy": "warp project select",
1416
"deploy": "warp deploy ./ ../backend/",
1517
"test": "ng test",
1618
"lint": "ng lint",
@@ -26,7 +28,7 @@
2628
"@angular/platform-browser": "~11.2.11",
2729
"@angular/platform-browser-dynamic": "~11.2.11",
2830
"@angular/router": "~11.2.11",
29-
"@warpjs/engine": "^4.0.9",
31+
"@warpjs/engine": "^4.0.11",
3032
"rxjs": "~6.6.0",
3133
"tslib": "^2.3.0",
3234
"zone.js": "~0.11.3"
@@ -51,6 +53,6 @@
5153
"ts-node": "~8.3.0",
5254
"tslint": "~6.1.0",
5355
"typescript": "~4.1.5",
54-
"warp": "^4.0.9"
56+
"warp": "^4.0.11"
5557
}
5658
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Component, OnInit } from '@angular/core';
2-
32
import Backend from 'backend';
4-
const { hello, fetchMovies } = new Backend() as any;
3+
4+
const backend = new Backend();
55

66
@Component({
77
selector: 'app-root',
@@ -14,13 +14,13 @@ export class AppComponent implements OnInit {
1414
movies = {};
1515

1616
ngOnInit() {
17-
hello().then((msg: string) => {
17+
backend.hello().then((msg: string) => {
1818
this.message = msg;
1919
});
2020

2121
// fetchMovies from mongodb
22-
fetchMovies('Star Trek').then(
23-
(data: any) => (this.movies = JSON.stringify(data, null, 2))
24-
);
22+
backend.fetchMovies('Star Trek').then((data) => {
23+
this.movies = JSON.stringify(data, null, 2);
24+
});
2525
}
2626
}

backend/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
# dependencies
44
node_modules/
5+
dist/
56
.warp
67

78

backend/package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
{
22
"name": "backend",
33
"version": "1.0.0",
4-
"main": "index.js",
4+
"main": "src/index.js",
55
"license": "MIT",
6+
"scripts": {
7+
"ts-watch": "tsc --watch",
8+
"ts-build": "tsc"
9+
},
610
"dependencies": {
711
"mongodb": "^3.6.6"
12+
},
13+
"devDependencies": {
14+
"typescript": "^4.3.5"
815
}
916
}

backend/index.js renamed to backend/src/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
const { fetchMovies } = require('./src/mongodb');
1+
const { fetchMovies } = require("./mongodb");
22

3+
/**
4+
*
5+
* @returns {Promise<string>} return a hello from your backend module
6+
*/
37
const hello = () => {
48
return `Hello from ScaleDynamics Platform, MongoDB, Angular and Node.js ${process.version} !`;
59
};

backend/src/mongodb.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,38 @@
1-
const { MongoClient } = require('mongodb');
1+
const { MongoClient } = require("mongodb");
2+
3+
/**
4+
* A movie
5+
* @typedef {Object} Movie
6+
* @property {string} title - Title of the movie
7+
* @property {string} year - Year of release of the movie
8+
* @property {string} plot - Plot of the movie
9+
* @property {string} poster - Link to the poster of the movie
10+
*/
211

312
// connection URI
4-
const URI = 'mongodb+srv://test:test@movies-scqxj.gcp.mongodb.net/';
13+
const URI = "mongodb+srv://test:test@movies-scqxj.gcp.mongodb.net/";
514

615
// create & connect a new MongoDB client
716
const connection = MongoClient(URI, {
817
useNewUrlParser: true,
918
useUnifiedTopology: true,
1019
}).connect();
1120

21+
/**
22+
*
23+
* @param {string} search the name of the movies you seek
24+
* @returns {Promise<Movie[]>} return an array of movies
25+
*/
1226
const fetchMovies = async (search) => {
1327
// await database connection
1428
const client = await connection.catch((error) => {
1529
throw new Error(`Database connection failed (${error.message})`);
1630
});
1731
// request database
1832
return client
19-
.db('sample_mflix')
20-
.collection('movies')
21-
.find({ poster: { $exists: true }, title: { $regex: search, $options: 'i' } })
33+
.db("sample_mflix")
34+
.collection("movies")
35+
.find({ poster: { $exists: true }, title: { $regex: search, $options: "i" } })
2236
.project({ _id: 0, title: 1, year: 1, plot: 1, poster: 1 })
2337
.sort({ year: -1 })
2438
.limit(50)

backend/tsconfig.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"compilerOptions": {
3+
"strict": true,
4+
"allowJs": true,
5+
"declaration": true,
6+
"emitDeclarationOnly": true,
7+
"outDir": "dist",
8+
"moduleResolution": "node"
9+
},
10+
"include": ["src/**/*.js"]
11+
}

backend/warp.config.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
module.exports = {
22
output: {
3-
format: 'node-module',
4-
projectPath: '../angular-app',
5-
name: 'backend',
3+
format: "node-module",
4+
projectPath: "../angular-app",
5+
name: "backend",
6+
},
7+
expose: {
8+
source: "src/index.js",
9+
type: "dist/index.d.ts",
610
},
711
};

0 commit comments

Comments
 (0)