diff --git a/index.d.ts b/index.d.ts index 0b71ace..bbf7dd8 100644 --- a/index.d.ts +++ b/index.d.ts @@ -2,3 +2,31 @@ declare module '@exajs/core' { const exa: any; export default exa; } + +declare module '@exajs/core/database' { + const connection: any; + const models: any; + export { connection, models }; +} + +declare module '@exajs/core/database/models' { + const models: any; + export default models; +} + +declare module '@exajs/core/database/connection' { + const connection: any; + export default connection; +} + +declare module '@exajs/core/system/sequelize' { + const sequelize: any; + export default sequelize; + export * from 'sequelize'; +} + +declare module '@exajs/core/util' { + import json from '#exa/util/json.js'; + + export { json }; +} diff --git a/lib/core/config.js b/lib/core/config.js index 8eef0ac..76669b0 100644 --- a/lib/core/config.js +++ b/lib/core/config.js @@ -3,7 +3,7 @@ let config = { /** * internal config */ - version: '0.0.12', + version: '0.0.13', paths: { root: '', diff --git a/lib/database/index.js b/lib/database/index.js new file mode 100644 index 0000000..96b952b --- /dev/null +++ b/lib/database/index.js @@ -0,0 +1,4 @@ +import connection from '#exa/database/connection.js'; +import models from '#exa/database/models.js'; + +export { connection, models }; diff --git a/lib/http/express.js b/lib/http/express.js index fae8ad9..baa1b17 100644 --- a/lib/http/express.js +++ b/lib/http/express.js @@ -29,6 +29,7 @@ export const init = async () => { app.use(cors()); app.use(multer({ storage: multer.memoryStorage() }).any()); app.use(Express.json({ limit: '16mb' })); + app.use(Express.urlencoded({ extended: true })); app.use('/public', Express.static(`${config.paths.root}/public`)); // mounted http controller routes diff --git a/lib/index.js b/lib/index.js index 3ddcf57..7c3a09c 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,5 +1,6 @@ import * as dotenv from 'dotenv'; -dotenv.config(); +import dotenv_expand from 'dotenv-expand'; +dotenv_expand.expand(dotenv.config()); import config, { init as init_config } from '#exa/core/config.js'; import connection, { init as init_db } from '#exa/database/connection.js'; diff --git a/lib/system/index.js b/lib/system/index.js deleted file mode 100644 index e69de29..0000000 diff --git a/lib/util/index.js b/lib/util/index.js new file mode 100644 index 0000000..43efb12 --- /dev/null +++ b/lib/util/index.js @@ -0,0 +1,3 @@ +import json from '#exa/util/json.js'; + +export { json }; diff --git a/lib/util/json.js b/lib/util/json.js new file mode 100644 index 0000000..3db05a5 --- /dev/null +++ b/lib/util/json.js @@ -0,0 +1,11 @@ +export default new class { + + safe_parse(json, def) { + try { + return JSON.parse(json); + } catch { + return def ?? json; + } + } + +}; diff --git a/package-lock.json b/package-lock.json index 6bef552..0c5d1ee 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,17 +1,18 @@ { "name": "@exajs/core", - "version": "0.0.10", + "version": "0.0.13", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@exajs/core", - "version": "0.0.10", + "version": "0.0.13", "license": "MIT", "dependencies": { "chalk": "5.3.0", "cors": "2.8.5", "dotenv": "16.4.5", + "dotenv-expand": "11.0.6", "express": "4.19.2", "glob": "10.4.1", "luxon": "3.4.4", @@ -22,7 +23,7 @@ "pg-hstore": "2.3.4", "sequelize": "6.37.3", "sqlite3": "5.1.7", - "ws": "^8.18.0" + "ws": "8.18.0" }, "bin": { "exajs": "bin/exa.js" @@ -852,6 +853,20 @@ "url": "https://dotenvx.com" } }, + "node_modules/dotenv-expand": { + "version": "11.0.6", + "resolved": "https://registry.npmjs.org/dotenv-expand/-/dotenv-expand-11.0.6.tgz", + "integrity": "sha512-8NHi73otpWsZGBSZwwknTXS5pqMOrk9+Ssrna8xCaxkzEpU9OTf9R5ArQGVw03//Zmk9MOwLPng9WwndvpAJ5g==", + "dependencies": { + "dotenv": "^16.4.4" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, "node_modules/dottie": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/dottie/-/dottie-2.0.6.tgz", diff --git a/package.json b/package.json index e1854b1..ed55bf0 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "@exajs/core", "type": "module", "author": "Brian Seymour <@realtux>", - "version": "0.0.12", + "version": "0.0.13", "description": "modern opinionated node.js framework", "license": "MIT", "homepage": "https://github.com/realtux/exa", @@ -20,15 +20,17 @@ }, "exports": { ".": "./lib/index.js", + "./database": "./lib/database/index.js", "./database/models": "./lib/database/models.js", "./database/connection": "./lib/database/connection.js", - "./system": "./lib/system/index.js", - "./system/sequelize": "./lib/system/sequelize.js" + "./system/sequelize": "./lib/system/sequelize.js", + "./util": "./lib/util/index.js" }, "dependencies": { "chalk": "5.3.0", "cors": "2.8.5", "dotenv": "16.4.5", + "dotenv-expand": "11.0.6", "express": "4.19.2", "glob": "10.4.1", "luxon": "3.4.4",