Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add websocket query params #200

Merged
merged 3 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@nitric/sdk",
"description": "Nitric NodeJS client sdk",
"nitric": "v0.30.0",
"nitric": "v0.32.0",
"author": "Nitric <https://github.com/nitrictech>",
"repository": "https://github.com/nitrictech/node-sdk",
"main": "lib/index.js",
Expand Down
23 changes: 21 additions & 2 deletions src/faas/v0/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -625,12 +625,28 @@ export class WebsocketNotificationContext<T> extends TriggerContext<
): WebsocketNotificationContext<any> {
const ctx = new WebsocketNotificationContext();

const query = (
trigger
.getWebsocket()
.getQueryParamsMap()
// 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]: val.map((v) => decodeURIComponent(v)),
}),
{} as Record<string, string[]>
);

ctx.request = new WebsocketNotificationRequest(
trigger.getData_asU8(),
getTraceContext(trigger.getTraceContext()),
trigger.getWebsocket().getSocket(),
trigger.getWebsocket().getEvent(),
trigger.getWebsocket().getConnectionid()
trigger.getWebsocket().getConnectionid(),
query
);

ctx.response = {
Expand Down Expand Up @@ -662,20 +678,23 @@ export class WebsocketNotificationRequest<T> extends AbstractRequest<T> {
public readonly socket: string;
public readonly notificationType: WebsocketNotificationType;
public readonly connectionId: string;
public readonly query: Record<string, string[]>;

constructor(
data: string | Uint8Array,
traceContext: api.Context,
socket: string,
notificationType: WebsocketNotificationType,
connectionId: string
connectionId: string,
query: Record<string, string[]>
) {
super(data, traceContext);

// Get reference to the bucket
this.socket = socket;
this.notificationType = notificationType;
this.connectionId = connectionId;
this.query = query;
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/gen/proto/faas/v1/faas_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,8 @@ export class WebsocketTriggerContext extends jspb.Message {
getConnectionid(): string;
setConnectionid(value: string): void;

getQueryParamsMap(): jspb.Map<string, QueryValue>;
clearQueryParamsMap(): void;
serializeBinary(): Uint8Array;
toObject(includeInstance?: boolean): WebsocketTriggerContext.AsObject;
static toObject(includeInstance: boolean, msg: WebsocketTriggerContext): WebsocketTriggerContext.AsObject;
Expand All @@ -702,6 +704,7 @@ export namespace WebsocketTriggerContext {
socket: string,
event: WebsocketEventMap[keyof WebsocketEventMap],
connectionid: string,
queryParamsMap: Array<[string, QueryValue.AsObject]>,
}
}

Expand Down
35 changes: 34 additions & 1 deletion src/gen/proto/faas/v1/faas_pb.js
Original file line number Diff line number Diff line change
Expand Up @@ -5353,7 +5353,8 @@ proto.nitric.faas.v1.WebsocketTriggerContext.toObject = function(includeInstance
var f, obj = {
socket: jspb.Message.getFieldWithDefault(msg, 1, ""),
event: jspb.Message.getFieldWithDefault(msg, 2, 0),
connectionid: jspb.Message.getFieldWithDefault(msg, 3, "")
connectionid: jspb.Message.getFieldWithDefault(msg, 3, ""),
queryParamsMap: (f = msg.getQueryParamsMap()) ? f.toObject(includeInstance, proto.nitric.faas.v1.QueryValue.toObject) : []
};

if (includeInstance) {
Expand Down Expand Up @@ -5402,6 +5403,12 @@ proto.nitric.faas.v1.WebsocketTriggerContext.deserializeBinaryFromReader = funct
var value = /** @type {string} */ (reader.readString());
msg.setConnectionid(value);
break;
case 6:
var value = msg.getQueryParamsMap();
reader.readMessage(value, function(message, reader) {
jspb.Map.deserializeBinary(message, reader, jspb.BinaryReader.prototype.readString, jspb.BinaryReader.prototype.readMessage, proto.nitric.faas.v1.QueryValue.deserializeBinaryFromReader, "", new proto.nitric.faas.v1.QueryValue());
});
break;
default:
reader.skipField();
break;
Expand Down Expand Up @@ -5452,6 +5459,10 @@ proto.nitric.faas.v1.WebsocketTriggerContext.serializeBinaryToWriter = function(
f
);
}
f = message.getQueryParamsMap(true);
if (f && f.getLength() > 0) {
f.serializeBinary(6, writer, jspb.BinaryWriter.prototype.writeString, jspb.BinaryWriter.prototype.writeMessage, proto.nitric.faas.v1.QueryValue.serializeBinaryToWriter);
}
};


Expand Down Expand Up @@ -5509,6 +5520,28 @@ proto.nitric.faas.v1.WebsocketTriggerContext.prototype.setConnectionid = functio
};


/**
* map<string, QueryValue> query_params = 6;
* @param {boolean=} opt_noLazyCreate Do not create the map if
* empty, instead returning `undefined`
* @return {!jspb.Map<string,!proto.nitric.faas.v1.QueryValue>}
*/
proto.nitric.faas.v1.WebsocketTriggerContext.prototype.getQueryParamsMap = function(opt_noLazyCreate) {
return /** @type {!jspb.Map<string,!proto.nitric.faas.v1.QueryValue>} */ (
jspb.Message.getMapField(this, 6, opt_noLazyCreate,
proto.nitric.faas.v1.QueryValue));
};


/**
* Clears values from the map. The map will be non-null.
* @return {!proto.nitric.faas.v1.WebsocketTriggerContext} returns this
*/
proto.nitric.faas.v1.WebsocketTriggerContext.prototype.clearQueryParamsMap = function() {
this.getQueryParamsMap().clear();
return this;};



/**
* Oneof group definitions for this message. Each group defines the field
Expand Down
Loading