@encore.dev/sdk 2.0.0-beta.7 → 2.0.0-beta.9

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 (424) hide show
  1. package/README.md +109 -0
  2. package/app_meta.test.ts +25 -5
  3. package/app_meta.ts +51 -12
  4. package/config/config.test.ts +18 -15
  5. package/config/config.ts +89 -31
  6. package/config/mod.ts +4 -3
  7. package/config/secrets.ts +79 -53
  8. package/config/value.ts +13 -17
  9. package/cron/mod.test.ts +52 -0
  10. package/cron/mod.ts +41 -2
  11. package/dist/app_meta.d.ts +44 -12
  12. package/dist/app_meta.d.ts.map +1 -0
  13. package/dist/app_meta.js +2 -0
  14. package/dist/app_meta.js.map +1 -1
  15. package/dist/config/config.d.ts +58 -28
  16. package/dist/config/config.d.ts.map +1 -0
  17. package/dist/config/config.js +46 -18
  18. package/dist/config/config.js.map +1 -1
  19. package/dist/config/mod.d.ts +5 -4
  20. package/dist/config/mod.d.ts.map +1 -0
  21. package/dist/config/mod.js +2 -2
  22. package/dist/config/mod.js.map +1 -1
  23. package/dist/config/secrets.d.ts +71 -39
  24. package/dist/config/secrets.d.ts.map +1 -0
  25. package/dist/config/secrets.js +31 -38
  26. package/dist/config/secrets.js.map +1 -1
  27. package/dist/config/value.d.ts +8 -5
  28. package/dist/config/value.d.ts.map +1 -0
  29. package/dist/config/value.js +10 -7
  30. package/dist/config/value.js.map +1 -1
  31. package/dist/cron/mod.d.ts +36 -1
  32. package/dist/cron/mod.d.ts.map +1 -0
  33. package/dist/cron/mod.js +31 -1
  34. package/dist/cron/mod.js.map +1 -1
  35. package/dist/frontends/mod.d.ts +39 -0
  36. package/dist/frontends/mod.d.ts.map +1 -0
  37. package/dist/frontends/mod.js +47 -0
  38. package/dist/frontends/mod.js.map +1 -0
  39. package/dist/gateway/errors.d.ts +101 -0
  40. package/dist/gateway/errors.d.ts.map +1 -0
  41. package/dist/gateway/errors.js +146 -0
  42. package/dist/gateway/errors.js.map +1 -0
  43. package/dist/gateway/match.d.ts +127 -0
  44. package/dist/gateway/match.d.ts.map +1 -0
  45. package/dist/gateway/match.js +206 -0
  46. package/dist/gateway/match.js.map +1 -0
  47. package/dist/gateway/middleware.d.ts +108 -0
  48. package/dist/gateway/middleware.d.ts.map +1 -0
  49. package/dist/gateway/middleware.js +9 -0
  50. package/dist/gateway/middleware.js.map +1 -0
  51. package/dist/gateway/mod.d.ts +130 -0
  52. package/dist/gateway/mod.d.ts.map +1 -0
  53. package/dist/gateway/mod.js +188 -0
  54. package/dist/gateway/mod.js.map +1 -0
  55. package/dist/gateway/request.d.ts +304 -0
  56. package/dist/gateway/request.d.ts.map +1 -0
  57. package/dist/gateway/request.js +403 -0
  58. package/dist/gateway/request.js.map +1 -0
  59. package/dist/gateway/serve.d.ts +114 -0
  60. package/dist/gateway/serve.d.ts.map +1 -0
  61. package/dist/gateway/serve.js +510 -0
  62. package/dist/gateway/serve.js.map +1 -0
  63. package/dist/gateways/mod.d.ts +42 -0
  64. package/dist/gateways/mod.d.ts.map +1 -0
  65. package/dist/gateways/mod.js +55 -0
  66. package/dist/gateways/mod.js.map +1 -0
  67. package/dist/internal/clients/call.d.ts +147 -0
  68. package/dist/internal/clients/call.d.ts.map +1 -0
  69. package/dist/internal/clients/call.js +274 -0
  70. package/dist/internal/clients/call.js.map +1 -0
  71. package/dist/internal/clients/grpc.d.ts +90 -0
  72. package/dist/internal/clients/grpc.d.ts.map +1 -0
  73. package/dist/internal/clients/grpc.js +355 -0
  74. package/dist/internal/clients/grpc.js.map +1 -0
  75. package/dist/internal/clients/mod.d.ts +81 -0
  76. package/dist/internal/clients/mod.d.ts.map +1 -0
  77. package/dist/internal/clients/mod.js +237 -0
  78. package/dist/internal/clients/mod.js.map +1 -0
  79. package/dist/internal/fetch.d.ts +58 -0
  80. package/dist/internal/fetch.d.ts.map +1 -0
  81. package/dist/internal/fetch.js +251 -0
  82. package/dist/internal/fetch.js.map +1 -0
  83. package/dist/internal/otel/backend.d.ts +2 -0
  84. package/dist/internal/otel/backend.d.ts.map +1 -0
  85. package/dist/internal/otel/context.d.ts +1 -0
  86. package/dist/internal/otel/context.d.ts.map +1 -0
  87. package/dist/internal/otel/context_manager.d.ts +1 -0
  88. package/dist/internal/otel/context_manager.d.ts.map +1 -0
  89. package/dist/internal/otel/encode.d.ts +2 -0
  90. package/dist/internal/otel/encode.d.ts.map +1 -0
  91. package/dist/internal/otel/http.d.ts +11 -0
  92. package/dist/internal/otel/http.d.ts.map +1 -0
  93. package/dist/internal/otel/http.js +64 -0
  94. package/dist/internal/otel/http.js.map +1 -0
  95. package/dist/internal/otel/index.d.ts +2 -2
  96. package/dist/internal/otel/index.d.ts.map +1 -0
  97. package/dist/internal/otel/index.js +1 -2
  98. package/dist/internal/otel/index.js.map +1 -1
  99. package/dist/internal/otel/meter.d.ts +1 -0
  100. package/dist/internal/otel/meter.d.ts.map +1 -0
  101. package/dist/internal/otel/propagator.d.ts +1 -0
  102. package/dist/internal/otel/propagator.d.ts.map +1 -0
  103. package/dist/internal/otel/provider.d.ts +4 -0
  104. package/dist/internal/otel/provider.d.ts.map +1 -0
  105. package/dist/internal/otel/provider.js +3 -0
  106. package/dist/internal/otel/provider.js.map +1 -1
  107. package/dist/internal/otel/span.d.ts +15 -1
  108. package/dist/internal/otel/span.d.ts.map +1 -0
  109. package/dist/internal/otel/span.js +30 -2
  110. package/dist/internal/otel/span.js.map +1 -1
  111. package/dist/internal/otel/tracer.d.ts +1 -0
  112. package/dist/internal/otel/tracer.d.ts.map +1 -0
  113. package/dist/internal/otel/tracer.js +11 -5
  114. package/dist/internal/otel/tracer.js.map +1 -1
  115. package/dist/internal/reqfields.d.ts +170 -0
  116. package/dist/internal/reqfields.d.ts.map +1 -0
  117. package/dist/internal/reqfields.js +349 -0
  118. package/dist/internal/reqfields.js.map +1 -0
  119. package/dist/internal/runtime/meter.d.ts +1 -0
  120. package/dist/internal/runtime/meter.d.ts.map +1 -0
  121. package/dist/internal/runtime/mod.d.ts +6 -0
  122. package/dist/internal/runtime/mod.d.ts.map +1 -0
  123. package/dist/internal/runtime/mod.js +32 -2
  124. package/dist/internal/runtime/mod.js.map +1 -1
  125. package/dist/internal/runtime/napi/napi.cjs +192 -16
  126. package/dist/internal/runtime/napi/napi.d.cts +573 -33
  127. package/dist/internal/runtime/shutdown.d.ts +5 -0
  128. package/dist/internal/runtime/shutdown.d.ts.map +1 -0
  129. package/dist/internal/runtime/shutdown.js +9 -1
  130. package/dist/internal/runtime/shutdown.js.map +1 -1
  131. package/dist/internal/testing/carry.d.ts +49 -0
  132. package/dist/internal/testing/carry.d.ts.map +1 -0
  133. package/dist/internal/testing/carry.js +77 -0
  134. package/dist/internal/testing/carry.js.map +1 -0
  135. package/dist/internal/testing/runner.d.ts +2 -0
  136. package/dist/internal/testing/runner.d.ts.map +1 -0
  137. package/dist/internal/testing/runner.js +10 -0
  138. package/dist/internal/testing/runner.js.map +1 -0
  139. package/dist/internal/testing/scope.d.ts +109 -0
  140. package/dist/internal/testing/scope.d.ts.map +1 -0
  141. package/dist/internal/testing/scope.js +335 -0
  142. package/dist/internal/testing/scope.js.map +1 -0
  143. package/dist/internal/testing/steps.d.ts +55 -0
  144. package/dist/internal/testing/steps.d.ts.map +1 -0
  145. package/dist/internal/testing/steps.js +295 -0
  146. package/dist/internal/testing/steps.js.map +1 -0
  147. package/dist/internal/testing/telemetry.d.ts +305 -0
  148. package/dist/internal/testing/telemetry.d.ts.map +1 -0
  149. package/dist/internal/testing/telemetry.js +188 -0
  150. package/dist/internal/testing/telemetry.js.map +1 -0
  151. package/dist/internal/utils/constraints.d.ts +1 -0
  152. package/dist/internal/utils/constraints.d.ts.map +1 -0
  153. package/dist/log/index.d.ts +1 -0
  154. package/dist/log/index.d.ts.map +1 -0
  155. package/dist/log/logger.d.ts +2 -0
  156. package/dist/log/logger.d.ts.map +1 -0
  157. package/dist/log/runtime.d.ts +2 -0
  158. package/dist/log/runtime.d.ts.map +1 -0
  159. package/dist/log/stderr.d.ts +1 -0
  160. package/dist/log/stderr.d.ts.map +1 -0
  161. package/dist/metrics/mod.d.ts +45 -118
  162. package/dist/metrics/mod.d.ts.map +1 -0
  163. package/dist/metrics/mod.js +44 -179
  164. package/dist/metrics/mod.js.map +1 -1
  165. package/dist/mod.d.ts +2 -3
  166. package/dist/mod.d.ts.map +1 -0
  167. package/dist/mod.js +0 -1
  168. package/dist/mod.js.map +1 -1
  169. package/dist/otel.d.ts +1 -0
  170. package/dist/otel.d.ts.map +1 -0
  171. package/dist/pubsub/encoding.d.ts +5 -0
  172. package/dist/pubsub/encoding.d.ts.map +1 -0
  173. package/dist/pubsub/encoding.js +10 -2
  174. package/dist/pubsub/encoding.js.map +1 -1
  175. package/dist/pubsub/mod.d.ts +5 -4
  176. package/dist/pubsub/mod.d.ts.map +1 -0
  177. package/dist/pubsub/mod.js +2 -2
  178. package/dist/pubsub/mod.js.map +1 -1
  179. package/dist/pubsub/refs.d.ts +8 -0
  180. package/dist/pubsub/refs.d.ts.map +1 -0
  181. package/dist/pubsub/refs.js.map +1 -1
  182. package/dist/pubsub/subscription.d.ts +110 -15
  183. package/dist/pubsub/subscription.d.ts.map +1 -0
  184. package/dist/pubsub/subscription.js +98 -16
  185. package/dist/pubsub/subscription.js.map +1 -1
  186. package/dist/pubsub/topic.d.ts +101 -31
  187. package/dist/pubsub/topic.d.ts.map +1 -0
  188. package/dist/pubsub/topic.js +168 -51
  189. package/dist/pubsub/topic.js.map +1 -1
  190. package/dist/reqctx/mod.d.ts +174 -0
  191. package/dist/reqctx/mod.d.ts.map +1 -0
  192. package/dist/reqctx/mod.js +144 -0
  193. package/dist/reqctx/mod.js.map +1 -0
  194. package/dist/services/index.d.ts +147 -5
  195. package/dist/services/index.d.ts.map +1 -0
  196. package/dist/services/index.js +157 -9
  197. package/dist/services/index.js.map +1 -1
  198. package/dist/shutdown/mod.d.ts +1 -0
  199. package/dist/shutdown/mod.d.ts.map +1 -0
  200. package/dist/storage/objects/bucket.d.ts +313 -7
  201. package/dist/storage/objects/bucket.d.ts.map +1 -0
  202. package/dist/storage/objects/bucket.js +306 -15
  203. package/dist/storage/objects/bucket.js.map +1 -1
  204. package/dist/storage/objects/error.d.ts +10 -0
  205. package/dist/storage/objects/error.d.ts.map +1 -0
  206. package/dist/storage/objects/error.js +25 -1
  207. package/dist/storage/objects/error.js.map +1 -1
  208. package/dist/storage/objects/mod.d.ts +4 -3
  209. package/dist/storage/objects/mod.d.ts.map +1 -0
  210. package/dist/storage/objects/mod.js +1 -1
  211. package/dist/storage/objects/mod.js.map +1 -1
  212. package/dist/storage/objects/refs.d.ts +20 -4
  213. package/dist/storage/objects/refs.d.ts.map +1 -0
  214. package/dist/storage/objects/refs.js +6 -0
  215. package/dist/storage/objects/refs.js.map +1 -1
  216. package/dist/storage/postgres/database.d.ts +85 -25
  217. package/dist/storage/postgres/database.d.ts.map +1 -0
  218. package/dist/storage/postgres/database.js +129 -37
  219. package/dist/storage/postgres/database.js.map +1 -1
  220. package/dist/storage/postgres/errors.d.ts +120 -0
  221. package/dist/storage/postgres/errors.d.ts.map +1 -0
  222. package/dist/storage/postgres/errors.js +162 -0
  223. package/dist/storage/postgres/errors.js.map +1 -0
  224. package/dist/storage/postgres/interval.d.ts +44 -0
  225. package/dist/storage/postgres/interval.d.ts.map +1 -0
  226. package/dist/storage/postgres/interval.js +153 -0
  227. package/dist/storage/postgres/interval.js.map +1 -0
  228. package/dist/storage/postgres/mod.d.ts +4 -1
  229. package/dist/storage/postgres/mod.d.ts.map +1 -0
  230. package/dist/storage/postgres/mod.js +2 -0
  231. package/dist/storage/postgres/mod.js.map +1 -1
  232. package/dist/storage/redis/bitfield.d.ts +67 -0
  233. package/dist/storage/redis/bitfield.d.ts.map +1 -0
  234. package/dist/storage/redis/bitfield.js +114 -0
  235. package/dist/storage/redis/bitfield.js.map +1 -0
  236. package/dist/storage/redis/command.d.ts +45 -0
  237. package/dist/storage/redis/command.d.ts.map +1 -0
  238. package/dist/storage/redis/command.js +78 -0
  239. package/dist/storage/redis/command.js.map +1 -0
  240. package/dist/storage/redis/commands.d.ts +223 -139
  241. package/dist/storage/redis/commands.d.ts.map +1 -0
  242. package/dist/storage/redis/commands.js +128 -6
  243. package/dist/storage/redis/commands.js.map +1 -1
  244. package/dist/storage/redis/database.d.ts +56 -22
  245. package/dist/storage/redis/database.d.ts.map +1 -0
  246. package/dist/storage/redis/database.js +62 -0
  247. package/dist/storage/redis/database.js.map +1 -1
  248. package/dist/storage/redis/mod.d.ts +31 -4
  249. package/dist/storage/redis/mod.d.ts.map +1 -0
  250. package/dist/storage/redis/mod.js +26 -1
  251. package/dist/storage/redis/mod.js.map +1 -1
  252. package/dist/storage/redis/native.d.ts +8 -0
  253. package/dist/storage/redis/native.d.ts.map +1 -0
  254. package/dist/storage/redis/native.js +10 -0
  255. package/dist/storage/redis/native.js.map +1 -1
  256. package/dist/storage/redis/options.d.ts +1 -0
  257. package/dist/storage/redis/options.d.ts.map +1 -0
  258. package/dist/storage/redis/pubsub.d.ts +2 -0
  259. package/dist/storage/redis/pubsub.d.ts.map +1 -0
  260. package/dist/storage/redis/reply.d.ts +34 -0
  261. package/dist/storage/redis/reply.d.ts.map +1 -0
  262. package/dist/storage/redis/reply.js +40 -1
  263. package/dist/storage/redis/reply.js.map +1 -1
  264. package/dist/storage/redis/scan.d.ts +1 -0
  265. package/dist/storage/redis/scan.d.ts.map +1 -0
  266. package/dist/storage/redis/script.d.ts +1 -0
  267. package/dist/storage/redis/script.d.ts.map +1 -0
  268. package/dist/storage/redis/target.d.ts +5 -3
  269. package/dist/storage/redis/target.d.ts.map +1 -0
  270. package/dist/storage/redis/target.js +39 -28
  271. package/dist/storage/redis/target.js.map +1 -1
  272. package/dist/storage/redis/wire.d.ts +7 -10
  273. package/dist/storage/redis/wire.d.ts.map +1 -0
  274. package/dist/storage/redis/wire.js +8 -32
  275. package/dist/storage/redis/wire.js.map +1 -1
  276. package/dist/testing/bun.d.ts +8 -0
  277. package/dist/testing/bun.d.ts.map +1 -0
  278. package/dist/testing/bun.js +13 -0
  279. package/dist/testing/bun.js.map +1 -0
  280. package/dist/testing/jest.d.ts +8 -0
  281. package/dist/testing/jest.d.ts.map +1 -0
  282. package/dist/testing/jest.js +11 -0
  283. package/dist/testing/jest.js.map +1 -0
  284. package/dist/testing/mod.d.ts +183 -0
  285. package/dist/testing/mod.d.ts.map +1 -0
  286. package/dist/testing/mod.js +271 -0
  287. package/dist/testing/mod.js.map +1 -0
  288. package/dist/testing/node.d.ts +9 -0
  289. package/dist/testing/node.d.ts.map +1 -0
  290. package/dist/testing/node.js +12 -0
  291. package/dist/testing/node.js.map +1 -0
  292. package/dist/testing/playwright.d.ts +93 -0
  293. package/dist/testing/playwright.d.ts.map +1 -0
  294. package/dist/testing/playwright.js +164 -0
  295. package/dist/testing/playwright.js.map +1 -0
  296. package/dist/testing/puppeteer.d.ts +36 -0
  297. package/dist/testing/puppeteer.d.ts.map +1 -0
  298. package/dist/testing/puppeteer.js +70 -0
  299. package/dist/testing/puppeteer.js.map +1 -0
  300. package/dist/testing/system.d.ts +181 -0
  301. package/dist/testing/system.d.ts.map +1 -0
  302. package/dist/testing/system.js +255 -0
  303. package/dist/testing/system.js.map +1 -0
  304. package/dist/testing/vitest.d.ts +8 -0
  305. package/dist/testing/vitest.d.ts.map +1 -0
  306. package/dist/testing/vitest.js +13 -0
  307. package/dist/testing/vitest.js.map +1 -0
  308. package/dist/tracing/http.d.ts +11 -0
  309. package/dist/tracing/http.d.ts.map +1 -0
  310. package/dist/tracing/http.js +34 -0
  311. package/dist/tracing/http.js.map +1 -0
  312. package/dist/tracing/mod.d.ts +20 -0
  313. package/dist/tracing/mod.d.ts.map +1 -0
  314. package/dist/tracing/mod.js +47 -0
  315. package/dist/tracing/mod.js.map +1 -0
  316. package/dist/tracing/node.d.ts +10 -0
  317. package/dist/tracing/node.d.ts.map +1 -0
  318. package/dist/tracing/node.js +142 -0
  319. package/dist/tracing/node.js.map +1 -0
  320. package/dist/tsconfig.build.tsbuildinfo +1 -1
  321. package/dist/types/mod.d.ts +1 -0
  322. package/dist/types/mod.d.ts.map +1 -0
  323. package/frontends/mod.test.ts +51 -0
  324. package/frontends/mod.ts +50 -0
  325. package/gateway/errors.ts +172 -0
  326. package/gateway/gateway.e2e.test.ts +297 -0
  327. package/gateway/gateway.test.ts +891 -0
  328. package/gateway/match.ts +239 -0
  329. package/gateway/middleware.ts +134 -0
  330. package/gateway/mod.ts +211 -0
  331. package/gateway/request.ts +578 -0
  332. package/gateway/serve.ts +738 -0
  333. package/gateways/mod.ts +60 -0
  334. package/internal/clients/call.ts +389 -0
  335. package/internal/clients/grpc.test.ts +368 -0
  336. package/internal/clients/grpc.ts +485 -0
  337. package/internal/clients/mod.test.ts +464 -0
  338. package/internal/clients/mod.ts +337 -0
  339. package/internal/fetch.ts +287 -0
  340. package/internal/otel/http.ts +91 -0
  341. package/internal/otel/index.ts +1 -7
  342. package/internal/otel/provider.ts +3 -0
  343. package/internal/otel/span.ts +31 -2
  344. package/internal/otel/tracer.test.ts +43 -15
  345. package/internal/otel/tracer.ts +12 -5
  346. package/internal/reqfields.ts +423 -0
  347. package/internal/runtime/mod.ts +41 -2
  348. package/internal/runtime/napi/napi.cjs +192 -16
  349. package/internal/runtime/napi/napi.d.cts +573 -33
  350. package/internal/runtime/shutdown.ts +11 -1
  351. package/internal/testing/carry.test.ts +242 -0
  352. package/internal/testing/carry.ts +101 -0
  353. package/internal/testing/runner.ts +10 -0
  354. package/internal/testing/scope.ts +372 -0
  355. package/internal/testing/steps.test.ts +152 -0
  356. package/internal/testing/steps.ts +342 -0
  357. package/internal/testing/telemetry.test.ts +210 -0
  358. package/internal/testing/telemetry.ts +466 -0
  359. package/metrics/mod.test.ts +13 -16
  360. package/metrics/mod.ts +57 -226
  361. package/mod.ts +1 -8
  362. package/otel.test.ts +13 -6
  363. package/package.json +92 -15
  364. package/pubsub/encoding.ts +11 -1
  365. package/pubsub/mod.ts +16 -4
  366. package/pubsub/pubsub.test.ts +233 -14
  367. package/pubsub/refs.ts +16 -0
  368. package/pubsub/subscription.ts +200 -21
  369. package/pubsub/topic.test.ts +26 -0
  370. package/pubsub/topic.ts +255 -36
  371. package/reqctx/mod.ts +267 -0
  372. package/reqctx/reqctx.test.ts +216 -0
  373. package/scripts/postprocess-docs.test.ts +58 -0
  374. package/services/index.test.ts +341 -1
  375. package/services/index.ts +185 -9
  376. package/storage/objects/bucket.test.ts +573 -0
  377. package/storage/objects/bucket.ts +650 -20
  378. package/storage/objects/error.ts +28 -1
  379. package/storage/objects/mod.ts +15 -0
  380. package/storage/objects/refs.ts +51 -3
  381. package/storage/postgres/database.integration.test.ts +275 -0
  382. package/storage/postgres/database.test.ts +193 -6
  383. package/storage/postgres/database.ts +206 -55
  384. package/storage/postgres/errors.ts +186 -0
  385. package/storage/postgres/interval.test.ts +72 -0
  386. package/storage/postgres/interval.ts +170 -0
  387. package/storage/postgres/mod.ts +4 -0
  388. package/storage/redis/bitfield.ts +162 -0
  389. package/storage/redis/command.ts +84 -0
  390. package/storage/redis/commands.ts +271 -21
  391. package/storage/redis/database.ts +77 -23
  392. package/storage/redis/mod.ts +38 -2
  393. package/storage/redis/native.ts +11 -0
  394. package/storage/redis/redis.test.ts +170 -10
  395. package/storage/redis/reply.ts +76 -1
  396. package/storage/redis/runtime.test.ts +15 -0
  397. package/storage/redis/target.ts +47 -44
  398. package/storage/redis/wire.ts +8 -32
  399. package/testing/bun.ts +13 -0
  400. package/testing/jest.ts +11 -0
  401. package/testing/mod.ts +393 -0
  402. package/testing/node.ts +12 -0
  403. package/testing/playwright.ts +247 -0
  404. package/testing/puppeteer.ts +101 -0
  405. package/testing/system.test.ts +108 -0
  406. package/testing/system.ts +373 -0
  407. package/testing/vitest.ts +13 -0
  408. package/tracing/http.ts +49 -0
  409. package/tracing/mod.ts +83 -0
  410. package/tracing/native.test.ts +267 -0
  411. package/tracing/node.ts +176 -0
  412. package/tracing/tracing.test.ts +953 -0
  413. package/dist/internal/otel/request_context.d.ts +0 -11
  414. package/dist/internal/otel/request_context.js +0 -20
  415. package/dist/internal/otel/request_context.js.map +0 -1
  416. package/dist/internal/reqtrack/mod.d.ts +0 -6
  417. package/dist/internal/reqtrack/mod.js +0 -28
  418. package/dist/internal/reqtrack/mod.js.map +0 -1
  419. package/dist/req_meta.d.ts +0 -47
  420. package/dist/req_meta.js +0 -26
  421. package/dist/req_meta.js.map +0 -1
  422. package/internal/otel/request_context.ts +0 -32
  423. package/internal/reqtrack/mod.ts +0 -39
  424. package/req_meta.ts +0 -75
@@ -32,6 +32,12 @@ import {
32
32
  type StreamMaxlen,
33
33
  type Unit,
34
34
  } from './options';
35
+ import {
36
+ Bitfield,
37
+ BitfieldRo,
38
+ QueuedBitfield,
39
+ QueuedBitfieldRo,
40
+ } from './bitfield';
35
41
  import {as, Reply, ReplyPromise} from './reply';
36
42
  import {scanFields, scanKeys, scanMembers, scanScored} from './scan';
37
43
  import {subscribe, type Subscription} from './pubsub';
@@ -41,13 +47,35 @@ import {Cmd, type Pairs, type RedisArg, type Value} from './wire';
41
47
  /** A score bound: a number, `"-inf"` or `"+inf"`, or exclusive as `"(1.5"`. */
42
48
  export type ScoreBound = number | string;
43
49
 
44
- /** A command: whether it writes, how it is built, and what its reply is read as. */
45
- interface CommandDef<A extends unknown[], R, W extends boolean> {
50
+ /**
51
+ * A command: whether it writes, whether it blocks, how it is built, and what
52
+ * its reply is read as. A command that blocks waits for something to pop, on
53
+ * a connection of its own, and has no queued form: it would hold up the
54
+ * batch's connection.
55
+ */
56
+ interface CommandDef<
57
+ A extends unknown[],
58
+ R,
59
+ W extends boolean,
60
+ B extends boolean = boolean,
61
+ > {
46
62
  readonly write: W;
63
+ readonly blocking: B;
47
64
  readonly build: (...args: A) => Cmd;
48
65
  readonly reply: (v: Value) => R;
49
66
  }
50
67
 
68
+ /**
69
+ * A command built up by the caller before it runs, `bitfield`'s: what `start`
70
+ * makes of it to run now, and what `queued` makes of it to queue.
71
+ */
72
+ interface BuilderDef<A extends unknown[], R, Q, W extends boolean> {
73
+ readonly write: W;
74
+ readonly build: (...args: A) => Cmd;
75
+ readonly start: (t: Target, c: Cmd) => R;
76
+ readonly queued: (queue: Cmd[], c: Cmd) => Q;
77
+ }
78
+
51
79
  /**
52
80
  * What runs now and is no command of its own to queue: a scan, which returns
53
81
  * an iteration, and a subscription.
@@ -61,16 +89,50 @@ interface RunDef<A extends unknown[], R, W extends boolean> {
61
89
  function read<A extends unknown[], R>(
62
90
  build: (...args: A) => Cmd,
63
91
  reply: (v: Value) => R,
64
- ): CommandDef<A, R, false> {
65
- return {write: false, build, reply};
92
+ ): CommandDef<A, R, false, false> {
93
+ return {write: false, blocking: false, build, reply};
66
94
  }
67
95
 
68
96
  /** A command that writes. */
69
97
  function write<A extends unknown[], R>(
70
98
  build: (...args: A) => Cmd,
71
99
  reply: (v: Value) => R,
72
- ): CommandDef<A, R, true> {
73
- return {write: true, build, reply};
100
+ ): CommandDef<A, R, true, false> {
101
+ return {write: true, blocking: false, build, reply};
102
+ }
103
+
104
+ /** A command that only reads, and blocks. */
105
+ function readBlocking<A extends unknown[], R>(
106
+ build: (...args: A) => Cmd,
107
+ reply: (v: Value) => R,
108
+ ): CommandDef<A, R, false, true> {
109
+ return {write: false, blocking: true, build, reply};
110
+ }
111
+
112
+ /** A command that writes, and blocks. */
113
+ function writeBlocking<A extends unknown[], R>(
114
+ build: (...args: A) => Cmd,
115
+ reply: (v: Value) => R,
116
+ ): CommandDef<A, R, true, true> {
117
+ return {write: true, blocking: true, build, reply};
118
+ }
119
+
120
+ /** A command built up by the caller that only reads. */
121
+ function readBuilder<A extends unknown[], R, Q>(
122
+ build: (...args: A) => Cmd,
123
+ start: (t: Target, c: Cmd) => R,
124
+ queued: (queue: Cmd[], c: Cmd) => Q,
125
+ ): BuilderDef<A, R, Q, false> {
126
+ return {write: false, build, start, queued};
127
+ }
128
+
129
+ /** A command built up by the caller that writes. */
130
+ function writeBuilder<A extends unknown[], R, Q>(
131
+ build: (...args: A) => Cmd,
132
+ start: (t: Target, c: Cmd) => R,
133
+ queued: (queue: Cmd[], c: Cmd) => Q,
134
+ ): BuilderDef<A, R, Q, true> {
135
+ return {write: true, build, start, queued};
74
136
  }
75
137
 
76
138
  /** What runs now and only reads. */
@@ -91,6 +153,10 @@ function cmd(name: string): Cmd {
91
153
  /** A bit as Redis takes one. */
92
154
  const bitArg = (b: boolean) => (b ? 1 : 0);
93
155
 
156
+ /** One key, or several. */
157
+ const keyList = (keys: string | string[]): string[] =>
158
+ typeof keys === 'string' ? [keys] : keys;
159
+
94
160
  const generic = {
95
161
  /** Whether the key exists. */
96
162
  exists: read((key: string) => cmd('EXISTS').key(key), as.bool),
@@ -327,6 +393,21 @@ const bitmap = {
327
393
  cmd('BITOP').arg('NOT').key(destination).key(source),
328
394
  as.number,
329
395
  ),
396
+ /**
397
+ * Integers of any width up to 64 bits, read and written at any bit offset of
398
+ * the string: add the operations, then {@link Bitfield.invoke}.
399
+ */
400
+ bitfield: writeBuilder(
401
+ (key: string) => cmd('BITFIELD').key(key),
402
+ (t, c) => new Bitfield(t, c),
403
+ (queue, c) => new QueuedBitfield(queue, c),
404
+ ),
405
+ /** {@link Bitfield} that only reads (`BITFIELD_RO`). */
406
+ bitfieldRo: readBuilder(
407
+ (key: string) => cmd('BITFIELD_RO').key(key),
408
+ (t, c) => new BitfieldRo(t, c),
409
+ (queue, c) => new QueuedBitfieldRo(queue, c),
410
+ ),
330
411
  };
331
412
 
332
413
  const hash = {
@@ -521,6 +602,58 @@ const list = {
521
602
  .arg(directionArg(to)),
522
603
  as.reply,
523
604
  ),
605
+
606
+ /**
607
+ * Removes and returns the first element of the first of `keys` that has
608
+ * one, with its key, waiting up to `timeout` seconds for one to be pushed:
609
+ * 0 waits for ever. `null` once the timeout passes.
610
+ */
611
+ blpop: writeBlocking(
612
+ (keys: string | string[], timeout: number) =>
613
+ cmd('BLPOP').keys(keyList(keys)).arg(timeout),
614
+ as.popped,
615
+ ),
616
+ /** `blpop`, from the end of the list. */
617
+ brpop: writeBlocking(
618
+ (keys: string | string[], timeout: number) =>
619
+ cmd('BRPOP').keys(keyList(keys)).arg(timeout),
620
+ as.popped,
621
+ ),
622
+ /**
623
+ * `lmove`, waiting up to `timeout` seconds for `source`
624
+ * to have an element: 0 waits for ever. A nil reply once the timeout passes.
625
+ */
626
+ blmove: writeBlocking(
627
+ (
628
+ source: string,
629
+ destination: string,
630
+ from: Direction,
631
+ to: Direction,
632
+ timeout: number,
633
+ ) =>
634
+ cmd('BLMOVE')
635
+ .key(source)
636
+ .key(destination)
637
+ .arg(directionArg(from))
638
+ .arg(directionArg(to))
639
+ .arg(timeout),
640
+ as.reply,
641
+ ),
642
+ /**
643
+ * Removes and returns up to `count` elements from one end of the first of
644
+ * `keys` that has any, with its key, waiting up to `timeout` seconds for
645
+ * one: 0 waits for ever. `null` once the timeout passes.
646
+ */
647
+ blmpop: writeBlocking(
648
+ (keys: string[], from: Direction, count: number, timeout: number) =>
649
+ cmd('BLMPOP')
650
+ .arg(timeout)
651
+ .numkeys(keys)
652
+ .arg(directionArg(from))
653
+ .arg('COUNT')
654
+ .arg(count),
655
+ as.poppedMany,
656
+ ),
524
657
  };
525
658
 
526
659
  const set = {
@@ -762,6 +895,39 @@ const sortedSet = {
762
895
  cmd('ZUNIONSTORE').key(destination).numkeys(keys),
763
896
  as.number,
764
897
  ),
898
+
899
+ /**
900
+ * Removes and returns the lowest scored member of the first of `keys` that
901
+ * has one, with its key and score, waiting up to `timeout` seconds for one
902
+ * to be added: 0 waits for ever. `null` once the timeout passes.
903
+ */
904
+ bzpopmin: writeBlocking(
905
+ (keys: string | string[], timeout: number) =>
906
+ cmd('BZPOPMIN').keys(keyList(keys)).arg(timeout),
907
+ as.poppedScored,
908
+ ),
909
+ /** `bzpopmin`, the highest scored member. */
910
+ bzpopmax: writeBlocking(
911
+ (keys: string | string[], timeout: number) =>
912
+ cmd('BZPOPMAX').keys(keyList(keys)).arg(timeout),
913
+ as.poppedScored,
914
+ ),
915
+ /**
916
+ * Removes and returns up to `count` of the lowest (`'min'`) or highest
917
+ * (`'max'`) scored members of the first of `keys` that has any, with its
918
+ * key and their scores, waiting up to `timeout` seconds for one: 0 waits
919
+ * for ever. `null` once the timeout passes.
920
+ */
921
+ bzmpop: writeBlocking(
922
+ (keys: string[], which: 'min' | 'max', count: number, timeout: number) =>
923
+ cmd('BZMPOP')
924
+ .arg(timeout)
925
+ .numkeys(keys)
926
+ .arg(which === 'max' ? 'MAX' : 'MIN')
927
+ .arg('COUNT')
928
+ .arg(count),
929
+ as.poppedScoredMany,
930
+ ),
765
931
  };
766
932
 
767
933
  const geo = {
@@ -875,7 +1041,7 @@ const stream = {
875
1041
  */
876
1042
  xread: read(
877
1043
  (keys: string[], ids: string[]) =>
878
- cmd('XREAD').arg('STREAMS').keys(keys).argsOf(ids).withReplyKeys(),
1044
+ cmd('XREAD').arg('STREAMS').keys(keys).argsOf(ids),
879
1045
  as.reply,
880
1046
  ),
881
1047
  /**
@@ -966,8 +1132,7 @@ const stream = {
966
1132
  .argsOf(count === undefined ? [] : ['COUNT', count])
967
1133
  .arg('STREAMS')
968
1134
  .keys(keys)
969
- .argsOf(ids)
970
- .withReplyKeys(),
1135
+ .argsOf(ids),
971
1136
  as.reply,
972
1137
  ),
973
1138
  /**
@@ -1019,6 +1184,70 @@ const stream = {
1019
1184
  .arg(start),
1020
1185
  as.reply,
1021
1186
  ),
1187
+
1188
+ /**
1189
+ * `xread`, waiting up to `blockMs` milliseconds for an
1190
+ * entry if there is none yet: 0 waits for ever. With a `count`, at most that
1191
+ * many per stream. A nil reply once the wait passes.
1192
+ */
1193
+ xreadBlock: readBlocking(
1194
+ (keys: string[], ids: string[], blockMs: number, count?: number) =>
1195
+ cmd('XREAD')
1196
+ .argsOf(count === undefined ? [] : ['COUNT', count])
1197
+ .arg('BLOCK')
1198
+ .arg(blockMs)
1199
+ .arg('STREAMS')
1200
+ .keys(keys)
1201
+ .argsOf(ids),
1202
+ as.reply,
1203
+ ),
1204
+ /**
1205
+ * `xreadGroup`, waiting up to `blockMs` milliseconds
1206
+ * for an entry if there is none yet: 0 waits for ever. A nil reply once the
1207
+ * wait passes.
1208
+ */
1209
+ xreadGroupBlock: writeBlocking(
1210
+ (
1211
+ group: string,
1212
+ consumer: string,
1213
+ keys: string[],
1214
+ ids: string[],
1215
+ blockMs: number,
1216
+ count?: number,
1217
+ ) =>
1218
+ cmd('XREADGROUP')
1219
+ .arg('GROUP')
1220
+ .arg(group)
1221
+ .arg(consumer)
1222
+ .argsOf(count === undefined ? [] : ['COUNT', count])
1223
+ .arg('BLOCK')
1224
+ .arg(blockMs)
1225
+ .arg('STREAMS')
1226
+ .keys(keys)
1227
+ .argsOf(ids),
1228
+ as.reply,
1229
+ ),
1230
+ };
1231
+
1232
+ const hyperloglog = {
1233
+ /**
1234
+ * The estimated number of distinct elements added to the keys, counted as
1235
+ * their union.
1236
+ */
1237
+ pfcount: read((...keys: string[]) => cmd('PFCOUNT').keys(keys), as.number),
1238
+
1239
+ /** Adds the elements, returning whether the estimate changed. */
1240
+ pfadd: write(
1241
+ (key: string, ...elements: RedisArg[]) =>
1242
+ cmd('PFADD').key(key).argsOf(elements),
1243
+ as.bool,
1244
+ ),
1245
+ /** Stores at `destination` the union of itself and the sources. */
1246
+ pfmerge: write(
1247
+ (destination: string, ...sources: string[]) =>
1248
+ cmd('PFMERGE').key(destination).keys(sources),
1249
+ as.none,
1250
+ ),
1022
1251
  };
1023
1252
 
1024
1253
  const pubsub = {
@@ -1059,6 +1288,7 @@ const groups = {
1059
1288
  sortedSet,
1060
1289
  geo,
1061
1290
  stream,
1291
+ hyperloglog,
1062
1292
  pubsub,
1063
1293
  };
1064
1294
 
@@ -1066,11 +1296,13 @@ type Groups = typeof groups;
1066
1296
 
1067
1297
  /** A command run now: a reply for the caller to read, or one of one shape. */
1068
1298
  type RunForm<D> =
1069
- D extends CommandDef<infer A, infer R, boolean>
1070
- ? (...args: A) => R extends Reply ? ReplyPromise : Promise<R>
1071
- : D extends RunDef<infer A, infer R, boolean>
1072
- ? (...args: A) => R
1073
- : never;
1299
+ D extends BuilderDef<infer A, infer R, any, boolean>
1300
+ ? (...args: A) => R
1301
+ : D extends CommandDef<infer A, infer R, boolean>
1302
+ ? (...args: A) => R extends Reply ? ReplyPromise : Promise<R>
1303
+ : D extends RunDef<infer A, infer R, boolean>
1304
+ ? (...args: A) => R
1305
+ : never;
1074
1306
 
1075
1307
  /** A command group's commands, run as they are called. */
1076
1308
  export type Commands<G> = {readonly [K in keyof G]: RunForm<G[K]>};
@@ -1088,10 +1320,15 @@ export type ReadCommands<G> = {
1088
1320
  */
1089
1321
  export type Queue<G> = {
1090
1322
  readonly [
1091
- K in keyof G as G[K] extends CommandDef<any, any, boolean> ? K : never
1092
- ]: G[K] extends CommandDef<infer A, any, boolean>
1093
- ? (...args: A) => Queue<G>
1094
- : never;
1323
+ K in keyof G as G[K] extends
1324
+ BuilderDef<any, any, any, boolean> | CommandDef<any, any, boolean, false>
1325
+ ? K
1326
+ : never
1327
+ ]: G[K] extends BuilderDef<infer A, any, infer Q, boolean>
1328
+ ? (...args: A) => Q
1329
+ : G[K] extends CommandDef<infer A, any, boolean>
1330
+ ? (...args: A) => Queue<G>
1331
+ : never;
1095
1332
  };
1096
1333
 
1097
1334
  /** Commands that work on a key of any type: expiry, deletion, renaming. */
@@ -1112,6 +1349,8 @@ export type SortedSetCommands = Commands<Groups['sortedSet']>;
1112
1349
  export type GeoCommands = Commands<Groups['geo']>;
1113
1350
  /** Commands on streams. */
1114
1351
  export type StreamCommands = Commands<Groups['stream']>;
1352
+ /** Commands on HyperLogLogs: estimates of how many distinct elements were added. */
1353
+ export type HyperLogLogCommands = Commands<Groups['hyperloglog']>;
1115
1354
  /** Publishing to channels, and subscribing to them. */
1116
1355
  export type PubsubCommands = Commands<Groups['pubsub']>;
1117
1356
 
@@ -1131,18 +1370,20 @@ function operation(name: string): string {
1131
1370
  return name.replace(/[A-Z]/g, c => `_${c.toLowerCase()}`);
1132
1371
  }
1133
1372
 
1134
- type AnyDef = CommandDef<any[], any, boolean> | RunDef<any[], any, boolean>;
1373
+ type AnyDef =
1374
+ | CommandDef<any[], any, boolean>
1375
+ | BuilderDef<any[], any, any, boolean>
1376
+ | RunDef<any[], any, boolean>;
1135
1377
 
1136
1378
  /** The command `def` builds from `args`, named and marked as it is. */
1137
1379
  function built(
1138
1380
  op: string,
1139
- def: CommandDef<any[], any, boolean>,
1381
+ def: CommandDef<any[], any, boolean> | BuilderDef<any[], any, any, boolean>,
1140
1382
  args: unknown[],
1141
1383
  ): Cmd {
1142
1384
  const c = def.build(...args);
1143
1385
  const out = new Cmd(op, c.name, def.write);
1144
1386
  out.args.push(...c.args);
1145
- out.replyKeys = c.replyKeys;
1146
1387
  return out;
1147
1388
  }
1148
1389
 
@@ -1163,6 +1404,10 @@ function runForms(t: Target, readOnly: boolean) {
1163
1404
  continue;
1164
1405
  }
1165
1406
  const op = operation(name);
1407
+ if ('start' in def) {
1408
+ forms[name] = (...args) => def.start(t, built(op, def, args));
1409
+ continue;
1410
+ }
1166
1411
  if (def.reply === as.reply) {
1167
1412
  // Any error, the command's or that of sending it, is the reply's to
1168
1413
  // report when read.
@@ -1210,6 +1455,11 @@ export function queueGroups(queue: Cmd[]): QueueGroups {
1210
1455
  for (const [name, def] of Object.entries(group)) {
1211
1456
  if (!('build' in def)) continue;
1212
1457
  const op = operation(name);
1458
+ if ('queued' in def) {
1459
+ forms[name] = (...args) => def.queued(queue, built(op, def, args));
1460
+ continue;
1461
+ }
1462
+ if (def.blocking) continue;
1213
1463
  forms[name] = (...args) => {
1214
1464
  queue.push(built(op, def, args));
1215
1465
  return forms;
@@ -9,30 +9,16 @@ import {
9
9
  type QueueGroups,
10
10
  type ReadCommandGroups,
11
11
  } from './commands';
12
+ import {
13
+ CommandInvocation,
14
+ QueuedCommandInvocation,
15
+ rawCommand,
16
+ } from './command';
12
17
  import {BatchError, Reply} from './reply';
13
18
  import {Invocation, QueuedInvocation, Script} from './script';
14
19
  import {ConnTarget, PoolTarget, type Target} from './target';
15
20
  import {encodeList, type Cmd, type Value} from './wire';
16
21
 
17
- /** What a database evicts when it runs out of memory. */
18
- export type EvictionPolicy =
19
- /** Evict nothing: a write that needs memory fails. */
20
- | 'noeviction'
21
- /** The least recently used key, of all keys. */
22
- | 'allkeys-lru'
23
- /** The least frequently used key, of all keys. */
24
- | 'allkeys-lfu'
25
- /** A random key, of all keys. */
26
- | 'allkeys-random'
27
- /** The least recently used key, of those with an expiry. */
28
- | 'volatile-lru'
29
- /** The least frequently used key, of those with an expiry. */
30
- | 'volatile-lfu'
31
- /** The key closest to expiring. */
32
- | 'volatile-ttl'
33
- /** A random key, of those with an expiry. */
34
- | 'volatile-random';
35
-
36
22
  /**
37
23
  * A database's configuration. Encore reads it from the declaration, so its
38
24
  * fields must be literals.
@@ -45,11 +31,12 @@ export interface DatabaseConfig {
45
31
  persistent?: boolean;
46
32
 
47
33
  /**
48
- * What to evict when the database runs out of memory: the least recently
49
- * used key, unless said otherwise. A persistent database evicts nothing and
50
- * takes no policy.
34
+ * Tags that classify the database, for policies to read: written out as
35
+ * string literals, as in `{data: "pci"}`. Keys and values are lowercase
36
+ * letters, digits, `_` and `-`, at most 63 characters; a key starts with a
37
+ * letter, and not with `encore`, which is reserved. At most 32 tags.
51
38
  */
52
- evictionPolicy?: EvictionPolicy;
39
+ tags?: Record<string, string>;
53
40
  }
54
41
 
55
42
  /** The replies of a batch, or the error some of its commands failed with. */
@@ -89,6 +76,15 @@ export class ReadOnlyDatabaseRef {
89
76
  script(script: Script): Invocation {
90
77
  return new Invocation(this.t, script, true);
91
78
  }
79
+
80
+ /**
81
+ * A command the command groups lack, by its name, as
82
+ * {@link DatabaseRef.command} sends one. Only a command Redis says doesn't
83
+ * write is sent.
84
+ */
85
+ command<N extends string>(name: StringLiteral<N>): CommandInvocation {
86
+ return new CommandInvocation(this.t, rawCommand(name, true));
87
+ }
92
88
  }
93
89
 
94
90
  /**
@@ -197,6 +193,26 @@ export class DatabaseRef {
197
193
  return new Invocation(this.t, script, false);
198
194
  }
199
195
 
196
+ /**
197
+ * A command the command groups lack, by its name, which must be a string
198
+ * literal: give its arguments in order, marking the keys, then invoke it.
199
+ *
200
+ * ```ts
201
+ * const freq = await SESSIONS.command("OBJECT").arg("FREQ").key("hot").invoke().number();
202
+ * ```
203
+ *
204
+ * Encore reads the name to grant the access the command needs. Before it is
205
+ * sent, the runtime checks it against Redis's command table, and fails it
206
+ * with a `TypeError` if a key it takes isn't passed with `key`, which gives
207
+ * it the database's prefix, or if it is one that would reach past the
208
+ * database, change a connection other calls share, or has a call of its own
209
+ * here (`MULTI`, `SUBSCRIBE`, `EVAL`, `SCAN`, `FLUSHALL`, …). A command the
210
+ * table doesn't know, such as a module's, is sent with its keys as marked.
211
+ */
212
+ command<N extends string>(name: StringLiteral<N>): CommandInvocation {
213
+ return new CommandInvocation(this.t, rawCommand(name, false));
214
+ }
215
+
200
216
  /**
201
217
  * The connection string to connect to this database with, for a client
202
218
  * other than this SDK.
@@ -308,6 +324,16 @@ export class Pipeline {
308
324
  return new QueuedInvocation(this.queued, script);
309
325
  }
310
326
 
327
+ /**
328
+ * Queues a command the command groups lack, by its name: see
329
+ * {@link DatabaseRef.command}. Finish it with
330
+ * {@link QueuedCommandInvocation.queue}. A command that blocks can't be
331
+ * queued: the batch fails.
332
+ */
333
+ command<N extends string>(name: StringLiteral<N>): QueuedCommandInvocation {
334
+ return new QueuedCommandInvocation(this.queued, rawCommand(name, false));
335
+ }
336
+
311
337
  /**
312
338
  * Sends the queued commands and returns their replies, in order. If the
313
339
  * server rejected any, fails with a {@link BatchError} holding them all.
@@ -346,6 +372,16 @@ export class Transaction {
346
372
  return new QueuedInvocation(this.queued, script);
347
373
  }
348
374
 
375
+ /**
376
+ * Queues a command the command groups lack, by its name: see
377
+ * {@link DatabaseRef.command}. Finish it with
378
+ * {@link QueuedCommandInvocation.queue}. A command that blocks can't be
379
+ * queued: the batch fails.
380
+ */
381
+ command<N extends string>(name: StringLiteral<N>): QueuedCommandInvocation {
382
+ return new QueuedCommandInvocation(this.queued, rawCommand(name, false));
383
+ }
384
+
349
385
  /**
350
386
  * Runs the queued commands as one transaction and returns their replies, as
351
387
  * {@link Pipeline.exec} does. A command the server rejects when it runs does
@@ -391,6 +427,16 @@ export class WatchedTransaction {
391
427
  return new QueuedInvocation(this.queued, script);
392
428
  }
393
429
 
430
+ /**
431
+ * Queues a command the command groups lack, by its name: see
432
+ * {@link DatabaseRef.command}. Finish it with
433
+ * {@link QueuedCommandInvocation.queue}. A command that blocks can't be
434
+ * queued: the batch fails.
435
+ */
436
+ command<N extends string>(name: StringLiteral<N>): QueuedCommandInvocation {
437
+ return new QueuedCommandInvocation(this.queued, rawCommand(name, false));
438
+ }
439
+
394
440
  /**
395
441
  * Runs the queued commands as one transaction and returns their replies, as
396
442
  * {@link Transaction.exec} does, or `null` if a watched key changed, in
@@ -452,6 +498,14 @@ export class Connection implements AsyncDisposable {
452
498
  return new Invocation(this.t, script, false);
453
499
  }
454
500
 
501
+ /**
502
+ * A command the command groups lack, on this connection: see
503
+ * {@link DatabaseRef.command}. One that blocks is refused here.
504
+ */
505
+ command<N extends string>(name: StringLiteral<N>): CommandInvocation {
506
+ return new CommandInvocation(this.t, rawCommand(name, false));
507
+ }
508
+
455
509
  /**
456
510
  * Returns the connection to its pool. Keys it still watches are unwatched
457
511
  * first.
@@ -20,7 +20,8 @@
20
20
  *
21
21
  * Commands are grouped by the data type they work on, each group a property of
22
22
  * the database: `string`, `hash`, `list`, `set`, `sortedSet`, `stream`, `geo`,
23
- * `bitmap`, `pubsub`, and `generic` for the ones that work on any key. Within a
23
+ * `bitmap`, `hyperloglog`, `pubsub`, and `generic` for the ones that work on
24
+ * any key. Within a
24
25
  * group a command is named after the Redis command it runs — `get`, `hset`,
25
26
  * `zadd`, `xadd` — with words of its own for its variants: `setEx`,
26
27
  * `zrangeWithscores`.
@@ -43,6 +44,28 @@
43
44
  * stored or passed on instead says nothing about what it will be used for, and
44
45
  * is reported as an error — to do that, start from a handle.
45
46
  *
47
+ * A command that waits for something to pop — `list.blpop`,
48
+ * `sortedSet.bzpopmin`, `stream.xreadBlock` and the like — runs on a
49
+ * connection of its own, so it holds up no other call. A timeout resolves to
50
+ * `null`. These can't be queued, and don't run on an acquired connection.
51
+ *
52
+ * ## Any command
53
+ *
54
+ * {@link DatabaseRef.command} sends a command the groups lack, by its name,
55
+ * with the arguments that are keys marked:
56
+ *
57
+ * ```ts
58
+ * const freq = await SESSIONS.command("OBJECT").arg("FREQ").key("hot").invoke().number();
59
+ * ```
60
+ *
61
+ * The name must be a string literal, which Encore reads to grant the access
62
+ * the command needs. Before it is sent, the runtime checks it against Redis's
63
+ * command table: each key it takes must be passed with `key`, and the commands
64
+ * that would reach past the database, change a connection other calls share,
65
+ * or have a call of their own here (`MULTI`, `SUBSCRIBE`, `EVAL`, `SCAN`,
66
+ * `FLUSHALL`, …) fail with a `TypeError`. A handle that can only read sends
67
+ * only the commands Redis says don't write.
68
+ *
46
69
  * ## Handles
47
70
  *
48
71
  * A database cannot be passed around as a value. To hand it to other code,
@@ -86,7 +109,7 @@ export {
86
109
  WatchedTransaction,
87
110
  Connection,
88
111
  } from './database';
89
- export type {DatabaseConfig, EvictionPolicy} from './database';
112
+ export type {DatabaseConfig} from './database';
90
113
  export type {
91
114
  BitmapCommands,
92
115
  CommandGroups,
@@ -94,6 +117,7 @@ export type {
94
117
  GenericCommands,
95
118
  GeoCommands,
96
119
  HashCommands,
120
+ HyperLogLogCommands,
97
121
  ListCommands,
98
122
  PubsubCommands,
99
123
  Queue,
@@ -128,8 +152,20 @@ export type {
128
152
  StreamEntry,
129
153
  StreamInfo,
130
154
  StreamPending,
155
+ Popped,
156
+ PoppedMany,
157
+ PoppedScored,
158
+ PoppedScoredMany,
131
159
  } from './reply';
132
160
  export {Script, Invocation, QueuedInvocation} from './script';
161
+ export {CommandInvocation, QueuedCommandInvocation} from './command';
162
+ export {
163
+ Bitfield,
164
+ BitfieldRo,
165
+ QueuedBitfield,
166
+ QueuedBitfieldRo,
167
+ } from './bitfield';
168
+ export type {BitOffset, BitfieldType, Overflow} from './bitfield';
133
169
  export {Message, Subscription} from './pubsub';
134
170
  export {ServerError} from './wire';
135
171
  export type {Pairs, RedisArg} from './wire';
@@ -1,4 +1,5 @@
1
1
  import * as runtime from '../../internal/runtime/mod';
2
+ import {currentScope} from '../../internal/testing/scope';
2
3
 
3
4
  /**
4
5
  * The native handle of the database `name`: where the SDK meets the runtime,
@@ -9,3 +10,13 @@ import * as runtime from '../../internal/runtime/mod';
9
10
  export function openDatabase(name: string): runtime.RedisDatabase {
10
11
  return runtime.RT.redisDatabase(name);
11
12
  }
13
+
14
+ /**
15
+ * The current test's instance of the database `name`, in test mode; `null`
16
+ * for the process's own.
17
+ *
18
+ * @internal
19
+ */
20
+ export function testDatabase(name: string): runtime.RedisDatabase | null {
21
+ return currentScope()?.redisDatabase(name) ?? null;
22
+ }