Skip to content

Commit

Permalink
fix(core-server): updated false return on formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanMatthias committed Dec 16, 2018
1 parent 9824759 commit 6aca57d
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 63 deletions.
121 changes: 62 additions & 59 deletions packages/core-lib/src/types/Origami.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,121 +7,120 @@ export namespace Origami {
/**
* Settings for the overall project
*/
'app': ConfigApp;
app: ConfigApp;

/**
* Settings for the store/database
*/
'store'?: ConfigStore;
store?: ConfigStore;

/**
* Settings for the server setup
*/
'server': ConfigServer;
server: ConfigServer;

/**
* Admin node module
*/
'admin'?: boolean | string;
admin?: boolean | string;

/**
* Model/Controller resources to automatically create
*/
'resources'?: {
resources?: {
[name: string]: ConfigResource | string;
};

/**
* Plugins to integrate into Origami
*/
'plugins'?: {
plugins?: {
[name: string]: boolean | object;
};

/**
* Add controllers by individual files or directories
*/
'controllers'?: {
controllers?: {
[path: string]: ConfigController | string | boolean;
};

/**
* Applications to install into Origami
*/
'apps'?: {
apps?: {
[name: string]: boolean | object;
};
}


export interface ConfigApp {
/**
* Name of the project
*/
'name': string;
name: string;
}


export interface ConfigStore {
/**
* Store/Database type to integrate with
*/
'type': string;
type: string;
/**
* Store/Database hostname to connect with
*/
'host': string;
host: string;
/**
* Store/Database port to connect with
*/
'port': number;
port: number;
/**
* Store/Database db name to connect with
*/
'database': string;
database: string;
/**
* Store/Database username to connect with
*/
'username': string;
username: string;
/**
* Store/Database password to connect with
*/
'password': string;
password: string;
}

export interface ConfigTheme {
/**
* Theme name to run
*/
'name'?: string;
'path'?: string;
name?: string;
path?: string;
}

export interface ConfigServer {
/**
* Secret code to encrypt data and authentication tokens with
*/
'secret'?: string;
secret?: string;
/**
* Port number to run the server on
*/
'port'?: number;
port?: number;
/**
* Server language
*/
'ln'?: string;
ln?: string;
/**
* Static directories to serve
*/
'static'?: string | string[] | boolean;
static?: string | string[] | boolean;
}


export interface ConfigResource {
model: string;
auth?: boolean | {
[key in 'get' | 'head' | 'post' | 'put' | 'delete' | 'list']: boolean
};
auth?:
| boolean
| {
[key in 'get' | 'head' | 'post' | 'put' | 'delete' | 'list']: boolean
};
}

export interface ConfigController {
Expand All @@ -131,41 +130,57 @@ export namespace Origami {
prefix?: string;
}


/**
* Valid types of Origami modules to install via NPM
* @example origami-theme-snow, origami-store-mongodb, origami-plugin-facebook
*/
export type ModuleType = 'theme' | 'store' | 'plugin' | 'admin';


export namespace Server {

export type Position = 'init' | 'pre-store' | 'store' | 'post-store' |
'pre-render' | 'render' | 'post-render' | 'pre-send';
export type Position =
| 'init'
| 'pre-store'
| 'store'
| 'post-store'
| 'pre-render'
| 'render'
| 'post-render'
| 'pre-send';

export type URL = string | null | RegExp;

export type Method = 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' |
'CONNECT' | 'OPTIONS' | 'PATCH' | 'USE';
export type Method =
| 'GET'
| 'HEAD'
| 'POST'
| 'PUT'
| 'DELETE'
| 'CONNECT'
| 'OPTIONS'
| 'PATCH'
| 'USE';

// tslint:disable-next-line no-shadowed-variable
export interface Config {
/**
* Secret code to encrypt data and authentication tokens with
*/
'secret': string;
secret: string;
/**
* Port number to run the server on
*/
'port': number;
port: number;
/**
* Server language
*/
'ln': string;
ln: string;
}

export type RequestHandler = (req: Request, res: Response, next: express.NextFunction) => any;
export type RequestHandler = (
req: Request,
res: Response,
next: express.NextFunction
) => any;

export interface Request extends express.Request {
jwt: {
Expand All @@ -187,15 +202,14 @@ export namespace Origami {
}

// tslint:disable-next-line no-empty-interface
export interface NextFunction extends express.NextFunction { }
export interface NextFunction extends express.NextFunction {}

export interface DataError extends Error {
data: object;
statusCode?: number;
}
}


export namespace Theme {
// tslint:disable-next-line no-shadowed-variable
export interface Config {
Expand All @@ -211,19 +225,16 @@ export namespace Origami {
}
}


export namespace Store {
// tslint:disable-next-line no-shadowed-variable
export declare const Store: {
new(options: StoreOptions): Store;
new (options: StoreOptions): Store;
};
// tslint:disable-next-line no-shadowed-variable
export interface Store {

models: { [name: string]: Model };
connURI: string;


connect(): Promise<any>;
model(name: string, schema?: Schema): Model | void;
}
Expand All @@ -236,42 +247,35 @@ export namespace Origami {
database: string;
}


export interface Schema {
tree?: boolean;
properties: {
[key: string]: any;
};
}


export declare const Model: {
new(name: string, schema: Schema): Model;
new (name: string, schema: Schema): Model;
};
export interface Model {
create(resource: Resource): Resource;

find(query: object, opts?: object):
Promise<Resource | Resource[] | null>;
find(query: object, opts?: object): Promise<Resource | Resource[] | null>;
}


export interface Resource {
id?: string;
deletedAt?: Date | null;
children?: Resource[];

[key: string]: any;
}

}


export interface AppManifest {
name: string;
icon?: string;


admin?: {
uriBase?: string;
entryElement?: string;
Expand All @@ -280,7 +284,6 @@ export namespace Origami {
public?: string;
};


resources?: object[];
plugins?: object[];
routes?: object[];
Expand All @@ -296,22 +299,22 @@ export namespace Origami {
private _content?;
private _responseCode;
constructor(req: Server.Request, res: Server.Response);
public override(content: ResponseContent): void;
public set(content: ResponseContent): void;
public get(): ResponseContent | false;
public clear(): void;
}
}


export interface PackageJson {
'name'?: string;
'dependencies'?: {
name?: string;
dependencies?: {
[pkg: string]: string;
};
'devDependencies'?: {
devDependencies?: {
[pkg: string]: string;
};
'scripts'?: {
scripts?: {
[name: string]: string;
};
}
4 changes: 2 additions & 2 deletions packages/core-server/src/lib/Content/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export class Content {
this._content = content;
}

public get(): ResponseContent | void {
if (!this.hasContent) { return; }
public get(): ResponseContent | false {
if (!this.hasContent) { return false; }
return this._content!;
}

Expand Down
6 changes: 4 additions & 2 deletions packages/core-server/src/middleware/format/lib/Formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,11 @@ export class Formatter {

private _sendJSON(data: any) {
const obj = {
statusCode: this.res.statusCode,
data
statusCode: this.res.statusCode
} as ReturningJSON;

if (data || data === 0) obj.data = data;

if (this.message) obj.message = this.message;

return this.res.json(obj);
Expand Down
20 changes: 20 additions & 0 deletions packages/plugin-sitemap/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@origami/plugin-sitemap",
"version": "0.0.0",
"description": "Automatic sitemap generator for Origami",
"repository": "https://github.com/origami-cms/core/tree/master/packages/plugin-sitemap",
"homepage": "http://www.origami.so",
"author": "Tristan Matthias <[email protected]>",
"license": "MIT",
"main": "./build/index.js",
"typings": "./build/index.d.ts",
"scripts": {
"clean": "rm -rf build",
"watch": "tsc -w",
"build": "yarn clean && tsc"
},
"dependencies": {
"@origami/core": "0.0.3-alpha.7",
"sitemap": "^2.1.0"
}
}

0 comments on commit 6aca57d

Please sign in to comment.