@upstash/redis 0.0.0-ci.608697de-20221215 → 0.0.0-ci.66958ac1-20230501

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/README.md +8 -1
  2. package/esm/pkg/commands/command.js +12 -3
  3. package/esm/pkg/commands/json_arrappend.js +9 -0
  4. package/esm/pkg/commands/json_arrindex.js +9 -0
  5. package/esm/pkg/commands/json_arrinsert.js +9 -0
  6. package/esm/pkg/commands/json_arrlen.js +9 -0
  7. package/esm/pkg/commands/json_arrpop.js +9 -0
  8. package/esm/pkg/commands/json_arrtrim.js +12 -0
  9. package/esm/pkg/commands/json_clear.js +9 -0
  10. package/esm/pkg/commands/json_del.js +9 -0
  11. package/esm/pkg/commands/json_forget.js +9 -0
  12. package/esm/pkg/commands/json_get.js +30 -0
  13. package/esm/pkg/commands/json_mget.js +9 -0
  14. package/esm/pkg/commands/json_numincrby.js +9 -0
  15. package/esm/pkg/commands/json_nummultby.js +9 -0
  16. package/esm/pkg/commands/json_objkeys.js +9 -0
  17. package/esm/pkg/commands/json_objlen.js +9 -0
  18. package/esm/pkg/commands/json_resp.js +9 -0
  19. package/esm/pkg/commands/json_set.js +18 -0
  20. package/esm/pkg/commands/json_strappend.js +9 -0
  21. package/esm/pkg/commands/json_strlen.js +9 -0
  22. package/esm/pkg/commands/json_toggle.js +9 -0
  23. package/esm/pkg/commands/json_type.js +9 -0
  24. package/esm/pkg/commands/lmove.js +9 -0
  25. package/esm/pkg/commands/mod.js +23 -0
  26. package/esm/pkg/commands/smismember.js +9 -0
  27. package/esm/pkg/commands/zdiffstore.js +9 -0
  28. package/esm/pkg/http.js +26 -16
  29. package/esm/pkg/pipeline.js +121 -1
  30. package/esm/pkg/redis.js +145 -1
  31. package/esm/platforms/cloudflare.js +6 -6
  32. package/esm/platforms/fastly.js +5 -0
  33. package/esm/platforms/node_with_fetch.js +23 -11
  34. package/esm/platforms/nodejs.js +19 -11
  35. package/esm/version.js +1 -1
  36. package/package.json +41 -16
  37. package/script/pkg/commands/command.js +12 -3
  38. package/script/pkg/commands/json_arrappend.js +13 -0
  39. package/script/pkg/commands/json_arrindex.js +13 -0
  40. package/script/pkg/commands/json_arrinsert.js +13 -0
  41. package/script/pkg/commands/json_arrlen.js +13 -0
  42. package/script/pkg/commands/json_arrpop.js +13 -0
  43. package/script/pkg/commands/json_arrtrim.js +16 -0
  44. package/script/pkg/commands/json_clear.js +13 -0
  45. package/script/pkg/commands/json_del.js +13 -0
  46. package/script/pkg/commands/json_forget.js +13 -0
  47. package/script/pkg/commands/json_get.js +34 -0
  48. package/script/pkg/commands/json_mget.js +13 -0
  49. package/script/pkg/commands/json_numincrby.js +13 -0
  50. package/script/pkg/commands/json_nummultby.js +13 -0
  51. package/script/pkg/commands/json_objkeys.js +13 -0
  52. package/script/pkg/commands/json_objlen.js +13 -0
  53. package/script/pkg/commands/json_resp.js +13 -0
  54. package/script/pkg/commands/json_set.js +22 -0
  55. package/script/pkg/commands/json_strappend.js +13 -0
  56. package/script/pkg/commands/json_strlen.js +13 -0
  57. package/script/pkg/commands/json_toggle.js +13 -0
  58. package/script/pkg/commands/json_type.js +13 -0
  59. package/script/pkg/commands/lmove.js +13 -0
  60. package/script/pkg/commands/mod.js +23 -0
  61. package/script/pkg/commands/smismember.js +13 -0
  62. package/script/pkg/commands/zdiffstore.js +13 -0
  63. package/script/pkg/http.js +26 -16
  64. package/script/pkg/pipeline.js +120 -0
  65. package/script/pkg/redis.js +144 -0
  66. package/script/platforms/cloudflare.js +6 -6
  67. package/script/platforms/fastly.js +5 -0
  68. package/script/platforms/node_with_fetch.js +23 -11
  69. package/script/platforms/nodejs.js +19 -11
  70. package/script/version.js +1 -1
  71. package/types/pkg/commands/command.d.ts +5 -5
  72. package/types/pkg/commands/json_arrappend.d.ts +7 -0
  73. package/types/pkg/commands/json_arrindex.d.ts +13 -0
  74. package/types/pkg/commands/json_arrinsert.d.ts +7 -0
  75. package/types/pkg/commands/json_arrlen.d.ts +7 -0
  76. package/types/pkg/commands/json_arrpop.d.ts +7 -0
  77. package/types/pkg/commands/json_arrtrim.d.ts +7 -0
  78. package/types/pkg/commands/json_clear.d.ts +7 -0
  79. package/types/pkg/commands/json_del.d.ts +7 -0
  80. package/types/pkg/commands/json_forget.d.ts +7 -0
  81. package/types/pkg/commands/json_get.d.ts +15 -0
  82. package/types/pkg/commands/json_mget.d.ts +7 -0
  83. package/types/pkg/commands/json_numincrby.d.ts +7 -0
  84. package/types/pkg/commands/json_nummultby.d.ts +7 -0
  85. package/types/pkg/commands/json_objkeys.d.ts +7 -0
  86. package/types/pkg/commands/json_objlen.d.ts +7 -0
  87. package/types/pkg/commands/json_resp.d.ts +7 -0
  88. package/types/pkg/commands/json_set.d.ts +18 -0
  89. package/types/pkg/commands/json_strappend.d.ts +7 -0
  90. package/types/pkg/commands/json_strlen.d.ts +7 -0
  91. package/types/pkg/commands/json_toggle.d.ts +7 -0
  92. package/types/pkg/commands/json_type.d.ts +7 -0
  93. package/types/pkg/commands/lmove.d.ts +12 -0
  94. package/types/pkg/commands/mod.d.ts +23 -0
  95. package/types/pkg/commands/scan.d.ts +1 -1
  96. package/types/pkg/commands/script_flush.d.ts +1 -1
  97. package/types/pkg/commands/set.d.ts +1 -1
  98. package/types/pkg/commands/smembers.d.ts +2 -2
  99. package/types/pkg/commands/smismember.d.ts +7 -0
  100. package/types/pkg/commands/type.d.ts +1 -1
  101. package/types/pkg/commands/zadd.d.ts +3 -3
  102. package/types/pkg/commands/zdiffstore.d.ts +7 -0
  103. package/types/pkg/commands/zinterstore.d.ts +1 -1
  104. package/types/pkg/commands/zrange.d.ts +1 -1
  105. package/types/pkg/commands/zunionstore.d.ts +1 -1
  106. package/types/pkg/http.d.ts +12 -23
  107. package/types/pkg/pipeline.d.ts +40 -2
  108. package/types/pkg/redis.d.ts +113 -10
  109. package/types/pkg/types.d.ts +27 -1
  110. package/types/platforms/cloudflare.d.ts +2 -2
  111. package/types/platforms/fastly.d.ts +1 -1
  112. package/types/platforms/node_with_fetch.d.ts +1 -1
  113. package/types/platforms/nodejs.d.ts +1 -1
  114. package/types/version.d.ts +1 -1
package/esm/pkg/redis.js CHANGED
@@ -1,7 +1,8 @@
1
- import { AppendCommand, BitCountCommand, BitOpCommand, BitPosCommand, DBSizeCommand, DecrByCommand, DecrCommand, DelCommand, EchoCommand, EvalCommand, EvalshaCommand, ExistsCommand, ExpireAtCommand, ExpireCommand, FlushAllCommand, FlushDBCommand, GetBitCommand, GetCommand, GetDelCommand, GetRangeCommand, GetSetCommand, HDelCommand, HExistsCommand, HGetAllCommand, HGetCommand, HIncrByCommand, HIncrByFloatCommand, HKeysCommand, HLenCommand, HMGetCommand, HMSetCommand, HRandFieldCommand, HScanCommand, HSetCommand, HSetNXCommand, HStrLenCommand, HValsCommand, IncrByCommand, IncrByFloatCommand, IncrCommand, KeysCommand, LIndexCommand, LInsertCommand, LLenCommand, LPopCommand, LPosCommand, LPushCommand, LPushXCommand, LRangeCommand, LRemCommand, LSetCommand, LTrimCommand, MGetCommand, MSetCommand, MSetNXCommand, PersistCommand, PExpireAtCommand, PExpireCommand, PingCommand, PSetEXCommand, PTtlCommand, PublishCommand, RandomKeyCommand, RenameCommand, RenameNXCommand, RPopCommand, RPushCommand, RPushXCommand, SAddCommand, ScanCommand, SCardCommand, ScriptExistsCommand, ScriptFlushCommand, ScriptLoadCommand, SDiffCommand, SDiffStoreCommand, SetBitCommand, SetCommand, SetExCommand, SetNxCommand, SetRangeCommand, SInterCommand, SInterStoreCommand, SIsMemberCommand, SMembersCommand, SMoveCommand, SPopCommand, SRandMemberCommand, SRemCommand, SScanCommand, StrLenCommand, SUnionCommand, SUnionStoreCommand, TimeCommand, TouchCommand, TtlCommand, TypeCommand, UnlinkCommand, ZAddCommand, ZCardCommand, ZCountCommand, ZIncrByCommand, ZInterStoreCommand, ZLexCountCommand, ZPopMaxCommand, ZPopMinCommand, ZRangeCommand, ZRankCommand, ZRemCommand, ZRemRangeByLexCommand, ZRemRangeByRankCommand, ZRemRangeByScoreCommand, ZRevRankCommand, ZScanCommand, ZScoreCommand, ZUnionStoreCommand, } from "./commands/mod.js";
1
+ import { AppendCommand, BitCountCommand, BitOpCommand, BitPosCommand, DBSizeCommand, DecrByCommand, DecrCommand, DelCommand, EchoCommand, EvalCommand, EvalshaCommand, ExistsCommand, ExpireAtCommand, ExpireCommand, FlushAllCommand, FlushDBCommand, GetBitCommand, GetCommand, GetDelCommand, GetRangeCommand, GetSetCommand, HDelCommand, HExistsCommand, HGetAllCommand, HGetCommand, HIncrByCommand, HIncrByFloatCommand, HKeysCommand, HLenCommand, HMGetCommand, HMSetCommand, HRandFieldCommand, HScanCommand, HSetCommand, HSetNXCommand, HStrLenCommand, HValsCommand, IncrByCommand, IncrByFloatCommand, IncrCommand, JsonArrAppendCommand, JsonArrIndexCommand, JsonArrInsertCommand, JsonArrLenCommand, JsonArrPopCommand, JsonArrTrimCommand, JsonClearCommand, JsonDelCommand, JsonForgetCommand, JsonGetCommand, JsonMGetCommand, JsonNumIncrByCommand, JsonNumMultByCommand, JsonObjKeysCommand, JsonObjLenCommand, JsonRespCommand, JsonSetCommand, JsonStrAppendCommand, JsonStrLenCommand, JsonToggleCommand, JsonTypeCommand, KeysCommand, LIndexCommand, LInsertCommand, LLenCommand, LMoveCommand, LPopCommand, LPosCommand, LPushCommand, LPushXCommand, LRangeCommand, LRemCommand, LSetCommand, LTrimCommand, MGetCommand, MSetCommand, MSetNXCommand, PersistCommand, PExpireAtCommand, PExpireCommand, PingCommand, PSetEXCommand, PTtlCommand, PublishCommand, RandomKeyCommand, RenameCommand, RenameNXCommand, RPopCommand, RPushCommand, RPushXCommand, SAddCommand, ScanCommand, SCardCommand, ScriptExistsCommand, ScriptFlushCommand, ScriptLoadCommand, SDiffCommand, SDiffStoreCommand, SetBitCommand, SetCommand, SetExCommand, SetNxCommand, SetRangeCommand, SInterCommand, SInterStoreCommand, SIsMemberCommand, SMembersCommand, SMIsMemberCommand, SMoveCommand, SPopCommand, SRandMemberCommand, SRemCommand, SScanCommand, StrLenCommand, SUnionCommand, SUnionStoreCommand, TimeCommand, TouchCommand, TtlCommand, TypeCommand, UnlinkCommand, ZAddCommand, ZCardCommand, ZCountCommand, ZIncrByCommand, ZInterStoreCommand, ZLexCountCommand, ZPopMaxCommand, ZPopMinCommand, ZRangeCommand, ZRankCommand, ZRemCommand, ZRemRangeByLexCommand, ZRemRangeByRankCommand, ZRemRangeByScoreCommand, ZRevRankCommand, ZScanCommand, ZScoreCommand, ZUnionStoreCommand, } from "./commands/mod.js";
2
2
  import { Pipeline } from "./pipeline.js";
3
3
  import { Script } from "./script.js";
4
4
  import { ZMScoreCommand } from "./commands/zmscore.js";
5
+ import { ZDiffStoreCommand } from "./commands/zdiffstore.js";
5
6
  /**
6
7
  * Serverless redis client for upstash.
7
8
  */
@@ -30,6 +31,12 @@ export class Redis {
30
31
  writable: true,
31
32
  value: void 0
32
33
  });
34
+ Object.defineProperty(this, "enableTelemetry", {
35
+ enumerable: true,
36
+ configurable: true,
37
+ writable: true,
38
+ value: void 0
39
+ });
33
40
  /**
34
41
  * Wrap a new middleware around the HTTP client.
35
42
  */
@@ -42,6 +49,27 @@ export class Redis {
42
49
  this.client.request = (req) => middleware(req, makeRequest);
43
50
  }
44
51
  });
52
+ /**
53
+ * Technically this is not private, we can hide it from intellisense by doing this
54
+ */
55
+ Object.defineProperty(this, "addTelemetry", {
56
+ enumerable: true,
57
+ configurable: true,
58
+ writable: true,
59
+ value: (telemetry) => {
60
+ if (!this.enableTelemetry) {
61
+ return;
62
+ }
63
+ try {
64
+ // @ts-ignore - The `Requester` interface does not know about this method but it will be there
65
+ // as long as the user uses the standard HttpClient
66
+ this.client.mergeTelemetry(telemetry);
67
+ }
68
+ catch {
69
+ // ignore
70
+ }
71
+ }
72
+ });
45
73
  /**
46
74
  * Create a new pipeline that allows you to send requests in bulk.
47
75
  *
@@ -473,6 +501,15 @@ export class Redis {
473
501
  writable: true,
474
502
  value: (...args) => new LLenCommand(args, this.opts).exec(this.client)
475
503
  });
504
+ /**
505
+ * @see https://redis.io/commands/lmove
506
+ */
507
+ Object.defineProperty(this, "lmove", {
508
+ enumerable: true,
509
+ configurable: true,
510
+ writable: true,
511
+ value: (...args) => new LMoveCommand(args, this.opts).exec(this.client)
512
+ });
476
513
  /**
477
514
  * @see https://redis.io/commands/lpop
478
515
  */
@@ -833,6 +870,15 @@ export class Redis {
833
870
  writable: true,
834
871
  value: (key, member) => new SIsMemberCommand([key, member], this.opts).exec(this.client)
835
872
  });
873
+ /**
874
+ * @see https://redis.io/commands/smismember
875
+ */
876
+ Object.defineProperty(this, "smismember", {
877
+ enumerable: true,
878
+ configurable: true,
879
+ writable: true,
880
+ value: (key, members) => new SMIsMemberCommand([key, members], this.opts).exec(this.client)
881
+ });
836
882
  /**
837
883
  * @see https://redis.io/commands/smembers
838
884
  */
@@ -991,6 +1037,15 @@ export class Redis {
991
1037
  writable: true,
992
1038
  value: (...args) => new ZCountCommand(args, this.opts).exec(this.client)
993
1039
  });
1040
+ /**
1041
+ * @see https://redis.io/commands/zdiffstore
1042
+ */
1043
+ Object.defineProperty(this, "zdiffstore", {
1044
+ enumerable: true,
1045
+ configurable: true,
1046
+ writable: true,
1047
+ value: (...args) => new ZDiffStoreCommand(args, this.opts).exec(this.client)
1048
+ });
994
1049
  /**
995
1050
  * @see https://redis.io/commands/zincrby
996
1051
  */
@@ -1137,6 +1192,95 @@ export class Redis {
1137
1192
  });
1138
1193
  this.client = client;
1139
1194
  this.opts = opts;
1195
+ this.enableTelemetry = opts?.enableTelemetry ?? true;
1196
+ }
1197
+ get json() {
1198
+ return {
1199
+ /**
1200
+ * @see https://redis.io/commands/json.arrappend
1201
+ */
1202
+ arrappend: (...args) => new JsonArrAppendCommand(args, this.opts).exec(this.client),
1203
+ /**
1204
+ * @see https://redis.io/commands/json.arrindex
1205
+ */
1206
+ arrindex: (...args) => new JsonArrIndexCommand(args, this.opts).exec(this.client),
1207
+ /**
1208
+ * @see https://redis.io/commands/json.arrinsert
1209
+ */
1210
+ arrinsert: (...args) => new JsonArrInsertCommand(args, this.opts).exec(this.client),
1211
+ /**
1212
+ * @see https://redis.io/commands/json.arrlen
1213
+ */
1214
+ arrlen: (...args) => new JsonArrLenCommand(args, this.opts).exec(this.client),
1215
+ /**
1216
+ * @see https://redis.io/commands/json.arrpop
1217
+ */
1218
+ arrpop: (...args) => new JsonArrPopCommand(args, this.opts).exec(this.client),
1219
+ /**
1220
+ * @see https://redis.io/commands/json.arrtrim
1221
+ */
1222
+ arrtrim: (...args) => new JsonArrTrimCommand(args, this.opts).exec(this.client),
1223
+ /**
1224
+ * @see https://redis.io/commands/json.clear
1225
+ */
1226
+ clear: (...args) => new JsonClearCommand(args, this.opts).exec(this.client),
1227
+ /**
1228
+ * @see https://redis.io/commands/json.del
1229
+ */
1230
+ del: (...args) => new JsonDelCommand(args, this.opts).exec(this.client),
1231
+ /**
1232
+ * @see https://redis.io/commands/json.forget
1233
+ */
1234
+ forget: (...args) => new JsonForgetCommand(args, this.opts).exec(this.client),
1235
+ /**
1236
+ * @see https://redis.io/commands/json.get
1237
+ */
1238
+ get: (...args) => new JsonGetCommand(args, this.opts).exec(this.client),
1239
+ /**
1240
+ * @see https://redis.io/commands/json.mget
1241
+ */
1242
+ mget: (...args) => new JsonMGetCommand(args, this.opts).exec(this.client),
1243
+ /**
1244
+ * @see https://redis.io/commands/json.numincrby
1245
+ */
1246
+ numincrby: (...args) => new JsonNumIncrByCommand(args, this.opts).exec(this.client),
1247
+ /**
1248
+ * @see https://redis.io/commands/json.nummultby
1249
+ */
1250
+ nummultby: (...args) => new JsonNumMultByCommand(args, this.opts).exec(this.client),
1251
+ /**
1252
+ * @see https://redis.io/commands/json.objkeys
1253
+ */
1254
+ objkeys: (...args) => new JsonObjKeysCommand(args, this.opts).exec(this.client),
1255
+ /**
1256
+ * @see https://redis.io/commands/json.objlen
1257
+ */
1258
+ objlen: (...args) => new JsonObjLenCommand(args, this.opts).exec(this.client),
1259
+ /**
1260
+ * @see https://redis.io/commands/json.resp
1261
+ */
1262
+ resp: (...args) => new JsonRespCommand(args, this.opts).exec(this.client),
1263
+ /**
1264
+ * @see https://redis.io/commands/json.set
1265
+ */
1266
+ set: (...args) => new JsonSetCommand(args, this.opts).exec(this.client),
1267
+ /**
1268
+ * @see https://redis.io/commands/json.strappend
1269
+ */
1270
+ strappend: (...args) => new JsonStrAppendCommand(args, this.opts).exec(this.client),
1271
+ /**
1272
+ * @see https://redis.io/commands/json.strlen
1273
+ */
1274
+ strlen: (...args) => new JsonStrLenCommand(args, this.opts).exec(this.client),
1275
+ /**
1276
+ * @see https://redis.io/commands/json.toggle
1277
+ */
1278
+ toggle: (...args) => new JsonToggleCommand(args, this.opts).exec(this.client),
1279
+ /**
1280
+ * @see https://redis.io/commands/json.type
1281
+ */
1282
+ type: (...args) => new JsonTypeCommand(args, this.opts).exec(this.client),
1283
+ };
1140
1284
  }
1141
1285
  createScript(script) {
1142
1286
  return new Script(this, script);
@@ -27,21 +27,21 @@ export class Redis extends core.Redis {
27
27
  /\r|\n/.test(config.token)) {
28
28
  console.warn("The redis token contains whitespace or newline, which can cause errors!");
29
29
  }
30
- const telemetry = {};
31
- if (!env?.UPSTASH_DISABLE_TELEMETRY) {
32
- telemetry.platform = "cloudflare";
33
- telemetry.sdk = `@upstash/redis@${VERSION}`;
34
- }
35
30
  const client = new HttpClient({
36
31
  retry: config.retry,
37
32
  baseUrl: config.url,
38
33
  headers: { authorization: `Bearer ${config.token}` },
39
34
  responseEncoding: config.responseEncoding,
40
- telemetry,
41
35
  });
42
36
  super(client, {
37
+ enableTelemetry: !env?.UPSTASH_DISABLE_TELEMETRY,
43
38
  automaticDeserialization: config.automaticDeserialization,
44
39
  });
40
+ // This is only added of the user has not disabled telemetry
41
+ this.addTelemetry({
42
+ platform: "cloudflare",
43
+ sdk: `@upstash/redis@${VERSION}`,
44
+ });
45
45
  }
46
46
  /*
47
47
  * Create a new Upstash Redis instance from environment variables on cloudflare.
@@ -1,5 +1,6 @@
1
1
  import * as core from "../pkg/redis.js";
2
2
  import { HttpClient } from "../pkg/http.js";
3
+ import { VERSION } from "../version.js";
3
4
  /**
4
5
  * Serverless redis client for upstash.
5
6
  */
@@ -37,5 +38,9 @@ export class Redis extends core.Redis {
37
38
  super(client, {
38
39
  automaticDeserialization: config.automaticDeserialization,
39
40
  });
41
+ this.addTelemetry({
42
+ sdk: `@upstash/redis@${VERSION}`,
43
+ platform: "fastly",
44
+ });
40
45
  }
41
46
  }
@@ -3,6 +3,19 @@ import * as core from "../pkg/redis.js";
3
3
  import { HttpClient, } from "../pkg/http.js";
4
4
  import { VERSION } from "../version.js";
5
5
  import "isomorphic-fetch";
6
+ // @ts-ignore Deno can't compile
7
+ // import https from "https";
8
+ // @ts-ignore Deno can't compile
9
+ // import http from "http";
10
+ // import "isomorphic-fetch";
11
+ /**
12
+ * Workaround for nodejs 14, where atob is not included in the standardlib
13
+ */
14
+ if (typeof atob === "undefined") {
15
+ global.atob = function (b64) {
16
+ return Buffer.from(b64, "base64").toString("utf-8");
17
+ };
18
+ }
6
19
  /**
7
20
  * Serverless redis client for upstash.
8
21
  */
@@ -22,26 +35,25 @@ export class Redis extends core.Redis {
22
35
  /\r|\n/.test(configOrRequester.token)) {
23
36
  console.warn("The redis token contains whitespace or newline, which can cause errors!");
24
37
  }
25
- const telemetry = {};
26
- if (!process.env.UPSTASH_DISABLE_TELEMETRY) {
27
- telemetry.runtime = `node@${process.version}`;
28
- telemetry.platform = process.env.VERCEL
29
- ? "vercel"
30
- : process.env.AWS_REGION
31
- ? "aws"
32
- : "unknown";
33
- telemetry.sdk = `@upstash/redis@${VERSION}`;
34
- }
35
38
  const client = new HttpClient({
36
39
  baseUrl: configOrRequester.url,
37
40
  retry: configOrRequester.retry,
38
41
  headers: { authorization: `Bearer ${configOrRequester.token}` },
39
42
  // agent: configOrRequester.agent,
40
43
  responseEncoding: configOrRequester.responseEncoding,
41
- telemetry,
42
44
  });
43
45
  super(client, {
44
46
  automaticDeserialization: configOrRequester.automaticDeserialization,
47
+ enableTelemetry: !process.env.UPSTASH_DISABLE_TELEMETRY,
48
+ });
49
+ this.addTelemetry({
50
+ runtime: `node@${process.version}`,
51
+ platform: process.env.VERCEL
52
+ ? "vercel"
53
+ : process.env.AWS_REGION
54
+ ? "aws"
55
+ : "unknown",
56
+ sdk: `@upstash/redis@${VERSION}`,
45
57
  });
46
58
  }
47
59
  /**
@@ -2,6 +2,14 @@
2
2
  import * as core from "../pkg/redis.js";
3
3
  import { HttpClient, } from "../pkg/http.js";
4
4
  import { VERSION } from "../version.js";
5
+ /**
6
+ * Workaround for nodejs 14, where atob is not included in the standardlib
7
+ */
8
+ if (typeof atob === "undefined") {
9
+ global.atob = function (b64) {
10
+ return Buffer.from(b64, "base64").toString("utf-8");
11
+ };
12
+ }
5
13
  /**
6
14
  * Serverless redis client for upstash.
7
15
  */
@@ -21,26 +29,26 @@ export class Redis extends core.Redis {
21
29
  /\r|\n/.test(configOrRequester.token)) {
22
30
  console.warn("The redis token contains whitespace or newline, which can cause errors!");
23
31
  }
24
- const telemetry = {};
25
- if (!process.env.UPSTASH_DISABLE_TELEMETRY) {
26
- telemetry.runtime = `node@${process.version}`;
27
- telemetry.platform = process.env.VERCEL
28
- ? "vercel"
29
- : process.env.AWS_REGION
30
- ? "aws"
31
- : "unknown";
32
- telemetry.sdk = `@upstash/redis@${VERSION}`;
33
- }
34
32
  const client = new HttpClient({
35
33
  baseUrl: configOrRequester.url,
36
34
  retry: configOrRequester.retry,
37
35
  headers: { authorization: `Bearer ${configOrRequester.token}` },
38
36
  agent: configOrRequester.agent,
39
37
  responseEncoding: configOrRequester.responseEncoding,
40
- telemetry,
38
+ cache: "no-store",
41
39
  });
42
40
  super(client, {
43
41
  automaticDeserialization: configOrRequester.automaticDeserialization,
42
+ enableTelemetry: !process.env.UPSTASH_DISABLE_TELEMETRY,
43
+ });
44
+ this.addTelemetry({
45
+ runtime: `node@${process.version}`,
46
+ platform: process.env.VERCEL
47
+ ? "vercel"
48
+ : process.env.AWS_REGION
49
+ ? "aws"
50
+ : "unknown",
51
+ sdk: `@upstash/redis@${VERSION}`,
44
52
  });
45
53
  }
46
54
  /**
package/esm/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "v0.0.0-ci.608697de-20221215";
1
+ export const VERSION = "v0.0.0-ci.66958ac1-20230501";
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "main": "./script/platforms/nodejs.js",
4
4
  "types": "./types/platforms/nodejs.d.ts",
5
5
  "name": "@upstash/redis",
6
- "version": "v0.0.0-ci.608697de-20221215",
6
+ "version": "v0.0.0-ci.66958ac1-20230501",
7
7
  "description": "An HTTP/REST based Redis client built on top of Upstash REST API.",
8
8
  "repository": {
9
9
  "type": "git",
@@ -35,29 +35,54 @@
35
35
  },
36
36
  "exports": {
37
37
  ".": {
38
- "import": "./esm/platforms/nodejs.js",
39
- "require": "./script/platforms/nodejs.js",
40
- "types": "./types/platforms/nodejs.d.ts"
38
+ "import": {
39
+ "types": "./types/platforms/nodejs.d.ts",
40
+ "default": "./esm/platforms/nodejs.js"
41
+ },
42
+ "require": {
43
+ "types": "./types/platforms/nodejs.d.ts",
44
+ "default": "./script/platforms/nodejs.js"
45
+ }
41
46
  },
42
47
  "./nodejs": {
43
- "import": "./esm/platforms/nodejs.js",
44
- "require": "./script/platforms/nodejs.js",
45
- "types": "./types/platforms/nodejs.d.ts"
48
+ "import": {
49
+ "types": "./types/platforms/nodejs.d.ts",
50
+ "default": "./esm/platforms/nodejs.js"
51
+ },
52
+ "require": {
53
+ "types": "./types/platforms/nodejs.d.ts",
54
+ "default": "./script/platforms/nodejs.js"
55
+ }
46
56
  },
47
57
  "./cloudflare": {
48
- "import": "./esm/platforms/cloudflare.js",
49
- "require": "./script/platforms/cloudflare.js",
50
- "types": "./types/platforms/cloudflare.d.ts"
58
+ "import": {
59
+ "types": "./types/platforms/cloudflare.d.ts",
60
+ "default": "./esm/platforms/cloudflare.js"
61
+ },
62
+ "require": {
63
+ "types": "./types/platforms/cloudflare.d.ts",
64
+ "default": "./script/platforms/cloudflare.js"
65
+ }
51
66
  },
52
67
  "./fastly": {
53
- "import": "./esm/platforms/fastly.js",
54
- "require": "./script/platforms/fastly.js",
55
- "types": "./types/platforms/fastly.d.ts"
68
+ "import": {
69
+ "types": "./types/platforms/fastly.d.ts",
70
+ "default": "./esm/platforms/fastly.js"
71
+ },
72
+ "require": {
73
+ "types": "./types/platforms/fastly.d.ts",
74
+ "default": "./script/platforms/fastly.js"
75
+ }
56
76
  },
57
77
  "./with-fetch": {
58
- "import": "./esm/platforms/node_with_fetch.js",
59
- "require": "./script/platforms/node_with_fetch.js",
60
- "types": "./types/platforms/node_with_fetch.d.ts"
78
+ "import": {
79
+ "types": "./types/platforms/node_with_fetch.d.ts",
80
+ "default": "./esm/platforms/node_with_fetch.js"
81
+ },
82
+ "require": {
83
+ "types": "./types/platforms/node_with_fetch.d.ts",
84
+ "default": "./script/platforms/node_with_fetch.js"
85
+ }
61
86
  }
62
87
  }
63
88
  }
@@ -3,7 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Command = void 0;
4
4
  const error_js_1 = require("../error.js");
5
5
  const util_js_1 = require("../util.js");
6
- const defaultSerializer = (c) => typeof c === "string" ? c : JSON.stringify(c);
6
+ const defaultSerializer = (c) => {
7
+ switch (typeof c) {
8
+ case "string":
9
+ case "number":
10
+ case "boolean":
11
+ return c;
12
+ default:
13
+ return JSON.stringify(c);
14
+ }
15
+ };
7
16
  /**
8
17
  * Command offers default (de)serialization and the exec method to all commands.
9
18
  *
@@ -40,7 +49,7 @@ class Command {
40
49
  opts.automaticDeserialization
41
50
  ? opts?.deserialize ?? util_js_1.parseResponse
42
51
  : (x) => x;
43
- this.command = command.map(this.serialize);
52
+ this.command = command.map((c) => this.serialize(c));
44
53
  }
45
54
  /**
46
55
  * Execute the command using a client.
@@ -53,7 +62,7 @@ class Command {
53
62
  throw new error_js_1.UpstashError(error);
54
63
  }
55
64
  if (typeof result === "undefined") {
56
- throw new Error(`Request did not return a result`);
65
+ throw new Error("Request did not return a result");
57
66
  }
58
67
  return this.deserialize(result);
59
68
  }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JsonArrAppendCommand = void 0;
4
+ const command_js_1 = require("./command.js");
5
+ /**
6
+ * @see https://redis.io/commands/json.arrappend
7
+ */
8
+ class JsonArrAppendCommand extends command_js_1.Command {
9
+ constructor(cmd, opts) {
10
+ super(["JSON.ARRAPPEND", ...cmd], opts);
11
+ }
12
+ }
13
+ exports.JsonArrAppendCommand = JsonArrAppendCommand;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JsonArrIndexCommand = void 0;
4
+ const command_js_1 = require("./command.js");
5
+ /**
6
+ * @see https://redis.io/commands/json.arrindex
7
+ */
8
+ class JsonArrIndexCommand extends command_js_1.Command {
9
+ constructor(cmd, opts) {
10
+ super(["JSON.ARRINDEX", ...cmd], opts);
11
+ }
12
+ }
13
+ exports.JsonArrIndexCommand = JsonArrIndexCommand;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JsonArrInsertCommand = void 0;
4
+ const command_js_1 = require("./command.js");
5
+ /**
6
+ * @see https://redis.io/commands/json.arrinsert
7
+ */
8
+ class JsonArrInsertCommand extends command_js_1.Command {
9
+ constructor(cmd, opts) {
10
+ super(["JSON.ARRINSERT", ...cmd], opts);
11
+ }
12
+ }
13
+ exports.JsonArrInsertCommand = JsonArrInsertCommand;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JsonArrLenCommand = void 0;
4
+ const command_js_1 = require("./command.js");
5
+ /**
6
+ * @see https://redis.io/commands/json.arrlen
7
+ */
8
+ class JsonArrLenCommand extends command_js_1.Command {
9
+ constructor(cmd, opts) {
10
+ super(["JSON.ARRLEN", cmd[0], cmd[1] ?? "$"], opts);
11
+ }
12
+ }
13
+ exports.JsonArrLenCommand = JsonArrLenCommand;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JsonArrPopCommand = void 0;
4
+ const command_js_1 = require("./command.js");
5
+ /**
6
+ * @see https://redis.io/commands/json.arrpop
7
+ */
8
+ class JsonArrPopCommand extends command_js_1.Command {
9
+ constructor(cmd, opts) {
10
+ super(["JSON.ARRPOP", ...cmd], opts);
11
+ }
12
+ }
13
+ exports.JsonArrPopCommand = JsonArrPopCommand;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JsonArrTrimCommand = void 0;
4
+ const command_js_1 = require("./command.js");
5
+ /**
6
+ * @see https://redis.io/commands/json.arrtrim
7
+ */
8
+ class JsonArrTrimCommand extends command_js_1.Command {
9
+ constructor(cmd, opts) {
10
+ const path = cmd[1] ?? "$";
11
+ const start = cmd[2] ?? 0;
12
+ const stop = cmd[3] ?? 0;
13
+ super(["JSON.ARRTRIM", cmd[0], path, start, stop], opts);
14
+ }
15
+ }
16
+ exports.JsonArrTrimCommand = JsonArrTrimCommand;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JsonClearCommand = void 0;
4
+ const command_js_1 = require("./command.js");
5
+ /**
6
+ * @see https://redis.io/commands/json.clear
7
+ */
8
+ class JsonClearCommand extends command_js_1.Command {
9
+ constructor(cmd, opts) {
10
+ super(["JSON.CLEAR", ...cmd], opts);
11
+ }
12
+ }
13
+ exports.JsonClearCommand = JsonClearCommand;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JsonDelCommand = void 0;
4
+ const command_js_1 = require("./command.js");
5
+ /**
6
+ * @see https://redis.io/commands/json.del
7
+ */
8
+ class JsonDelCommand extends command_js_1.Command {
9
+ constructor(cmd, opts) {
10
+ super(["JSON.DEL", ...cmd], opts);
11
+ }
12
+ }
13
+ exports.JsonDelCommand = JsonDelCommand;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JsonForgetCommand = void 0;
4
+ const command_js_1 = require("./command.js");
5
+ /**
6
+ * @see https://redis.io/commands/json.forget
7
+ */
8
+ class JsonForgetCommand extends command_js_1.Command {
9
+ constructor(cmd, opts) {
10
+ super(["JSON.FORGET", ...cmd], opts);
11
+ }
12
+ }
13
+ exports.JsonForgetCommand = JsonForgetCommand;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JsonGetCommand = void 0;
4
+ const command_js_1 = require("./command.js");
5
+ /**
6
+ * @see https://redis.io/commands/json.get
7
+ */
8
+ class JsonGetCommand extends command_js_1.Command {
9
+ constructor(cmd, opts) {
10
+ const command = ["JSON.GET"];
11
+ if (typeof cmd[1] === "string") {
12
+ // @ts-ignore - we know this is a string
13
+ command.push(...cmd);
14
+ }
15
+ else {
16
+ command.push(cmd[0]);
17
+ if (cmd[1]) {
18
+ if (cmd[1].indent) {
19
+ command.push("INDENT", cmd[1].indent);
20
+ }
21
+ if (cmd[1].newline) {
22
+ command.push("NEWLINE", cmd[1].newline);
23
+ }
24
+ if (cmd[1].space) {
25
+ command.push("SPACE", cmd[1].space);
26
+ }
27
+ }
28
+ // @ts-ignore - we know this is a string
29
+ command.push(...cmd.slice(2));
30
+ }
31
+ super(command, opts);
32
+ }
33
+ }
34
+ exports.JsonGetCommand = JsonGetCommand;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JsonMGetCommand = void 0;
4
+ const command_js_1 = require("./command.js");
5
+ /**
6
+ * @see https://redis.io/commands/json.mget
7
+ */
8
+ class JsonMGetCommand extends command_js_1.Command {
9
+ constructor(cmd, opts) {
10
+ super(["JSON.MGET", ...cmd[0], cmd[1]], opts);
11
+ }
12
+ }
13
+ exports.JsonMGetCommand = JsonMGetCommand;