rest-easy-loki
Advanced tools
Comparing version 1.0.0 to 1.2.0
@@ -32,2 +32,3 @@ "use strict"; | ||
const koa_static_1 = __importDefault(require("koa-static")); | ||
const koa_compress_1 = __importDefault(require("koa-compress")); | ||
const path = __importStar(require("path")); | ||
@@ -39,15 +40,4 @@ const authorization_1 = require("./authorization"); | ||
const upload_service_1 = require("./upload-service"); | ||
const state = { | ||
pretty: false, | ||
port: 3000, | ||
cors: false, | ||
}; | ||
const createApi = (config) => { | ||
if (config.pretty) { | ||
state.pretty = config.pretty; | ||
} | ||
logging_1.setLoggingOptions(state.pretty); | ||
if (config.port) { | ||
state.port = config.port; | ||
} | ||
logging_1.setLoggingOptions(config.pretty); | ||
const api = new koa_1.default(); | ||
@@ -67,2 +57,7 @@ // custom 404 | ||
} | ||
if (config.compression) { | ||
console.log('Enabled compression with koa-compress.'); | ||
// api.use(cors({ credentials: true })); | ||
api.use(koa_compress_1.default()); | ||
} | ||
const ss = config.io ? socket_service_1.createSocketService(api) : undefined; | ||
@@ -69,0 +64,0 @@ api.use(koa_body_1.default({ |
@@ -33,2 +33,17 @@ "use strict"; | ||
{ | ||
name: 'compression', | ||
alias: 'z', | ||
type: Boolean, | ||
typeLabel: 'Boolean', | ||
defaultValue: config_1.config.compression, | ||
description: `Enable ZIP compression ($LOKI_COMPRESSION ${config_1.config.compression}).`, | ||
}, | ||
{ | ||
name: 'config', | ||
defaultValue: config_1.config.config, | ||
type: String, | ||
typeLabel: 'String', | ||
description: `Name of configuration file to configure the DB ($LOKI_CONFIG).`, | ||
}, | ||
{ | ||
name: 'io', | ||
@@ -88,9 +103,2 @@ alias: 'i', | ||
}, | ||
{ | ||
name: 'config', | ||
defaultValue: config_1.config.config, | ||
type: String, | ||
typeLabel: 'String', | ||
description: `Name of configuration file to configure the DB ($LOKI_CONFIG).`, | ||
}, | ||
]; | ||
@@ -97,0 +105,0 @@ CommandLineInterface.sections = [ |
@@ -14,9 +14,9 @@ "use strict"; | ||
/** Pretty print logs */ | ||
pretty: process.env.LOKI_PRETTY ? process.env.LOKI_PRETTY : true, | ||
pretty: typeof process.env.LOKI_CORS !== 'undefined' ? process.env.LOKI_PRETTY : true, | ||
/** Define port to use */ | ||
port: process.env.LOKI_PORT || 3000, | ||
/** Allow CORS */ | ||
cors: process.env.LOKI_CORS ? process.env.LOKI_CORS : true, | ||
cors: typeof process.env.LOKI_CORS !== 'undefined' ? process.env.LOKI_CORS : true, | ||
/** Enable socket.io */ | ||
io: process.env.LOKI_IO ? process.env.LOKI_IO : true, | ||
io: typeof process.env.LOKI_IO !== 'undefined' ? process.env.LOKI_IO : true, | ||
/** Name of the database file in the DB folder */ | ||
@@ -28,3 +28,5 @@ db: process.env.LOKI_DB || 'rest_easy_loki.db', | ||
config: process.env.LOKI_CONFIG, | ||
/** Use compression */ | ||
compression: typeof process.env.LOKI_COMPRESSION !== 'undefined' ? process.env.LOKI_COMPRESSION : true, | ||
}; | ||
//# sourceMappingURL=config.js.map |
@@ -5,3 +5,3 @@ "use strict"; | ||
const state = { prettyLog: false }; | ||
const setLoggingOptions = (verbose) => state.prettyLog = verbose; | ||
const setLoggingOptions = (verbose) => (state.prettyLog = verbose); | ||
exports.setLoggingOptions = setLoggingOptions; | ||
@@ -27,3 +27,3 @@ function outputLog(data, thrownError) { | ||
url: ctx.url, | ||
query: ctx.query, | ||
query: ctx.request.querystring, | ||
remoteAddress: ctx.request.ip, | ||
@@ -30,0 +30,0 @@ host: ctx.headers['host'], |
@@ -22,2 +22,4 @@ export interface ICommandOptions { | ||
config?: string; | ||
/** If true, use zip compression for the messages */ | ||
compression?: boolean; | ||
} |
import Router from 'koa-router'; | ||
import IO from 'socket.io'; | ||
export declare const createRouter: (io?: IO.Server | undefined) => Router<any, {}>; | ||
export declare const createRouter: (io?: IO.Server<import("socket.io/dist/typed-events").DefaultEventsMap, import("socket.io/dist/typed-events").DefaultEventsMap> | undefined) => Router<any, {}>; |
@@ -30,3 +30,4 @@ "use strict"; | ||
const filter = utils_1.paginationFilter(ctx.query); | ||
const results = database_1.all(collection, ctx.query.q); | ||
const query = ctx.query.q instanceof Array ? ctx.query.q.join('&') : ctx.query.q; | ||
const results = database_1.all(collection, query); | ||
ctx.body = map && results ? (filter ? results.filter(filter).map(map) : results.map(map)) : results; | ||
@@ -51,3 +52,4 @@ }); | ||
const pages = utils_1.paginationFilter(ctx.query); | ||
const results = database_1.all(collection, ctx.query.q); | ||
const query = ctx.query.q instanceof Array ? ctx.query.q.join('&') : ctx.query.q; | ||
const results = database_1.all(collection, query); | ||
ctx.body = pages && results ? results.filter(pages) : results; | ||
@@ -54,0 +56,0 @@ }); |
@@ -8,5 +8,9 @@ "use strict"; | ||
const fs_1 = __importDefault(require("fs")); | ||
const path_1 = __importDefault(require("path")); | ||
const config_1 = require("./config"); | ||
const index_1 = require("./index"); | ||
const startService = (configuration = config_1.config) => { | ||
const folderPath = path_1.default.dirname(path_1.default.resolve(process.cwd(), configuration.db || '')); | ||
if (!fs_1.default.existsSync(folderPath)) | ||
fs_1.default.mkdirSync(folderPath, { recursive: true }); | ||
const dbOptions = configuration.config && fs_1.default.existsSync(configuration.config) | ||
@@ -13,0 +17,0 @@ ? JSON.parse(fs_1.default.readFileSync(configuration.config).toString()) |
@@ -6,4 +6,4 @@ /// <reference types="node" /> | ||
export declare const createSocketService: (api: Koa) => { | ||
io: Server; | ||
io: Server<import("socket.io/dist/typed-events").DefaultEventsMap, import("socket.io/dist/typed-events").DefaultEventsMap>; | ||
server: http.Server; | ||
}; |
{ | ||
"name": "rest-easy-loki", | ||
"version": "1.0.0", | ||
"version": "1.2.0", | ||
"description": "A REST interface for lokijs supporting CRUD operations and automatic creation of new collections.", | ||
@@ -27,2 +27,4 @@ "main": "./dist/index.js", | ||
"REST", | ||
"API", | ||
"Koa", | ||
"lokijs", | ||
@@ -38,26 +40,28 @@ "database" | ||
"dependencies": { | ||
"@koa/cors": "^3.1.0", | ||
"command-line-args": "^5.1.1", | ||
"command-line-usage": "^6.1.1", | ||
"dotenv": "^8.2.0", | ||
"koa": "^2.13.0", | ||
"koa": "^2.13.1", | ||
"koa-body": "^4.2.0", | ||
"koa-compress": "^5.0.1", | ||
"koa-router": "^10.0.0", | ||
"koa-static": "^5.0.0", | ||
"@koa/cors": "^3.1.0", | ||
"lokijs": "^1.5.11", | ||
"rfc6902": "^4.0.1", | ||
"socket.io": "^3.0.3" | ||
"rfc6902": "^4.0.2", | ||
"socket.io": "^4.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/command-line-args": "^5.0.0", | ||
"@types/koa": "^2.11.6", | ||
"@types/koa": "^2.13.1", | ||
"@types/koa-compose": "^3.2.5", | ||
"@types/koa-compress": "^4.0.1", | ||
"@types/koa-router": "^7.4.1", | ||
"@types/koa-static": "^4.0.1", | ||
"@types/lokijs": "^1.5.3", | ||
"@types/node": "^14.14.10", | ||
"@types/node": "^14.14.35", | ||
"rimraf": "^3.0.2", | ||
"tsc-watch": "^4.2.9", | ||
"typescript": "^4.1.2" | ||
"typescript": "^4.2.3" | ||
} | ||
} |
@@ -8,4 +8,6 @@ # REST-EASY-LOKI | ||
- Statically sharing the public folder | ||
- Uploading files using the upload folder | ||
- Retrieving environment variables starting with `LOKI_` via REST | ||
- Configuring the database collections using a config file | ||
- Add support for CORS and compression | ||
@@ -12,0 +14,0 @@ This version has moved from the default `LokiFsAdapter` to the more performing `LokiFsStructuredAdapter`. Besides a [performance gain](https://github.com/techfort/LokiJS/wiki/LokiJS-persistence-and-adapters#an-example-using-fastest-and-most-scalable-lokifsstructuredadapter-for-nodejs-might-look-like-), it also means that we don't end up with a single database file anymore, but one overall database file and one per collection. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
57830
1139
179
12
11
17
+ Addedkoa-compress@^5.0.1
+ Added@socket.io/component-emitter@3.1.2(transitive)
+ Addedcompressible@2.0.18(transitive)
+ Addedcookie@0.7.2(transitive)
+ Addedengine.io@6.6.2(transitive)
+ Addedengine.io-parser@5.2.3(transitive)
+ Addedkoa-compress@5.1.1(transitive)
+ Addedkoa-is-json@1.0.0(transitive)
+ Addedmime-db@1.53.0(transitive)
+ Addedsocket.io@4.8.1(transitive)
+ Addedsocket.io-adapter@2.5.5(transitive)
+ Addedsocket.io-parser@4.2.4(transitive)
+ Addedws@8.17.1(transitive)
- Removed@types/component-emitter@1.2.14(transitive)
- Removedbase64-arraybuffer@0.1.4(transitive)
- Removedcomponent-emitter@1.3.1(transitive)
- Removedcookie@0.4.2(transitive)
- Removedengine.io@4.1.2(transitive)
- Removedengine.io-parser@4.0.3(transitive)
- Removedsocket.io@3.1.2(transitive)
- Removedsocket.io-adapter@2.1.0(transitive)
- Removedsocket.io-parser@4.0.5(transitive)
- Removedws@7.4.6(transitive)
Updatedkoa@^2.13.1
Updatedrfc6902@^4.0.2
Updatedsocket.io@^4.0.0