Skip to content

Commit

Permalink
Project structure to enable shared code
Browse files Browse the repository at this point in the history
- The "shared" project is now in the "functions" project, because all the code that functions use, should be in that directory.
- Yarn workspaces are introduced, to be able to access the code in "functions" from the "web" project.
  • Loading branch information
BenjaVR committed Dec 18, 2018
1 parent 2cea74c commit 1b74347
Show file tree
Hide file tree
Showing 48 changed files with 12,683 additions and 21,109 deletions.
4 changes: 4 additions & 0 deletions functions/dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/// <reference types="express" />
import * as functions from "firebase-functions";
export declare const test: functions.TriggerAnnotated & ((req: functions.Request, resp: functions.Response) => void) & functions.Runnable<any>;
export declare const addSchool: functions.TriggerAnnotated & ((req: functions.Request, resp: functions.Response) => void) & functions.Runnable<any>;
7 changes: 7 additions & 0 deletions functions/dist/shared/firebase/interfaces.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Language } from "../translations/types";
export interface IFirebaseFunctionParam<T> {
lang: Language;
data: T;
}
export interface IFirebaseFunctionResponse<T> {
}
6 changes: 6 additions & 0 deletions functions/dist/shared/models/LoginDetails.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { ValidationResult } from "../validators/ValidationResult";
export interface ILoginDetails {
username: string;
password: string;
}
export declare function validateLoginDetails(loginDetails: ILoginDetails): ValidationResult<ILoginDetails>;
6 changes: 6 additions & 0 deletions functions/dist/shared/models/School.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { ValidationResult } from "../validators/ValidationResult";
export interface ISchool {
id?: string;
name: string;
}
export declare function validateSchool(school: ISchool): ValidationResult<ISchool>;
4 changes: 4 additions & 0 deletions functions/dist/shared/translations/En.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { ILanguage, I18nextResourceTranslations } from "./types";
export declare class En implements ILanguage {
getTranslations(): I18nextResourceTranslations;
}
4 changes: 4 additions & 0 deletions functions/dist/shared/translations/Nl.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { I18nextResourceTranslations, ILanguage } from "./types";
export declare class Nl implements ILanguage {
getTranslations(): I18nextResourceTranslations;
}
16 changes: 16 additions & 0 deletions functions/dist/shared/translations/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export interface I18nextResource {
[key: string]: any;
}
export declare type I18nextResourceTranslations = I18nextResource & ITranslations;
export interface ILanguage {
getTranslations(): ITranslations;
}
export declare type Language = "nl" | "en";
export interface ITranslations {
"validation.field_should_not_be_empty": string;
"validation.model_should_not_have_id": string;
"auth.logged_in_successfully": string;
"auth.logging_in_failed": string;
"auth.logged_out_successfully": string;
"auth.welcome_back{{username}}": string;
}
5 changes: 5 additions & 0 deletions functions/dist/shared/validators/FirebaseValidator.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export declare class FirebaseValidator {
static hasId(value: {
id?: string;
}): boolean;
}
3 changes: 3 additions & 0 deletions functions/dist/shared/validators/StringValidator.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export declare class StringValidator {
static isEmpty(value: string): boolean;
}
9 changes: 9 additions & 0 deletions functions/dist/shared/validators/ValidationError.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ITranslations } from "../translations/types";
export declare class ValidationError<T> {
readonly field: keyof T;
/**
* Translation key that contains the error message.
*/
readonly translationKey: keyof ITranslations;
constructor(field: keyof T, translationKey: keyof ITranslations);
}
9 changes: 9 additions & 0 deletions functions/dist/shared/validators/ValidationResult.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ValidationError } from "./ValidationError";
export declare class ValidationResult<T> {
readonly instance: T;
readonly errors: Array<ValidationError<T>>;
constructor(instance: T);
add(error: ValidationError<T>): void;
hasErrors(): boolean;
getErrorsWithField(field: keyof T): Array<ValidationError<T>>;
}
12 changes: 6 additions & 6 deletions functions/package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{
"name": "functions",
"name": "@studentplanner/functions",
"version": "1.0.0",
"scripts": {
"lint": "tslint --project tsconfig.json",
"build": "tsc",
"build:watch": "tsc -w",
"build": "tsc --skipLibCheck",
"build:watch": "tsc -w --skipLibCheck",
"serve": "npm run build && firebase serve --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"main": "lib/index.js",
"main": "dist/index.js",
"dependencies": {
"firebase-admin": "~6.0.0",
"firebase-functions": "^2.1.0",
"shared": "file:../shared"
"firebase-functions": "^2.1.0"
},
"devDependencies": {
"tslint": "~5.8.0",
Expand Down
4 changes: 2 additions & 2 deletions functions/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as functions from "firebase-functions";
import * as admin from "firebase-admin";
import { CallableContext, HttpsError } from "firebase-functions/lib/providers/https";
import { ISchool, validateSchool } from "shared/dist/models/School";
import { IFirebaseFunctionParam } from "shared/dist/firebase/interfaces";
import { ISchool, validateSchool } from "./shared/models/School";
import { IFirebaseFunctionParam } from "./shared/firebase/interfaces";

admin.initializeApp();
const db = admin.firestore();
Expand Down
1 change: 1 addition & 0 deletions functions/src/shared/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ValidationResult } from "../validators/ValidationResult";
import { StringValidator } from "../validators";
import { StringValidator } from "../validators/StringValidator";
import { ValidationError } from "../validators/ValidationError";

export interface ILoginDetails {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { FirebaseValidator, StringValidator } from "../validators";
import { FirebaseValidator } from "../validators/FirebaseValidator";
import { StringValidator } from "../validators/StringValidator";
import { ValidationResult } from "../validators/ValidationResult";
import { ValidationError } from "../validators/ValidationError";

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
interface I18nextResource {
export interface I18nextResource {
[key: string]: any;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default class FirebaseValidator {
export class FirebaseValidator {
public static hasId(value: { id?: string }) {
return value.id !== undefined;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default class StringValidator {
export class StringValidator {
public static isEmpty(value: string): boolean {
return value === undefined
|| value.length === 0;
Expand Down
File renamed without changes.
File renamed without changes.
5 changes: 3 additions & 2 deletions functions/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
"compilerOptions": {
"lib": ["es6"],
"module": "commonjs",
"declaration": true,
"noImplicitReturns": true,
"outDir": "lib",
"outDir": "dist",
"sourceMap": true,
"target": "es6"
"target": "es5"
},
"compileOnSave": true,
"include": [
Expand Down
Loading

0 comments on commit 1b74347

Please sign in to comment.