Skip to content

Commit f5cdd2f

Browse files
committed
improved error logging, improved type def, version bump
1 parent 760a711 commit f5cdd2f

File tree

10 files changed

+63
-30
lines changed

10 files changed

+63
-30
lines changed

bin/scripts/init.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ export default async () => {
8989
*/
9090
let package_json = JSON.parse(await fs.readFile(`${project_path}/package.json`));
9191

92+
// delete internal
93+
delete package_json.scripts.__internal_test;
94+
9295
// ensure user gets latest version
9396
package_json.dependencies['@exajs/core'] = 'latest';
9497

index.d.ts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,31 @@ declare module '@exajs/core/database' {
99
export { connection, models };
1010
}
1111

12-
declare module '@exajs/core/database/models' {
13-
const models: any;
14-
export default models;
15-
}
16-
17-
declare module '@exajs/core/database/connection' {
18-
const connection: any;
19-
export default connection;
20-
}
21-
2212
declare module '@exajs/core/system/sequelize' {
2313
const sequelize: any;
2414
export default sequelize;
2515
export * from 'sequelize';
2616
}
2717

2818
declare module '@exajs/core/util' {
29-
import hash from '#exa/util/hash.js';
30-
import json from '#exa/util/json.js';
31-
import string from '#exa/util/string.js';
32-
export { hash, json, string };
19+
class Hash {
20+
sha1(string?: any): string;
21+
sha2(string?: any): string;
22+
}
23+
class Json {
24+
safe_parse(json: string, def?: any): any;
25+
merge(...objects: any[]): object;
26+
minify(jsonString: string): string;
27+
compare(obj1: any, obj2: any): boolean;
28+
}
29+
class String {
30+
ucwords(string: any): string;
31+
to_slug(string: any): string;
32+
to_currency(amount: any): string;
33+
strip_html(str: any): any;
34+
}
35+
36+
export const hash: Hash;
37+
export const json: Json;
38+
export const string: String;
3339
}

lib/core/logger.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import chalk from 'chalk';
33
export default new class {
44

55
error(...msg) {
6-
console.log(`${chalk.red('!')}`, ...msg);
6+
console.log(`${chalk.red('!')}`, ...this.dim(...msg));
77
}
88

99
warning(...msg) {
@@ -14,4 +14,22 @@ export default new class {
1414
console.log(`${chalk.cyan('*')}`, ...msg);
1515
}
1616

17+
dim(...msg) {
18+
return msg.map(line => {
19+
if (typeof line !== 'string') {
20+
return line;
21+
}
22+
23+
return line
24+
.split('\n')
25+
.map(line => {
26+
if (line.match(/at.+(node_modules|node:internal)/gi)) {
27+
return chalk.gray(line);
28+
}
29+
return line;
30+
})
31+
.join('\n');
32+
});
33+
}
34+
1735
}

lib/database/models.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import config from '#exa/core/config.js';
2+
import logger from '#exa/core/logger.js';
23
import connection from '#exa/database/connection.js';
4+
import chalk from 'chalk';
35
import { glob } from 'glob';
46

57
let models = {};
68

7-
export const init = async () => {
9+
export const init = async quiet => {
810
let files = await glob(`${config.paths.root}${config.paths.models}/*.js`);
911

1012
for (const file of files) {
@@ -45,6 +47,10 @@ export const init = async () => {
4547

4648
model.associate && model.associate(models);
4749
}
50+
51+
if (!quiet) {
52+
logger.info(`initialized ${chalk.green(Object.entries(models).length)} models`);
53+
}
4854
};
4955

5056
export default models;

lib/http/express.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export const init = async () => {
8181

8282
// start server
8383
const server = app.listen(config.http.port, () => {
84-
logger.info(`server running on ${config.http.host}:${config.http.port}`);
84+
logger.info(`http server running on ${config.http.host}:${config.http.port}`);
8585
});
8686

8787
if (config.websocket.use) {

lib/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ const handle_fatal_logging = err => {
2020
if (err instanceof Error) {
2121
logger.error(chalk.red('error:'), err.message);
2222
logger.error(chalk.red('stack:'), err.stack.toString());
23+
if (err.sql) {
24+
logger.error(chalk.red('query:'), err.sql);
25+
logger.error(chalk.red('parameters:'), err.parameters);
26+
}
2327
} else if (typeof err === 'string') {
2428
logger.error(err);
2529
} else if (typeof err === 'object') {
@@ -33,7 +37,7 @@ process.on('uncaughtException', err => {
3337
handle_fatal_logging(err);
3438
});
3539

36-
process.on('unhandledRejection', err => {
40+
process.on('unhandledRejection', (err, promise) => {
3741
logger.error(`exa unhandled rejection:`);
3842
handle_fatal_logging(err);
3943
});
@@ -101,11 +105,7 @@ export default new class {
101105
*/
102106
if (config.database.use) {
103107
await init_db();
104-
await init_models();
105-
106-
if (!quiet) {
107-
logger.info('database initialized');
108-
}
108+
await init_models(quiet);
109109
}
110110

111111
if (is_console) {

package.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@exajs/core",
33
"type": "module",
44
"author": "Brian Seymour <@realtux>",
5-
"version": "0.0.21",
5+
"version": "0.0.22",
66
"description": "modern opinionated node.js framework",
77
"license": "MIT",
88
"homepage": "https://github.com/realtux/exa",
@@ -21,10 +21,8 @@
2121
"exports": {
2222
".": "./lib/index.js",
2323
"./database": "./lib/database/index.js",
24-
"./database/models": "./lib/database/models.js",
25-
"./database/connection": "./lib/database/connection.js",
26-
"./system/sequelize": "./lib/system/sequelize.js",
27-
"./util": "./lib/util/index.js"
24+
"./util": "./lib/util/index.js",
25+
"./system/sequelize": "./lib/system/sequelize.js"
2826
},
2927
"dependencies": {
3028
"chalk": "5.3.0",

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## IMPORTANT!!! THIS PROJECT IS AN EARLY ACCESS PREVIEW THAT IS BEING ACTIVELY DEVELOPED. IT MAY OR MAY NOT BE SUITABLE FOR PRODUCTION. EXPECTED 1.0 DATE IS FEBRUARY OR MARCH 2025. THE PROJECT STATE IS: USEFUL BUT INCOMPLETE
1+
## IMPORTANT!!! THIS PROJECT IS AN EARLY ACCESS PREVIEW THAT IS BEING ACTIVELY DEVELOPED. IT MAY OR MAY NOT BE SUITABLE FOR PRODUCTION. EXPECTED 1.0 DATE IS APRIL 2025. THE PROJECT STATE IS: VERY USEFUL AND BEING REFINED
22

33
## exa.js by [tux](https://github.com/realtux)
44
exa.js is a minimal node.js backend framework that has a strong focus on simplicity, modularity, and convention over configuration. it makes available the most important stuff needed for a node.js web framework, and nothing more.

var/template/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
22
.env
3+
.exa

var/template/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"scripts": {
1111
"watch": "nodemon -q --watch ../.. --ignore node_modules/ -e '*' -x '%%RUNTIME%% app.js || touch app.js'",
1212
"start": "%%RUNTIME%% app.js",
13-
"console": "%%RUNTIME%% app.js console $*"
13+
"console": "%%RUNTIME%% app.js console $*",
14+
"__internal_test": "nodemon -q --watch ../.. --ignore node_modules/ -e '*' -x 'node app.js || touch app.js'"
1415
}
1516
}

0 commit comments

Comments
 (0)