fatsify核心功能示例测试!!!
This commit is contained in:
919
node_modules/light-my-request/lib/config-validator.js
generated
vendored
Normal file
919
node_modules/light-my-request/lib/config-validator.js
generated
vendored
Normal file
@@ -0,0 +1,919 @@
|
||||
// This file is autogenerated by build/build-validation.js, do not edit
|
||||
/* c8 ignore start */
|
||||
/* eslint-disable */
|
||||
"use strict";
|
||||
module.exports = validate10;
|
||||
module.exports.default = validate10;
|
||||
const schema11 = {"type":"object","properties":{"url":{"oneOf":[{"type":"string"},{"type":"object","properties":{"protocol":{"type":"string"},"hostname":{"type":"string"},"pathname":{"type":"string"}},"additionalProperties":true,"required":["pathname"]}]},"path":{"oneOf":[{"type":"string"},{"type":"object","properties":{"protocol":{"type":"string"},"hostname":{"type":"string"},"pathname":{"type":"string"}},"additionalProperties":true,"required":["pathname"]}]},"cookies":{"type":"object","additionalProperties":true},"headers":{"type":"object","additionalProperties":true},"query":{"anyOf":[{"type":"object","additionalProperties":true},{"type":"string"}]},"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":["ACL","BIND","CHECKOUT","CONNECT","COPY","DELETE","GET","HEAD","LINK","LOCK","M-SEARCH","MERGE","MKACTIVITY","MKCALENDAR","MKCOL","MOVE","NOTIFY","OPTIONS","PATCH","POST","PROPFIND","PROPPATCH","PURGE","PUT","QUERY","REBIND","REPORT","SEARCH","SOURCE","SUBSCRIBE","TRACE","UNBIND","UNLINK","UNLOCK","UNSUBSCRIBE","acl","bind","checkout","connect","copy","delete","get","head","link","lock","m-search","merge","mkactivity","mkcalendar","mkcol","move","notify","options","patch","post","propfind","proppatch","purge","put","query","rebind","report","search","source","subscribe","trace","unbind","unlink","unlock","unsubscribe"]},"validate":{"type":"boolean"}},"additionalProperties":true,"oneOf":[{"required":["url"]},{"required":["path"]}]};
|
||||
|
||||
function validate10(data, {instancePath="", parentData, parentDataProperty, rootData=data}={}){
|
||||
let vErrors = null;
|
||||
let errors = 0;
|
||||
const _errs1 = errors;
|
||||
let valid0 = false;
|
||||
let passing0 = null;
|
||||
const _errs2 = errors;
|
||||
if(data && typeof data == "object" && !Array.isArray(data)){
|
||||
let missing0;
|
||||
if((data.url === undefined) && (missing0 = "url")){
|
||||
const err0 = {instancePath,schemaPath:"#/oneOf/0/required",keyword:"required",params:{missingProperty: missing0},message:"must have required property '"+missing0+"'"};
|
||||
if(vErrors === null){
|
||||
vErrors = [err0];
|
||||
}
|
||||
else {
|
||||
vErrors.push(err0);
|
||||
}
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
var _valid0 = _errs2 === errors;
|
||||
if(_valid0){
|
||||
valid0 = true;
|
||||
passing0 = 0;
|
||||
}
|
||||
const _errs3 = errors;
|
||||
if(data && typeof data == "object" && !Array.isArray(data)){
|
||||
let missing1;
|
||||
if((data.path === undefined) && (missing1 = "path")){
|
||||
const err1 = {instancePath,schemaPath:"#/oneOf/1/required",keyword:"required",params:{missingProperty: missing1},message:"must have required property '"+missing1+"'"};
|
||||
if(vErrors === null){
|
||||
vErrors = [err1];
|
||||
}
|
||||
else {
|
||||
vErrors.push(err1);
|
||||
}
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
var _valid0 = _errs3 === errors;
|
||||
if(_valid0 && valid0){
|
||||
valid0 = false;
|
||||
passing0 = [passing0, 1];
|
||||
}
|
||||
else {
|
||||
if(_valid0){
|
||||
valid0 = true;
|
||||
passing0 = 1;
|
||||
}
|
||||
}
|
||||
if(!valid0){
|
||||
const err2 = {instancePath,schemaPath:"#/oneOf",keyword:"oneOf",params:{passingSchemas: passing0},message:"must match exactly one schema in oneOf"};
|
||||
if(vErrors === null){
|
||||
vErrors = [err2];
|
||||
}
|
||||
else {
|
||||
vErrors.push(err2);
|
||||
}
|
||||
errors++;
|
||||
validate10.errors = vErrors;
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
errors = _errs1;
|
||||
if(vErrors !== null){
|
||||
if(_errs1){
|
||||
vErrors.length = _errs1;
|
||||
}
|
||||
else {
|
||||
vErrors = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(errors === 0){
|
||||
if(data && typeof data == "object" && !Array.isArray(data)){
|
||||
if(data.url !== undefined){
|
||||
let data0 = data.url;
|
||||
const _errs5 = errors;
|
||||
const _errs6 = errors;
|
||||
let valid2 = false;
|
||||
let passing1 = null;
|
||||
const _errs7 = errors;
|
||||
if(typeof data0 !== "string"){
|
||||
let dataType0 = typeof data0;
|
||||
let coerced0 = undefined;
|
||||
if(!(coerced0 !== undefined)){
|
||||
if(dataType0 == "number" || dataType0 == "boolean"){
|
||||
coerced0 = "" + data0;
|
||||
}
|
||||
else if(data0 === null){
|
||||
coerced0 = "";
|
||||
}
|
||||
else {
|
||||
const err3 = {instancePath:instancePath+"/url",schemaPath:"#/properties/url/oneOf/0/type",keyword:"type",params:{type: "string"},message:"must be string"};
|
||||
if(vErrors === null){
|
||||
vErrors = [err3];
|
||||
}
|
||||
else {
|
||||
vErrors.push(err3);
|
||||
}
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if(coerced0 !== undefined){
|
||||
data0 = coerced0;
|
||||
if(data !== undefined){
|
||||
data["url"] = coerced0;
|
||||
}
|
||||
}
|
||||
}
|
||||
var _valid1 = _errs7 === errors;
|
||||
if(_valid1){
|
||||
valid2 = true;
|
||||
passing1 = 0;
|
||||
}
|
||||
const _errs9 = errors;
|
||||
if(errors === _errs9){
|
||||
if(data0 && typeof data0 == "object" && !Array.isArray(data0)){
|
||||
let missing2;
|
||||
if((data0.pathname === undefined) && (missing2 = "pathname")){
|
||||
const err4 = {instancePath:instancePath+"/url",schemaPath:"#/properties/url/oneOf/1/required",keyword:"required",params:{missingProperty: missing2},message:"must have required property '"+missing2+"'"};
|
||||
if(vErrors === null){
|
||||
vErrors = [err4];
|
||||
}
|
||||
else {
|
||||
vErrors.push(err4);
|
||||
}
|
||||
errors++;
|
||||
}
|
||||
else {
|
||||
if(data0.protocol !== undefined){
|
||||
let data1 = data0.protocol;
|
||||
const _errs12 = errors;
|
||||
if(typeof data1 !== "string"){
|
||||
let dataType1 = typeof data1;
|
||||
let coerced1 = undefined;
|
||||
if(!(coerced1 !== undefined)){
|
||||
if(dataType1 == "number" || dataType1 == "boolean"){
|
||||
coerced1 = "" + data1;
|
||||
}
|
||||
else if(data1 === null){
|
||||
coerced1 = "";
|
||||
}
|
||||
else {
|
||||
const err5 = {instancePath:instancePath+"/url/protocol",schemaPath:"#/properties/url/oneOf/1/properties/protocol/type",keyword:"type",params:{type: "string"},message:"must be string"};
|
||||
if(vErrors === null){
|
||||
vErrors = [err5];
|
||||
}
|
||||
else {
|
||||
vErrors.push(err5);
|
||||
}
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if(coerced1 !== undefined){
|
||||
data1 = coerced1;
|
||||
if(data0 !== undefined){
|
||||
data0["protocol"] = coerced1;
|
||||
}
|
||||
}
|
||||
}
|
||||
var valid3 = _errs12 === errors;
|
||||
}
|
||||
else {
|
||||
var valid3 = true;
|
||||
}
|
||||
if(valid3){
|
||||
if(data0.hostname !== undefined){
|
||||
let data2 = data0.hostname;
|
||||
const _errs14 = errors;
|
||||
if(typeof data2 !== "string"){
|
||||
let dataType2 = typeof data2;
|
||||
let coerced2 = undefined;
|
||||
if(!(coerced2 !== undefined)){
|
||||
if(dataType2 == "number" || dataType2 == "boolean"){
|
||||
coerced2 = "" + data2;
|
||||
}
|
||||
else if(data2 === null){
|
||||
coerced2 = "";
|
||||
}
|
||||
else {
|
||||
const err6 = {instancePath:instancePath+"/url/hostname",schemaPath:"#/properties/url/oneOf/1/properties/hostname/type",keyword:"type",params:{type: "string"},message:"must be string"};
|
||||
if(vErrors === null){
|
||||
vErrors = [err6];
|
||||
}
|
||||
else {
|
||||
vErrors.push(err6);
|
||||
}
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if(coerced2 !== undefined){
|
||||
data2 = coerced2;
|
||||
if(data0 !== undefined){
|
||||
data0["hostname"] = coerced2;
|
||||
}
|
||||
}
|
||||
}
|
||||
var valid3 = _errs14 === errors;
|
||||
}
|
||||
else {
|
||||
var valid3 = true;
|
||||
}
|
||||
if(valid3){
|
||||
if(data0.pathname !== undefined){
|
||||
let data3 = data0.pathname;
|
||||
const _errs16 = errors;
|
||||
if(typeof data3 !== "string"){
|
||||
let dataType3 = typeof data3;
|
||||
let coerced3 = undefined;
|
||||
if(!(coerced3 !== undefined)){
|
||||
if(dataType3 == "number" || dataType3 == "boolean"){
|
||||
coerced3 = "" + data3;
|
||||
}
|
||||
else if(data3 === null){
|
||||
coerced3 = "";
|
||||
}
|
||||
else {
|
||||
const err7 = {instancePath:instancePath+"/url/pathname",schemaPath:"#/properties/url/oneOf/1/properties/pathname/type",keyword:"type",params:{type: "string"},message:"must be string"};
|
||||
if(vErrors === null){
|
||||
vErrors = [err7];
|
||||
}
|
||||
else {
|
||||
vErrors.push(err7);
|
||||
}
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if(coerced3 !== undefined){
|
||||
data3 = coerced3;
|
||||
if(data0 !== undefined){
|
||||
data0["pathname"] = coerced3;
|
||||
}
|
||||
}
|
||||
}
|
||||
var valid3 = _errs16 === errors;
|
||||
}
|
||||
else {
|
||||
var valid3 = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
const err8 = {instancePath:instancePath+"/url",schemaPath:"#/properties/url/oneOf/1/type",keyword:"type",params:{type: "object"},message:"must be object"};
|
||||
if(vErrors === null){
|
||||
vErrors = [err8];
|
||||
}
|
||||
else {
|
||||
vErrors.push(err8);
|
||||
}
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
var _valid1 = _errs9 === errors;
|
||||
if(_valid1 && valid2){
|
||||
valid2 = false;
|
||||
passing1 = [passing1, 1];
|
||||
}
|
||||
else {
|
||||
if(_valid1){
|
||||
valid2 = true;
|
||||
passing1 = 1;
|
||||
}
|
||||
}
|
||||
if(!valid2){
|
||||
const err9 = {instancePath:instancePath+"/url",schemaPath:"#/properties/url/oneOf",keyword:"oneOf",params:{passingSchemas: passing1},message:"must match exactly one schema in oneOf"};
|
||||
if(vErrors === null){
|
||||
vErrors = [err9];
|
||||
}
|
||||
else {
|
||||
vErrors.push(err9);
|
||||
}
|
||||
errors++;
|
||||
validate10.errors = vErrors;
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
errors = _errs6;
|
||||
if(vErrors !== null){
|
||||
if(_errs6){
|
||||
vErrors.length = _errs6;
|
||||
}
|
||||
else {
|
||||
vErrors = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
var valid1 = _errs5 === errors;
|
||||
}
|
||||
else {
|
||||
var valid1 = true;
|
||||
}
|
||||
if(valid1){
|
||||
if(data.path !== undefined){
|
||||
let data4 = data.path;
|
||||
const _errs18 = errors;
|
||||
const _errs19 = errors;
|
||||
let valid4 = false;
|
||||
let passing2 = null;
|
||||
const _errs20 = errors;
|
||||
if(typeof data4 !== "string"){
|
||||
let dataType4 = typeof data4;
|
||||
let coerced4 = undefined;
|
||||
if(!(coerced4 !== undefined)){
|
||||
if(dataType4 == "number" || dataType4 == "boolean"){
|
||||
coerced4 = "" + data4;
|
||||
}
|
||||
else if(data4 === null){
|
||||
coerced4 = "";
|
||||
}
|
||||
else {
|
||||
const err10 = {instancePath:instancePath+"/path",schemaPath:"#/properties/path/oneOf/0/type",keyword:"type",params:{type: "string"},message:"must be string"};
|
||||
if(vErrors === null){
|
||||
vErrors = [err10];
|
||||
}
|
||||
else {
|
||||
vErrors.push(err10);
|
||||
}
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if(coerced4 !== undefined){
|
||||
data4 = coerced4;
|
||||
if(data !== undefined){
|
||||
data["path"] = coerced4;
|
||||
}
|
||||
}
|
||||
}
|
||||
var _valid2 = _errs20 === errors;
|
||||
if(_valid2){
|
||||
valid4 = true;
|
||||
passing2 = 0;
|
||||
}
|
||||
const _errs22 = errors;
|
||||
if(errors === _errs22){
|
||||
if(data4 && typeof data4 == "object" && !Array.isArray(data4)){
|
||||
let missing3;
|
||||
if((data4.pathname === undefined) && (missing3 = "pathname")){
|
||||
const err11 = {instancePath:instancePath+"/path",schemaPath:"#/properties/path/oneOf/1/required",keyword:"required",params:{missingProperty: missing3},message:"must have required property '"+missing3+"'"};
|
||||
if(vErrors === null){
|
||||
vErrors = [err11];
|
||||
}
|
||||
else {
|
||||
vErrors.push(err11);
|
||||
}
|
||||
errors++;
|
||||
}
|
||||
else {
|
||||
if(data4.protocol !== undefined){
|
||||
let data5 = data4.protocol;
|
||||
const _errs25 = errors;
|
||||
if(typeof data5 !== "string"){
|
||||
let dataType5 = typeof data5;
|
||||
let coerced5 = undefined;
|
||||
if(!(coerced5 !== undefined)){
|
||||
if(dataType5 == "number" || dataType5 == "boolean"){
|
||||
coerced5 = "" + data5;
|
||||
}
|
||||
else if(data5 === null){
|
||||
coerced5 = "";
|
||||
}
|
||||
else {
|
||||
const err12 = {instancePath:instancePath+"/path/protocol",schemaPath:"#/properties/path/oneOf/1/properties/protocol/type",keyword:"type",params:{type: "string"},message:"must be string"};
|
||||
if(vErrors === null){
|
||||
vErrors = [err12];
|
||||
}
|
||||
else {
|
||||
vErrors.push(err12);
|
||||
}
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if(coerced5 !== undefined){
|
||||
data5 = coerced5;
|
||||
if(data4 !== undefined){
|
||||
data4["protocol"] = coerced5;
|
||||
}
|
||||
}
|
||||
}
|
||||
var valid5 = _errs25 === errors;
|
||||
}
|
||||
else {
|
||||
var valid5 = true;
|
||||
}
|
||||
if(valid5){
|
||||
if(data4.hostname !== undefined){
|
||||
let data6 = data4.hostname;
|
||||
const _errs27 = errors;
|
||||
if(typeof data6 !== "string"){
|
||||
let dataType6 = typeof data6;
|
||||
let coerced6 = undefined;
|
||||
if(!(coerced6 !== undefined)){
|
||||
if(dataType6 == "number" || dataType6 == "boolean"){
|
||||
coerced6 = "" + data6;
|
||||
}
|
||||
else if(data6 === null){
|
||||
coerced6 = "";
|
||||
}
|
||||
else {
|
||||
const err13 = {instancePath:instancePath+"/path/hostname",schemaPath:"#/properties/path/oneOf/1/properties/hostname/type",keyword:"type",params:{type: "string"},message:"must be string"};
|
||||
if(vErrors === null){
|
||||
vErrors = [err13];
|
||||
}
|
||||
else {
|
||||
vErrors.push(err13);
|
||||
}
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if(coerced6 !== undefined){
|
||||
data6 = coerced6;
|
||||
if(data4 !== undefined){
|
||||
data4["hostname"] = coerced6;
|
||||
}
|
||||
}
|
||||
}
|
||||
var valid5 = _errs27 === errors;
|
||||
}
|
||||
else {
|
||||
var valid5 = true;
|
||||
}
|
||||
if(valid5){
|
||||
if(data4.pathname !== undefined){
|
||||
let data7 = data4.pathname;
|
||||
const _errs29 = errors;
|
||||
if(typeof data7 !== "string"){
|
||||
let dataType7 = typeof data7;
|
||||
let coerced7 = undefined;
|
||||
if(!(coerced7 !== undefined)){
|
||||
if(dataType7 == "number" || dataType7 == "boolean"){
|
||||
coerced7 = "" + data7;
|
||||
}
|
||||
else if(data7 === null){
|
||||
coerced7 = "";
|
||||
}
|
||||
else {
|
||||
const err14 = {instancePath:instancePath+"/path/pathname",schemaPath:"#/properties/path/oneOf/1/properties/pathname/type",keyword:"type",params:{type: "string"},message:"must be string"};
|
||||
if(vErrors === null){
|
||||
vErrors = [err14];
|
||||
}
|
||||
else {
|
||||
vErrors.push(err14);
|
||||
}
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if(coerced7 !== undefined){
|
||||
data7 = coerced7;
|
||||
if(data4 !== undefined){
|
||||
data4["pathname"] = coerced7;
|
||||
}
|
||||
}
|
||||
}
|
||||
var valid5 = _errs29 === errors;
|
||||
}
|
||||
else {
|
||||
var valid5 = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
const err15 = {instancePath:instancePath+"/path",schemaPath:"#/properties/path/oneOf/1/type",keyword:"type",params:{type: "object"},message:"must be object"};
|
||||
if(vErrors === null){
|
||||
vErrors = [err15];
|
||||
}
|
||||
else {
|
||||
vErrors.push(err15);
|
||||
}
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
var _valid2 = _errs22 === errors;
|
||||
if(_valid2 && valid4){
|
||||
valid4 = false;
|
||||
passing2 = [passing2, 1];
|
||||
}
|
||||
else {
|
||||
if(_valid2){
|
||||
valid4 = true;
|
||||
passing2 = 1;
|
||||
}
|
||||
}
|
||||
if(!valid4){
|
||||
const err16 = {instancePath:instancePath+"/path",schemaPath:"#/properties/path/oneOf",keyword:"oneOf",params:{passingSchemas: passing2},message:"must match exactly one schema in oneOf"};
|
||||
if(vErrors === null){
|
||||
vErrors = [err16];
|
||||
}
|
||||
else {
|
||||
vErrors.push(err16);
|
||||
}
|
||||
errors++;
|
||||
validate10.errors = vErrors;
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
errors = _errs19;
|
||||
if(vErrors !== null){
|
||||
if(_errs19){
|
||||
vErrors.length = _errs19;
|
||||
}
|
||||
else {
|
||||
vErrors = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
var valid1 = _errs18 === errors;
|
||||
}
|
||||
else {
|
||||
var valid1 = true;
|
||||
}
|
||||
if(valid1){
|
||||
if(data.cookies !== undefined){
|
||||
let data8 = data.cookies;
|
||||
const _errs31 = errors;
|
||||
if(errors === _errs31){
|
||||
if(!(data8 && typeof data8 == "object" && !Array.isArray(data8))){
|
||||
validate10.errors = [{instancePath:instancePath+"/cookies",schemaPath:"#/properties/cookies/type",keyword:"type",params:{type: "object"},message:"must be object"}];
|
||||
return false;
|
||||
}
|
||||
}
|
||||
var valid1 = _errs31 === errors;
|
||||
}
|
||||
else {
|
||||
var valid1 = true;
|
||||
}
|
||||
if(valid1){
|
||||
if(data.headers !== undefined){
|
||||
let data9 = data.headers;
|
||||
const _errs34 = errors;
|
||||
if(errors === _errs34){
|
||||
if(!(data9 && typeof data9 == "object" && !Array.isArray(data9))){
|
||||
validate10.errors = [{instancePath:instancePath+"/headers",schemaPath:"#/properties/headers/type",keyword:"type",params:{type: "object"},message:"must be object"}];
|
||||
return false;
|
||||
}
|
||||
}
|
||||
var valid1 = _errs34 === errors;
|
||||
}
|
||||
else {
|
||||
var valid1 = true;
|
||||
}
|
||||
if(valid1){
|
||||
if(data.query !== undefined){
|
||||
let data10 = data.query;
|
||||
const _errs37 = errors;
|
||||
const _errs38 = errors;
|
||||
let valid6 = false;
|
||||
const _errs39 = errors;
|
||||
if(errors === _errs39){
|
||||
if(!(data10 && typeof data10 == "object" && !Array.isArray(data10))){
|
||||
const err17 = {instancePath:instancePath+"/query",schemaPath:"#/properties/query/anyOf/0/type",keyword:"type",params:{type: "object"},message:"must be object"};
|
||||
if(vErrors === null){
|
||||
vErrors = [err17];
|
||||
}
|
||||
else {
|
||||
vErrors.push(err17);
|
||||
}
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
var _valid3 = _errs39 === errors;
|
||||
valid6 = valid6 || _valid3;
|
||||
if(!valid6){
|
||||
const _errs42 = errors;
|
||||
if(typeof data10 !== "string"){
|
||||
let dataType8 = typeof data10;
|
||||
let coerced8 = undefined;
|
||||
if(!(coerced8 !== undefined)){
|
||||
if(dataType8 == "number" || dataType8 == "boolean"){
|
||||
coerced8 = "" + data10;
|
||||
}
|
||||
else if(data10 === null){
|
||||
coerced8 = "";
|
||||
}
|
||||
else {
|
||||
const err18 = {instancePath:instancePath+"/query",schemaPath:"#/properties/query/anyOf/1/type",keyword:"type",params:{type: "string"},message:"must be string"};
|
||||
if(vErrors === null){
|
||||
vErrors = [err18];
|
||||
}
|
||||
else {
|
||||
vErrors.push(err18);
|
||||
}
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if(coerced8 !== undefined){
|
||||
data10 = coerced8;
|
||||
if(data !== undefined){
|
||||
data["query"] = coerced8;
|
||||
}
|
||||
}
|
||||
}
|
||||
var _valid3 = _errs42 === errors;
|
||||
valid6 = valid6 || _valid3;
|
||||
}
|
||||
if(!valid6){
|
||||
const err19 = {instancePath:instancePath+"/query",schemaPath:"#/properties/query/anyOf",keyword:"anyOf",params:{},message:"must match a schema in anyOf"};
|
||||
if(vErrors === null){
|
||||
vErrors = [err19];
|
||||
}
|
||||
else {
|
||||
vErrors.push(err19);
|
||||
}
|
||||
errors++;
|
||||
validate10.errors = vErrors;
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
errors = _errs38;
|
||||
if(vErrors !== null){
|
||||
if(_errs38){
|
||||
vErrors.length = _errs38;
|
||||
}
|
||||
else {
|
||||
vErrors = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
var valid1 = _errs37 === errors;
|
||||
}
|
||||
else {
|
||||
var valid1 = true;
|
||||
}
|
||||
if(valid1){
|
||||
if(data.simulate !== undefined){
|
||||
let data11 = data.simulate;
|
||||
const _errs44 = errors;
|
||||
if(errors === _errs44){
|
||||
if(data11 && typeof data11 == "object" && !Array.isArray(data11)){
|
||||
if(data11.end !== undefined){
|
||||
let data12 = data11.end;
|
||||
const _errs46 = errors;
|
||||
if(typeof data12 !== "boolean"){
|
||||
let coerced9 = undefined;
|
||||
if(!(coerced9 !== undefined)){
|
||||
if(data12 === "false" || data12 === 0 || data12 === null){
|
||||
coerced9 = false;
|
||||
}
|
||||
else if(data12 === "true" || data12 === 1){
|
||||
coerced9 = true;
|
||||
}
|
||||
else {
|
||||
validate10.errors = [{instancePath:instancePath+"/simulate/end",schemaPath:"#/properties/simulate/properties/end/type",keyword:"type",params:{type: "boolean"},message:"must be boolean"}];
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(coerced9 !== undefined){
|
||||
data12 = coerced9;
|
||||
if(data11 !== undefined){
|
||||
data11["end"] = coerced9;
|
||||
}
|
||||
}
|
||||
}
|
||||
var valid7 = _errs46 === errors;
|
||||
}
|
||||
else {
|
||||
var valid7 = true;
|
||||
}
|
||||
if(valid7){
|
||||
if(data11.split !== undefined){
|
||||
let data13 = data11.split;
|
||||
const _errs48 = errors;
|
||||
if(typeof data13 !== "boolean"){
|
||||
let coerced10 = undefined;
|
||||
if(!(coerced10 !== undefined)){
|
||||
if(data13 === "false" || data13 === 0 || data13 === null){
|
||||
coerced10 = false;
|
||||
}
|
||||
else if(data13 === "true" || data13 === 1){
|
||||
coerced10 = true;
|
||||
}
|
||||
else {
|
||||
validate10.errors = [{instancePath:instancePath+"/simulate/split",schemaPath:"#/properties/simulate/properties/split/type",keyword:"type",params:{type: "boolean"},message:"must be boolean"}];
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(coerced10 !== undefined){
|
||||
data13 = coerced10;
|
||||
if(data11 !== undefined){
|
||||
data11["split"] = coerced10;
|
||||
}
|
||||
}
|
||||
}
|
||||
var valid7 = _errs48 === errors;
|
||||
}
|
||||
else {
|
||||
var valid7 = true;
|
||||
}
|
||||
if(valid7){
|
||||
if(data11.error !== undefined){
|
||||
let data14 = data11.error;
|
||||
const _errs50 = errors;
|
||||
if(typeof data14 !== "boolean"){
|
||||
let coerced11 = undefined;
|
||||
if(!(coerced11 !== undefined)){
|
||||
if(data14 === "false" || data14 === 0 || data14 === null){
|
||||
coerced11 = false;
|
||||
}
|
||||
else if(data14 === "true" || data14 === 1){
|
||||
coerced11 = true;
|
||||
}
|
||||
else {
|
||||
validate10.errors = [{instancePath:instancePath+"/simulate/error",schemaPath:"#/properties/simulate/properties/error/type",keyword:"type",params:{type: "boolean"},message:"must be boolean"}];
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(coerced11 !== undefined){
|
||||
data14 = coerced11;
|
||||
if(data11 !== undefined){
|
||||
data11["error"] = coerced11;
|
||||
}
|
||||
}
|
||||
}
|
||||
var valid7 = _errs50 === errors;
|
||||
}
|
||||
else {
|
||||
var valid7 = true;
|
||||
}
|
||||
if(valid7){
|
||||
if(data11.close !== undefined){
|
||||
let data15 = data11.close;
|
||||
const _errs52 = errors;
|
||||
if(typeof data15 !== "boolean"){
|
||||
let coerced12 = undefined;
|
||||
if(!(coerced12 !== undefined)){
|
||||
if(data15 === "false" || data15 === 0 || data15 === null){
|
||||
coerced12 = false;
|
||||
}
|
||||
else if(data15 === "true" || data15 === 1){
|
||||
coerced12 = true;
|
||||
}
|
||||
else {
|
||||
validate10.errors = [{instancePath:instancePath+"/simulate/close",schemaPath:"#/properties/simulate/properties/close/type",keyword:"type",params:{type: "boolean"},message:"must be boolean"}];
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(coerced12 !== undefined){
|
||||
data15 = coerced12;
|
||||
if(data11 !== undefined){
|
||||
data11["close"] = coerced12;
|
||||
}
|
||||
}
|
||||
}
|
||||
var valid7 = _errs52 === errors;
|
||||
}
|
||||
else {
|
||||
var valid7 = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
validate10.errors = [{instancePath:instancePath+"/simulate",schemaPath:"#/properties/simulate/type",keyword:"type",params:{type: "object"},message:"must be object"}];
|
||||
return false;
|
||||
}
|
||||
}
|
||||
var valid1 = _errs44 === errors;
|
||||
}
|
||||
else {
|
||||
var valid1 = true;
|
||||
}
|
||||
if(valid1){
|
||||
if(data.authority !== undefined){
|
||||
let data16 = data.authority;
|
||||
const _errs54 = errors;
|
||||
if(typeof data16 !== "string"){
|
||||
let dataType13 = typeof data16;
|
||||
let coerced13 = undefined;
|
||||
if(!(coerced13 !== undefined)){
|
||||
if(dataType13 == "number" || dataType13 == "boolean"){
|
||||
coerced13 = "" + data16;
|
||||
}
|
||||
else if(data16 === null){
|
||||
coerced13 = "";
|
||||
}
|
||||
else {
|
||||
validate10.errors = [{instancePath:instancePath+"/authority",schemaPath:"#/properties/authority/type",keyword:"type",params:{type: "string"},message:"must be string"}];
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(coerced13 !== undefined){
|
||||
data16 = coerced13;
|
||||
if(data !== undefined){
|
||||
data["authority"] = coerced13;
|
||||
}
|
||||
}
|
||||
}
|
||||
var valid1 = _errs54 === errors;
|
||||
}
|
||||
else {
|
||||
var valid1 = true;
|
||||
}
|
||||
if(valid1){
|
||||
if(data.remoteAddress !== undefined){
|
||||
let data17 = data.remoteAddress;
|
||||
const _errs56 = errors;
|
||||
if(typeof data17 !== "string"){
|
||||
let dataType14 = typeof data17;
|
||||
let coerced14 = undefined;
|
||||
if(!(coerced14 !== undefined)){
|
||||
if(dataType14 == "number" || dataType14 == "boolean"){
|
||||
coerced14 = "" + data17;
|
||||
}
|
||||
else if(data17 === null){
|
||||
coerced14 = "";
|
||||
}
|
||||
else {
|
||||
validate10.errors = [{instancePath:instancePath+"/remoteAddress",schemaPath:"#/properties/remoteAddress/type",keyword:"type",params:{type: "string"},message:"must be string"}];
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(coerced14 !== undefined){
|
||||
data17 = coerced14;
|
||||
if(data !== undefined){
|
||||
data["remoteAddress"] = coerced14;
|
||||
}
|
||||
}
|
||||
}
|
||||
var valid1 = _errs56 === errors;
|
||||
}
|
||||
else {
|
||||
var valid1 = true;
|
||||
}
|
||||
if(valid1){
|
||||
if(data.method !== undefined){
|
||||
let data18 = data.method;
|
||||
const _errs58 = errors;
|
||||
if(typeof data18 !== "string"){
|
||||
let dataType15 = typeof data18;
|
||||
let coerced15 = undefined;
|
||||
if(!(coerced15 !== undefined)){
|
||||
if(dataType15 == "number" || dataType15 == "boolean"){
|
||||
coerced15 = "" + data18;
|
||||
}
|
||||
else if(data18 === null){
|
||||
coerced15 = "";
|
||||
}
|
||||
else {
|
||||
validate10.errors = [{instancePath:instancePath+"/method",schemaPath:"#/properties/method/type",keyword:"type",params:{type: "string"},message:"must be string"}];
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(coerced15 !== undefined){
|
||||
data18 = coerced15;
|
||||
if(data !== undefined){
|
||||
data["method"] = coerced15;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((data18 === "ACL") || (data18 === "BIND")) || (data18 === "CHECKOUT")) || (data18 === "CONNECT")) || (data18 === "COPY")) || (data18 === "DELETE")) || (data18 === "GET")) || (data18 === "HEAD")) || (data18 === "LINK")) || (data18 === "LOCK")) || (data18 === "M-SEARCH")) || (data18 === "MERGE")) || (data18 === "MKACTIVITY")) || (data18 === "MKCALENDAR")) || (data18 === "MKCOL")) || (data18 === "MOVE")) || (data18 === "NOTIFY")) || (data18 === "OPTIONS")) || (data18 === "PATCH")) || (data18 === "POST")) || (data18 === "PROPFIND")) || (data18 === "PROPPATCH")) || (data18 === "PURGE")) || (data18 === "PUT")) || (data18 === "QUERY")) || (data18 === "REBIND")) || (data18 === "REPORT")) || (data18 === "SEARCH")) || (data18 === "SOURCE")) || (data18 === "SUBSCRIBE")) || (data18 === "TRACE")) || (data18 === "UNBIND")) || (data18 === "UNLINK")) || (data18 === "UNLOCK")) || (data18 === "UNSUBSCRIBE")) || (data18 === "acl")) || (data18 === "bind")) || (data18 === "checkout")) || (data18 === "connect")) || (data18 === "copy")) || (data18 === "delete")) || (data18 === "get")) || (data18 === "head")) || (data18 === "link")) || (data18 === "lock")) || (data18 === "m-search")) || (data18 === "merge")) || (data18 === "mkactivity")) || (data18 === "mkcalendar")) || (data18 === "mkcol")) || (data18 === "move")) || (data18 === "notify")) || (data18 === "options")) || (data18 === "patch")) || (data18 === "post")) || (data18 === "propfind")) || (data18 === "proppatch")) || (data18 === "purge")) || (data18 === "put")) || (data18 === "query")) || (data18 === "rebind")) || (data18 === "report")) || (data18 === "search")) || (data18 === "source")) || (data18 === "subscribe")) || (data18 === "trace")) || (data18 === "unbind")) || (data18 === "unlink")) || (data18 === "unlock")) || (data18 === "unsubscribe"))){
|
||||
validate10.errors = [{instancePath:instancePath+"/method",schemaPath:"#/properties/method/enum",keyword:"enum",params:{allowedValues: schema11.properties.method.enum},message:"must be equal to one of the allowed values"}];
|
||||
return false;
|
||||
}
|
||||
var valid1 = _errs58 === errors;
|
||||
}
|
||||
else {
|
||||
var valid1 = true;
|
||||
}
|
||||
if(valid1){
|
||||
if(data.validate !== undefined){
|
||||
let data19 = data.validate;
|
||||
const _errs60 = errors;
|
||||
if(typeof data19 !== "boolean"){
|
||||
let coerced16 = undefined;
|
||||
if(!(coerced16 !== undefined)){
|
||||
if(data19 === "false" || data19 === 0 || data19 === null){
|
||||
coerced16 = false;
|
||||
}
|
||||
else if(data19 === "true" || data19 === 1){
|
||||
coerced16 = true;
|
||||
}
|
||||
else {
|
||||
validate10.errors = [{instancePath:instancePath+"/validate",schemaPath:"#/properties/validate/type",keyword:"type",params:{type: "boolean"},message:"must be boolean"}];
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(coerced16 !== undefined){
|
||||
data19 = coerced16;
|
||||
if(data !== undefined){
|
||||
data["validate"] = coerced16;
|
||||
}
|
||||
}
|
||||
}
|
||||
var valid1 = _errs60 === errors;
|
||||
}
|
||||
else {
|
||||
var valid1 = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
validate10.errors = [{instancePath,schemaPath:"#/type",keyword:"type",params:{type: "object"},message:"must be object"}];
|
||||
return false;
|
||||
}
|
||||
}
|
||||
validate10.errors = vErrors;
|
||||
return errors === 0;
|
||||
}
|
||||
|
||||
79
node_modules/light-my-request/lib/form-data.js
generated
vendored
Normal file
79
node_modules/light-my-request/lib/form-data.js
generated
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
'use strict'
|
||||
|
||||
const { randomUUID } = require('node:crypto')
|
||||
const { Readable } = require('node:stream')
|
||||
|
||||
let textEncoder
|
||||
|
||||
function isFormDataLike (payload) {
|
||||
return (
|
||||
payload &&
|
||||
typeof payload === 'object' &&
|
||||
typeof payload.append === 'function' &&
|
||||
typeof payload.delete === 'function' &&
|
||||
typeof payload.get === 'function' &&
|
||||
typeof payload.getAll === 'function' &&
|
||||
typeof payload.has === 'function' &&
|
||||
typeof payload.set === 'function' &&
|
||||
payload[Symbol.toStringTag] === 'FormData'
|
||||
)
|
||||
}
|
||||
|
||||
/*
|
||||
partial code extraction and refactoring of `undici`.
|
||||
MIT License. https://github.com/nodejs/undici/blob/043d8f1a89f606b1db259fc71f4c9bc8eb2aa1e6/lib/web/fetch/LICENSE
|
||||
Reference https://github.com/nodejs/undici/blob/043d8f1a89f606b1db259fc71f4c9bc8eb2aa1e6/lib/web/fetch/body.js#L102-L168
|
||||
*/
|
||||
function formDataToStream (formdata) {
|
||||
// lazy creation of TextEncoder
|
||||
textEncoder = textEncoder ?? new TextEncoder()
|
||||
|
||||
// we expect the function argument must be FormData
|
||||
const boundary = `----formdata-${randomUUID()}`
|
||||
const prefix = `--${boundary}\r\nContent-Disposition: form-data`
|
||||
|
||||
/*! formdata-polyfill. MIT License. Jimmy Wärting <https://jimmy.warting.se/opensource> */
|
||||
const escape = (str) =>
|
||||
str.replace(/\n/g, '%0A').replace(/\r/g, '%0D').replace(/"/g, '%22')
|
||||
const normalizeLinefeeds = (value) => value.replace(/\r?\n|\r/g, '\r\n')
|
||||
|
||||
const linebreak = new Uint8Array([13, 10]) // '\r\n'
|
||||
|
||||
async function * asyncIterator () {
|
||||
for (const [name, value] of formdata) {
|
||||
if (typeof value === 'string') {
|
||||
// header
|
||||
yield textEncoder.encode(`${prefix}; name="${escape(normalizeLinefeeds(name))}"\r\n\r\n`)
|
||||
// body
|
||||
yield textEncoder.encode(`${normalizeLinefeeds(value)}\r\n`)
|
||||
} else {
|
||||
let header = `${prefix}; name="${escape(normalizeLinefeeds(name))}"`
|
||||
value.name && (header += `; filename="${escape(value.name)}"`)
|
||||
header += `\r\nContent-Type: ${value.type || 'application/octet-stream'}\r\n\r\n`
|
||||
// header
|
||||
yield textEncoder.encode(header)
|
||||
// body
|
||||
if (value.stream) {
|
||||
yield * value.stream()
|
||||
} /* c8 ignore start */ else {
|
||||
// shouldn't be here since Blob / File should provide .stream
|
||||
// and FormData always convert to USVString
|
||||
yield value
|
||||
} /* c8 ignore stop */
|
||||
yield linebreak
|
||||
}
|
||||
}
|
||||
// end
|
||||
yield textEncoder.encode(`--${boundary}--`)
|
||||
}
|
||||
|
||||
const stream = Readable.from(asyncIterator())
|
||||
|
||||
return {
|
||||
stream,
|
||||
contentType: `multipart/form-data; boundary=${boundary}`
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.isFormDataLike = isFormDataLike
|
||||
module.exports.formDataToStream = formDataToStream
|
||||
47
node_modules/light-my-request/lib/parse-url.js
generated
vendored
Normal file
47
node_modules/light-my-request/lib/parse-url.js
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
'use strict'
|
||||
|
||||
const { URL } = require('node:url')
|
||||
|
||||
const BASE_URL = 'http://localhost'
|
||||
|
||||
/**
|
||||
* Parse URL
|
||||
*
|
||||
* @param {(Object|String)} url
|
||||
* @param {Object} [query]
|
||||
* @return {URL}
|
||||
*/
|
||||
module.exports = function parseURL (url, query) {
|
||||
if ((typeof url === 'string' || Object.prototype.toString.call(url) === '[object String]') && url.startsWith('//')) {
|
||||
url = BASE_URL + url
|
||||
}
|
||||
const result = typeof url === 'object'
|
||||
? Object.assign(new URL(BASE_URL), url)
|
||||
: new URL(url, BASE_URL)
|
||||
|
||||
if (typeof query === 'string') {
|
||||
query = new URLSearchParams(query)
|
||||
for (const key of query.keys()) {
|
||||
result.searchParams.delete(key)
|
||||
for (const value of query.getAll(key)) {
|
||||
result.searchParams.append(key, value)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const merged = Object.assign({}, url.query, query)
|
||||
for (const key in merged) {
|
||||
const value = merged[key]
|
||||
|
||||
if (Array.isArray(value)) {
|
||||
result.searchParams.delete(key)
|
||||
for (const param of value) {
|
||||
result.searchParams.append(key, param)
|
||||
}
|
||||
} else {
|
||||
result.searchParams.set(key, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
290
node_modules/light-my-request/lib/request.js
generated
vendored
Normal file
290
node_modules/light-my-request/lib/request.js
generated
vendored
Normal file
@@ -0,0 +1,290 @@
|
||||
'use strict'
|
||||
|
||||
/* eslint no-prototype-builtins: 0 */
|
||||
|
||||
const { Readable, addAbortSignal } = require('node:stream')
|
||||
const util = require('node:util')
|
||||
const cookie = require('cookie')
|
||||
const assert = require('node:assert')
|
||||
const { createDeprecation } = require('process-warning')
|
||||
|
||||
const parseURL = require('./parse-url')
|
||||
const { isFormDataLike, formDataToStream } = require('./form-data')
|
||||
const { EventEmitter } = require('node:events')
|
||||
|
||||
// request.connectin deprecation https://nodejs.org/api/http.html#http_request_connection
|
||||
const FST_LIGHTMYREQUEST_DEP01 = createDeprecation({
|
||||
name: 'FastifyDeprecationLightMyRequest',
|
||||
code: 'FST_LIGHTMYREQUEST_DEP01',
|
||||
message: 'You are accessing "request.connection", use "request.socket" instead.'
|
||||
})
|
||||
|
||||
/**
|
||||
* Get hostname:port
|
||||
*
|
||||
* @param {URL} parsedURL
|
||||
* @return {String}
|
||||
*/
|
||||
function hostHeaderFromURL (parsedURL) {
|
||||
return parsedURL.port
|
||||
? parsedURL.host
|
||||
: parsedURL.hostname + (parsedURL.protocol === 'https:' ? ':443' : ':80')
|
||||
}
|
||||
|
||||
/**
|
||||
* Mock socket object used to fake access to a socket for a request
|
||||
*
|
||||
* @constructor
|
||||
* @param {String} remoteAddress the fake address to show consumers of the socket
|
||||
*/
|
||||
class MockSocket extends EventEmitter {
|
||||
constructor (remoteAddress) {
|
||||
super()
|
||||
this.remoteAddress = remoteAddress
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* CustomRequest
|
||||
*
|
||||
* @constructor
|
||||
* @param {Object} options
|
||||
* @param {(Object|String)} options.url || options.path
|
||||
* @param {String} [options.method='GET']
|
||||
* @param {String} [options.remoteAddress]
|
||||
* @param {Object} [options.cookies]
|
||||
* @param {Object} [options.headers]
|
||||
* @param {Object} [options.query]
|
||||
* @param {Object} [options.Request]
|
||||
* @param {any} [options.payload]
|
||||
*/
|
||||
function CustomRequest (options) {
|
||||
return new _CustomLMRRequest(this)
|
||||
|
||||
function _CustomLMRRequest (obj) {
|
||||
Request.call(obj, {
|
||||
...options,
|
||||
Request: undefined
|
||||
})
|
||||
Object.assign(this, obj)
|
||||
|
||||
for (const fn of Object.keys(Request.prototype)) {
|
||||
this.constructor.prototype[fn] = Request.prototype[fn]
|
||||
}
|
||||
|
||||
util.inherits(this.constructor, options.Request)
|
||||
return this
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Request
|
||||
*
|
||||
* @constructor
|
||||
* @param {Object} options
|
||||
* @param {(Object|String)} options.url || options.path
|
||||
* @param {String} [options.method='GET']
|
||||
* @param {String} [options.remoteAddress]
|
||||
* @param {Object} [options.cookies]
|
||||
* @param {Object} [options.headers]
|
||||
* @param {Object} [options.query]
|
||||
* @param {any} [options.payload]
|
||||
*/
|
||||
function Request (options) {
|
||||
Readable.call(this, {
|
||||
autoDestroy: false
|
||||
})
|
||||
|
||||
const parsedURL = parseURL(options.url || options.path, options.query)
|
||||
|
||||
this.url = parsedURL.pathname + parsedURL.search
|
||||
|
||||
this.aborted = false
|
||||
this.httpVersionMajor = 1
|
||||
this.httpVersionMinor = 1
|
||||
this.httpVersion = '1.1'
|
||||
this.method = options.method ? options.method.toUpperCase() : 'GET'
|
||||
|
||||
this.headers = {}
|
||||
this.rawHeaders = []
|
||||
|
||||
const headers = options.headers || {}
|
||||
|
||||
for (const field in headers) {
|
||||
const fieldLowerCase = field.toLowerCase()
|
||||
if (
|
||||
(
|
||||
fieldLowerCase === 'user-agent' ||
|
||||
fieldLowerCase === 'content-type'
|
||||
) && headers[field] === undefined
|
||||
) {
|
||||
this.headers[fieldLowerCase] = undefined
|
||||
continue
|
||||
}
|
||||
const value = headers[field]
|
||||
assert(value !== undefined, 'invalid value "undefined" for header ' + field)
|
||||
this.headers[fieldLowerCase] = '' + value
|
||||
}
|
||||
|
||||
if (('user-agent' in this.headers) === false) {
|
||||
this.headers['user-agent'] = 'lightMyRequest'
|
||||
}
|
||||
this.headers.host = this.headers.host || options.authority || hostHeaderFromURL(parsedURL)
|
||||
|
||||
if (options.cookies) {
|
||||
const { cookies } = options
|
||||
const cookieValues = Object.keys(cookies).map(key => cookie.serialize(key, cookies[key]))
|
||||
if (this.headers.cookie) {
|
||||
cookieValues.unshift(this.headers.cookie)
|
||||
}
|
||||
this.headers.cookie = cookieValues.join('; ')
|
||||
}
|
||||
|
||||
this.socket = new MockSocket(options.remoteAddress || '127.0.0.1')
|
||||
|
||||
Object.defineProperty(this, 'connection', {
|
||||
get () {
|
||||
FST_LIGHTMYREQUEST_DEP01()
|
||||
return this.socket
|
||||
},
|
||||
configurable: true
|
||||
})
|
||||
|
||||
// we keep both payload and body for compatibility reasons
|
||||
let payload = options.payload || options.body || null
|
||||
let payloadResume = payload && typeof payload.resume === 'function'
|
||||
|
||||
if (isFormDataLike(payload)) {
|
||||
const stream = formDataToStream(payload)
|
||||
payload = stream.stream
|
||||
payloadResume = true
|
||||
// we override the content-type
|
||||
this.headers['content-type'] = stream.contentType
|
||||
this.headers['transfer-encoding'] = 'chunked'
|
||||
}
|
||||
|
||||
if (payload && typeof payload !== 'string' && !payloadResume && !Buffer.isBuffer(payload)) {
|
||||
payload = JSON.stringify(payload)
|
||||
|
||||
if (('content-type' in this.headers) === false) {
|
||||
this.headers['content-type'] = 'application/json'
|
||||
}
|
||||
}
|
||||
|
||||
// Set the content-length for the corresponding payload if none set
|
||||
if (payload && !payloadResume && !Object.hasOwn(this.headers, 'content-length')) {
|
||||
this.headers['content-length'] = (Buffer.isBuffer(payload) ? payload.length : Buffer.byteLength(payload)).toString()
|
||||
}
|
||||
|
||||
for (const header of Object.keys(this.headers)) {
|
||||
this.rawHeaders.push(header, this.headers[header])
|
||||
}
|
||||
|
||||
// Use _lightMyRequest namespace to avoid collision with Node
|
||||
this._lightMyRequest = {
|
||||
payload,
|
||||
isDone: false,
|
||||
simulate: options.simulate || {},
|
||||
payloadAsStream: options.payloadAsStream,
|
||||
signal: options.signal
|
||||
}
|
||||
|
||||
const signal = options.signal
|
||||
/* c8 ignore next 3 */
|
||||
if (signal) {
|
||||
addAbortSignal(signal, this)
|
||||
}
|
||||
|
||||
{
|
||||
const payload = this._lightMyRequest.payload
|
||||
if (payload?._readableState) { // does quack like a modern stream
|
||||
this._read = readStream
|
||||
|
||||
payload.on('error', (err) => {
|
||||
this.destroy(err)
|
||||
})
|
||||
|
||||
payload.on('end', () => {
|
||||
this.push(null)
|
||||
})
|
||||
} else {
|
||||
// Stream v1 are handled in index.js synchronously
|
||||
this._read = readEverythingElse
|
||||
}
|
||||
}
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
function readStream () {
|
||||
const payload = this._lightMyRequest.payload
|
||||
|
||||
let more = true
|
||||
let pushed = false
|
||||
let chunk
|
||||
while (more && (chunk = payload.read())) {
|
||||
pushed = true
|
||||
more = this.push(chunk)
|
||||
}
|
||||
|
||||
// We set up a recursive 'readable' event only if we didn't read anything.
|
||||
// Otheriwse, the stream machinery will call _read() for us.
|
||||
if (more && !pushed) {
|
||||
this._lightMyRequest.payload.once('readable', this._read.bind(this))
|
||||
}
|
||||
}
|
||||
|
||||
function readEverythingElse () {
|
||||
setImmediate(() => {
|
||||
if (this._lightMyRequest.isDone) {
|
||||
// 'end' defaults to true
|
||||
if (this._lightMyRequest.simulate.end !== false) {
|
||||
this.push(null)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
this._lightMyRequest.isDone = true
|
||||
|
||||
if (this._lightMyRequest.payload) {
|
||||
if (this._lightMyRequest.simulate.split) {
|
||||
this.push(this._lightMyRequest.payload.slice(0, 1))
|
||||
this.push(this._lightMyRequest.payload.slice(1))
|
||||
} else {
|
||||
this.push(this._lightMyRequest.payload)
|
||||
}
|
||||
}
|
||||
|
||||
if (this._lightMyRequest.simulate.error) {
|
||||
this.emit('error', new Error('Simulated'))
|
||||
}
|
||||
|
||||
if (this._lightMyRequest.simulate.close) {
|
||||
this.emit('close')
|
||||
}
|
||||
|
||||
// 'end' defaults to true
|
||||
if (this._lightMyRequest.simulate.end !== false) {
|
||||
this.push(null)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
util.inherits(Request, Readable)
|
||||
util.inherits(CustomRequest, Request)
|
||||
|
||||
Request.prototype.destroy = function (error) {
|
||||
if (this.destroyed || this._lightMyRequest.isDone) return
|
||||
this.destroyed = true
|
||||
|
||||
if (error) {
|
||||
this._error = true
|
||||
process.nextTick(() => this.emit('error', error))
|
||||
}
|
||||
|
||||
process.nextTick(() => this.emit('close'))
|
||||
}
|
||||
|
||||
module.exports = Request
|
||||
module.exports.Request = Request
|
||||
module.exports.CustomRequest = CustomRequest
|
||||
240
node_modules/light-my-request/lib/response.js
generated
vendored
Normal file
240
node_modules/light-my-request/lib/response.js
generated
vendored
Normal file
@@ -0,0 +1,240 @@
|
||||
'use strict'
|
||||
|
||||
const http = require('node:http')
|
||||
const { Writable, Readable, addAbortSignal } = require('node:stream')
|
||||
const util = require('node:util')
|
||||
|
||||
const setCookie = require('set-cookie-parser')
|
||||
|
||||
function Response (req, onEnd, reject) {
|
||||
http.ServerResponse.call(this, req)
|
||||
|
||||
if (req._lightMyRequest?.payloadAsStream) {
|
||||
const read = this.emit.bind(this, 'drain')
|
||||
this._lightMyRequest = { headers: null, trailers: {}, stream: new Readable({ read }) }
|
||||
const signal = req._lightMyRequest.signal
|
||||
|
||||
if (signal) {
|
||||
addAbortSignal(signal, this._lightMyRequest.stream)
|
||||
}
|
||||
} else {
|
||||
this._lightMyRequest = { headers: null, trailers: {}, payloadChunks: [] }
|
||||
}
|
||||
// This forces node@8 to always render the headers
|
||||
this.setHeader('foo', 'bar'); this.removeHeader('foo')
|
||||
|
||||
this.assignSocket(getNullSocket())
|
||||
|
||||
this._promiseCallback = typeof reject === 'function'
|
||||
|
||||
let called = false
|
||||
const onEndSuccess = (payload) => {
|
||||
if (called) return
|
||||
called = true
|
||||
if (this._promiseCallback) {
|
||||
return process.nextTick(() => onEnd(payload))
|
||||
}
|
||||
process.nextTick(() => onEnd(null, payload))
|
||||
}
|
||||
this._lightMyRequest.onEndSuccess = onEndSuccess
|
||||
|
||||
let finished = false
|
||||
const onEndFailure = (err) => {
|
||||
if (called) {
|
||||
if (this._lightMyRequest.stream && !finished) {
|
||||
if (!err) {
|
||||
err = new Error('response destroyed before completion')
|
||||
err.code = 'LIGHT_ECONNRESET'
|
||||
}
|
||||
this._lightMyRequest.stream.destroy(err)
|
||||
this._lightMyRequest.stream.on('error', () => {})
|
||||
}
|
||||
return
|
||||
}
|
||||
called = true
|
||||
if (!err) {
|
||||
err = new Error('response destroyed before completion')
|
||||
err.code = 'LIGHT_ECONNRESET'
|
||||
}
|
||||
if (this._promiseCallback) {
|
||||
return process.nextTick(() => reject(err))
|
||||
}
|
||||
process.nextTick(() => onEnd(err, null))
|
||||
}
|
||||
|
||||
if (this._lightMyRequest.stream) {
|
||||
this.once('finish', () => {
|
||||
finished = true
|
||||
this._lightMyRequest.stream.push(null)
|
||||
})
|
||||
} else {
|
||||
this.once('finish', () => {
|
||||
const res = generatePayload(this)
|
||||
res.raw.req = req
|
||||
onEndSuccess(res)
|
||||
})
|
||||
}
|
||||
|
||||
this.connection.once('error', onEndFailure)
|
||||
|
||||
this.once('error', onEndFailure)
|
||||
|
||||
this.once('close', onEndFailure)
|
||||
}
|
||||
|
||||
util.inherits(Response, http.ServerResponse)
|
||||
|
||||
Response.prototype.setTimeout = function (msecs, callback) {
|
||||
this.timeoutHandle = setTimeout(() => {
|
||||
this.emit('timeout')
|
||||
}, msecs)
|
||||
this.on('timeout', callback)
|
||||
return this
|
||||
}
|
||||
|
||||
Response.prototype.writeHead = function () {
|
||||
const result = http.ServerResponse.prototype.writeHead.apply(this, arguments)
|
||||
|
||||
copyHeaders(this)
|
||||
|
||||
if (this._lightMyRequest.stream) {
|
||||
this._lightMyRequest.onEndSuccess(generatePayload(this))
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
Response.prototype.write = function (data, encoding, callback) {
|
||||
if (this.timeoutHandle) {
|
||||
clearTimeout(this.timeoutHandle)
|
||||
}
|
||||
http.ServerResponse.prototype.write.call(this, data, encoding, callback)
|
||||
if (this._lightMyRequest.stream) {
|
||||
return this._lightMyRequest.stream.push(Buffer.from(data, encoding))
|
||||
} else {
|
||||
this._lightMyRequest.payloadChunks.push(Buffer.from(data, encoding))
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
Response.prototype.end = function (data, encoding, callback) {
|
||||
if (data) {
|
||||
this.write(data, encoding)
|
||||
}
|
||||
|
||||
http.ServerResponse.prototype.end.call(this, callback)
|
||||
|
||||
this.emit('finish')
|
||||
|
||||
// We need to emit 'close' otherwise stream.finished() would
|
||||
// not pick it up on Node v16
|
||||
|
||||
this.destroy()
|
||||
}
|
||||
|
||||
Response.prototype.destroy = function (error) {
|
||||
if (this.destroyed) return
|
||||
this.destroyed = true
|
||||
|
||||
if (error) {
|
||||
process.nextTick(() => this.emit('error', error))
|
||||
}
|
||||
|
||||
process.nextTick(() => this.emit('close'))
|
||||
}
|
||||
|
||||
Response.prototype.addTrailers = function (trailers) {
|
||||
for (const key in trailers) {
|
||||
this._lightMyRequest.trailers[key.toLowerCase().trim()] = trailers[key].toString().trim()
|
||||
}
|
||||
}
|
||||
|
||||
function generatePayload (response) {
|
||||
// This seems only to happen when using `fastify-express` - see https://github.com/fastify/fastify-express/issues/47
|
||||
/* c8 ignore next 3 */
|
||||
if (response._lightMyRequest.headers === null) {
|
||||
copyHeaders(response)
|
||||
}
|
||||
serializeHeaders(response)
|
||||
// Prepare response object
|
||||
const res = {
|
||||
raw: {
|
||||
res: response
|
||||
},
|
||||
headers: response._lightMyRequest.headers,
|
||||
statusCode: response.statusCode,
|
||||
statusMessage: response.statusMessage,
|
||||
trailers: {},
|
||||
get cookies () {
|
||||
return setCookie.parse(this)
|
||||
}
|
||||
}
|
||||
|
||||
res.trailers = response._lightMyRequest.trailers
|
||||
|
||||
if (response._lightMyRequest.payloadChunks) {
|
||||
// Prepare payload and trailers
|
||||
const rawBuffer = Buffer.concat(response._lightMyRequest.payloadChunks)
|
||||
res.rawPayload = rawBuffer
|
||||
|
||||
// we keep both of them for compatibility reasons
|
||||
res.payload = rawBuffer.toString()
|
||||
res.body = res.payload
|
||||
|
||||
// Prepare payload parsers
|
||||
res.json = function parseJsonPayload () {
|
||||
return JSON.parse(res.payload)
|
||||
}
|
||||
} else {
|
||||
res.json = function () {
|
||||
throw new Error('Response payload is not available with payloadAsStream: true')
|
||||
}
|
||||
}
|
||||
|
||||
// Provide stream Readable for advanced user
|
||||
res.stream = function streamPayload () {
|
||||
if (response._lightMyRequest.stream) {
|
||||
return response._lightMyRequest.stream
|
||||
}
|
||||
return Readable.from(response._lightMyRequest.payloadChunks)
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
// Throws away all written data to prevent response from buffering payload
|
||||
function getNullSocket () {
|
||||
return new Writable({
|
||||
write (_chunk, _encoding, callback) {
|
||||
setImmediate(callback)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function serializeHeaders (response) {
|
||||
const headers = response._lightMyRequest.headers
|
||||
|
||||
for (const headerName of Object.keys(headers)) {
|
||||
const headerValue = headers[headerName]
|
||||
if (Array.isArray(headerValue)) {
|
||||
headers[headerName] = headerValue.map(value => '' + value)
|
||||
} else {
|
||||
headers[headerName] = '' + headerValue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function copyHeaders (response) {
|
||||
response._lightMyRequest.headers = Object.assign({}, response.getHeaders())
|
||||
|
||||
// Add raw headers
|
||||
;['Date', 'Connection', 'Transfer-Encoding'].forEach((name) => {
|
||||
const regex = new RegExp('\\r\\n' + name + ': ([^\\r]*)\\r\\n')
|
||||
const field = response._header?.match(regex)
|
||||
if (field) {
|
||||
response._lightMyRequest.headers[name.toLowerCase()] = field[1]
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = Response
|
||||
Reference in New Issue
Block a user