@devvit/protos 0.11.5-next-2024-12-09-f0c92ebca.0 → 0.11.5-next-2024-12-09-b30c26d0a.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  import { TwirpServer, TwirpError, TwirpErrorCode, TwirpContentType, chainInterceptors, } from 'twirp-ts';
2
- import { KeyRequest, SetRequest, KeysRequest, IncrByRequest, HSetRequest, HGetRequest, RedisFieldValues, HDelRequest, HScanRequest, HScanResponse, KeysResponse, HIncrByRequest, TransactionId, TransactionResponses, WatchRequest, KeyRangeRequest, SetRangeRequest, RedisValues, KeyValuesRequest, ExpireRequest, ZAddRequest, ZRangeRequest, ZMembers, ZRemRequest, ZRemRangeByLexRequest, ZRemRangeByRankRequest, ZRemRangeByScoreRequest, ZScoreRequest, ZRankRequest, ZIncrByRequest, ZScanRequest, ZScanResponse, } from './redisapi.js';
2
+ import { KeyRequest, SetRequest, KeysRequest, IncrByRequest, HSetRequest, HGetRequest, HMGetRequest, RedisValues, RedisFieldValues, HDelRequest, HScanRequest, HScanResponse, KeysResponse, HIncrByRequest, TransactionId, TransactionResponses, WatchRequest, KeyRangeRequest, SetRangeRequest, KeyValuesRequest, ExpireRequest, ZAddRequest, ZRangeRequest, ZMembers, ZRemRequest, ZRemRangeByLexRequest, ZRemRangeByRankRequest, ZRemRangeByScoreRequest, ZScoreRequest, ZRankRequest, ZIncrByRequest, ZScanRequest, ZScanResponse, } from './redisapi.js';
3
3
  import { StringValue, Int64Value, DoubleValue, } from '../../../google/protobuf/wrappers.js';
4
4
  import { Empty } from '../../../google/protobuf/empty.js';
5
5
  export var RedisAPIMethod;
@@ -11,6 +11,7 @@ export var RedisAPIMethod;
11
11
  RedisAPIMethod["IncrBy"] = "IncrBy";
12
12
  RedisAPIMethod["HSet"] = "HSet";
13
13
  RedisAPIMethod["HGet"] = "HGet";
14
+ RedisAPIMethod["HMGet"] = "HMGet";
14
15
  RedisAPIMethod["HGetAll"] = "HGetAll";
15
16
  RedisAPIMethod["HDel"] = "HDel";
16
17
  RedisAPIMethod["HScan"] = "HScan";
@@ -49,6 +50,7 @@ export const RedisAPIMethodList = [
49
50
  RedisAPIMethod.IncrBy,
50
51
  RedisAPIMethod.HSet,
51
52
  RedisAPIMethod.HGet,
53
+ RedisAPIMethod.HMGet,
52
54
  RedisAPIMethod.HGetAll,
53
55
  RedisAPIMethod.HDel,
54
56
  RedisAPIMethod.HScan,
@@ -132,6 +134,12 @@ function matchRedisAPIRoute(method, events) {
132
134
  await events.onMatch(ctx);
133
135
  return handleRedisAPIHGetRequest(ctx, service, data, interceptors);
134
136
  };
137
+ case 'HMGet':
138
+ return async (ctx, service, data, interceptors) => {
139
+ ctx = { ...ctx, methodName: 'HMGet' };
140
+ await events.onMatch(ctx);
141
+ return handleRedisAPIHMGetRequest(ctx, service, data, interceptors);
142
+ };
135
143
  case 'HGetAll':
136
144
  return async (ctx, service, data, interceptors) => {
137
145
  ctx = { ...ctx, methodName: 'HGetAll' };
@@ -389,6 +397,17 @@ function handleRedisAPIHGetRequest(ctx, service, data, interceptors) {
389
397
  throw new TwirpError(TwirpErrorCode.BadRoute, msg);
390
398
  }
391
399
  }
400
+ function handleRedisAPIHMGetRequest(ctx, service, data, interceptors) {
401
+ switch (ctx.contentType) {
402
+ case TwirpContentType.JSON:
403
+ return handleRedisAPIHMGetJSON(ctx, service, data, interceptors);
404
+ case TwirpContentType.Protobuf:
405
+ return handleRedisAPIHMGetProtobuf(ctx, service, data, interceptors);
406
+ default:
407
+ const msg = 'unexpected Content-Type';
408
+ throw new TwirpError(TwirpErrorCode.BadRoute, msg);
409
+ }
410
+ }
392
411
  function handleRedisAPIHGetAllRequest(ctx, service, data, interceptors) {
393
412
  switch (ctx.contentType) {
394
413
  case TwirpContentType.JSON:
@@ -876,6 +895,30 @@ async function handleRedisAPIHGetJSON(ctx, service, data, interceptors) {
876
895
  }
877
896
  return JSON.stringify(StringValue.toJSON(response));
878
897
  }
898
+ async function handleRedisAPIHMGetJSON(ctx, service, data, interceptors) {
899
+ let request;
900
+ let response;
901
+ try {
902
+ const body = JSON.parse(data.toString() || '{}');
903
+ request = HMGetRequest.fromJSON(body);
904
+ }
905
+ catch (e) {
906
+ if (e instanceof Error) {
907
+ const msg = 'the json request could not be decoded';
908
+ throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
909
+ }
910
+ }
911
+ if (interceptors && interceptors.length > 0) {
912
+ const interceptor = chainInterceptors(...interceptors);
913
+ response = await interceptor(ctx, request, (ctx, inputReq) => {
914
+ return service.HMGet(ctx, inputReq);
915
+ });
916
+ }
917
+ else {
918
+ response = await service.HMGet(ctx, request);
919
+ }
920
+ return JSON.stringify(RedisValues.toJSON(response));
921
+ }
879
922
  async function handleRedisAPIHGetAllJSON(ctx, service, data, interceptors) {
880
923
  let request;
881
924
  let response;
@@ -1733,6 +1776,29 @@ async function handleRedisAPIHGetProtobuf(ctx, service, data, interceptors) {
1733
1776
  }
1734
1777
  return Buffer.from(StringValue.encode(response).finish());
1735
1778
  }
1779
+ async function handleRedisAPIHMGetProtobuf(ctx, service, data, interceptors) {
1780
+ let request;
1781
+ let response;
1782
+ try {
1783
+ request = HMGetRequest.decode(data);
1784
+ }
1785
+ catch (e) {
1786
+ if (e instanceof Error) {
1787
+ const msg = 'the protobuf request could not be decoded';
1788
+ throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
1789
+ }
1790
+ }
1791
+ if (interceptors && interceptors.length > 0) {
1792
+ const interceptor = chainInterceptors(...interceptors);
1793
+ response = await interceptor(ctx, request, (ctx, inputReq) => {
1794
+ return service.HMGet(ctx, inputReq);
1795
+ });
1796
+ }
1797
+ else {
1798
+ response = await service.HMGet(ctx, request);
1799
+ }
1800
+ return Buffer.from(RedisValues.encode(response).finish());
1801
+ }
1736
1802
  async function handleRedisAPIHGetAllProtobuf(ctx, service, data, interceptors) {
1737
1803
  let request;
1738
1804
  let response;