Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.

Commit 7832fed

Browse files
Merge pull request #243 from apiaryio/core-app-prepare
Bundles Gavel to UMD module
2 parents d9eaba1 + c177e91 commit 7832fed

19 files changed

+301
-2436
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ cov.*
88
.nyc_output
99

1010
# List specific to .gitignore
11+
build
1112
node_modules
1213
.idea/

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ cov.*
1010
# List specific to .npmignore
1111
.travis.yml
1212
.npmignore
13+
lib
1314
docs/
1415
img/
1516
test/

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ install:
1414
- 'npm install --no-save'
1515
script:
1616
- 'npm run ci:lint'
17+
- 'npm run ci:build'
1718
- 'npm run ci:test'
1819
after_success:
1920
- 'npm run ci:release'

appveyor.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
environment:
2-
nodejs_version: "10"
2+
nodejs_version: '10'
33
cache:
4-
- "node_modules"
4+
- 'node_modules'
55
install:
66
- ps: Install-Product node 10
7-
- "npm -g install npm@6"
7+
- 'npm -g install npm@6'
88
- "set PATH=%APPDATA%\\npm;%PATH%"
9-
- "npm install"
9+
- 'npm install'
1010
build: off
1111
test_script:
12-
- "node --version"
13-
- "npm --version"
14-
- "npm test"
12+
- 'node --version'
13+
- 'npm --version'
14+
- 'npm run build'
15+
- 'npm test'

lib/units/normalize/normalizeHeaders.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ const normalizeHeaders = (headers) => {
2020
}
2121

2222
return Object.keys(headers).reduce(
23-
(normalizedHeaders, name) => ({
24-
...normalizedHeaders,
25-
[name.toLowerCase()]:
26-
typeof headers[name] === 'string'
27-
? normalizeStringValue(headers[name])
28-
: headers[name]
29-
}),
23+
(normalizedHeaders, name) =>
24+
Object.assign({}, normalizedHeaders, {
25+
[name.toLowerCase()]:
26+
typeof headers[name] === 'string'
27+
? normalizeStringValue(headers[name])
28+
: headers[name]
29+
}),
3030
{}
3131
);
3232
};

lib/units/validateBody.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
const jph = require('json-parse-helpfulerror');
21
const mediaTyper = require('media-typer');
32
const contentTypeUtils = require('content-type');
43

4+
const { isValidField } = require('./isValid');
55
const { TextDiff, JsonExample, JsonSchema } = require('../validators');
66
const isset = require('../utils/isset');
7-
const { isValidField } = require('./isValid');
7+
const parseJson = require('../utils/parseJson');
88

99
function isPlainText(mediaType) {
1010
return mediaType.type === 'text' && mediaType.subtype === 'plain';
@@ -69,7 +69,7 @@ function getBodyType(body, contentType, httpMessageOrigin) {
6969
const hasJsonContentType = isJsonContentType(contentType);
7070

7171
try {
72-
jph.parse(body);
72+
parseJson(body);
7373
const bodyMediaType = parseContentType(
7474
hasJsonContentType ? contentType : 'application/json'
7575
);
@@ -101,7 +101,7 @@ function getBodySchemaType(bodySchema) {
101101
}
102102

103103
try {
104-
jph.parse(bodySchema);
104+
parseJson(bodySchema);
105105
return [null, jsonSchemaType];
106106
} catch (error) {
107107
// Gavel must throw when given malformed JSON Schema.

lib/utils/evolve.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ const evolve = (schema, { strict = false } = {}) => (data) => {
3838
: value;
3939
/* eslint-enable no-nested-ternary */
4040

41-
return isArray ? acc.concat(nextValue) : { ...acc, [key]: nextValue };
41+
return isArray
42+
? acc.concat(nextValue)
43+
: Object.assign({}, acc, { [key]: nextValue });
4244
};
4345

4446
const nextData = Object.keys(data).reduce(reducer, result);

lib/utils/parseJson.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const { parse } = require('jju/lib/parse');
2+
3+
const parseJson = (json, revivew) => {
4+
try {
5+
return parse(json, revivew);
6+
} catch (error) {
7+
throw error;
8+
}
9+
};
10+
11+
module.exports = parseJson;

0 commit comments

Comments
 (0)