diff --git a/package.json b/package.json index be5de870..8f2b57c0 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@nitric/sdk", "description": "Nitric NodeJS client sdk", - "nitric": "v0.30.0", + "nitric": "v0.32.0", "author": "Nitric ", "repository": "https://github.com/nitrictech/node-sdk", "main": "lib/index.js", diff --git a/src/faas/v0/context.ts b/src/faas/v0/context.ts index 7ef161ff..ab3019a6 100644 --- a/src/faas/v0/context.ts +++ b/src/faas/v0/context.ts @@ -625,12 +625,28 @@ export class WebsocketNotificationContext extends TriggerContext< ): WebsocketNotificationContext { 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 + ); + 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 = { @@ -662,13 +678,15 @@ export class WebsocketNotificationRequest extends AbstractRequest { public readonly socket: string; public readonly notificationType: WebsocketNotificationType; public readonly connectionId: string; + public readonly query: Record; constructor( data: string | Uint8Array, traceContext: api.Context, socket: string, notificationType: WebsocketNotificationType, - connectionId: string + connectionId: string, + query: Record ) { super(data, traceContext); @@ -676,6 +694,7 @@ export class WebsocketNotificationRequest extends AbstractRequest { this.socket = socket; this.notificationType = notificationType; this.connectionId = connectionId; + this.query = query; } } diff --git a/src/gen/proto/faas/v1/faas_pb.d.ts b/src/gen/proto/faas/v1/faas_pb.d.ts index 34f0a246..a49c8f8f 100644 --- a/src/gen/proto/faas/v1/faas_pb.d.ts +++ b/src/gen/proto/faas/v1/faas_pb.d.ts @@ -687,6 +687,8 @@ export class WebsocketTriggerContext extends jspb.Message { getConnectionid(): string; setConnectionid(value: string): void; + getQueryParamsMap(): jspb.Map; + clearQueryParamsMap(): void; serializeBinary(): Uint8Array; toObject(includeInstance?: boolean): WebsocketTriggerContext.AsObject; static toObject(includeInstance: boolean, msg: WebsocketTriggerContext): WebsocketTriggerContext.AsObject; @@ -702,6 +704,7 @@ export namespace WebsocketTriggerContext { socket: string, event: WebsocketEventMap[keyof WebsocketEventMap], connectionid: string, + queryParamsMap: Array<[string, QueryValue.AsObject]>, } } diff --git a/src/gen/proto/faas/v1/faas_pb.js b/src/gen/proto/faas/v1/faas_pb.js index 586137e3..b01e567d 100644 --- a/src/gen/proto/faas/v1/faas_pb.js +++ b/src/gen/proto/faas/v1/faas_pb.js @@ -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) { @@ -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; @@ -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); + } }; @@ -5509,6 +5520,28 @@ proto.nitric.faas.v1.WebsocketTriggerContext.prototype.setConnectionid = functio }; +/** + * map query_params = 6; + * @param {boolean=} opt_noLazyCreate Do not create the map if + * empty, instead returning `undefined` + * @return {!jspb.Map} + */ +proto.nitric.faas.v1.WebsocketTriggerContext.prototype.getQueryParamsMap = function(opt_noLazyCreate) { + return /** @type {!jspb.Map} */ ( + 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