memserver
Advanced tools
Comparing version 2.2.5 to 2.3.0
@@ -6,3 +6,2 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const qs_1 = __importDefault(require("qs")); | ||
const ansi_colors_1 = __importDefault(require("ansi-colors")); | ||
@@ -28,9 +27,7 @@ const ember_inflector_1 = require("ember-inflector"); | ||
}, {}); | ||
var contentHeader = request.headers["Content-Type"] || request.headers["content-type"]; | ||
if (request.requestBody && contentHeader && contentHeader.includes("application/json")) { | ||
request.params = nilifyStrings(Object.assign(request.params, JSON.parse(request.requestBody))); | ||
let newParamsFromBody = tryConvertingJSONStringToObject(request.requestBody) || | ||
tryConvertingQueryStringToObject(request.requestBody); | ||
if (newParamsFromBody) { | ||
request.params = nilifyStrings(Object.assign(request.params, newParamsFromBody)); | ||
} | ||
else { | ||
request.params = nilifyStrings(Object.assign(request.params, qs_1.default.parse(request.requestBody))); | ||
} | ||
} | ||
@@ -54,2 +51,25 @@ return match; | ||
} | ||
function tryConvertingJSONStringToObject(string) { | ||
let object; | ||
try { | ||
object = JSON.parse(string); | ||
} | ||
catch (e) { | ||
return false; | ||
} | ||
if (typeof object === "object" && object !== null) { | ||
return object; | ||
} | ||
return false; | ||
} | ||
function tryConvertingQueryStringToObject(queryString) { | ||
let result = {}; | ||
let entries = new URLSearchParams(queryString); | ||
for (const [key, value] of entries) { // each 'entry' is a [queryParamKey, queryParamValue] tupple | ||
result[key] = value; | ||
} | ||
if (Object.keys(result).length > 0) { | ||
return result; | ||
} | ||
} | ||
function nilifyStrings(value) { | ||
@@ -56,0 +76,0 @@ if (value !== null && typeof value === "object") { |
{ | ||
"name": "memserver", | ||
"version": "2.2.5", | ||
"version": "2.3.0", | ||
"description": "in-memory database/ORM and http mock server you can run in-browser and node environments. Built for large frontend teams, fast tests and rapid prototyping", | ||
@@ -10,6 +10,2 @@ "author": "Izel Nakri", | ||
}, | ||
"funding": { | ||
"type": "opencollective", | ||
"url": "https://opencollective.com/memserver" | ||
}, | ||
"license": "MIT", | ||
@@ -20,5 +16,5 @@ "bin": { | ||
"scripts": { | ||
"typecheck": "tsc --project tsconfig.json --noEmit", | ||
"dev": "tsc --watch", | ||
"bin": "sh cli.sh", | ||
"typecheck": "node_modules/.bin/tsc --project tsconfig.json --noEmit", | ||
"dev": "node_modules/.bin/tsc --watch", | ||
"bin": "src/cli.ts", | ||
"test": "node_modules/.bin/ava --verbose", | ||
@@ -30,2 +26,3 @@ "prepublishOnly": "npm run npm-link-ember-packages && tsc --build && npm run publish-modules-for-browser", | ||
"dependencies": { | ||
"@types/node": "^14.14.10", | ||
"ansi-colors": "4.1.1", | ||
@@ -36,6 +33,4 @@ "fake-xml-http-request": "^2.1.1", | ||
"pretender": "^3.4.3", | ||
"qs": "^6.9.4", | ||
"route-recognizer": "^0.3.4", | ||
"ts-node": "^9.0.0", | ||
"@types/node": "^14.14.10" | ||
"ts-node": "^9.0.0" | ||
}, | ||
@@ -42,0 +37,0 @@ "devDependencies": { |
@@ -218,7 +218,7 @@ <a href="https://circleci.com/gh/izelnakri/memserver/"> | ||
const serializedUserForEndpoint = User.serializer(user); // or User.serialize(user); | ||
const serializedUserForEndpoint = { user: User.serializer(user); } // or User.serialize(user); | ||
const users = User.findAll({ active: true }); | ||
const serializedUsersForEndpoint = User.serializer(users); // or users.map((user) => User.serialize(user)); | ||
const serializedUsersForEndpoint = { users: User.serializer(users); } // or users.map((user) => User.serialize(user)); | ||
``` | ||
@@ -249,7 +249,7 @@ | ||
const serializedUserForEndpoint = User.customSerializer(user); // or User.customSerialize(user); | ||
const serializedUserForEndpoint = { user: User.customSerializer(user) }; // or User.customSerialize(user); | ||
const users = User.findAll({ active: true }); | ||
const serializedUsersForEndpoint = User.customSerializer(users); // or users.map((user) => User.customSerialize(user)); | ||
const serializedUsersForEndpoint = { users: User.customSerializer(users); } // or users.map((user) => User.customSerialize(user)); | ||
``` | ||
@@ -275,4 +275,4 @@ | ||
runtimes. Autogenerating things after a model gets created is an implicit thus bad behavior. Validations could be done | ||
in future as types or TS type decorators, thus validations won't happen in runtime and all would be check during | ||
development via typescript typecheck/linting. | ||
in future as types or TS type decorators(like `class-validator` npm package), thus validations don't need to happen in | ||
runtime and all would be check during development via typescript typecheck/linting. | ||
@@ -279,0 +279,0 @@ - No implicit relationship tracking, creating and updating a relationship should be done on the foreign-key of the |
@@ -1,2 +0,1 @@ | ||
import qs from "qs"; | ||
import chalk from "ansi-colors"; | ||
@@ -28,10 +27,6 @@ import { singularize } from "ember-inflector"; | ||
var contentHeader = request.headers["Content-Type"] || request.headers["content-type"]; | ||
if (request.requestBody && contentHeader && contentHeader.includes("application/json")) { | ||
request.params = nilifyStrings( | ||
Object.assign(request.params, JSON.parse(request.requestBody)) | ||
); | ||
} else { | ||
request.params = nilifyStrings(Object.assign(request.params, qs.parse(request.requestBody))); | ||
let newParamsFromBody = tryConvertingJSONStringToObject(request.requestBody) || | ||
tryConvertingQueryStringToObject(request.requestBody); | ||
if (newParamsFromBody) { | ||
request.params = nilifyStrings(Object.assign(request.params, newParamsFromBody)); | ||
} | ||
@@ -57,2 +52,29 @@ } | ||
function tryConvertingJSONStringToObject(string) { | ||
let object; | ||
try { | ||
object = JSON.parse(string); | ||
} catch (e) { | ||
return false; | ||
} | ||
if (typeof object === "object" && object !== null) { | ||
return object; | ||
} | ||
return false; | ||
} | ||
function tryConvertingQueryStringToObject(queryString) { | ||
let result = {}; | ||
let entries = new URLSearchParams(queryString); | ||
for (const [key, value] of entries) { // each 'entry' is a [queryParamKey, queryParamValue] tupple | ||
result[key] = value; | ||
} | ||
if (Object.keys(result).length > 0) { | ||
return result; | ||
} | ||
} | ||
function nilifyStrings(value) { | ||
@@ -59,0 +81,0 @@ if (value !== null && typeof value === "object") { |
Sorry, the diff of this file is too big to display
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
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
8
14
4
496537
43
13306
- Removedqs@^6.9.4
- Removedcall-bind@1.0.7(transitive)
- Removeddefine-data-property@1.1.4(transitive)
- Removedes-define-property@1.0.0(transitive)
- Removedes-errors@1.3.0(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-intrinsic@1.2.4(transitive)
- Removedgopd@1.0.1(transitive)
- Removedhas-property-descriptors@1.0.2(transitive)
- Removedhas-proto@1.0.3(transitive)
- Removedhas-symbols@1.0.3(transitive)
- Removedhasown@2.0.2(transitive)
- Removedobject-inspect@1.13.3(transitive)
- Removedqs@6.13.0(transitive)
- Removedset-function-length@1.2.2(transitive)
- Removedside-channel@1.0.6(transitive)