Comparing version 0.14.3 to 0.14.4
@@ -10,3 +10,3 @@ "use strict"; | ||
var writeRouteFile_1 = __importDefault(require("../writeRouteFile")); | ||
var watchInputDir_1 = __importDefault(require("../watchInputDir")); | ||
var watchInputDir_1 = __importDefault(require("./watchInputDir")); | ||
var build_1 = require("./build"); | ||
@@ -13,0 +13,0 @@ var command_1 = require("./command"); |
"use strict"; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var quoteRegExp = /['"]/; | ||
var getStringValue = function (text) { | ||
var openRegExp = /[(<{]/; | ||
var closeRegExp = /[)>}]/; | ||
var operatorRegExp = /[|&]/; | ||
var parseString = function (text) { | ||
var textLength = text.length; | ||
var value = ''; | ||
var value = text[0]; | ||
var cursor = 1; | ||
@@ -20,2 +39,3 @@ var isEscapingQuote = false; | ||
else if (text.startsWith(char)) { | ||
value += char; | ||
break; | ||
@@ -29,3 +49,3 @@ } | ||
}; | ||
var getName = function (text) { | ||
var parseName = function (text) { | ||
var value = ''; | ||
@@ -35,4 +55,4 @@ var hasQuestion = false; | ||
if (quoteRegExp.test(text[0])) { | ||
var stringValue = getStringValue(text); | ||
value = stringValue.value; | ||
var stringValue = parseString(text); | ||
value = stringValue.value.slice(1, -1); | ||
hasQuestion = text[stringValue.length] === '?'; | ||
@@ -49,61 +69,136 @@ length = stringValue.length + +hasQuestion; | ||
}; | ||
var getProp = function (text) { | ||
var textLength = text.length; | ||
var name = getName(text); | ||
var value = { value: '', hasQuestion: name.hasQuestion }; | ||
var cursor = name.length; | ||
var countIgnored = function (text) { | ||
var length = text.length; | ||
var cursor = 0; | ||
var isLineComment = false; | ||
var isMultiComment = false; | ||
while (cursor < length) { | ||
var _a = __read(text.slice(cursor), 2), first = _a[0], second = _a[1]; | ||
if (isLineComment) { | ||
if (first === '\n') { | ||
isLineComment = false; | ||
} | ||
} | ||
else if (isMultiComment) { | ||
if (first === '*' && second === '/') { | ||
cursor += 1; | ||
isMultiComment = false; | ||
} | ||
} | ||
else if (first === '/') { | ||
if (second === '/') { | ||
isLineComment = true; | ||
} | ||
else { | ||
isMultiComment = true; | ||
} | ||
cursor += 1; | ||
} | ||
else if (/[^ \n]/.test(first)) { | ||
break; | ||
} | ||
cursor += 1; | ||
} | ||
return cursor; | ||
}; | ||
var parseTypeName = function (text) { | ||
var length = text.length; | ||
var value = ''; | ||
var cursor = 0; | ||
while (!countIgnored(text.slice(cursor)) && !openRegExp.test(text[cursor]) && cursor < length) { | ||
value += text[cursor]; | ||
cursor += 1; | ||
} | ||
return { value: value, length: cursor }; | ||
}; | ||
var parseObject = function (text) { | ||
var length = text.length; | ||
var value = ''; | ||
var cursor = 0; | ||
var indentLevel = 0; | ||
while (cursor < textLength) { | ||
while (cursor < length) { | ||
var char = text[cursor]; | ||
if (quoteRegExp.test(char)) { | ||
var stringValue = getStringValue(text.slice(cursor)); | ||
cursor += stringValue.length; | ||
value.value += stringValue.value; | ||
var val = parseString(text.slice(cursor)); | ||
value += val.value; | ||
cursor += val.length; | ||
} | ||
else { | ||
cursor += 1; | ||
if (char === '{') { | ||
if (openRegExp.test(char)) | ||
indentLevel += 1; | ||
} | ||
else if (char === '}') { | ||
else if (closeRegExp.test(char)) | ||
indentLevel -= 1; | ||
} | ||
else if (indentLevel === 0 && char === ';' && /[^|&]/.test(text[cursor])) { | ||
break; | ||
} | ||
value.value += char; | ||
value += char; | ||
cursor += 1; | ||
} | ||
cursor += countIgnored(text.slice(cursor)); | ||
if (!indentLevel) | ||
break; | ||
} | ||
return { name: name.value, value: value, length: cursor }; | ||
return { value: value, length: cursor }; | ||
}; | ||
var getMethod = function (targetText) { | ||
var textLength = targetText.length; | ||
if (targetText.startsWith('}')) | ||
return { method: null, length: textLength }; | ||
var methodName = getName(targetText); | ||
var cursor = methodName.length; | ||
var props = {}; | ||
while (cursor < textLength) { | ||
var text = targetText.slice(cursor); | ||
if (text.startsWith('}')) { | ||
cursor += text[1] === ';' ? 2 : 1; | ||
break; | ||
var parseProp = function (text) { | ||
var length = text.length; | ||
var name = parseName(text); | ||
var prop = { value: '', hasQuestion: name.hasQuestion }; | ||
var cursor = name.length; | ||
while (cursor < length) { | ||
cursor += countIgnored(text.slice(cursor)); | ||
if (operatorRegExp.test(text[cursor])) { | ||
prop.value += text[cursor]; | ||
cursor += 1; | ||
cursor += countIgnored(text.slice(cursor)); | ||
} | ||
var char = text[cursor]; | ||
if (quoteRegExp.test(char)) { | ||
var val = parseString(text.slice(cursor)); | ||
prop.value += val.value; | ||
cursor += val.length; | ||
} | ||
else { | ||
var prop = getProp(text.replace(/^{;?/, '')); | ||
cursor += prop.length + (text.startsWith('{;') ? 2 : text.startsWith(';') ? 1 : 0); | ||
props[prop.name] = prop.value; | ||
var typeName = parseTypeName(text.slice(cursor)); | ||
prop.value += typeName.value; | ||
cursor += typeName.length; | ||
if (openRegExp.test(text[cursor])) { | ||
var val = parseObject(text.slice(cursor)); | ||
prop.value += val.value; | ||
cursor += val.length; | ||
} | ||
} | ||
cursor += countIgnored(text.slice(cursor)); | ||
if (text.slice(cursor, cursor + 2) === '[]') { | ||
cursor += 2; | ||
cursor += countIgnored(text.slice(cursor)); | ||
} | ||
if (!operatorRegExp.test(text[cursor])) | ||
break; | ||
} | ||
return { method: { name: methodName.value, props: props }, length: cursor }; | ||
return { name: name.value, value: prop, length: cursor }; | ||
}; | ||
var getMethods = function (targetText) { | ||
var textLength = targetText.length; | ||
var parseMethod = function (text) { | ||
var length = text.length; | ||
var methodName = parseName(text); | ||
var cursor = methodName.length; | ||
var props = {}; | ||
cursor += countIgnored(text.slice(cursor)) + 1; // '{' | ||
cursor += countIgnored(text.slice(cursor)); | ||
while (text[cursor] !== '}' && cursor < length) { | ||
var prop = parseProp(text.slice(cursor)); | ||
cursor += prop.length; | ||
props[prop.name] = prop.value; | ||
} | ||
cursor += 1; // '}' | ||
return { value: { name: methodName.value, props: props }, length: cursor }; | ||
}; | ||
var parseMethods = function (text) { | ||
var length = text.length; | ||
var methods = []; | ||
var cursor = 0; | ||
while (cursor < textLength) { | ||
var _a = getMethod(targetText.slice(cursor).replace(/^{;?/, '')), method = _a.method, length_1 = _a.length; | ||
cursor += length_1 + (targetText.startsWith('{;') ? 2 : targetText.startsWith(';') ? 1 : 0); | ||
if (method) | ||
methods.push(method); | ||
while (cursor < length) { | ||
cursor += countIgnored(text.slice(cursor)); | ||
if (text[cursor] === '}') | ||
break; | ||
var method = parseMethod(text.slice(cursor)); | ||
cursor += method.length; | ||
methods.push(method.value); | ||
} | ||
@@ -116,9 +211,5 @@ return methods; | ||
return null; | ||
return getMethods(text | ||
.split(interfaceRegExp)[2] | ||
.replace(/\n/g, ';') | ||
.replace(/ /g, '') | ||
.replace(';', '') | ||
.replace(/;+/g, ';')); | ||
var methods = parseMethods(text.split(interfaceRegExp)[2]); | ||
return methods.length ? methods : null; | ||
}); | ||
//# sourceMappingURL=parseInterface.js.map |
{ | ||
"name": "aspida", | ||
"version": "0.14.3", | ||
"version": "0.14.4", | ||
"description": "TypeScript friendly HTTP client wrapper for the browser and node.js", | ||
@@ -28,4 +28,4 @@ "author": "m-mitsuhide <m.mitsuhide@amatelus.com>", | ||
"chokidar": "^3.3.1", | ||
"minimist": "^1.2.3" | ||
"minimist": "^1.2.4" | ||
} | ||
} |
@@ -220,2 +220,27 @@ | aspida | [aspida-mock] | [openapi2aspida] | [pathpida] | [@aspida/axios] | [@aspida/ky] | [@aspida/fetch] | | ||
### Serialize GET parameters manually | ||
aspida leaves GET parameter serialization to standard HTTP client behavior | ||
If you want to serialize manually, you can use config object of HTTP client | ||
`src/index.ts` | ||
```typescript | ||
import axios from 'axios' | ||
import qs from 'qs' | ||
import aspida from "@aspida/axios" | ||
import api from "../apis/$api" | ||
;(async () => { | ||
const client = api(aspida(axios, { paramsSerializer: (params) => qs.stringify(params, { indices: false }) })) | ||
const users = await client.v1.users.$get({ | ||
// config: { paramsSerializer: (params) => qs.stringify(params, { indices: false }) }, | ||
query: { ids: [1, 2, 3] } | ||
}) | ||
console.log(users) | ||
// req -> GET: /v1/users/?ids=1&ids=2&ids=3 | ||
// res -> [{ id: 1, name: 'taro1' }, { id: 2, name: 'taro2' }, { id: 3, name: 'taro3' }] | ||
})() | ||
``` | ||
### POST with FormData | ||
@@ -249,6 +274,3 @@ | ||
;(async () => { | ||
const userId = 0 | ||
const limit = 10 | ||
const client = api(aspida()) | ||
const iconImage = imageBuffer | ||
@@ -258,7 +280,7 @@ const user = await client.v1.users.$post({ | ||
name: "taro", | ||
icon: iconImage | ||
icon: imageBuffer | ||
} | ||
}) | ||
console.log(user) | ||
// req -> POST: h/v1/users/0 | ||
// req -> POST: h/v1/users | ||
// res -> { id: 0, name: 'taro' } | ||
@@ -295,4 +317,2 @@ })() | ||
;(async () => { | ||
const userId = 0 | ||
const limit = 10 | ||
const client = api(aspida()) | ||
@@ -302,3 +322,3 @@ | ||
console.log(user) | ||
// req -> POST: /v1/users/0 | ||
// req -> POST: /v1/users | ||
// res -> { id: 0, name: 'taro' } | ||
@@ -330,4 +350,2 @@ })() | ||
;(async () => { | ||
const userId = 0 | ||
const limit = 10 | ||
const client = api(aspida()) | ||
@@ -337,3 +355,3 @@ | ||
console.log(user) | ||
// req -> POST: /v1/users/0 | ||
// req -> GET: /v1/users/?name=taro | ||
// res -> ArrayBuffer | ||
@@ -340,0 +358,0 @@ })() |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
64916
747
364
Updatedminimist@^1.2.4