Skip to content

Commit

Permalink
Merge pull request #100 from drashland/cleanup-for-v1
Browse files Browse the repository at this point in the history
Cleanup for v1
  • Loading branch information
ebebbington authored Nov 2, 2020
2 parents f015bba + 5adc74d commit bb8ff72
Show file tree
Hide file tree
Showing 27 changed files with 8,858 additions and 130 deletions.
6 changes: 3 additions & 3 deletions .docker/drash.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ RUN apt update -y \
&& apt install -y --no-install-recommends npm \
&& npm install -g npm@latest

RUN curl -fsSL https://deno.land/x/install/install.sh | DENO_INSTALL=/usr/local sh -s v1.1.1
RUN export DENO_INSTALL="/root/.local"
RUN export PATH="$DENO_INSTALL/bin:$PATH"
RUN curl -fsSL https://deno.land/x/install/install.sh | DENO_INSTALL=/usr/local sh -s v1.5.0
RUN export DENO_INSTALL="/usr/bin"
RUN export PATH="$DENO_INSTALL/bin:$PATH"
36 changes: 36 additions & 0 deletions .github/workflows/bumper.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: bumper
on:
schedule:
- cron: '0 0 * * *'

jobs:
update-dep:

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Install Deno
uses: denolib/setup-deno@v2

- name: Update Dependencies
run: |
cd src
deno run --allow-net --allow-read --allow-write https://deno.land/x/dmm/mod.ts update
- name: Update Test Dependencies
run: |
cd src/tests
deno run --allow-net --allow-read --allow-write https://deno.land/x/dmm/mod.ts update
- name: Update Dockerfile
run: deno run --allow-all console/bumper.ts

- name: Create Pull Request
uses: peter-evans/create-pull-request@v2
with:
token: ${{ secrets.CI_USER_PAT }}
commit-message: Update dependencies
title: Update dependencies
body: This was auto-generated by GitHub Actions.
branch: update-dependencies
11 changes: 4 additions & 7 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ on:
jobs:

tests:
strategy:
matrix:
deno: ["1.1.1"]

runs-on: ubuntu-latest

Expand All @@ -40,7 +37,7 @@ jobs:
uses: denolib/setup-deno@master

- name: Formatter
run: deno fmt --check

#- name: Linter
# run: deno lint --unstable
run: deno fmt --check --unstable --ignore='src/public,src/vue,src/package.json,src/webpack.config.js'
#
# - name: Linter
# run: deno lint --unstable --ignore='src/public,src/vue,src/package.json,src/webpack.config.js'
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
# ![Drash Example App](logo.png)

___This respository is still very much under development. Things will change. Things will break. Please take caution when looking at or using the code in this repository.___
___This repository is still very much under development. Things will change. Things will break. Please take caution when looking at or using the code in this repository.___

### Drash codebase containing real world examples (CRUD, auth, advanced patterns, etc) that adheres to the [RealWorld](https://github.com/gothinkster/realworld-example-apps) spec and API.

This real world example application uses Deno, Drash, Vue, webpack, PostgreSQL, and docker-compose.

Requires:
* Deno v1.1.1
* Drash v1.0.6

# How to Run

```
Expand Down Expand Up @@ -59,5 +55,7 @@ Email: user32@hotmail.com
- [Postgres](https://github.com/deno-postgres/deno-postgres) - Postgres driver for the applications database
- [Bcrypt](https://github.com/jamesbroadberry/deno-bcrypt/tree/master) - Hashing and comparing passwords
- [Rhum](https://github.com/drashland/rhum) - Testing framework
- [Dmm](https://github.com/drashland/dmm) - Module Manager for Deno to update our dependencies
- [Vue-input](https://www.npmjs.com/package/@johmun/vue-tags-input) - Library used to help the display of article tags as 'pills', allowing them to be removed and added like a shopping cart
- [Cypress](https://cypress.io/) - Browser testing framework

11 changes: 11 additions & 0 deletions console/bumper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { BumperService } from "https://raw.githubusercontent.com/drashland/services/master/ci/bumper_service.ts";

const b = new BumperService("realworld");

b.bump([
{
filename: "./.docker/drash.dockerfile",
replaceTheRegex: /-s v[0-9.]+[0-9.]+[0-9]/g,
replaceWith: "-s v{{ latestDenoVersion }}",
},
]);
12 changes: 6 additions & 6 deletions src/deps.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export { Drash } from "https://deno.land/x/drash@v1.0.6/mod.ts";
export { Drash } from "https://deno.land/x/drash@v1.2.5/mod.ts";

export {
Client as PostgresClient,
Pool,
} from "https://deno.land/x/postgres@v0.4.2/mod.ts";
export { Column } from "https://deno.land/x/postgres@v0.4.2/connection.ts";
export { QueryResult } from "https://deno.land/x/postgres@v0.4.2/query.ts";
export { PoolClient } from "https://deno.land/x/postgres@v0.4.2/client.ts";
import * as bcrypt from "https://deno.land/x/bcrypt@v0.2.1/mod.ts";
} from "https://deno.land/x/postgres@v0.4.5/mod.ts";
export { Column } from "https://deno.land/x/postgres@v0.4.5/connection.ts";
export type { QueryResult } from "https://deno.land/x/postgres@v0.4.5/query.ts";
export { PoolClient } from "https://deno.land/x/postgres@v0.4.5/client.ts";
import * as bcrypt from "https://deno.land/x/bcrypt@v0.2.4/mod.ts";
export { bcrypt };
19 changes: 9 additions & 10 deletions src/models/article_comments_model.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import BaseModel from "./base_model.ts";
import { ArticleModel } from "./article_model.ts";
import type { ArticleModel } from "./article_model.ts";

export type ArticleCommentEntity = {
created_at: number;
Expand Down Expand Up @@ -196,8 +196,7 @@ export class ArticleCommentsModel extends BaseModel {
await client.query(query);
client.release();

// @ts-ignore
// (crookse) We ignore this because this will never return null.
// @ts-ignore (crookse) We ignore this because this will never return null.
const tmp = await ArticleCommentsModel.where(
{ author_id: this.author_id, body: this.body },
);
Expand Down Expand Up @@ -255,7 +254,7 @@ export class ArticleCommentsModel extends BaseModel {
const dbResult = await client.query(query);
client.release();

let results = BaseModel.formatResults(
const results = BaseModel.formatResults(
dbResult.rows,
dbResult.rowDescription.columns,
);
Expand All @@ -266,14 +265,14 @@ export class ArticleCommentsModel extends BaseModel {
* @description
* See BaseModel.where()
*
* @param any fields
* @param fields
*
* @return Promise<ArticleModel[]|[]>
*/
static async where(
fields: any,
fields: { [key: string]: string | number },
): Promise<ArticleCommentsModel[] | []> {
let results = await BaseModel.Where("article_comments", fields);
const results = await BaseModel.Where("article_comments", fields);

if (results.length <= 0) {
return [];
Expand All @@ -287,15 +286,15 @@ export class ArticleCommentsModel extends BaseModel {
* See BaseModel.whereIn()
*
* @param string column
* @param any values
* @param string[] values
*
* @return Promise<ArticleModel[]|[]>
*/
static async whereIn(
column: string,
values: any,
values: Array<string | number>,
): Promise<ArticleCommentsModel[] | []> {
let results = await BaseModel.WhereIn("article_comments", {
const results = await BaseModel.WhereIn("article_comments", {
column,
values,
});
Expand Down
14 changes: 7 additions & 7 deletions src/models/article_model.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import BaseModel from "./base_model.ts";
import { UserEntity, UserModel } from "./user_model.ts";
import { QueryResult } from "../deps.ts";
import type { UserEntity, UserModel } from "./user_model.ts";
import type { QueryResult } from "../deps.ts";

export type ArticleEntity = {
author?: UserEntity | null;
Expand Down Expand Up @@ -94,14 +94,14 @@ export class ArticleModel extends BaseModel {
*
* If the article is favorited
*/
public favorited: boolean = false;
public favorited = false;

/**
* @var numbers [=0]
*
* Number of favourites the article has accumulated
*/
public favoritesCount: number = 0;
public favoritesCount = 0;

/**
* @var number
Expand Down Expand Up @@ -305,7 +305,7 @@ export class ArticleModel extends BaseModel {
return [];
}

let results = BaseModel.formatResults(
const results = BaseModel.formatResults(
dbResult.rows,
dbResult.rowDescription.columns,
);
Expand Down Expand Up @@ -353,7 +353,7 @@ export class ArticleModel extends BaseModel {
static async where(
fields: { [key: string]: string | number },
): Promise<ArticleModel[] | []> {
let results = await BaseModel.Where("articles", fields);
const results = await BaseModel.Where("articles", fields);

if (results.length <= 0) {
return [];
Expand Down Expand Up @@ -401,7 +401,7 @@ export class ArticleModel extends BaseModel {
column: string,
values: string[] | number[],
): Promise<ArticleModel[] | []> {
let results = await BaseModel.WhereIn("articles", {
const results = await BaseModel.WhereIn("articles", {
column,
values,
});
Expand Down
12 changes: 6 additions & 6 deletions src/models/articles_favorites_model.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import BaseModel from "./base_model.ts";
import { QueryResult } from "../deps.ts";
import type { QueryResult } from "../deps.ts";

export type ArticlesFavoritesEntity = {
article_id: number;
Expand Down Expand Up @@ -65,10 +65,10 @@ export class ArticlesFavoritesModel extends BaseModel {
/**
* TODO(ebebbington) What is this property used for?
*/
public query: string = "";
public query = "";

//////////////////////////////////////////////////////////////////////////////
// FILE MARKER - CONSTRCUTOR /////////////////////////////////////////////////
// FILE MARKER - CONSTRUCTOR /////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////

/**
Expand Down Expand Up @@ -210,7 +210,7 @@ export class ArticlesFavoritesModel extends BaseModel {
static async where(
fields: { [key: string]: string | number },
): Promise<ArticlesFavoritesModel[] | []> {
let results = await BaseModel.Where("articles_favorites", fields);
const results = await BaseModel.Where("articles_favorites", fields);

if (results.length <= 0) {
return [];
Expand Down Expand Up @@ -244,9 +244,9 @@ export class ArticlesFavoritesModel extends BaseModel {
*/
static async whereIn(
column: string,
values: string[] | number[],
values: Array<number | string>,
): Promise<ArticlesFavoritesModel[] | []> {
let results = await BaseModel.WhereIn("articles_favorites", {
const results = await BaseModel.WhereIn("articles_favorites", {
column,
values,
});
Expand Down
19 changes: 10 additions & 9 deletions src/models/base_model.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Column, Pool, PoolClient, QueryResult } from "../deps.ts";
import { Column, Pool, PoolClient } from "../deps.ts";
import type { QueryResult } from "../deps.ts";

export const dbPool = new Pool({
user: "user",
Expand Down Expand Up @@ -56,9 +57,9 @@ export default abstract class BaseModel {
const columnNames: string[] = columns.map((column) => {
return column.name;
});
let newResult: Array<{ [key: string]: string }> = [];
const newResult: Array<{ [key: string]: string }> = [];
rows.forEach((row, rowIndex) => {
let rowData: { [key: string]: string } = {};
const rowData: { [key: string]: string } = {};
row.forEach((rVal, rIndex) => {
const columnName: string = columnNames[rIndex];
rowData[columnName] = row[rIndex];
Expand All @@ -82,9 +83,9 @@ export default abstract class BaseModel {
fields: { [key: string]: string | number },
): Promise<[] | Array<{ [key: string]: string | number | boolean }>> {
let query = `SELECT * FROM ${table} WHERE `;
let clauses: string[] = [];
for (let field in fields) {
let value = fields[field];
const clauses: string[] = [];
for (const field in fields) {
const value = fields[field];
clauses.push(`${field} = '${value}'`);
}
query += clauses.join(" AND ");
Expand Down Expand Up @@ -117,13 +118,13 @@ export default abstract class BaseModel {
*/
static async WhereIn(
table: string,
data: { values: string[] | number[]; column: string },
data: { values: Array<number | string> | number[]; column: string },
): Promise<[] | Array<{ [key: string]: string | number | boolean }>> {
if (data.values.length <= 0) {
return [];
}

let query = `SELECT * FROM ${table} ` +
const query = `SELECT * FROM ${table} ` +
` WHERE ${data.column} ` +
` IN (${data.values.join(",")})`;

Expand Down Expand Up @@ -167,7 +168,7 @@ export default abstract class BaseModel {
return query;
}
// First create an array item for each placeholder
let occurrences = query.split("?");
const occurrences = query.split("?");
if (occurrences[occurrences.length - 1] === "") { // for when last item is ""
occurrences.splice(occurrences.length - 1);
}
Expand Down
2 changes: 1 addition & 1 deletion src/models/session_model.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import BaseModel from "./base_model.ts";
import { QueryResult } from "../deps.ts";
import type { QueryResult } from "../deps.ts";

interface SessionModelEntity {
session_one: string;
Expand Down
6 changes: 3 additions & 3 deletions src/models/user_model.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import BaseModel from "./base_model.ts";
import { QueryResult } from "../deps.ts";
import type { QueryResult } from "../deps.ts";

export type UserEntity = {
bio?: string;
Expand Down Expand Up @@ -241,7 +241,7 @@ export class UserModel extends BaseModel {
static async where(
fields: { [key: string]: string | number },
): Promise<UserModel[] | []> {
let results = await BaseModel.Where("users", fields);
const results = await BaseModel.Where("users", fields);

if (results.length <= 0) {
return [];
Expand All @@ -267,7 +267,7 @@ export class UserModel extends BaseModel {
column: string,
values: string[] | number[],
): Promise<UserModel[] | []> {
let results = await BaseModel.WhereIn("users", {
const results = await BaseModel.WhereIn("users", {
column,
values,
});
Expand Down
Loading

0 comments on commit bb8ff72

Please sign in to comment.