@upstash/redis 1.0.0-alpha.1 → 1.0.0-alpha.2

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 (264) hide show
  1. package/.eslintrc.js +49 -0
  2. package/.prettierrc.js +7 -0
  3. package/dist/chunk-7YUZYRJS.mjs +29 -0
  4. package/dist/chunk-FJSI5EBJ.mjs +38 -0
  5. package/dist/chunk-U7OXAQMQ.mjs +37 -0
  6. package/dist/chunk-Y5TC4HX2.mjs +798 -0
  7. package/dist/{chunk-RYSRH3HC.mjs → chunk-ZIB6XPPC.mjs} +4 -27
  8. package/dist/cloudflare.d.ts +38 -0
  9. package/dist/cloudflare.js +1738 -0
  10. package/dist/cloudflare.mjs +35 -0
  11. package/dist/commands.d.ts +3 -2
  12. package/dist/commands.js +1 -1
  13. package/dist/commands.mjs +2 -1
  14. package/dist/fastly.d.ts +44 -0
  15. package/dist/fastly.js +1728 -0
  16. package/dist/fastly.mjs +25 -0
  17. package/dist/http.d.ts +29 -0
  18. package/dist/http.js +84 -0
  19. package/dist/http.mjs +7 -0
  20. package/dist/index.d.ts +5 -1003
  21. package/dist/index.js +62 -72
  22. package/dist/index.mjs +8 -857
  23. package/dist/nodejs.d.ts +47 -0
  24. package/dist/nodejs.js +1742 -0
  25. package/dist/nodejs.mjs +10 -0
  26. package/dist/package.json +1 -0
  27. package/dist/redis-dd052782.d.ts +962 -0
  28. package/dist/{zunionstore-462de5d3.d.ts → zunionstore-dffa797d.d.ts} +2 -27
  29. package/jest.config.js +195 -0
  30. package/package.json +1 -1
  31. package/pkg/cloudflare.ts +77 -0
  32. package/pkg/command.ts +40 -0
  33. package/pkg/commands/append.test.ts +28 -0
  34. package/pkg/commands/append.ts +10 -0
  35. package/pkg/commands/bitcount.test.ts +36 -0
  36. package/pkg/commands/bitcount.ts +19 -0
  37. package/pkg/commands/bitop.test.ts +44 -0
  38. package/pkg/commands/bitop.ts +22 -0
  39. package/pkg/commands/bitpos.test.ts +26 -0
  40. package/pkg/commands/bitpos.ts +10 -0
  41. package/pkg/commands/dbsize.test.ts +17 -0
  42. package/pkg/commands/dbsize.ts +10 -0
  43. package/pkg/commands/decr.test.ts +22 -0
  44. package/pkg/commands/decr.ts +10 -0
  45. package/pkg/commands/decrby.test.ts +23 -0
  46. package/pkg/commands/decrby.ts +10 -0
  47. package/pkg/commands/del.test.ts +38 -0
  48. package/pkg/commands/del.ts +11 -0
  49. package/pkg/commands/echo.test.ts +11 -0
  50. package/pkg/commands/echo.ts +10 -0
  51. package/pkg/commands/exists.test.ts +37 -0
  52. package/pkg/commands/exists.ts +11 -0
  53. package/pkg/commands/expire.test.ts +22 -0
  54. package/pkg/commands/expire.ts +10 -0
  55. package/pkg/commands/expireat.test.ts +24 -0
  56. package/pkg/commands/expireat.ts +10 -0
  57. package/pkg/commands/flushall.test.ts +17 -0
  58. package/pkg/commands/flushall.ts +13 -0
  59. package/pkg/commands/flushdb.test.ts +17 -0
  60. package/pkg/commands/flushdb.ts +13 -0
  61. package/pkg/commands/get.test.ts +34 -0
  62. package/pkg/commands/get.ts +10 -0
  63. package/pkg/commands/getbit.test.ts +16 -0
  64. package/pkg/commands/getbit.ts +10 -0
  65. package/pkg/commands/getrange.test.ts +25 -0
  66. package/pkg/commands/getrange.ts +10 -0
  67. package/pkg/commands/getset.test.ts +33 -0
  68. package/pkg/commands/getset.ts +10 -0
  69. package/pkg/commands/hdel.test.ts +30 -0
  70. package/pkg/commands/hdel.ts +10 -0
  71. package/pkg/commands/hexists.test.ts +31 -0
  72. package/pkg/commands/hexists.ts +10 -0
  73. package/pkg/commands/hget.test.ts +47 -0
  74. package/pkg/commands/hget.ts +10 -0
  75. package/pkg/commands/hgetall.test.ts +32 -0
  76. package/pkg/commands/hgetall.ts +35 -0
  77. package/pkg/commands/hincrby.test.ts +27 -0
  78. package/pkg/commands/hincrby.ts +10 -0
  79. package/pkg/commands/hincrbyfloat.test.ts +25 -0
  80. package/pkg/commands/hincrbyfloat.ts +10 -0
  81. package/pkg/commands/hkeys.test.ts +22 -0
  82. package/pkg/commands/hkeys.ts +10 -0
  83. package/pkg/commands/hlen.test.ts +24 -0
  84. package/pkg/commands/hlen.ts +10 -0
  85. package/pkg/commands/hmget.test.ts +48 -0
  86. package/pkg/commands/hmget.ts +41 -0
  87. package/pkg/commands/hmset.test.ts +24 -0
  88. package/pkg/commands/hmset.ts +10 -0
  89. package/pkg/commands/hscan.test.ts +46 -0
  90. package/pkg/commands/hscan.ts +22 -0
  91. package/pkg/commands/hset.test.ts +21 -0
  92. package/pkg/commands/hset.ts +10 -0
  93. package/pkg/commands/hsetnx.test.ts +37 -0
  94. package/pkg/commands/hsetnx.ts +10 -0
  95. package/pkg/commands/hstrlen.test.ts +24 -0
  96. package/pkg/commands/hstrlen.ts +10 -0
  97. package/pkg/commands/hvals.test.ts +23 -0
  98. package/pkg/commands/hvals.ts +10 -0
  99. package/pkg/commands/incr.test.ts +23 -0
  100. package/pkg/commands/incr.ts +10 -0
  101. package/pkg/commands/incrby.test.ts +23 -0
  102. package/pkg/commands/incrby.ts +10 -0
  103. package/pkg/commands/incrbyfloat.test.ts +24 -0
  104. package/pkg/commands/incrbyfloat.ts +10 -0
  105. package/pkg/commands/index.ts +107 -0
  106. package/pkg/commands/keys.test.ts +17 -0
  107. package/pkg/commands/keys.ts +10 -0
  108. package/pkg/commands/lindex.test.ts +33 -0
  109. package/pkg/commands/lindex.ts +7 -0
  110. package/pkg/commands/linsert.test.ts +19 -0
  111. package/pkg/commands/linsert.ts +6 -0
  112. package/pkg/commands/llen.test.ts +26 -0
  113. package/pkg/commands/llen.ts +10 -0
  114. package/pkg/commands/lpop.test.ts +27 -0
  115. package/pkg/commands/lpop.ts +10 -0
  116. package/pkg/commands/lpush.test.ts +17 -0
  117. package/pkg/commands/lpush.ts +11 -0
  118. package/pkg/commands/lpushx.test.ts +29 -0
  119. package/pkg/commands/lpushx.ts +11 -0
  120. package/pkg/commands/lrange.test.ts +22 -0
  121. package/pkg/commands/lrange.ts +7 -0
  122. package/pkg/commands/lrem.test.ts +19 -0
  123. package/pkg/commands/lrem.ts +6 -0
  124. package/pkg/commands/lset.test.ts +40 -0
  125. package/pkg/commands/lset.ts +7 -0
  126. package/pkg/commands/ltrim.test.ts +29 -0
  127. package/pkg/commands/ltrim.ts +7 -0
  128. package/pkg/commands/mget.test.ts +44 -0
  129. package/pkg/commands/mget.ts +9 -0
  130. package/pkg/commands/mset.test.ts +24 -0
  131. package/pkg/commands/mset.ts +10 -0
  132. package/pkg/commands/msetnx.test.ts +46 -0
  133. package/pkg/commands/msetnx.ts +10 -0
  134. package/pkg/commands/persist.test.ts +22 -0
  135. package/pkg/commands/persist.ts +10 -0
  136. package/pkg/commands/pexpire.test.ts +24 -0
  137. package/pkg/commands/pexpire.ts +10 -0
  138. package/pkg/commands/pexpireat.test.ts +24 -0
  139. package/pkg/commands/pexpireat.ts +10 -0
  140. package/pkg/commands/ping.test.ts +19 -0
  141. package/pkg/commands/ping.ts +13 -0
  142. package/pkg/commands/psetex.test.ts +23 -0
  143. package/pkg/commands/psetex.ts +10 -0
  144. package/pkg/commands/pttl.test.ts +17 -0
  145. package/pkg/commands/pttl.ts +10 -0
  146. package/pkg/commands/randomkey.test.ts +17 -0
  147. package/pkg/commands/randomkey.ts +10 -0
  148. package/pkg/commands/rename.test.ts +18 -0
  149. package/pkg/commands/rename.ts +10 -0
  150. package/pkg/commands/renamenx.test.ts +32 -0
  151. package/pkg/commands/renamenx.ts +10 -0
  152. package/pkg/commands/rpop.test.ts +27 -0
  153. package/pkg/commands/rpop.ts +10 -0
  154. package/pkg/commands/rpush.test.ts +17 -0
  155. package/pkg/commands/rpush.ts +11 -0
  156. package/pkg/commands/rpushx.test.ts +29 -0
  157. package/pkg/commands/rpushx.ts +11 -0
  158. package/pkg/commands/sadd.test.ts +16 -0
  159. package/pkg/commands/sadd.ts +11 -0
  160. package/pkg/commands/scan.test.ts +50 -0
  161. package/pkg/commands/scan.ts +21 -0
  162. package/pkg/commands/scard.test.ts +15 -0
  163. package/pkg/commands/scard.ts +9 -0
  164. package/pkg/commands/sdiff.test.ts +20 -0
  165. package/pkg/commands/sdiff.ts +9 -0
  166. package/pkg/commands/sdiffstore.test.ts +21 -0
  167. package/pkg/commands/sdiffstore.ts +10 -0
  168. package/pkg/commands/set.test.ts +112 -0
  169. package/pkg/commands/set.ts +53 -0
  170. package/pkg/commands/setbit.test.ts +16 -0
  171. package/pkg/commands/setbit.ts +10 -0
  172. package/pkg/commands/setex.test.ts +22 -0
  173. package/pkg/commands/setex.ts +10 -0
  174. package/pkg/commands/setnx.test.ts +27 -0
  175. package/pkg/commands/setnx.ts +10 -0
  176. package/pkg/commands/setrange.test.ts +25 -0
  177. package/pkg/commands/setrange.ts +10 -0
  178. package/pkg/commands/sinter.test.ts +36 -0
  179. package/pkg/commands/sinter.ts +9 -0
  180. package/pkg/commands/sinterstore.test.ts +21 -0
  181. package/pkg/commands/sinterstore.ts +9 -0
  182. package/pkg/commands/sismember.test.ts +30 -0
  183. package/pkg/commands/sismember.ts +9 -0
  184. package/pkg/commands/smembers.test.ts +22 -0
  185. package/pkg/commands/smembers.ts +10 -0
  186. package/pkg/commands/smove.test.ts +18 -0
  187. package/pkg/commands/smove.ts +9 -0
  188. package/pkg/commands/spop.test.ts +35 -0
  189. package/pkg/commands/spop.ts +13 -0
  190. package/pkg/commands/srandmember.test.ts +32 -0
  191. package/pkg/commands/srandmember.ts +13 -0
  192. package/pkg/commands/srem.test.ts +18 -0
  193. package/pkg/commands/srem.ts +10 -0
  194. package/pkg/commands/sscan.test.ts +50 -0
  195. package/pkg/commands/sscan.ts +22 -0
  196. package/pkg/commands/strlen.test.ts +16 -0
  197. package/pkg/commands/strlen.ts +10 -0
  198. package/pkg/commands/sunion.test.ts +22 -0
  199. package/pkg/commands/sunion.ts +10 -0
  200. package/pkg/commands/sunionstore.test.ts +29 -0
  201. package/pkg/commands/sunionstore.ts +10 -0
  202. package/pkg/commands/time.test.ts +11 -0
  203. package/pkg/commands/time.ts +9 -0
  204. package/pkg/commands/touch.test.ts +20 -0
  205. package/pkg/commands/touch.ts +10 -0
  206. package/pkg/commands/ttl.test.ts +17 -0
  207. package/pkg/commands/ttl.ts +10 -0
  208. package/pkg/commands/type.test.ts +72 -0
  209. package/pkg/commands/type.ts +11 -0
  210. package/pkg/commands/unlink.test.ts +21 -0
  211. package/pkg/commands/unlink.ts +10 -0
  212. package/pkg/commands/zadd.test.ts +177 -0
  213. package/pkg/commands/zadd.ts +64 -0
  214. package/pkg/commands/zcard.test.ts +15 -0
  215. package/pkg/commands/zcard.ts +10 -0
  216. package/pkg/commands/zcount.test.ts +15 -0
  217. package/pkg/commands/zcount.ts +9 -0
  218. package/pkg/commands/zincrby.test.ts +20 -0
  219. package/pkg/commands/zincrby.ts +9 -0
  220. package/pkg/commands/zinterstore.test.ts +239 -0
  221. package/pkg/commands/zinterstore.ts +55 -0
  222. package/pkg/commands/zlexcount.test.ts +22 -0
  223. package/pkg/commands/zlexcount.ts +9 -0
  224. package/pkg/commands/zpopmax.test.ts +45 -0
  225. package/pkg/commands/zpopmax.ts +13 -0
  226. package/pkg/commands/zpopmin.test.ts +49 -0
  227. package/pkg/commands/zpopmin.ts +13 -0
  228. package/pkg/commands/zrange.test.ts +52 -0
  229. package/pkg/commands/zrange.ts +22 -0
  230. package/pkg/commands/zrank.test.ts +22 -0
  231. package/pkg/commands/zrank.ts +10 -0
  232. package/pkg/commands/zrem.test.ts +20 -0
  233. package/pkg/commands/zrem.ts +10 -0
  234. package/pkg/commands/zremrangebylex.test.ts +26 -0
  235. package/pkg/commands/zremrangebylex.ts +9 -0
  236. package/pkg/commands/zremrangebyrank.test.ts +27 -0
  237. package/pkg/commands/zremrangebyrank.ts +9 -0
  238. package/pkg/commands/zremrangebyscore.test.ts +24 -0
  239. package/pkg/commands/zremrangebyscore.ts +9 -0
  240. package/pkg/commands/zrevrank.test.ts +22 -0
  241. package/pkg/commands/zrevrank.ts +10 -0
  242. package/pkg/commands/zscan.test.ts +50 -0
  243. package/pkg/commands/zscan.ts +22 -0
  244. package/pkg/commands/zscore.test.ts +18 -0
  245. package/pkg/commands/zscore.ts +10 -0
  246. package/pkg/commands/zunionstore.test.ts +215 -0
  247. package/pkg/commands/zunionstore.ts +55 -0
  248. package/pkg/commands/zz.ts +1 -0
  249. package/pkg/error.ts +9 -0
  250. package/pkg/fastly.ts +54 -0
  251. package/pkg/http.test.ts +34 -0
  252. package/pkg/http.ts +62 -0
  253. package/pkg/index.ts +2 -0
  254. package/pkg/nodejs.ts +83 -0
  255. package/pkg/pipeline.test.ts +177 -0
  256. package/pkg/pipeline.ts +999 -0
  257. package/pkg/redis.ts +930 -0
  258. package/pkg/test-utils.ts +41 -0
  259. package/pkg/types.ts +4 -0
  260. package/pkg/util.ts +22 -0
  261. package/pnpm-lock.yaml +3940 -0
  262. package/tsconfig.json +100 -0
  263. package/tsconfig.module.json +8 -0
  264. package/tsup.config.ts +16 -0
@@ -1,29 +1,4 @@
1
- declare type HttpRequest = {
2
- path?: string[];
3
- /**
4
- * Request body will be serialized to json
5
- */
6
- body?: unknown;
7
- headers?: Record<string, string>;
8
- retries?: number;
9
- };
10
- declare type HttpClientConfig = {
11
- headers?: Record<string, string>;
12
- baseUrl: string;
13
- options?: {
14
- backend?: string;
15
- };
16
- };
17
- declare class HttpClient {
18
- baseUrl: string;
19
- headers: Record<string, string>;
20
- readonly options?: {
21
- backend?: string;
22
- };
23
- constructor(config: HttpClientConfig);
24
- private request;
25
- post<TResponse>(req: HttpRequest): Promise<TResponse>;
26
- }
1
+ import { HttpClient } from './http';
27
2
 
28
3
  /**
29
4
  * Command offers default (de)serialization and the exec method to all commands.
@@ -692,4 +667,4 @@ declare class ZUnionStoreCommand extends Command<number, number> {
692
667
  constructor(destination: string, numKeys: number, keys: string[], opts?: ZUnionStoreCommandOptions);
693
668
  }
694
669
 
695
- export { SetBitCommand as $, AppendCommand as A, BitCountCommand as B, CommandArgs as C, DecrCommand as D, EchoCommand as E, FlushAllCommand as F, GetCommand as G, HttpClient as H, IncrCommand as I, LTrimCommand as J, KeysCommand as K, LIndexCommand as L, MGetCommand as M, NonEmptyArray as N, PExpireCommand as O, PersistCommand as P, PExpireAtCommand as Q, PingCommand as R, PTtlCommand as S, RenameCommand as T, RenameNXCommand as U, RPopCommand as V, ScanCommand as W, SCardCommand as X, SDiffCommand as Y, SDiffStoreCommand as Z, SetCommandOptions as _, BitPosCommand as a, SetRangeCommand as a0, SInterCommand as a1, SInterStoreCommand as a2, SMembersCommand as a3, SPopCommand as a4, SRandMemberCommand as a5, SScanCommand as a6, StrLenCommand as a7, SUnionCommand as a8, SUnionStoreCommand as a9, ZUnionStoreCommandOptions as aA, TouchCommand as aa, TtlCommand as ab, TypeCommand as ac, UnlinkCommand as ad, ScoreMember as ae, ZAddCommandOptions as af, ZAddCommandOptionsWithIncr as ag, ZCardCommand as ah, ZCountCommand as ai, ZInterStoreCommand as aj, ZLexCountCommand as ak, ZPopMaxCommand as al, ZPopMinCommand as am, ZRangeCommand as an, ZRemRangeByLexCommand as ao, ZRemRangeByRankCommand as ap, ZRemRangeByScoreCommand as aq, ZScanCommand as ar, ZUnionStoreCommand as as, Type as at, Command as au, ScanCommandOptions as av, SetCommand as aw, ZAddCommand as ax, ZInterStoreCommandOptions as ay, ZRangeCommandOptions as az, DecrByCommand as b, DelCommand as c, ExistsCommand as d, ExpireCommand as e, ExpireAtCommand as f, FlushDBCommand as g, GetBitCommand as h, GetRangeCommand as i, HDelCommand as j, HExistsCommand as k, HGetCommand as l, HGetAllCommand as m, HIncrByCommand as n, HIncrByFloatCommand as o, HKeysCommand as p, HLenCommand as q, HMGetCommand as r, HScanCommand as s, HStrLenCommand as t, HValsCommand as u, IncrByCommand as v, IncrByFloatCommand as w, LLenCommand as x, LPopCommand as y, LRangeCommand as z };
670
+ export { SetRangeCommand as $, AppendCommand as A, BitCountCommand as B, CommandArgs as C, DecrCommand as D, EchoCommand as E, FlushAllCommand as F, GetCommand as G, HDelCommand as H, IncrCommand as I, PExpireCommand as J, KeysCommand as K, LIndexCommand as L, MGetCommand as M, NonEmptyArray as N, PExpireAtCommand as O, PersistCommand as P, PingCommand as Q, PTtlCommand as R, RenameCommand as S, RenameNXCommand as T, RPopCommand as U, ScanCommand as V, SCardCommand as W, SDiffCommand as X, SDiffStoreCommand as Y, SetCommandOptions as Z, SetBitCommand as _, BitPosCommand as a, SInterCommand as a0, SInterStoreCommand as a1, SMembersCommand as a2, SPopCommand as a3, SRandMemberCommand as a4, SScanCommand as a5, StrLenCommand as a6, SUnionCommand as a7, SUnionStoreCommand as a8, TouchCommand as a9, TtlCommand as aa, TypeCommand as ab, UnlinkCommand as ac, ScoreMember as ad, ZAddCommandOptions as ae, ZAddCommandOptionsWithIncr as af, ZCardCommand as ag, ZCountCommand as ah, ZInterStoreCommand as ai, ZLexCountCommand as aj, ZPopMaxCommand as ak, ZPopMinCommand as al, ZRangeCommand as am, ZRemRangeByLexCommand as an, ZRemRangeByRankCommand as ao, ZRemRangeByScoreCommand as ap, ZScanCommand as aq, ZUnionStoreCommand as ar, Type as as, Command as at, ScanCommandOptions as au, SetCommand as av, ZAddCommand as aw, ZInterStoreCommandOptions as ax, ZRangeCommandOptions as ay, ZUnionStoreCommandOptions as az, DecrByCommand as b, DelCommand as c, ExistsCommand as d, ExpireCommand as e, ExpireAtCommand as f, FlushDBCommand as g, GetBitCommand as h, GetRangeCommand as i, HExistsCommand as j, HGetCommand as k, HGetAllCommand as l, HIncrByCommand as m, HIncrByFloatCommand as n, HKeysCommand as o, HLenCommand as p, HMGetCommand as q, HScanCommand as r, HStrLenCommand as s, HValsCommand as t, IncrByCommand as u, IncrByFloatCommand as v, LLenCommand as w, LPopCommand as x, LRangeCommand as y, LTrimCommand as z };
package/jest.config.js ADDED
@@ -0,0 +1,195 @@
1
+ /*
2
+ * For a detailed explanation regarding each configuration property and type check, visit:
3
+ * https://jestjs.io/docs/configuration
4
+ */
5
+
6
+ module.exports = {
7
+ // All imported modules in your tests should be mocked automatically
8
+ // automock: false,
9
+
10
+ // Stop running tests after `n` failures
11
+ bail: true,
12
+
13
+ // The directory where Jest should store its cached dependency information
14
+ // cacheDirectory: "/tmp/jest_rs",
15
+
16
+ // Automatically clear mock calls, instances and results before every test
17
+ // clearMocks: false,
18
+
19
+ // Indicates whether the coverage information should be collected while executing the test
20
+ collectCoverage: true,
21
+
22
+ // An array of glob patterns indicating a set of files for which coverage information should be collected
23
+ // collectCoverageFrom: undefined,
24
+
25
+ // The directory where Jest should output its coverage files
26
+ coverageDirectory: "coverage",
27
+
28
+ // An array of regexp pattern strings used to skip coverage collection
29
+ coveragePathIgnorePatterns: ["/node_modules/", "/dist/", "pkg/test-utils.ts"],
30
+
31
+ // Indicates which provider should be used to instrument code for coverage
32
+ coverageProvider: "v8",
33
+
34
+ // A list of reporter names that Jest uses when writing coverage reports
35
+ // coverageReporters: [
36
+ // "json",
37
+ // "text",
38
+ // "lcov",
39
+ // "clover"
40
+ // ],
41
+
42
+ // An object that configures minimum threshold enforcement for coverage results
43
+ // coverageThreshold: undefined,
44
+
45
+ // A path to a custom dependency extractor
46
+ // dependencyExtractor: undefined,
47
+
48
+ // Make calling deprecated APIs throw helpful error messages
49
+ errorOnDeprecated: false,
50
+
51
+ // Force coverage collection from ignored files using an array of glob patterns
52
+ // forceCoverageMatch: [],
53
+
54
+ // A path to a module which exports an async function that is triggered once before all test suites
55
+ // globalSetup: undefined,
56
+
57
+ // A path to a module which exports an async function that is triggered once after all test suites
58
+ // globalTeardown: "./pkg/test_teardown.ts",
59
+
60
+ // A set of global variables that need to be available in all test environments
61
+ // globals: {},
62
+
63
+ // The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
64
+ // maxWorkers: "50%",
65
+
66
+ // An array of directory names to be searched recursively up from the requiring module's location
67
+ // moduleDirectories: [
68
+ // "node_modules"
69
+ // ],
70
+
71
+ // An array of file extensions your modules use
72
+ // moduleFileExtensions: [
73
+ // "js",
74
+ // "jsx",
75
+ // "ts",
76
+ // "tsx",
77
+ // "json",
78
+ // "node"
79
+ // ],
80
+
81
+ // A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
82
+ // moduleNameMapper: {},
83
+
84
+ // An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
85
+ modulePathIgnorePatterns: ["dist/"],
86
+
87
+ // Activates notifications for test results
88
+ notify: false,
89
+
90
+ // An enum that specifies notification mode. Requires { notify: true }
91
+ // notifyMode: "failure-change",
92
+
93
+ // A preset that is used as a base for Jest's configuration
94
+ // preset: undefined,
95
+
96
+ // Run tests from one or more projects
97
+ // projects: undefined,
98
+
99
+ // Use this configuration option to add custom reporters to Jest
100
+ // reporters: undefined,
101
+
102
+ // Automatically reset mock state before every test
103
+ // resetMocks: false,
104
+
105
+ // Reset the module registry before running each individual test
106
+ // resetModules: false,
107
+
108
+ // A path to a custom resolver
109
+ // resolver: undefined,
110
+
111
+ // Automatically restore mock state and implementation before every test
112
+ // restoreMocks: false,
113
+
114
+ // The root directory that Jest should scan for tests and modules within
115
+ // rootDir: undefined,
116
+
117
+ // A list of paths to directories that Jest should use to search for files in
118
+ // roots: [
119
+ // "<rootDir>"
120
+ // ],
121
+
122
+ // Allows you to use a custom runner instead of Jest's default test runner
123
+ // runner: "jest-runner",
124
+
125
+ // The paths to modules that run some code to configure or set up the testing environment before each test
126
+ // setupFiles: [],
127
+
128
+ // A list of paths to modules that run some code to configure or set up the testing framework before each test
129
+ // setupFilesAfterEnv: [],
130
+
131
+ // The number of seconds after which a test is considered as slow and reported as such in the results.
132
+ // slowTestThreshold: 5,
133
+
134
+ // A list of paths to snapshot serializer modules Jest should use for snapshot testing
135
+ // snapshotSerializers: [],
136
+
137
+ // The test environment that will be used for testing
138
+ // testEnvironment: "jest-environment-node",
139
+
140
+ // Options that will be passed to the testEnvironment
141
+ // testEnvironmentOptions: {},
142
+
143
+ // Adds a location field to test results
144
+ // testLocationInResults: false,
145
+
146
+ // The glob patterns Jest uses to detect test files
147
+ // testMatch: [
148
+ // "**/__tests__/**/*.[jt]s?(x)",
149
+ // "**/?(*.)+(spec|test).[tj]s?(x)"
150
+ // ],
151
+
152
+ // An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
153
+ testPathIgnorePatterns: ["/node_modules/", "<rootDir>/pkg/test-utils.ts"],
154
+
155
+ // The regexp pattern or array of patterns that Jest uses to detect test files
156
+ // testRegex: [],
157
+
158
+ // This option allows the use of a custom results processor
159
+ // testResultsProcessor: undefined,
160
+
161
+ // This option allows use of a custom test runner
162
+ // testRunner: "jest-circus/runner",
163
+
164
+ // This option sets the URL for the jsdom environment. It is reflected in properties such as location.href
165
+ // testURL: "http://localhost",
166
+
167
+ // Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout"
168
+ // timers: "real",
169
+
170
+ // A map from regular expressions to paths to transformers
171
+ transform: {
172
+ "^.+\\.ts$": "ts-jest",
173
+ },
174
+
175
+ // An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
176
+ // transformIgnorePatterns: [
177
+ // "/node_modules/",
178
+ // "\\.pnp\\.[^\\/]+$"
179
+ // ],
180
+
181
+ // An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
182
+ // unmockedModulePathPatterns: undefined,
183
+
184
+ // Indicates whether each individual test should be reported during the run
185
+ verbose: true,
186
+
187
+ // An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
188
+ // watchPathIgnorePatterns: [],
189
+
190
+ // Whether to use watchman for file crawling
191
+ // watchman: true,
192
+
193
+ injectGlobals: false,
194
+ testTimeout: 60_000,
195
+ }
package/package.json CHANGED
@@ -1 +1 @@
1
- { "name": "@upstash/redis", "version": "v1.0.0-alpha.1", "engines": { "node": ">=10" }, "description": "An HTTP/REST based Redis client built on top of Upstash REST API.", "main": "./dist/index.js", "module": "./dist/index.mjs", "types": "./dist/index.d.ts", "exports": { ".": { "require": "./dist/index.js", "import": "./dist/index.mjs", "types": "./dist/index.d.ts" } }, "files": [ "package.json", "dist" ], "scripts": { "test": "jest -i", "fmt": "pnpm lint && pnpm prettier --write .", "lint": "eslint --ext .ts --fix --ignore-path .gitignore .", "build": "tsup && pnpm size-limit" }, "repository": { "type": "git", "url": "git+https://github.com/upstash/upstash-redis.git" }, "keywords": [ "redis", "database", "serverless", "edge", "upstash" ], "author": "Andreas Thomas <andreas.thomas@chronark.com>", "license": "MIT", "bugs": { "url": "https://github.com/upstash/upstash-redis/issues" }, "homepage": "https://github.com/upstash/upstash-redis#readme", "directories": { "examples": "examples" }, "devDependencies": { "@jest/globals": "^27.4.6", "@size-limit/preset-small-lib": "^7.0.8", "@trivago/prettier-plugin-sort-imports": "^3.2.0", "@types/jest": "^27.4.0", "@types/node": "^17.0.8", "@typescript-eslint/eslint-plugin": "^5.9.1", "@typescript-eslint/parser": "^5.9.1", "dotenv": "^12.0.3", "eslint": "^8.6.0", "eslint-config-prettier": "^8.3.0", "eslint-plugin-prettier": "^4.0.0", "jest": "^27.4.7", "prettier": "^2.5.1", "size-limit": "^7.0.8", "ts-jest": "^27.1.3", "tsup": "^5.11.11", "typescript": "^4.5.5" }, "dependencies": { "isomorphic-fetch": "^3.0.0" }, "browser": { "isomorphic-fetch": false }, "size-limit": [ { "path": "dist/index.js", "limit": "5 KB" }, { "path": "dist/index.mjs", "limit": "5 KB" } ] }
1
+ { "name": "@upstash/redis", "version": "v1.0.0-alpha.2", "engines": { "node": ">=10" }, "description": "An HTTP/REST based Redis client built on top of Upstash REST API.", "main": "./index.js", "module": "./index.mjs", "types": "./index.d.ts", "scripts": { "test": "jest -i", "fmt": "pnpm lint && pnpm prettier --write .", "lint": "eslint --ext .ts --fix --ignore-path .gitignore .", "build": "tsup && cp package.json ./dist/ && pnpm size-limit" }, "repository": { "type": "git", "url": "git+https://github.com/upstash/upstash-redis.git" }, "keywords": [ "redis", "database", "serverless", "edge", "upstash" ], "author": "Andreas Thomas <andreas.thomas@chronark.com>", "license": "MIT", "bugs": { "url": "https://github.com/upstash/upstash-redis/issues" }, "homepage": "https://github.com/upstash/upstash-redis#readme", "directories": { "examples": "examples" }, "devDependencies": { "@jest/globals": "^27.4.6", "@size-limit/preset-small-lib": "^7.0.8", "@trivago/prettier-plugin-sort-imports": "^3.2.0", "@types/jest": "^27.4.0", "@types/node": "^17.0.8", "@typescript-eslint/eslint-plugin": "^5.9.1", "@typescript-eslint/parser": "^5.9.1", "dotenv": "^12.0.3", "eslint": "^8.6.0", "eslint-config-prettier": "^8.3.0", "eslint-plugin-prettier": "^4.0.0", "jest": "^27.4.7", "prettier": "^2.5.1", "size-limit": "^7.0.8", "ts-jest": "^27.1.3", "tsup": "^5.11.11", "typescript": "^4.5.5" }, "dependencies": { "isomorphic-fetch": "^3.0.0" }, "browser": { "isomorphic-fetch": false }, "size-limit": [ { "path": "dist/index.js", "limit": "5 KB" }, { "path": "dist/index.mjs", "limit": "5 KB" } ] }
@@ -0,0 +1,77 @@
1
+ import * as core from "./redis"
2
+ import { HttpClient } from "./http"
3
+
4
+ /**
5
+ * Connection credentials for upstash redis.
6
+ * Get them from https://console.upstash.com/redis/<uuid>
7
+ */
8
+ export type RedisConfigCloudflare = {
9
+ /**
10
+ * UPSTASH_REDIS_REST_URL
11
+ */
12
+ url: string
13
+
14
+ /**
15
+ * UPSTASH_REDIS_REST_TOKEN
16
+ */
17
+ token: string
18
+ }
19
+
20
+ /**
21
+ * Serverless redis client for upstash.
22
+ */
23
+ export class Redis extends core.Redis {
24
+ /**
25
+ * Create a new redis client
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * const redis = new Redis({
30
+ * url: "<UPSTASH_REDIS_REST_URL>",
31
+ * token: "<UPSTASH_REDIS_REST_TOKEN>",
32
+ * });
33
+ * ```
34
+ */
35
+ constructor(config: RedisConfigCloudflare) {
36
+ const client = new HttpClient({
37
+ baseUrl: config.url,
38
+ headers: {
39
+ authorization: `Bearer ${config.token}`,
40
+ },
41
+ })
42
+
43
+ super(client)
44
+ }
45
+
46
+ /*
47
+ * Create a new Upstash Redis instance from environment variables on cloudflare.
48
+ *
49
+ * This tries to load `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN` from
50
+ * the global namespace
51
+ */
52
+ static fromEnv(): Redis {
53
+ /**
54
+ * These should be injected by cloudflare.
55
+ */
56
+
57
+ // @ts-ignore
58
+ // eslint-disable-next-line no-undef
59
+ const url = UPSTASH_REDIS_REST_URL
60
+
61
+ // @ts-ignore
62
+ // eslint-disable-next-line no-undef
63
+ const token = UPSTASH_REDIS_REST_TOKEN
64
+
65
+ if (!url) {
66
+ throw new Error(
67
+ "Unable to find environment variable: `UPSTASH_REDIS_REST_URL`. Please add it via `wrangler secret put UPSTASH_REDIS_REST_URL`",
68
+ )
69
+ }
70
+ if (!token) {
71
+ throw new Error(
72
+ "Unable to find environment variable: `UPSTASH_REDIS_REST_TOKEN`. Please add it via `wrangler secret put UPSTASH_REDIS_REST_TOKEN`",
73
+ )
74
+ }
75
+ return new Redis({ url, token })
76
+ }
77
+ }
package/pkg/command.ts ADDED
@@ -0,0 +1,40 @@
1
+ import { UpstashError } from "./error"
2
+ import { HttpClient, UpstashResponse } from "./http"
3
+ import { parseResponse } from "./util"
4
+
5
+ /**
6
+ * Command offers default (de)serialization and the exec method to all commands.
7
+ *
8
+ * TData represents what the user will enter or receive,
9
+ * TResult is the raw data returned from upstash, which may need to be transformed or parsed.
10
+ */
11
+ export abstract class Command<TData, TResult> {
12
+ public readonly command: string[]
13
+ public deserialize: (result: TResult) => TData
14
+ /**
15
+ * Create a new command instance.
16
+ *
17
+ * You can define a custom `deserialize` function. By default we try to deserialize as json.
18
+ */
19
+ constructor(command: (string | unknown)[], opts?: { deserialize?: (result: TResult) => TData }) {
20
+ this.command = command.map((c) => (typeof c === "string" ? c : JSON.stringify(c)))
21
+ this.deserialize = opts?.deserialize ?? parseResponse
22
+ }
23
+
24
+ /**
25
+ * Execute the command using a client.
26
+ */
27
+ public async exec(client: HttpClient): Promise<TData> {
28
+ const { result, error } = await client.request<UpstashResponse<TResult>>({
29
+ body: this.command,
30
+ })
31
+ if (error) {
32
+ throw new UpstashError(error)
33
+ }
34
+ if (typeof result === "undefined") {
35
+ throw new Error(`Request did not return a result`)
36
+ }
37
+
38
+ return this.deserialize(result)
39
+ }
40
+ }
@@ -0,0 +1,28 @@
1
+ import { AppendCommand } from "./append"
2
+ import { keygen, newHttpClient } from "../test-utils"
3
+ import { randomUUID } from "crypto"
4
+ import { describe, it, expect, afterAll } from "@jest/globals"
5
+ const client = newHttpClient()
6
+
7
+ const { newKey, cleanup } = keygen()
8
+ afterAll(cleanup)
9
+
10
+ describe("when key is not set", () => {
11
+ it("appends to empty value", async () => {
12
+ const key = newKey()
13
+ const value = randomUUID()
14
+ const res = await new AppendCommand(key, value).exec(client)
15
+ expect(res).toEqual(value.length)
16
+ })
17
+ })
18
+
19
+ describe("when key is set", () => {
20
+ it("appends to existing value", async () => {
21
+ const key = newKey()
22
+ const value = randomUUID()
23
+ const res = await new AppendCommand(key, value).exec(client)
24
+ expect(res).toEqual(value.length)
25
+ const res2 = await new AppendCommand(key, "_").exec(client)
26
+ expect(res2).toEqual(value.length + 1)
27
+ })
28
+ })
@@ -0,0 +1,10 @@
1
+ import { Command } from "../command"
2
+
3
+ /**
4
+ * @see https://redis.io/commands/append
5
+ */
6
+ export class AppendCommand extends Command<number, number> {
7
+ constructor(key: string, value: string) {
8
+ super(["append", key, value])
9
+ }
10
+ }
@@ -0,0 +1,36 @@
1
+ import { BitCountCommand } from "./bitcount"
2
+ import { keygen, newHttpClient } from "../test-utils"
3
+ import { describe, it, expect, afterAll } from "@jest/globals"
4
+ import { SetCommand } from "./set"
5
+ const client = newHttpClient()
6
+
7
+ const { newKey, cleanup } = keygen()
8
+ afterAll(cleanup)
9
+
10
+ describe("when key is not set", () => {
11
+ it("returns 0", async () => {
12
+ const key = newKey()
13
+ const res = await new BitCountCommand(key).exec(client)
14
+ expect(res).toEqual(0)
15
+ })
16
+ })
17
+
18
+ describe("when key is set", () => {
19
+ it("returns bitcount", async () => {
20
+ const key = newKey()
21
+ const value = "Hello World"
22
+ await new SetCommand(key, value).exec(client)
23
+ const res = await new BitCountCommand(key).exec(client)
24
+ expect(res).toEqual(43)
25
+ })
26
+
27
+ describe("with start and end", () => {
28
+ it("returns bitcount", async () => {
29
+ const key = newKey()
30
+ const value = "Hello World"
31
+ await new SetCommand(key, value).exec(client)
32
+ const res = await new BitCountCommand(key, 4, 8).exec(client)
33
+ expect(res).toEqual(22)
34
+ })
35
+ })
36
+ })
@@ -0,0 +1,19 @@
1
+ import { Command } from "../command"
2
+
3
+ /**
4
+ * @see https://redis.io/commands/bitcount
5
+ */
6
+ export class BitCountCommand extends Command<number, number> {
7
+ constructor(key: string, start?: never, end?: never)
8
+ constructor(key: string, start: number, end: number)
9
+ constructor(key: string, start?: number, end?: number) {
10
+ const command: unknown[] = ["bitcount", key]
11
+ if (typeof start === "number") {
12
+ command.push(start)
13
+ }
14
+ if (typeof end === "number") {
15
+ command.push(end)
16
+ }
17
+ super(command)
18
+ }
19
+ }
@@ -0,0 +1,44 @@
1
+ import { BitOpCommand } from "./bitop"
2
+ import { keygen, newHttpClient } from "../test-utils"
3
+ import { describe, it, expect, afterAll } from "@jest/globals"
4
+ import { SetCommand } from "./set"
5
+ const client = newHttpClient()
6
+
7
+ const { newKey, cleanup } = keygen()
8
+ afterAll(cleanup)
9
+
10
+ describe("when key is not set", () => {
11
+ it("returns 0", async () => {
12
+ const source = newKey()
13
+ const dest = newKey()
14
+ const res = await new BitOpCommand("and", dest, source).exec(client)
15
+ expect(res).toEqual(0)
16
+ })
17
+ })
18
+
19
+ describe("when key is set", () => {
20
+ describe("not", () => {
21
+ it("inverts all bits", async () => {
22
+ const source = newKey()
23
+ const sourcevalue = "Hello World"
24
+ const dest = newKey()
25
+ const destValue = "foo: bar"
26
+ await new SetCommand(source, sourcevalue).exec(client)
27
+ await new SetCommand(dest, destValue).exec(client)
28
+ const res = await new BitOpCommand("not", dest, source).exec(client)
29
+ expect(res).toEqual(11)
30
+ })
31
+ })
32
+ describe("and", () => {
33
+ it("works", async () => {
34
+ const source = newKey()
35
+ const sourcevalue = "Hello World"
36
+ const dest = newKey()
37
+ const destValue = "foo: bar"
38
+ await new SetCommand(source, sourcevalue).exec(client)
39
+ await new SetCommand(dest, destValue).exec(client)
40
+ const res = await new BitOpCommand("and", dest, source).exec(client)
41
+ expect(res).toEqual(11)
42
+ })
43
+ })
44
+ })
@@ -0,0 +1,22 @@
1
+ import { Command } from "../command"
2
+
3
+ /**
4
+ * @see https://redis.io/commands/bitop
5
+ */
6
+ export class BitOpCommand extends Command<number, number> {
7
+ constructor(
8
+ op: "and" | "or" | "xor",
9
+ destinationKey: string,
10
+ sourceKey: string,
11
+ ...sourceKeys: string[]
12
+ )
13
+ constructor(op: "not", destinationKey: string, sourceKey: string)
14
+ constructor(
15
+ op: "and" | "or" | "xor" | "not",
16
+ destinationKey: string,
17
+ sourceKey: string,
18
+ ...sourceKeys: string[]
19
+ ) {
20
+ super(["bitop", op, destinationKey, sourceKey, ...sourceKeys])
21
+ }
22
+ }
@@ -0,0 +1,26 @@
1
+ import { BitPosCommand } from "./bitpos"
2
+ import { keygen, newHttpClient } from "../test-utils"
3
+ import { describe, it, expect, afterAll } from "@jest/globals"
4
+ import { SetCommand } from "./set"
5
+ const client = newHttpClient()
6
+
7
+ const { newKey, cleanup } = keygen()
8
+ afterAll(cleanup)
9
+
10
+ describe("when key is not set", () => {
11
+ it("returns 0", async () => {
12
+ const key = newKey()
13
+ const res = await new BitPosCommand(key, 1, 1).exec(client)
14
+ expect(res).toEqual(-1)
15
+ })
16
+ })
17
+
18
+ describe("when key is set", () => {
19
+ it("returns position of first set bit", async () => {
20
+ const key = newKey()
21
+ const value = "Hello World"
22
+ await new SetCommand(key, value).exec(client)
23
+ const res = await new BitPosCommand(key, 2, 3).exec(client)
24
+ expect(res).toEqual(24)
25
+ })
26
+ })
@@ -0,0 +1,10 @@
1
+ import { Command } from "../command"
2
+
3
+ /**
4
+ * @see https://redis.io/commands/bitpos
5
+ */
6
+ export class BitPosCommand extends Command<number, number> {
7
+ constructor(key: string, start: number, end: number) {
8
+ super(["bitpos", key, start, end])
9
+ }
10
+ }
@@ -0,0 +1,17 @@
1
+ import { keygen, newHttpClient } from "../test-utils"
2
+ import { randomUUID } from "crypto"
3
+ import { it, expect, afterAll } from "@jest/globals"
4
+ import { SetCommand } from "./set"
5
+ import { DBSizeCommand } from "./dbsize"
6
+ const client = newHttpClient()
7
+
8
+ const { newKey, cleanup } = keygen()
9
+ afterAll(cleanup)
10
+
11
+ it("returns the db size", async () => {
12
+ const key = newKey()
13
+ const value = randomUUID()
14
+ await new SetCommand(key, value).exec(client)
15
+ const res = await new DBSizeCommand().exec(client)
16
+ expect(res).toBeGreaterThan(0)
17
+ })
@@ -0,0 +1,10 @@
1
+ import { Command } from "../command"
2
+
3
+ /**
4
+ * @see https://redis.io/commands/dbsize
5
+ */
6
+ export class DBSizeCommand extends Command<number, number> {
7
+ constructor() {
8
+ super(["dbsize"])
9
+ }
10
+ }
@@ -0,0 +1,22 @@
1
+ import { keygen, newHttpClient } from "../test-utils"
2
+ import { it, expect, afterAll } from "@jest/globals"
3
+ import { SetCommand } from "./set"
4
+ import { DecrCommand } from "./decr"
5
+ const client = newHttpClient()
6
+
7
+ const { newKey, cleanup } = keygen()
8
+ afterAll(cleanup)
9
+ it("decrements a non-existing value", async () => {
10
+ const key = newKey()
11
+ const res = await new DecrCommand(key).exec(client)
12
+
13
+ expect(res).toEqual(-1)
14
+ })
15
+
16
+ it("decrements and existing value", async () => {
17
+ const key = newKey()
18
+ await new SetCommand(key, 4).exec(client)
19
+ const res = await new DecrCommand(key).exec(client)
20
+
21
+ expect(res).toEqual(3)
22
+ })
@@ -0,0 +1,10 @@
1
+ import { Command } from "../command"
2
+
3
+ /**
4
+ * @see https://redis.io/commands/decr
5
+ */
6
+ export class DecrCommand extends Command<number, number> {
7
+ constructor(key: string) {
8
+ super(["decr", key])
9
+ }
10
+ }
@@ -0,0 +1,23 @@
1
+ import { keygen, newHttpClient } from "../test-utils"
2
+ import { SetCommand } from "./set"
3
+ import { DecrByCommand } from "./decrby"
4
+ import { it, expect, afterAll } from "@jest/globals"
5
+ const client = newHttpClient()
6
+
7
+ const { newKey, cleanup } = keygen()
8
+ afterAll(cleanup)
9
+
10
+ it("decrements a non-existing value", async () => {
11
+ const key = newKey()
12
+ const res = await new DecrByCommand(key, 2).exec(client)
13
+
14
+ expect(res).toEqual(-2)
15
+ })
16
+
17
+ it("decrements and existing value", async () => {
18
+ const key = newKey()
19
+ await new SetCommand(key, 5).exec(client)
20
+ const res = await new DecrByCommand(key, 2).exec(client)
21
+
22
+ expect(res).toEqual(3)
23
+ })