-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Ajv@7, remove dependency on Ajv (#115)
* Use Ajv@7, remove dependency on Ajv * automatically build
- Loading branch information
Showing
6 changed files
with
158 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,3 +60,5 @@ examples/typescript-server.js | |
test/type/index.js | ||
|
||
.vscode | ||
|
||
validate.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules | ||
jspm_packages | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# 0x | ||
profile-* | ||
|
||
# mac files | ||
.DS_Store | ||
|
||
# vim swap files | ||
*.swp | ||
|
||
# webstorm | ||
.idea | ||
|
||
# flamegraphs | ||
profile* | ||
|
||
# lock files | ||
yarn.lock | ||
package-lock.json | ||
|
||
# generated code | ||
examples/typescript-server.js | ||
test/type/index.js | ||
|
||
.vscode | ||
|
||
.dependabot | ||
.github |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
esm: false | ||
ts: false | ||
jsx: false | ||
flow: false | ||
coverage: true | ||
100: true | ||
nyc-arg: | ||
- --exclude=validate.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
'use strict' | ||
|
||
const Ajv = require('ajv').default | ||
const standaloneCode = require('ajv/dist/standalone').default | ||
const http = require('http') | ||
const fs = require('fs') | ||
const path = require('path') | ||
|
||
const ajv = new Ajv({ code: { source: true } }) | ||
|
||
const urlSchema = { | ||
oneOf: [ | ||
{ type: 'string' }, | ||
{ | ||
type: 'object', | ||
properties: { | ||
protocol: { type: 'string' }, | ||
hostname: { type: 'string' }, | ||
pathname: { type: 'string' } | ||
// port type => any | ||
// query type => any | ||
}, | ||
additionalProperties: true, | ||
required: ['pathname'] | ||
} | ||
] | ||
} | ||
|
||
const schema = { | ||
type: 'object', | ||
properties: { | ||
url: urlSchema, | ||
path: urlSchema, | ||
cookies: { | ||
type: 'object', | ||
additionalProperties: true | ||
}, | ||
headers: { | ||
type: 'object', | ||
additionalProperties: true | ||
}, | ||
query: { | ||
type: 'object', | ||
additionalProperties: true | ||
}, | ||
simulate: { | ||
type: 'object', | ||
properties: { | ||
end: { type: 'boolean' }, | ||
split: { type: 'boolean' }, | ||
error: { type: 'boolean' }, | ||
close: { type: 'boolean' } | ||
} | ||
}, | ||
authority: { type: 'string' }, | ||
remoteAddress: { type: 'string' }, | ||
method: { type: 'string', enum: http.METHODS.concat(http.METHODS.map(toLowerCase)) }, | ||
validate: { type: 'boolean' } | ||
// payload type => any | ||
}, | ||
additionalProperties: true, | ||
oneOf: [ | ||
{ required: ['url'] }, | ||
{ required: ['path'] } | ||
] | ||
} | ||
|
||
const validate = ajv.compile(schema) | ||
|
||
const moduleCode = standaloneCode(ajv, validate) | ||
|
||
fs.writeFileSync(path.join(__dirname, '/validate.js'), moduleCode) | ||
|
||
function toLowerCase (m) { return m.toLowerCase() } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters