Skip to content

Commit

Permalink
Merge pull request #75 from nitrictech/feature/update-base-api
Browse files Browse the repository at this point in the history
Update base API to latest prod release.
  • Loading branch information
tjholm committed Oct 28, 2021
2 parents 4692097 + ad1ce65 commit 3285d9b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
],
"dependencies": {
"@grpc/grpc-js": "^1.1.7",
"@nitric/api": "^0.12.0-rc.15",
"@nitric/api": "^0.12.0",
"common-tags": "^1.8.0",
"google-protobuf": "3.14.0",
"path-parser": "^6.1.0",
Expand Down
5 changes: 4 additions & 1 deletion src/faas/v0/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
TopicTriggerContext as GrpcTopicTriggerContext,
TriggerRequest,
HeaderValue,
QueryValue,
} from '@nitric/api/proto/faas/v1/faas_pb';
import { TriggerContext, HttpContext, EventContext } from './context';

Expand All @@ -34,7 +35,9 @@ describe('NitricTrigger.fromGrpcTriggerRequest', () => {
testHeader2.addValue('test2.2');
ctx.getHeadersMap().set('test', testHeader);
ctx.getHeadersMap().set('test2', testHeader2);
ctx.getQueryParamsMap().set('test', 'test');
const testQuery = new QueryValue();
testQuery.addValue("test");
ctx.getQueryParamsMap().set('test', testQuery);
const request = new TriggerRequest();
request.setData('Hello World');
request.setHttp(ctx);
Expand Down
34 changes: 28 additions & 6 deletions src/faas/v0/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ interface HttpRequestArgs {
data: string | Uint8Array;
method: Method | string;
path: string;
query: Record<string, string>;
query: Record<string, string[]>;
headers: Record<string, string[]>;
}

export class HttpRequest extends AbstractRequest {
public readonly method: Method | string;
public readonly path: string;
public readonly query: Record<string, string>;
public readonly query: Record<string, string[]>;
public readonly headers: Record<string, string[] | string>;

constructor({ data, method, path, query, headers }: HttpRequestArgs) {
Expand Down Expand Up @@ -179,6 +179,29 @@ export class HttpContext extends TriggerContext<HttpRequest, HttpResponse> {
{}
);

const query = ((http
.getQueryParamsMap()
// XXX: getEntryList claims to return [string, faas.HeaderValue][], but really returns [string, string[][]][]
// we force the type to match the real return type.
.getEntryList() as unknown) as [string, string[][]][]).reduce(
(acc, [key, [val]]) => ({
...acc,
[key.toLowerCase()]: val.length === 1 ? val[0] : val,
}),
{}
);

const oldQuery = http
.getQueryParamsOldMap()
.toArray()
.reduce(
(acc, [key, val]) => ({
...acc,
[key.toLowerCase()]: val,
}),
{}
);

const oldHeaders = http
.getHeadersOldMap()
.toArray()
Expand All @@ -193,10 +216,9 @@ export class HttpContext extends TriggerContext<HttpRequest, HttpResponse> {
ctx.request = new HttpRequest({
data: trigger.getData(),
path: http.getPath(),
query: http
.getQueryParamsMap()
.toArray()
.reduce((acc, [key, val]) => ({ ...acc, [key]: val }), {}),
// TODO: remove after 1.0
// check for old query if new query is unpopulated. This is for backwards compatibility.
query: Object.keys(query).length ? query : oldQuery,
// TODO: remove after 1.0
// check for old headers if new headers is unpopulated. This is for backwards compatibility.
headers: Object.keys(headers).length ? headers : oldHeaders,
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -521,10 +521,10 @@
"@types/yargs" "^15.0.0"
chalk "^4.0.0"

"@nitric/api@^0.12.0-rc.15":
version "0.12.0-rc.15"
resolved "https://registry.yarnpkg.com/@nitric/api/-/api-0.12.0-rc.15.tgz#f1aac4c1059d6b7325e66b6f86b0ddc43e20b27c"
integrity sha512-uGyn+6/poBgF6L1nzKVyWNTmjRh9cvpdcFdmc1MyjpLJGm7N5d0/Dq2BaApBz+SfzCvWzmtUX0a6ed24+swGtA==
"@nitric/api@^0.12.0":
version "0.12.0"
resolved "https://registry.yarnpkg.com/@nitric/api/-/api-0.12.0.tgz#99f49d072f5f1168ec75278713d6e7dc1ffdb849"
integrity sha512-6pChD2xpFKEzXP/Zr3WGT4tPa0d2zcxz0mTQf0k/joe44Rg7/2h4cvfKP86DL+Fi8yWaAZY0HHasBcOZ9SW55w==
dependencies:
"@grpc/grpc-js" "^1.1.7"
google-protobuf "3.14.0"
Expand Down

0 comments on commit 3285d9b

Please sign in to comment.