Skip to content

Commit

Permalink
fix: support latest v4 updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jfrconley committed Apr 6, 2020
1 parent 92f36cf commit 1a1743a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 67 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"husky": "^4.2.3",
"semantic-release": "^17.0.4",
"tslint": "^6.1.0",
"typescript": "^3.8.3"
"typescript": "^3.8.3",
"valory-runtime": "^4.0.0-v4.7"
},
"files": [
"dist/adaptor-polka.js",
Expand All @@ -30,8 +31,7 @@
"@types/node": "10.11.1"
},
"dependencies": {
"polka": "^0.5.2",
"valory-runtime": "^4.0.0-v4.2"
"polka": "^0.5.2"
},
"peerDependencies": {
"valory-runtime": ">=4"
Expand Down
29 changes: 3 additions & 26 deletions src/adaptor-polka.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {ApiContext, HttpMethod, ApiAdaptor} from "valory-runtime";
import {IncomingMessage, ServerResponse} from "http";
import qs = require("querystring");
import url = require("url");

const polka = require("polka");
Expand All @@ -27,23 +26,20 @@ export class PolkaAdaptor implements ApiAdaptor {

req.on("end", async () => {
const parsedUrl = url.parse(req.url, true);
const body = attemptParse(req.headers["content-type"], rawBody);
const ctx = new ApiContext({
headers: req.headers,
queryParams: parsedUrl.query,
pathParams: (req as any).params,
path,
method,
body,
formData: body as any,
rawBody,
});

await handler(ctx);
res.writeHead(ctx.response.statusCode, ctx.response.headers);
res.end(ctx.serializeResponse())
})
})
res.end(ctx.serializeResponse());
});
});
}

public start() {
Expand All @@ -54,22 +50,3 @@ export class PolkaAdaptor implements ApiAdaptor {
this.server.close()
}
}

function attemptParse(contentType: string, obj: any): any {
if (contentType == null) {
return obj;
}
const parsedContentType = contentType.split(";")[0];
try {
switch (parsedContentType) {
case "application/json":
return JSON.parse(obj);
case "application/x-www-form-urlencoded":
return qs.parse(obj);
default:
return obj;
}
} catch (err) {
return obj;
}
}
44 changes: 6 additions & 38 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1289,7 +1289,7 @@ debug@^3.1.0:
dependencies:
ms "^2.1.1"

debuglog@*, debuglog@^1.0.1:
debuglog@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/debuglog/-/debuglog-1.0.1.tgz#aa24ffb9ac3df9a2351837cfb2d279360cd78492"
integrity sha1-qiT/uaw9+aI1GDfPstJ5NgzXhJI=
Expand Down Expand Up @@ -2133,7 +2133,7 @@ import-lazy@^2.1.0:
resolved "https://registry.yarnpkg.com/import-lazy/-/import-lazy-2.1.0.tgz#05698e3d45c88e8d7e9d92cb0584e77f096f3e43"
integrity sha1-BWmOPUXIjo1+nZLLBYTnfwlvPkM=

imurmurhash@*, imurmurhash@^0.1.4:
imurmurhash@^0.1.4:
version "0.1.4"
resolved "https://registry.yarnpkg.com/imurmurhash/-/imurmurhash-0.1.4.tgz#9218b9b2b928a238b13dc4fb6b6d576f231453ea"
integrity sha1-khi5srkoojixPcT7a21XbyMUU+o=
Expand Down Expand Up @@ -2691,11 +2691,6 @@ lockfile@^1.0.4:
dependencies:
signal-exit "^3.0.2"

lodash._baseindexof@*:
version "3.1.0"
resolved "https://registry.yarnpkg.com/lodash._baseindexof/-/lodash._baseindexof-3.1.0.tgz#fe52b53a1c6761e42618d654e4a25789ed61822c"
integrity sha1-/lK1OhxnYeQmGNZU5KJXie1hgiw=

lodash._baseuniq@~4.6.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/lodash._baseuniq/-/lodash._baseuniq-4.6.0.tgz#0ebb44e456814af7905c6212fa2c9b2d51b841e8"
Expand All @@ -2704,33 +2699,11 @@ lodash._baseuniq@~4.6.0:
lodash._createset "~4.0.0"
lodash._root "~3.0.0"

lodash._bindcallback@*:
version "3.0.1"
resolved "https://registry.yarnpkg.com/lodash._bindcallback/-/lodash._bindcallback-3.0.1.tgz#e531c27644cf8b57a99e17ed95b35c748789392e"
integrity sha1-5THCdkTPi1epnhftlbNcdIeJOS4=

lodash._cacheindexof@*:
version "3.0.2"
resolved "https://registry.yarnpkg.com/lodash._cacheindexof/-/lodash._cacheindexof-3.0.2.tgz#3dc69ac82498d2ee5e3ce56091bafd2adc7bde92"
integrity sha1-PcaayCSY0u5ePOVgkbr9Ktx73pI=

lodash._createcache@*:
version "3.1.2"
resolved "https://registry.yarnpkg.com/lodash._createcache/-/lodash._createcache-3.1.2.tgz#56d6a064017625e79ebca6b8018e17440bdcf093"
integrity sha1-VtagZAF2JeeevKa4AY4XRAvc8JM=
dependencies:
lodash._getnative "^3.0.0"

lodash._createset@~4.0.0:
version "4.0.3"
resolved "https://registry.yarnpkg.com/lodash._createset/-/lodash._createset-4.0.3.tgz#0f4659fbb09d75194fa9e2b88a6644d363c9fe26"
integrity sha1-D0ZZ+7CddRlPqeK4imZE02PJ/iY=

lodash._getnative@*, lodash._getnative@^3.0.0:
version "3.9.1"
resolved "https://registry.yarnpkg.com/lodash._getnative/-/lodash._getnative-3.9.1.tgz#570bc7dede46d61cdcde687d65d3eecbaa3aaff5"
integrity sha1-VwvH3t5G1hzc3mh9ZdPuy6o6r/U=

lodash._reinterpolate@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz#0ccf2d89166af03b3663c796538b75ac6e114d9d"
Expand Down Expand Up @@ -2776,11 +2749,6 @@ lodash.map@^4.5.1:
resolved "https://registry.yarnpkg.com/lodash.map/-/lodash.map-4.6.0.tgz#771ec7839e3473d9c4cde28b19394c3562f4f6d3"
integrity sha1-dx7Hg540c9nEzeKLGTlMNWL09tM=

lodash.restparam@*:
version "3.6.1"
resolved "https://registry.yarnpkg.com/lodash.restparam/-/lodash.restparam-3.6.1.tgz#936a4e309ef330a7645ed4145986c85ae5b20805"
integrity sha1-k2pOMJ7zMKdkXtQUWYbIWuWyCAU=

lodash.template@^4.0.2:
version "4.5.0"
resolved "https://registry.yarnpkg.com/lodash.template/-/lodash.template-4.5.0.tgz#f976195cf3f347d0d5f52483569fe8031ccce8ab"
Expand Down Expand Up @@ -5091,10 +5059,10 @@ validate-npm-package-name@^3.0.0, validate-npm-package-name@~3.0.0:
dependencies:
builtins "^1.0.3"

valory-runtime@^4.0.0-v4.2:
version "4.0.0-v4.2"
resolved "https://registry.yarnpkg.com/valory-runtime/-/valory-runtime-4.0.0-v4.2.tgz#506bcc24ccbd2db56435baf03d8ae8f5d83216df"
integrity sha512-RGIzhwcXQGYQ2XXKHyUKAw7syLEIxEb1XpZqjk2u0iez5Hw2IbWYKdaDn5TWxV5h/DFpLJ1KVTdinJeHIWJY3w==
valory-runtime@^4.0.0-v4.7:
version "4.0.0-v4.7"
resolved "https://registry.yarnpkg.com/valory-runtime/-/valory-runtime-4.0.0-v4.7.tgz#7f60734fc38210bff3d659b6320953a77fd44a54"
integrity sha512-dvOp5qGhPAUmb+LSpGWvRXlEdvmfP80jKNVnuQy7LC7jECdwaFJTmltOC2TpXEmDc+43MtXMsVfAF+vyP6Xz+g==
dependencies:
"@types/pino" "^5.20.0"
openapi-types "^1.3.5"
Expand Down

0 comments on commit 1a1743a

Please sign in to comment.