@encore.dev/sdk 0.0.0 → 2.0.0-beta.11

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 (498) hide show
  1. package/LICENSE +362 -0
  2. package/README.md +245 -2
  3. package/app_meta.test.ts +154 -0
  4. package/app_meta.ts +226 -0
  5. package/config/config.test.ts +384 -0
  6. package/config/config.ts +236 -0
  7. package/config/mod.ts +15 -0
  8. package/config/secrets.ts +173 -0
  9. package/config/value.ts +239 -0
  10. package/cron/mod.test.ts +52 -0
  11. package/cron/mod.ts +62 -0
  12. package/dist/app_meta.d.ts +126 -0
  13. package/dist/app_meta.d.ts.map +1 -0
  14. package/dist/app_meta.js +67 -0
  15. package/dist/app_meta.js.map +1 -0
  16. package/dist/config/config.d.ts +135 -0
  17. package/dist/config/config.d.ts.map +1 -0
  18. package/dist/config/config.js +115 -0
  19. package/dist/config/config.js.map +1 -0
  20. package/dist/config/mod.d.ts +5 -0
  21. package/dist/config/mod.d.ts.map +1 -0
  22. package/dist/config/mod.js +3 -0
  23. package/dist/config/mod.js.map +1 -0
  24. package/dist/config/secrets.d.ts +124 -0
  25. package/dist/config/secrets.d.ts.map +1 -0
  26. package/dist/config/secrets.js +73 -0
  27. package/dist/config/secrets.js.map +1 -0
  28. package/dist/config/value.d.ts +54 -0
  29. package/dist/config/value.d.ts.map +1 -0
  30. package/dist/config/value.js +181 -0
  31. package/dist/config/value.js.map +1 -0
  32. package/dist/cron/mod.d.ts +57 -0
  33. package/dist/cron/mod.d.ts.map +1 -0
  34. package/dist/cron/mod.js +39 -0
  35. package/dist/cron/mod.js.map +1 -0
  36. package/dist/frontends/mod.d.ts +39 -0
  37. package/dist/frontends/mod.d.ts.map +1 -0
  38. package/dist/frontends/mod.js +47 -0
  39. package/dist/frontends/mod.js.map +1 -0
  40. package/dist/gateway/errors.d.ts +101 -0
  41. package/dist/gateway/errors.d.ts.map +1 -0
  42. package/dist/gateway/errors.js +146 -0
  43. package/dist/gateway/errors.js.map +1 -0
  44. package/dist/gateway/match.d.ts +127 -0
  45. package/dist/gateway/match.d.ts.map +1 -0
  46. package/dist/gateway/match.js +206 -0
  47. package/dist/gateway/match.js.map +1 -0
  48. package/dist/gateway/middleware.d.ts +108 -0
  49. package/dist/gateway/middleware.d.ts.map +1 -0
  50. package/dist/gateway/middleware.js +9 -0
  51. package/dist/gateway/middleware.js.map +1 -0
  52. package/dist/gateway/mod.d.ts +130 -0
  53. package/dist/gateway/mod.d.ts.map +1 -0
  54. package/dist/gateway/mod.js +188 -0
  55. package/dist/gateway/mod.js.map +1 -0
  56. package/dist/gateway/request.d.ts +304 -0
  57. package/dist/gateway/request.d.ts.map +1 -0
  58. package/dist/gateway/request.js +403 -0
  59. package/dist/gateway/request.js.map +1 -0
  60. package/dist/gateway/serve.d.ts +114 -0
  61. package/dist/gateway/serve.d.ts.map +1 -0
  62. package/dist/gateway/serve.js +510 -0
  63. package/dist/gateway/serve.js.map +1 -0
  64. package/dist/gateways/mod.d.ts +42 -0
  65. package/dist/gateways/mod.d.ts.map +1 -0
  66. package/dist/gateways/mod.js +55 -0
  67. package/dist/gateways/mod.js.map +1 -0
  68. package/dist/internal/clients/call.d.ts +171 -0
  69. package/dist/internal/clients/call.d.ts.map +1 -0
  70. package/dist/internal/clients/call.js +284 -0
  71. package/dist/internal/clients/call.js.map +1 -0
  72. package/dist/internal/clients/grpc.d.ts +108 -0
  73. package/dist/internal/clients/grpc.d.ts.map +1 -0
  74. package/dist/internal/clients/grpc.js +349 -0
  75. package/dist/internal/clients/grpc.js.map +1 -0
  76. package/dist/internal/clients/mod.d.ts +81 -0
  77. package/dist/internal/clients/mod.d.ts.map +1 -0
  78. package/dist/internal/clients/mod.js +237 -0
  79. package/dist/internal/clients/mod.js.map +1 -0
  80. package/dist/internal/fetch.d.ts +67 -0
  81. package/dist/internal/fetch.d.ts.map +1 -0
  82. package/dist/internal/fetch.js +271 -0
  83. package/dist/internal/fetch.js.map +1 -0
  84. package/dist/internal/otel/backend.d.ts +52 -0
  85. package/dist/internal/otel/backend.d.ts.map +1 -0
  86. package/dist/internal/otel/backend.js +2 -0
  87. package/dist/internal/otel/backend.js.map +1 -0
  88. package/dist/internal/otel/context.d.ts +11 -0
  89. package/dist/internal/otel/context.d.ts.map +1 -0
  90. package/dist/internal/otel/context.js +34 -0
  91. package/dist/internal/otel/context.js.map +1 -0
  92. package/dist/internal/otel/context_manager.d.ts +23 -0
  93. package/dist/internal/otel/context_manager.d.ts.map +1 -0
  94. package/dist/internal/otel/context_manager.js +120 -0
  95. package/dist/internal/otel/context_manager.js.map +1 -0
  96. package/dist/internal/otel/encode.d.ts +114 -0
  97. package/dist/internal/otel/encode.d.ts.map +1 -0
  98. package/dist/internal/otel/encode.js +290 -0
  99. package/dist/internal/otel/encode.js.map +1 -0
  100. package/dist/internal/otel/http.d.ts +11 -0
  101. package/dist/internal/otel/http.d.ts.map +1 -0
  102. package/dist/internal/otel/http.js +65 -0
  103. package/dist/internal/otel/http.js.map +1 -0
  104. package/dist/internal/otel/index.d.ts +9 -0
  105. package/dist/internal/otel/index.d.ts.map +1 -0
  106. package/dist/internal/otel/index.js +8 -0
  107. package/dist/internal/otel/index.js.map +1 -0
  108. package/dist/internal/otel/meter.d.ts +74 -0
  109. package/dist/internal/otel/meter.d.ts.map +1 -0
  110. package/dist/internal/otel/meter.js +265 -0
  111. package/dist/internal/otel/meter.js.map +1 -0
  112. package/dist/internal/otel/propagator.d.ts +15 -0
  113. package/dist/internal/otel/propagator.d.ts.map +1 -0
  114. package/dist/internal/otel/propagator.js +61 -0
  115. package/dist/internal/otel/propagator.js.map +1 -0
  116. package/dist/internal/otel/provider.d.ts +13 -0
  117. package/dist/internal/otel/provider.d.ts.map +1 -0
  118. package/dist/internal/otel/provider.js +22 -0
  119. package/dist/internal/otel/provider.js.map +1 -0
  120. package/dist/internal/otel/span.d.ts +75 -0
  121. package/dist/internal/otel/span.d.ts.map +1 -0
  122. package/dist/internal/otel/span.js +234 -0
  123. package/dist/internal/otel/span.js.map +1 -0
  124. package/dist/internal/otel/tracer.d.ts +16 -0
  125. package/dist/internal/otel/tracer.d.ts.map +1 -0
  126. package/dist/internal/otel/tracer.js +71 -0
  127. package/dist/internal/otel/tracer.js.map +1 -0
  128. package/dist/internal/reqfields.d.ts +170 -0
  129. package/dist/internal/reqfields.d.ts.map +1 -0
  130. package/dist/internal/reqfields.js +349 -0
  131. package/dist/internal/reqfields.js.map +1 -0
  132. package/dist/internal/runtime/meter.d.ts +12 -0
  133. package/dist/internal/runtime/meter.d.ts.map +1 -0
  134. package/dist/internal/runtime/meter.js +22 -0
  135. package/dist/internal/runtime/meter.js.map +1 -0
  136. package/dist/internal/runtime/mod.d.ts +18 -0
  137. package/dist/internal/runtime/mod.d.ts.map +1 -0
  138. package/dist/internal/runtime/mod.js +59 -0
  139. package/dist/internal/runtime/mod.js.map +1 -0
  140. package/dist/internal/runtime/napi/napi.cjs +308 -0
  141. package/dist/internal/runtime/napi/napi.d.cts +1249 -0
  142. package/dist/internal/runtime/shutdown.d.ts +91 -0
  143. package/dist/internal/runtime/shutdown.d.ts.map +1 -0
  144. package/dist/internal/runtime/shutdown.js +299 -0
  145. package/dist/internal/runtime/shutdown.js.map +1 -0
  146. package/dist/internal/testing/carry.d.ts +49 -0
  147. package/dist/internal/testing/carry.d.ts.map +1 -0
  148. package/dist/internal/testing/carry.js +77 -0
  149. package/dist/internal/testing/carry.js.map +1 -0
  150. package/dist/internal/testing/runner.d.ts +2 -0
  151. package/dist/internal/testing/runner.d.ts.map +1 -0
  152. package/dist/internal/testing/runner.js +10 -0
  153. package/dist/internal/testing/runner.js.map +1 -0
  154. package/dist/internal/testing/scope.d.ts +112 -0
  155. package/dist/internal/testing/scope.d.ts.map +1 -0
  156. package/dist/internal/testing/scope.js +346 -0
  157. package/dist/internal/testing/scope.js.map +1 -0
  158. package/dist/internal/testing/steps.d.ts +55 -0
  159. package/dist/internal/testing/steps.d.ts.map +1 -0
  160. package/dist/internal/testing/steps.js +295 -0
  161. package/dist/internal/testing/steps.js.map +1 -0
  162. package/dist/internal/testing/telemetry.d.ts +305 -0
  163. package/dist/internal/testing/telemetry.d.ts.map +1 -0
  164. package/dist/internal/testing/telemetry.js +188 -0
  165. package/dist/internal/testing/telemetry.js.map +1 -0
  166. package/dist/internal/utils/constraints.d.ts +10 -0
  167. package/dist/internal/utils/constraints.d.ts.map +1 -0
  168. package/dist/internal/utils/constraints.js +2 -0
  169. package/dist/internal/utils/constraints.js.map +1 -0
  170. package/dist/log/index.d.ts +40 -0
  171. package/dist/log/index.d.ts.map +1 -0
  172. package/dist/log/index.js +44 -0
  173. package/dist/log/index.js.map +1 -0
  174. package/dist/log/logger.d.ts +125 -0
  175. package/dist/log/logger.d.ts.map +1 -0
  176. package/dist/log/logger.js +203 -0
  177. package/dist/log/logger.js.map +1 -0
  178. package/dist/log/runtime.d.ts +21 -0
  179. package/dist/log/runtime.d.ts.map +1 -0
  180. package/dist/log/runtime.js +22 -0
  181. package/dist/log/runtime.js.map +1 -0
  182. package/dist/log/stderr.d.ts +10 -0
  183. package/dist/log/stderr.d.ts.map +1 -0
  184. package/dist/log/stderr.js +25 -0
  185. package/dist/log/stderr.js.map +1 -0
  186. package/dist/metrics/mod.d.ts +242 -0
  187. package/dist/metrics/mod.d.ts.map +1 -0
  188. package/dist/metrics/mod.js +353 -0
  189. package/dist/metrics/mod.js.map +1 -0
  190. package/dist/mod.d.ts +5 -0
  191. package/dist/mod.d.ts.map +1 -0
  192. package/dist/mod.js +3 -0
  193. package/dist/mod.js.map +1 -0
  194. package/dist/otel.d.ts +10 -0
  195. package/dist/otel.d.ts.map +1 -0
  196. package/dist/otel.js +13 -0
  197. package/dist/otel.js.map +1 -0
  198. package/dist/pubsub/encoding.d.ts +8 -0
  199. package/dist/pubsub/encoding.d.ts.map +1 -0
  200. package/dist/pubsub/encoding.js +18 -0
  201. package/dist/pubsub/encoding.js.map +1 -0
  202. package/dist/pubsub/mod.d.ts +7 -0
  203. package/dist/pubsub/mod.d.ts.map +1 -0
  204. package/dist/pubsub/mod.js +3 -0
  205. package/dist/pubsub/mod.js.map +1 -0
  206. package/dist/pubsub/refs.d.ts +20 -0
  207. package/dist/pubsub/refs.d.ts.map +1 -0
  208. package/dist/pubsub/refs.js +11 -0
  209. package/dist/pubsub/refs.js.map +1 -0
  210. package/dist/pubsub/subscription.d.ts +223 -0
  211. package/dist/pubsub/subscription.d.ts.map +1 -0
  212. package/dist/pubsub/subscription.js +121 -0
  213. package/dist/pubsub/subscription.js.map +1 -0
  214. package/dist/pubsub/topic.d.ts +218 -0
  215. package/dist/pubsub/topic.d.ts.map +1 -0
  216. package/dist/pubsub/topic.js +281 -0
  217. package/dist/pubsub/topic.js.map +1 -0
  218. package/dist/reqctx/mod.d.ts +174 -0
  219. package/dist/reqctx/mod.d.ts.map +1 -0
  220. package/dist/reqctx/mod.js +144 -0
  221. package/dist/reqctx/mod.js.map +1 -0
  222. package/dist/services/index.d.ts +171 -0
  223. package/dist/services/index.d.ts.map +1 -0
  224. package/dist/services/index.js +187 -0
  225. package/dist/services/index.js.map +1 -0
  226. package/dist/shutdown/mod.d.ts +60 -0
  227. package/dist/shutdown/mod.d.ts.map +1 -0
  228. package/dist/shutdown/mod.js +59 -0
  229. package/dist/shutdown/mod.js.map +1 -0
  230. package/dist/storage/clickhouse/database.d.ts +262 -0
  231. package/dist/storage/clickhouse/database.d.ts.map +1 -0
  232. package/dist/storage/clickhouse/database.js +362 -0
  233. package/dist/storage/clickhouse/database.js.map +1 -0
  234. package/dist/storage/clickhouse/errors.d.ts +67 -0
  235. package/dist/storage/clickhouse/errors.d.ts.map +1 -0
  236. package/dist/storage/clickhouse/errors.js +91 -0
  237. package/dist/storage/clickhouse/errors.js.map +1 -0
  238. package/dist/storage/clickhouse/mod.d.ts +31 -0
  239. package/dist/storage/clickhouse/mod.d.ts.map +1 -0
  240. package/dist/storage/clickhouse/mod.js +29 -0
  241. package/dist/storage/clickhouse/mod.js.map +1 -0
  242. package/dist/storage/objects/bucket.d.ts +522 -0
  243. package/dist/storage/objects/bucket.d.ts.map +1 -0
  244. package/dist/storage/objects/bucket.js +414 -0
  245. package/dist/storage/objects/bucket.js.map +1 -0
  246. package/dist/storage/objects/error.d.ts +24 -0
  247. package/dist/storage/objects/error.d.ts.map +1 -0
  248. package/dist/storage/objects/error.js +105 -0
  249. package/dist/storage/objects/error.js.map +1 -0
  250. package/dist/storage/objects/mod.d.ts +5 -0
  251. package/dist/storage/objects/mod.d.ts.map +1 -0
  252. package/dist/storage/objects/mod.js +3 -0
  253. package/dist/storage/objects/mod.js.map +1 -0
  254. package/dist/storage/objects/refs.d.ts +47 -0
  255. package/dist/storage/objects/refs.d.ts.map +1 -0
  256. package/dist/storage/objects/refs.js +26 -0
  257. package/dist/storage/objects/refs.js.map +1 -0
  258. package/dist/storage/postgres/database.d.ts +365 -0
  259. package/dist/storage/postgres/database.d.ts.map +1 -0
  260. package/dist/storage/postgres/database.js +480 -0
  261. package/dist/storage/postgres/database.js.map +1 -0
  262. package/dist/storage/postgres/errors.d.ts +120 -0
  263. package/dist/storage/postgres/errors.d.ts.map +1 -0
  264. package/dist/storage/postgres/errors.js +162 -0
  265. package/dist/storage/postgres/errors.js.map +1 -0
  266. package/dist/storage/postgres/interval.d.ts +44 -0
  267. package/dist/storage/postgres/interval.d.ts.map +1 -0
  268. package/dist/storage/postgres/interval.js +153 -0
  269. package/dist/storage/postgres/interval.js.map +1 -0
  270. package/dist/storage/postgres/mod.d.ts +5 -0
  271. package/dist/storage/postgres/mod.d.ts.map +1 -0
  272. package/dist/storage/postgres/mod.js +4 -0
  273. package/dist/storage/postgres/mod.js.map +1 -0
  274. package/dist/storage/redis/bitfield.d.ts +67 -0
  275. package/dist/storage/redis/bitfield.d.ts.map +1 -0
  276. package/dist/storage/redis/bitfield.js +114 -0
  277. package/dist/storage/redis/bitfield.js.map +1 -0
  278. package/dist/storage/redis/command.d.ts +45 -0
  279. package/dist/storage/redis/command.d.ts.map +1 -0
  280. package/dist/storage/redis/command.js +78 -0
  281. package/dist/storage/redis/command.js.map +1 -0
  282. package/dist/storage/redis/commands.d.ts +657 -0
  283. package/dist/storage/redis/commands.d.ts.map +1 -0
  284. package/dist/storage/redis/commands.js +759 -0
  285. package/dist/storage/redis/commands.js.map +1 -0
  286. package/dist/storage/redis/database.d.ts +336 -0
  287. package/dist/storage/redis/database.d.ts.map +1 -0
  288. package/dist/storage/redis/database.js +398 -0
  289. package/dist/storage/redis/database.js.map +1 -0
  290. package/dist/storage/redis/mod.d.ts +115 -0
  291. package/dist/storage/redis/mod.d.ts.map +1 -0
  292. package/dist/storage/redis/mod.js +109 -0
  293. package/dist/storage/redis/mod.js.map +1 -0
  294. package/dist/storage/redis/native.d.ts +16 -0
  295. package/dist/storage/redis/native.d.ts.map +1 -0
  296. package/dist/storage/redis/native.js +21 -0
  297. package/dist/storage/redis/native.js.map +1 -0
  298. package/dist/storage/redis/options.d.ts +90 -0
  299. package/dist/storage/redis/options.d.ts.map +1 -0
  300. package/dist/storage/redis/options.js +53 -0
  301. package/dist/storage/redis/options.js.map +1 -0
  302. package/dist/storage/redis/pubsub.d.ts +55 -0
  303. package/dist/storage/redis/pubsub.d.ts.map +1 -0
  304. package/dist/storage/redis/pubsub.js +88 -0
  305. package/dist/storage/redis/pubsub.js.map +1 -0
  306. package/dist/storage/redis/reply.d.ts +290 -0
  307. package/dist/storage/redis/reply.d.ts.map +1 -0
  308. package/dist/storage/redis/reply.js +611 -0
  309. package/dist/storage/redis/reply.js.map +1 -0
  310. package/dist/storage/redis/scan.d.ts +12 -0
  311. package/dist/storage/redis/scan.d.ts.map +1 -0
  312. package/dist/storage/redis/scan.js +76 -0
  313. package/dist/storage/redis/scan.js.map +1 -0
  314. package/dist/storage/redis/script.d.ts +92 -0
  315. package/dist/storage/redis/script.d.ts.map +1 -0
  316. package/dist/storage/redis/script.js +143 -0
  317. package/dist/storage/redis/script.js.map +1 -0
  318. package/dist/storage/redis/target.d.ts +49 -0
  319. package/dist/storage/redis/target.d.ts.map +1 -0
  320. package/dist/storage/redis/target.js +93 -0
  321. package/dist/storage/redis/target.js.map +1 -0
  322. package/dist/storage/redis/wire.d.ts +102 -0
  323. package/dist/storage/redis/wire.d.ts.map +1 -0
  324. package/dist/storage/redis/wire.js +309 -0
  325. package/dist/storage/redis/wire.js.map +1 -0
  326. package/dist/testing/bun.d.ts +8 -0
  327. package/dist/testing/bun.d.ts.map +1 -0
  328. package/dist/testing/bun.js +13 -0
  329. package/dist/testing/bun.js.map +1 -0
  330. package/dist/testing/jest.d.ts +8 -0
  331. package/dist/testing/jest.d.ts.map +1 -0
  332. package/dist/testing/jest.js +11 -0
  333. package/dist/testing/jest.js.map +1 -0
  334. package/dist/testing/mod.d.ts +183 -0
  335. package/dist/testing/mod.d.ts.map +1 -0
  336. package/dist/testing/mod.js +271 -0
  337. package/dist/testing/mod.js.map +1 -0
  338. package/dist/testing/node.d.ts +9 -0
  339. package/dist/testing/node.d.ts.map +1 -0
  340. package/dist/testing/node.js +12 -0
  341. package/dist/testing/node.js.map +1 -0
  342. package/dist/testing/playwright.d.ts +93 -0
  343. package/dist/testing/playwright.d.ts.map +1 -0
  344. package/dist/testing/playwright.js +164 -0
  345. package/dist/testing/playwright.js.map +1 -0
  346. package/dist/testing/puppeteer.d.ts +36 -0
  347. package/dist/testing/puppeteer.d.ts.map +1 -0
  348. package/dist/testing/puppeteer.js +70 -0
  349. package/dist/testing/puppeteer.js.map +1 -0
  350. package/dist/testing/system.d.ts +181 -0
  351. package/dist/testing/system.d.ts.map +1 -0
  352. package/dist/testing/system.js +255 -0
  353. package/dist/testing/system.js.map +1 -0
  354. package/dist/testing/vitest.d.ts +8 -0
  355. package/dist/testing/vitest.d.ts.map +1 -0
  356. package/dist/testing/vitest.js +13 -0
  357. package/dist/testing/vitest.js.map +1 -0
  358. package/dist/tracing/http.d.ts +11 -0
  359. package/dist/tracing/http.d.ts.map +1 -0
  360. package/dist/tracing/http.js +34 -0
  361. package/dist/tracing/http.js.map +1 -0
  362. package/dist/tracing/mod.d.ts +20 -0
  363. package/dist/tracing/mod.d.ts.map +1 -0
  364. package/dist/tracing/mod.js +47 -0
  365. package/dist/tracing/mod.js.map +1 -0
  366. package/dist/tracing/node.d.ts +10 -0
  367. package/dist/tracing/node.d.ts.map +1 -0
  368. package/dist/tracing/node.js +142 -0
  369. package/dist/tracing/node.js.map +1 -0
  370. package/dist/tsconfig.build.tsbuildinfo +1 -0
  371. package/dist/types/mod.d.ts +43 -0
  372. package/dist/types/mod.d.ts.map +1 -0
  373. package/dist/types/mod.js +65 -0
  374. package/dist/types/mod.js.map +1 -0
  375. package/frontends/mod.test.ts +51 -0
  376. package/frontends/mod.ts +50 -0
  377. package/gateway/errors.ts +172 -0
  378. package/gateway/gateway.e2e.test.ts +297 -0
  379. package/gateway/gateway.test.ts +891 -0
  380. package/gateway/match.ts +239 -0
  381. package/gateway/middleware.ts +134 -0
  382. package/gateway/mod.ts +211 -0
  383. package/gateway/request.ts +578 -0
  384. package/gateway/serve.ts +738 -0
  385. package/gateways/mod.ts +60 -0
  386. package/internal/clients/call.ts +418 -0
  387. package/internal/clients/grpc.test.ts +664 -0
  388. package/internal/clients/grpc.ts +485 -0
  389. package/internal/clients/mod.test.ts +481 -0
  390. package/internal/clients/mod.ts +337 -0
  391. package/internal/fetch.ts +320 -0
  392. package/internal/otel/backend.ts +60 -0
  393. package/internal/otel/context.test.ts +70 -0
  394. package/internal/otel/context.ts +48 -0
  395. package/internal/otel/context_manager.test.ts +154 -0
  396. package/internal/otel/context_manager.ts +141 -0
  397. package/internal/otel/encode.test.ts +266 -0
  398. package/internal/otel/encode.ts +408 -0
  399. package/internal/otel/http.ts +92 -0
  400. package/internal/otel/index.ts +14 -0
  401. package/internal/otel/meter.test.ts +231 -0
  402. package/internal/otel/meter.ts +332 -0
  403. package/internal/otel/propagator.test.ts +105 -0
  404. package/internal/otel/propagator.ts +68 -0
  405. package/internal/otel/provider.ts +26 -0
  406. package/internal/otel/span.ts +281 -0
  407. package/internal/otel/tracer.test.ts +380 -0
  408. package/internal/otel/tracer.ts +111 -0
  409. package/internal/reqfields.ts +423 -0
  410. package/internal/runtime/meter.ts +26 -0
  411. package/internal/runtime/mod.ts +81 -0
  412. package/internal/runtime/napi/napi.cjs +308 -0
  413. package/internal/runtime/napi/napi.d.cts +1249 -0
  414. package/internal/runtime/shutdown.test.ts +464 -0
  415. package/internal/runtime/shutdown.ts +350 -0
  416. package/internal/testing/carry.test.ts +242 -0
  417. package/internal/testing/carry.ts +101 -0
  418. package/internal/testing/runner.ts +10 -0
  419. package/internal/testing/scope.ts +384 -0
  420. package/internal/testing/steps.test.ts +152 -0
  421. package/internal/testing/steps.ts +342 -0
  422. package/internal/testing/telemetry.test.ts +210 -0
  423. package/internal/testing/telemetry.ts +466 -0
  424. package/internal/utils/constraints.ts +12 -0
  425. package/log/index.ts +107 -0
  426. package/log/logger.test.ts +194 -0
  427. package/log/logger.ts +308 -0
  428. package/log/runtime.test.ts +65 -0
  429. package/log/runtime.ts +40 -0
  430. package/log/stderr.test.ts +23 -0
  431. package/log/stderr.ts +24 -0
  432. package/metrics/export.test.ts +341 -0
  433. package/metrics/mod.test.ts +177 -0
  434. package/metrics/mod.ts +450 -0
  435. package/mod.ts +15 -0
  436. package/otel.test.ts +98 -0
  437. package/otel.ts +17 -0
  438. package/package.json +208 -5
  439. package/pubsub/encoding.ts +18 -0
  440. package/pubsub/mod.ts +26 -0
  441. package/pubsub/pubsub.test.ts +405 -0
  442. package/pubsub/refs.ts +38 -0
  443. package/pubsub/subscription.ts +359 -0
  444. package/pubsub/topic.test.ts +147 -0
  445. package/pubsub/topic.ts +431 -0
  446. package/reqctx/mod.ts +267 -0
  447. package/reqctx/reqctx.test.ts +216 -0
  448. package/scripts/postprocess-docs.test.ts +58 -0
  449. package/services/index.test.ts +393 -0
  450. package/services/index.ts +215 -0
  451. package/shutdown/mod.ts +78 -0
  452. package/storage/clickhouse/database.integration.test.ts +337 -0
  453. package/storage/clickhouse/database.test.ts +279 -0
  454. package/storage/clickhouse/database.ts +586 -0
  455. package/storage/clickhouse/errors.ts +130 -0
  456. package/storage/clickhouse/mod.ts +37 -0
  457. package/storage/objects/bucket.test.ts +573 -0
  458. package/storage/objects/bucket.ts +968 -0
  459. package/storage/objects/error.ts +121 -0
  460. package/storage/objects/mod.ts +50 -0
  461. package/storage/objects/refs.ts +117 -0
  462. package/storage/postgres/database.integration.test.ts +450 -0
  463. package/storage/postgres/database.test.ts +428 -0
  464. package/storage/postgres/database.ts +658 -0
  465. package/storage/postgres/errors.ts +186 -0
  466. package/storage/postgres/interval.test.ts +72 -0
  467. package/storage/postgres/interval.ts +170 -0
  468. package/storage/postgres/mod.ts +19 -0
  469. package/storage/redis/bitfield.ts +162 -0
  470. package/storage/redis/command.ts +84 -0
  471. package/storage/redis/commands.ts +1471 -0
  472. package/storage/redis/database.ts +520 -0
  473. package/storage/redis/mod.ts +171 -0
  474. package/storage/redis/native.ts +22 -0
  475. package/storage/redis/options.ts +119 -0
  476. package/storage/redis/pubsub.ts +92 -0
  477. package/storage/redis/redis.test.ts +866 -0
  478. package/storage/redis/reply.ts +780 -0
  479. package/storage/redis/runtime.test.ts +248 -0
  480. package/storage/redis/scan.ts +125 -0
  481. package/storage/redis/script.ts +162 -0
  482. package/storage/redis/target.ts +134 -0
  483. package/storage/redis/wire.ts +345 -0
  484. package/testing/bun.ts +13 -0
  485. package/testing/jest.ts +11 -0
  486. package/testing/mod.ts +393 -0
  487. package/testing/node.ts +12 -0
  488. package/testing/playwright.ts +247 -0
  489. package/testing/puppeteer.ts +101 -0
  490. package/testing/system.test.ts +108 -0
  491. package/testing/system.ts +373 -0
  492. package/testing/vitest.ts +13 -0
  493. package/tracing/http.ts +49 -0
  494. package/tracing/mod.ts +83 -0
  495. package/tracing/native.test.ts +276 -0
  496. package/tracing/node.ts +176 -0
  497. package/tracing/tracing.test.ts +953 -0
  498. package/types/mod.ts +92 -0
@@ -0,0 +1,759 @@
1
+ /**
2
+ * The command groups: one per Redis data type, each holding the commands on
3
+ * it in three forms: the ones that run now, the ones of those that only read,
4
+ * and the ones that queue on a pipeline or a transaction.
5
+ *
6
+ * All three come from one list per group, below, after the Rust SDK's
7
+ * (`sdk/rs/encore/src/storage/redis/commands.rs`): the same commands, named in
8
+ * TypeScript's casing. A command is written once: whether it reads or writes,
9
+ * its parameters, the Redis command it builds, with the arguments that are
10
+ * keys marked, and what its reply is read as. Encore's parser holds the same
11
+ * list (`TS_TABLES.families` in `encore_parser`), which is how it knows what
12
+ * each call needs to be granted; a test there reads this file and fails when
13
+ * the two differ.
14
+ *
15
+ * Two are TypeScript's own, as they are Go's: `incrFloat` and `hincrFloat`,
16
+ * where Rust picks `INCRBY` or `INCRBYFLOAT` by the type of the amount.
17
+ *
18
+ * @module
19
+ */
20
+ import { directionArg, expiryArgs, maxlenArgs, radiusArgs, setArgs, } from './options.js';
21
+ import { Bitfield, BitfieldRo, QueuedBitfield, QueuedBitfieldRo, } from './bitfield.js';
22
+ import { as, Reply, ReplyPromise } from './reply.js';
23
+ import { scanFields, scanKeys, scanMembers, scanScored } from './scan.js';
24
+ import { subscribe } from './pubsub.js';
25
+ import { Cmd } from './wire.js';
26
+ /** A command that only reads. */
27
+ function read(build, reply) {
28
+ return { write: false, blocking: false, build, reply };
29
+ }
30
+ /** A command that writes. */
31
+ function write(build, reply) {
32
+ return { write: true, blocking: false, build, reply };
33
+ }
34
+ /** A command that only reads, and blocks. */
35
+ function readBlocking(build, reply) {
36
+ return { write: false, blocking: true, build, reply };
37
+ }
38
+ /** A command that writes, and blocks. */
39
+ function writeBlocking(build, reply) {
40
+ return { write: true, blocking: true, build, reply };
41
+ }
42
+ /** A command built up by the caller that only reads. */
43
+ function readBuilder(build, start, queued) {
44
+ return { write: false, build, start, queued };
45
+ }
46
+ /** A command built up by the caller that writes. */
47
+ function writeBuilder(build, start, queued) {
48
+ return { write: true, build, start, queued };
49
+ }
50
+ /** What runs now and only reads. */
51
+ function readRun(run) {
52
+ return { write: false, run };
53
+ }
54
+ /**
55
+ * The command Redis calls `name`. Its trace name and whether it writes are
56
+ * the definition's, filled in as the group is put together.
57
+ */
58
+ function cmd(name) {
59
+ return new Cmd('', name, false);
60
+ }
61
+ /** A bit as Redis takes one. */
62
+ const bitArg = (b) => (b ? 1 : 0);
63
+ /** One key, or several. */
64
+ const keyList = (keys) => typeof keys === 'string' ? [keys] : keys;
65
+ const generic = {
66
+ /** Whether the key exists. */
67
+ exists: read((key) => cmd('EXISTS').key(key), as.bool),
68
+ /**
69
+ * The seconds until the key expires: -1 if it never does, -2 if it does not
70
+ * exist.
71
+ */
72
+ ttl: read((key) => cmd('TTL').key(key), as.number),
73
+ /**
74
+ * The milliseconds until the key expires: -1 if it never does, -2 if it does
75
+ * not exist.
76
+ */
77
+ pttl: read((key) => cmd('PTTL').key(key), as.number),
78
+ /**
79
+ * The type of the value at the key: `string`, `list`, `set`, `zset`, `hash`,
80
+ * `stream`, or `none` if it does not exist.
81
+ */
82
+ keyType: read((key) => cmd('TYPE').key(key), as.text),
83
+ /**
84
+ * The Unix time, in seconds, the key expires at: -1 if it never does, -2 if
85
+ * it does not exist.
86
+ */
87
+ expireTime: read((key) => cmd('EXPIRETIME').key(key), as.number),
88
+ /** Iterates over the database's keys. */
89
+ scan: readRun((t, options) => scanKeys(t, options)),
90
+ /** Deletes the keys, returning how many existed. */
91
+ del: write((...keys) => cmd('DEL').keys(keys), as.number),
92
+ /**
93
+ * Deletes the keys, reclaiming their memory in the background. Returns how
94
+ * many existed.
95
+ */
96
+ unlink: write((...keys) => cmd('UNLINK').keys(keys), as.number),
97
+ /** Has the key expire in `seconds`. `false` if it does not exist. */
98
+ expire: write((key, seconds) => cmd('EXPIRE').key(key).arg(seconds), as.bool),
99
+ /** Has the key expire in `milliseconds`. `false` if it does not exist. */
100
+ pexpire: write((key, milliseconds) => cmd('PEXPIRE').key(key).arg(milliseconds), as.bool),
101
+ /**
102
+ * Has the key expire at a Unix time, in seconds. `false` if it does not
103
+ * exist.
104
+ */
105
+ expireAt: write((key, timestamp) => cmd('EXPIREAT').key(key).arg(timestamp), as.bool),
106
+ /** Removes the key's expiry. `false` if it had none, or does not exist. */
107
+ persist: write((key) => cmd('PERSIST').key(key), as.bool),
108
+ /** Renames the key, replacing `newKey` if it exists. */
109
+ rename: write((key, newKey) => cmd('RENAME').key(key).key(newKey), as.none),
110
+ /** Renames the key unless `newKey` exists. `false` if it does. */
111
+ renameNx: write((key, newKey) => cmd('RENAMENX').key(key).key(newKey), as.bool),
112
+ /**
113
+ * Copies the value at `source` to `destination`. `false` if `destination`
114
+ * exists.
115
+ */
116
+ copy: write((source, destination) => cmd('COPY').key(source).key(destination), as.bool),
117
+ /** Marks the keys as used just now, returning how many exist. */
118
+ touch: write((...keys) => cmd('TOUCH').keys(keys), as.number),
119
+ };
120
+ const string = {
121
+ /** The value at the key: nil if it does not exist. */
122
+ get: read((key) => cmd('GET').key(key), as.reply),
123
+ /**
124
+ * The values at the keys, in order, each missing one as nil: read it with
125
+ * {@link Reply.optionalTexts}.
126
+ */
127
+ mget: read((...keys) => cmd('MGET').keys(keys), as.reply),
128
+ /** The length of the value at the key, in bytes. */
129
+ strlen: read((key) => cmd('STRLEN').key(key), as.number),
130
+ /**
131
+ * The part of the value from byte `from` to byte `to`, inclusive. Negative
132
+ * offsets count from the end.
133
+ */
134
+ getrange: read((key, from, to) => cmd('GETRANGE').key(key).arg(from).arg(to), as.reply),
135
+ /** Sets the key to the value. */
136
+ set: write((key, value) => cmd('SET').key(key).arg(value), as.none),
137
+ /** Sets the key to the value, expiring in `seconds`. */
138
+ setEx: write((key, value, seconds) => cmd('SETEX').key(key).arg(seconds).arg(value), as.none),
139
+ /** Sets the key to the value unless the key exists. `false` if it does. */
140
+ setNx: write((key, value) => cmd('SETNX').key(key).arg(value), as.bool),
141
+ /**
142
+ * Sets the key to the value as `options` say: only if it exists or does
143
+ * not, with an expiry, replying the old value.
144
+ */
145
+ setOptions: write((key, value, options) => cmd('SET').key(key).arg(value).argsOf(setArgs(options)), as.reply),
146
+ /** Sets each key to its value, all at once. */
147
+ mset: write((items) => cmd('MSET').pairs(items), as.none),
148
+ /**
149
+ * Sets each key to its value unless any of the keys exists. `false` if one
150
+ * does, in which case none is set.
151
+ */
152
+ msetNx: write((items) => cmd('MSETNX').pairs(items), as.bool),
153
+ /** The value at the key, which is deleted. */
154
+ getDel: write((key) => cmd('GETDEL').key(key), as.reply),
155
+ /** The value at the key, whose expiry is set as `expiry` says. */
156
+ getEx: write((key, expiry) => cmd('GETEX').key(key).argsOf(expiryArgs(expiry)), as.reply),
157
+ /** Appends to the value at the key, returning its new length. */
158
+ append: write((key, value) => cmd('APPEND').key(key).arg(value), as.number),
159
+ /** Overwrites the value from byte `offset`, returning its new length. */
160
+ setrange: write((key, offset, value) => cmd('SETRANGE').key(key).arg(offset).arg(value), as.number),
161
+ /**
162
+ * Adds `delta` to the integer at the key, returning the result. A missing
163
+ * key counts as 0.
164
+ */
165
+ incr: write((key, delta) => cmd('INCRBY').key(key).arg(delta), as.number),
166
+ /**
167
+ * Adds `delta` to the number at the key, returning the result. A missing key
168
+ * counts as 0.
169
+ */
170
+ incrFloat: write((key, delta) => cmd('INCRBYFLOAT').key(key).arg(delta), as.number),
171
+ /** Subtracts `delta` from the integer at the key, returning the result. */
172
+ decr: write((key, delta) => cmd('DECRBY').key(key).arg(delta), as.number),
173
+ };
174
+ const bitmap = {
175
+ /** The bit at `offset`. */
176
+ getbit: read((key, offset) => cmd('GETBIT').key(key).arg(offset), as.bool),
177
+ /** How many bits are set. */
178
+ bitcount: read((key) => cmd('BITCOUNT').key(key), as.number),
179
+ /** How many bits are set from byte `start` to byte `end`, inclusive. */
180
+ bitcountRange: read((key, start, end) => cmd('BITCOUNT').key(key).arg(start).arg(end), as.number),
181
+ /** The position of the first bit that is `bit`, or -1 if there is none. */
182
+ bitpos: read((key, bit) => cmd('BITPOS').key(key).arg(bitArg(bit)), as.number),
183
+ /** Sets the bit at `offset`, returning what it was. */
184
+ setbit: write((key, offset, value) => cmd('SETBIT').key(key).arg(offset).arg(bitArg(value)), as.bool),
185
+ /**
186
+ * Stores the AND of the sources at `destination`, returning its length in
187
+ * bytes.
188
+ */
189
+ bitAnd: write((destination, ...sources) => cmd('BITOP').arg('AND').key(destination).keys(sources), as.number),
190
+ /**
191
+ * Stores the OR of the sources at `destination`, returning its length in
192
+ * bytes.
193
+ */
194
+ bitOr: write((destination, ...sources) => cmd('BITOP').arg('OR').key(destination).keys(sources), as.number),
195
+ /**
196
+ * Stores the XOR of the sources at `destination`, returning its length in
197
+ * bytes.
198
+ */
199
+ bitXor: write((destination, ...sources) => cmd('BITOP').arg('XOR').key(destination).keys(sources), as.number),
200
+ /**
201
+ * Stores the inverse of the source at `destination`, returning its length in
202
+ * bytes.
203
+ */
204
+ bitNot: write((destination, source) => cmd('BITOP').arg('NOT').key(destination).key(source), as.number),
205
+ /**
206
+ * Integers of any width up to 64 bits, read and written at any bit offset of
207
+ * the string: add the operations, then {@link Bitfield.invoke}.
208
+ */
209
+ bitfield: writeBuilder((key) => cmd('BITFIELD').key(key), (t, c) => new Bitfield(t, c), (queue, c) => new QueuedBitfield(queue, c)),
210
+ /** {@link Bitfield} that only reads (`BITFIELD_RO`). */
211
+ bitfieldRo: readBuilder((key) => cmd('BITFIELD_RO').key(key), (t, c) => new BitfieldRo(t, c), (queue, c) => new QueuedBitfieldRo(queue, c)),
212
+ };
213
+ const hash = {
214
+ /** The value of a field: nil if it does not exist. */
215
+ hget: read((key, field) => cmd('HGET').key(key).arg(field), as.reply),
216
+ /**
217
+ * The values of the fields, in order, each missing one as nil: read it with
218
+ * {@link Reply.optionalTexts}.
219
+ */
220
+ hmget: read((key, ...fields) => cmd('HMGET').key(key).argsOf(fields), as.reply),
221
+ /** Every field and its value: read it with {@link Reply.textMap}. */
222
+ hgetall: read((key) => cmd('HGETALL').key(key), as.reply),
223
+ /** Whether the field exists. */
224
+ hexists: read((key, field) => cmd('HEXISTS').key(key).arg(field), as.bool),
225
+ /** How many fields the hash has. */
226
+ hlen: read((key) => cmd('HLEN').key(key), as.number),
227
+ /** The names of the fields. */
228
+ hkeys: read((key) => cmd('HKEYS').key(key), as.reply),
229
+ /** The values of the fields. */
230
+ hvals: read((key) => cmd('HVALS').key(key), as.reply),
231
+ /** The name of a field chosen at random. */
232
+ hrandfield: read((key) => cmd('HRANDFIELD').key(key), as.reply),
233
+ /** Iterates over the hash's fields, each with its value. */
234
+ hscan: readRun((t, key, options) => scanFields(t, key, options)),
235
+ /** Sets a field, returning 1 if it is new and 0 if it was replaced. */
236
+ hset: write((key, field, value) => cmd('HSET').key(key).arg(field).arg(value), as.number),
237
+ /** Sets several fields, returning how many are new. */
238
+ hsetMultiple: write((key, items) => cmd('HSET').key(key).fields(items), as.number),
239
+ /** Sets a field unless it exists. `false` if it does. */
240
+ hsetNx: write((key, field, value) => cmd('HSETNX').key(key).arg(field).arg(value), as.bool),
241
+ /** Deletes the fields, returning how many existed. */
242
+ hdel: write((key, ...fields) => cmd('HDEL').key(key).argsOf(fields), as.number),
243
+ /** Adds `delta` to the integer in a field, returning the result. */
244
+ hincr: write((key, field, delta) => cmd('HINCRBY').key(key).arg(field).arg(delta), as.number),
245
+ /** Adds `delta` to the number in a field, returning the result. */
246
+ hincrFloat: write((key, field, delta) => cmd('HINCRBYFLOAT').key(key).arg(field).arg(delta), as.number),
247
+ };
248
+ const list = {
249
+ /**
250
+ * The elements from index `start` to index `stop`, inclusive. Negative
251
+ * indexes count from the end: `0, -1` is the whole list.
252
+ */
253
+ lrange: read((key, start, stop) => cmd('LRANGE').key(key).arg(start).arg(stop), as.reply),
254
+ /** The element at an index. */
255
+ lindex: read((key, index) => cmd('LINDEX').key(key).arg(index), as.reply),
256
+ /** How many elements the list has. */
257
+ llen: read((key) => cmd('LLEN').key(key), as.number),
258
+ /** The index of the first element equal to `value`: `null` if there is none. */
259
+ lpos: read((key, value) => cmd('LPOS').key(key).arg(value), as.optionalNumber),
260
+ /** Prepends the values, returning the list's new length. */
261
+ lpush: write((key, ...values) => cmd('LPUSH').key(key).argsOf(values), as.number),
262
+ /** Appends the values, returning the list's new length. */
263
+ rpush: write((key, ...values) => cmd('RPUSH').key(key).argsOf(values), as.number),
264
+ /** Prepends the values if the list exists, returning its length. */
265
+ lpushExists: write((key, ...values) => cmd('LPUSHX').key(key).argsOf(values), as.number),
266
+ /** Appends the values if the list exists, returning its length. */
267
+ rpushExists: write((key, ...values) => cmd('RPUSHX').key(key).argsOf(values), as.number),
268
+ /**
269
+ * Removes and returns the first element, or with a `count`, that many, as a
270
+ * list.
271
+ */
272
+ lpop: write((key, count) => cmd('LPOP')
273
+ .key(key)
274
+ .argsOf(count === undefined ? [] : [count]), as.reply),
275
+ /**
276
+ * Removes and returns the last element, or with a `count`, that many, as a
277
+ * list.
278
+ */
279
+ rpop: write((key, count) => cmd('RPOP')
280
+ .key(key)
281
+ .argsOf(count === undefined ? [] : [count]), as.reply),
282
+ /** Replaces the element at an index. */
283
+ lset: write((key, index, value) => cmd('LSET').key(key).arg(index).arg(value), as.none),
284
+ /** Keeps only the elements from index `start` to index `stop`, inclusive. */
285
+ ltrim: write((key, start, stop) => cmd('LTRIM').key(key).arg(start).arg(stop), as.none),
286
+ /**
287
+ * Inserts the value before the first element equal to `pivot`, returning
288
+ * the list's new length, or -1 if there is no such element.
289
+ */
290
+ linsertBefore: write((key, pivot, value) => cmd('LINSERT').key(key).arg('BEFORE').arg(pivot).arg(value), as.number),
291
+ /**
292
+ * Inserts the value after the first element equal to `pivot`, returning the
293
+ * list's new length, or -1 if there is no such element.
294
+ */
295
+ linsertAfter: write((key, pivot, value) => cmd('LINSERT').key(key).arg('AFTER').arg(pivot).arg(value), as.number),
296
+ /**
297
+ * Removes elements equal to `value`: the first `count` of them, the last
298
+ * `-count` if it is negative, or all if it is 0. Returns how many.
299
+ */
300
+ lrem: write((key, count, value) => cmd('LREM').key(key).arg(count).arg(value), as.number),
301
+ /**
302
+ * Moves an element from one end of `source` to one end of `destination`,
303
+ * returning it.
304
+ */
305
+ lmove: write((source, destination, from, to) => cmd('LMOVE')
306
+ .key(source)
307
+ .key(destination)
308
+ .arg(directionArg(from))
309
+ .arg(directionArg(to)), as.reply),
310
+ /**
311
+ * Removes and returns the first element of the first of `keys` that has
312
+ * one, with its key, waiting up to `timeout` seconds for one to be pushed:
313
+ * 0 waits for ever. `null` once the timeout passes.
314
+ */
315
+ blpop: writeBlocking((keys, timeout) => cmd('BLPOP').keys(keyList(keys)).arg(timeout), as.popped),
316
+ /** `blpop`, from the end of the list. */
317
+ brpop: writeBlocking((keys, timeout) => cmd('BRPOP').keys(keyList(keys)).arg(timeout), as.popped),
318
+ /**
319
+ * `lmove`, waiting up to `timeout` seconds for `source`
320
+ * to have an element: 0 waits for ever. A nil reply once the timeout passes.
321
+ */
322
+ blmove: writeBlocking((source, destination, from, to, timeout) => cmd('BLMOVE')
323
+ .key(source)
324
+ .key(destination)
325
+ .arg(directionArg(from))
326
+ .arg(directionArg(to))
327
+ .arg(timeout), as.reply),
328
+ /**
329
+ * Removes and returns up to `count` elements from one end of the first of
330
+ * `keys` that has any, with its key, waiting up to `timeout` seconds for
331
+ * one: 0 waits for ever. `null` once the timeout passes.
332
+ */
333
+ blmpop: writeBlocking((keys, from, count, timeout) => cmd('BLMPOP')
334
+ .arg(timeout)
335
+ .numkeys(keys)
336
+ .arg(directionArg(from))
337
+ .arg('COUNT')
338
+ .arg(count), as.poppedMany),
339
+ };
340
+ const set = {
341
+ /** Every member. */
342
+ smembers: read((key) => cmd('SMEMBERS').key(key), as.reply),
343
+ /** Whether the value is a member. */
344
+ sismember: read((key, member) => cmd('SISMEMBER').key(key).arg(member), as.bool),
345
+ /** Whether each of the values is a member, in order. */
346
+ smismember: read((key, ...members) => cmd('SMISMEMBER').key(key).argsOf(members), as.bools),
347
+ /** How many members the set has. */
348
+ scard: read((key) => cmd('SCARD').key(key), as.number),
349
+ /** A member chosen at random. */
350
+ srandmember: read((key) => cmd('SRANDMEMBER').key(key), as.reply),
351
+ /**
352
+ * `count` distinct members chosen at random, or with a negative `count` that
353
+ * many, possibly repeated.
354
+ */
355
+ srandmemberMultiple: read((key, count) => cmd('SRANDMEMBER').key(key).arg(count), as.reply),
356
+ /** The members of the first set that are in none of the others. */
357
+ sdiff: read((...keys) => cmd('SDIFF').keys(keys), as.reply),
358
+ /** The members that are in every one of the sets. */
359
+ sinter: read((...keys) => cmd('SINTER').keys(keys), as.reply),
360
+ /** The members that are in any of the sets. */
361
+ sunion: read((...keys) => cmd('SUNION').keys(keys), as.reply),
362
+ /** Iterates over the set's members. */
363
+ sscan: readRun((t, key, options) => scanMembers(t, key, options)),
364
+ /** Adds the members, returning how many are new. */
365
+ sadd: write((key, ...members) => cmd('SADD').key(key).argsOf(members), as.number),
366
+ /** Removes the members, returning how many there were. */
367
+ srem: write((key, ...members) => cmd('SREM').key(key).argsOf(members), as.number),
368
+ /** Removes and returns a member chosen at random. */
369
+ spop: write((key) => cmd('SPOP').key(key), as.reply),
370
+ /**
371
+ * Moves a member from one set to another. `false` if it is not in `source`.
372
+ */
373
+ smove: write((source, destination, member) => cmd('SMOVE').key(source).key(destination).arg(member), as.bool),
374
+ /** Stores `sdiff` of the sets at `destination`, returning its size. */
375
+ sdiffstore: write((destination, ...keys) => cmd('SDIFFSTORE').key(destination).keys(keys), as.number),
376
+ /** Stores `sinter` of the sets at `destination`, returning its size. */
377
+ sinterstore: write((destination, ...keys) => cmd('SINTERSTORE').key(destination).keys(keys), as.number),
378
+ /** Stores `sunion` of the sets at `destination`, returning its size. */
379
+ sunionstore: write((destination, ...keys) => cmd('SUNIONSTORE').key(destination).keys(keys), as.number),
380
+ };
381
+ const sortedSet = {
382
+ /**
383
+ * The members ranked `start` to `stop`, inclusive, lowest score first.
384
+ * Negative ranks count from the highest: `0, -1` is every member.
385
+ */
386
+ zrange: read((key, start, stop) => cmd('ZRANGE').key(key).arg(start).arg(stop), as.reply),
387
+ /**
388
+ * `zrange`, each member with its score: read it with
389
+ * {@link Reply.scoredMembers}.
390
+ */
391
+ zrangeWithscores: read((key, start, stop) => cmd('ZRANGE').key(key).arg(start).arg(stop).arg('WITHSCORES'), as.reply),
392
+ /** The members ranked `start` to `stop`, inclusive, highest score first. */
393
+ zrevrange: read((key, start, stop) => cmd('ZREVRANGE').key(key).arg(start).arg(stop), as.reply),
394
+ /**
395
+ * `zrevrange`, each member with its score: read it with
396
+ * {@link Reply.scoredMembers}.
397
+ */
398
+ zrevrangeWithscores: read((key, start, stop) => cmd('ZREVRANGE').key(key).arg(start).arg(stop).arg('WITHSCORES'), as.reply),
399
+ /** The members with a score from `min` to `max`, lowest first. */
400
+ zrangebyscore: read((key, min, max) => cmd('ZRANGEBYSCORE').key(key).arg(min).arg(max), as.reply),
401
+ /**
402
+ * `zrangebyscore`, each member with its score: read it with
403
+ * {@link Reply.scoredMembers}.
404
+ */
405
+ zrangebyscoreWithscores: read((key, min, max) => cmd('ZRANGEBYSCORE').key(key).arg(min).arg(max).arg('WITHSCORES'), as.reply),
406
+ /** A member's score: `null` if it is not a member. */
407
+ zscore: read((key, member) => cmd('ZSCORE').key(key).arg(member), as.optionalNumber),
408
+ /**
409
+ * A member's rank, lowest score first, from 0: `null` if it is not a
410
+ * member.
411
+ */
412
+ zrank: read((key, member) => cmd('ZRANK').key(key).arg(member), as.optionalNumber),
413
+ /**
414
+ * A member's rank, highest score first, from 0: `null` if it is not a
415
+ * member.
416
+ */
417
+ zrevrank: read((key, member) => cmd('ZREVRANK').key(key).arg(member), as.optionalNumber),
418
+ /** How many members the set has. */
419
+ zcard: read((key) => cmd('ZCARD').key(key), as.number),
420
+ /** How many members have a score from `min` to `max`. */
421
+ zcount: read((key, min, max) => cmd('ZCOUNT').key(key).arg(min).arg(max), as.number),
422
+ /** A member chosen at random. */
423
+ zrandmember: read((key) => cmd('ZRANDMEMBER').key(key), as.reply),
424
+ /** Iterates over the sorted set's members, each with its score. */
425
+ zscan: readRun((t, key, options) => scanScored(t, key, options)),
426
+ /**
427
+ * Adds a member with a score, or updates its score. Returns 1 if it is new.
428
+ */
429
+ zadd: write((key, member, score) => cmd('ZADD').key(key).arg(score).arg(member), as.number),
430
+ /**
431
+ * Adds several members, each with its score, returning how many are new.
432
+ */
433
+ zaddMultiple: write((key, items) => cmd('ZADD').key(key).scores(items), as.number),
434
+ /** Removes the members, returning how many there were. */
435
+ zrem: write((key, ...members) => cmd('ZREM').key(key).argsOf(members), as.number),
436
+ /** Adds `delta` to a member's score, returning the result. */
437
+ zincr: write((key, member, delta) => cmd('ZINCRBY').key(key).arg(delta).arg(member), as.number),
438
+ /**
439
+ * Removes and returns the `count` members with the lowest scores, each with
440
+ * its score: read it with {@link Reply.scoredMembers}.
441
+ */
442
+ zpopmin: write((key, count) => cmd('ZPOPMIN').key(key).arg(count), as.reply),
443
+ /**
444
+ * Removes and returns the `count` members with the highest scores, each
445
+ * with its score: read it with {@link Reply.scoredMembers}.
446
+ */
447
+ zpopmax: write((key, count) => cmd('ZPOPMAX').key(key).arg(count), as.reply),
448
+ /**
449
+ * Removes the members with a score from `min` to `max`, returning how many.
450
+ */
451
+ zrembyscore: write((key, min, max) => cmd('ZREMRANGEBYSCORE').key(key).arg(min).arg(max), as.number),
452
+ /** Removes the members ranked `start` to `stop`, returning how many. */
453
+ zremrangebyrank: write((key, start, stop) => cmd('ZREMRANGEBYRANK').key(key).arg(start).arg(stop), as.number),
454
+ /**
455
+ * Stores at `destination` the members in every one of the sets, their
456
+ * scores summed. Returns its size.
457
+ */
458
+ zinterstore: write((destination, ...keys) => cmd('ZINTERSTORE').key(destination).numkeys(keys), as.number),
459
+ /**
460
+ * Stores at `destination` the members in any of the sets, their scores
461
+ * summed. Returns its size.
462
+ */
463
+ zunionstore: write((destination, ...keys) => cmd('ZUNIONSTORE').key(destination).numkeys(keys), as.number),
464
+ /**
465
+ * Removes and returns the lowest scored member of the first of `keys` that
466
+ * has one, with its key and score, waiting up to `timeout` seconds for one
467
+ * to be added: 0 waits for ever. `null` once the timeout passes.
468
+ */
469
+ bzpopmin: writeBlocking((keys, timeout) => cmd('BZPOPMIN').keys(keyList(keys)).arg(timeout), as.poppedScored),
470
+ /** `bzpopmin`, the highest scored member. */
471
+ bzpopmax: writeBlocking((keys, timeout) => cmd('BZPOPMAX').keys(keyList(keys)).arg(timeout), as.poppedScored),
472
+ /**
473
+ * Removes and returns up to `count` of the lowest (`'min'`) or highest
474
+ * (`'max'`) scored members of the first of `keys` that has any, with its
475
+ * key and their scores, waiting up to `timeout` seconds for one: 0 waits
476
+ * for ever. `null` once the timeout passes.
477
+ */
478
+ bzmpop: writeBlocking((keys, which, count, timeout) => cmd('BZMPOP')
479
+ .arg(timeout)
480
+ .numkeys(keys)
481
+ .arg(which === 'max' ? 'MAX' : 'MIN')
482
+ .arg('COUNT')
483
+ .arg(count), as.poppedScoredMany),
484
+ };
485
+ const geo = {
486
+ /**
487
+ * The positions of the members, each missing one as nil: read it with
488
+ * {@link Reply.geoPositions}.
489
+ */
490
+ geoPos: read((key, ...members) => cmd('GEOPOS').key(key).argsOf(members), as.reply),
491
+ /** The distance between two members: `null` if either is not a member. */
492
+ geoDist: read((key, from, to, unit) => cmd('GEODIST').key(key).arg(from).arg(to).arg(unit), as.optionalNumber),
493
+ /** The geohash of each member. */
494
+ geoHash: read((key, ...members) => cmd('GEOHASH').key(key).argsOf(members), as.reply),
495
+ /**
496
+ * The members within `radius` of a position: read it with
497
+ * {@link Reply.geoRadius}.
498
+ */
499
+ geoRadius: read((key, longitude, latitude, radius, unit, options) => cmd('GEORADIUS_RO')
500
+ .key(key)
501
+ .arg(longitude)
502
+ .arg(latitude)
503
+ .arg(radius)
504
+ .arg(unit)
505
+ .argsOf(radiusArgs(options)), as.reply),
506
+ /**
507
+ * The members within `radius` of another member: read it with
508
+ * {@link Reply.geoRadius}.
509
+ */
510
+ geoRadiusByMember: read((key, member, radius, unit, options) => cmd('GEORADIUSBYMEMBER_RO')
511
+ .key(key)
512
+ .arg(member)
513
+ .arg(radius)
514
+ .arg(unit)
515
+ .argsOf(radiusArgs(options)), as.reply),
516
+ /** Adds a member at a position, or moves it there. Returns 1 if it is new. */
517
+ geoAdd: write((key, longitude, latitude, member) => cmd('GEOADD').key(key).arg(longitude).arg(latitude).arg(member), as.number),
518
+ };
519
+ const stream = {
520
+ /**
521
+ * The entries with an id from `start` to `end`, oldest first. `"-"` and
522
+ * `"+"` are the lowest and highest ids. Read it with
523
+ * {@link Reply.streamEntries}.
524
+ */
525
+ xrange: read((key, start, end) => cmd('XRANGE').key(key).arg(start).arg(end), as.reply),
526
+ /** `xrange`, at most `count` entries. */
527
+ xrangeCount: read((key, start, end, count) => cmd('XRANGE').key(key).arg(start).arg(end).arg('COUNT').arg(count), as.reply),
528
+ /** The entries with an id from `end` down to `start`, newest first. */
529
+ xrevrange: read((key, end, start) => cmd('XREVRANGE').key(key).arg(end).arg(start), as.reply),
530
+ /** `xrevrange`, at most `count` entries. */
531
+ xrevrangeCount: read((key, end, start, count) => cmd('XREVRANGE').key(key).arg(end).arg(start).arg('COUNT').arg(count), as.reply),
532
+ /** How many entries the stream has. */
533
+ xlen: read((key) => cmd('XLEN').key(key), as.number),
534
+ /**
535
+ * The entries after an id in each of the streams, `ids` giving the id for
536
+ * each of `keys` in order. Returns at once with what is there. Read it with
537
+ * {@link Reply.streams}.
538
+ */
539
+ xread: read((keys, ids) => cmd('XREAD').arg('STREAMS').keys(keys).argsOf(ids), as.reply),
540
+ /**
541
+ * A summary of the entries a consumer group has been given and not
542
+ * acknowledged: read it with {@link Reply.streamPending}.
543
+ */
544
+ xpending: read((key, group) => cmd('XPENDING').key(key).arg(group), as.reply),
545
+ /**
546
+ * What the server knows about the stream: read it with
547
+ * {@link Reply.streamInfo}.
548
+ */
549
+ xinfoStream: read((key) => cmd('XINFO').arg('STREAM').key(key), as.reply),
550
+ /**
551
+ * Appends an entry with the given fields, replying its id. Pass `"*"` as
552
+ * the id to have the server choose it.
553
+ */
554
+ xadd: write((key, id, fields) => cmd('XADD').key(key).arg(id).fields(fields), as.reply),
555
+ /** `xadd`, trimming the stream to a maximum length. */
556
+ xaddMaxlen: write((key, maxlen, id, fields) => cmd('XADD').key(key).argsOf(maxlenArgs(maxlen)).arg(id).fields(fields), as.reply),
557
+ /** Deletes the entries with the given ids, returning how many existed. */
558
+ xdel: write((key, ...ids) => cmd('XDEL').key(key).argsOf(ids), as.number),
559
+ /**
560
+ * Trims the stream to a maximum length, returning how many entries were
561
+ * removed.
562
+ */
563
+ xtrim: write((key, maxlen) => cmd('XTRIM').key(key).argsOf(maxlenArgs(maxlen)), as.number),
564
+ /**
565
+ * Creates a consumer group that starts reading after `id`: `"$"` for only
566
+ * new entries, `"0"` for all. The stream must exist.
567
+ */
568
+ xgroupCreate: write((key, group, id) => cmd('XGROUP').arg('CREATE').key(key).arg(group).arg(id), as.none),
569
+ /** `xgroupCreate`, creating the stream if it does not exist. */
570
+ xgroupCreateMkstream: write((key, group, id) => cmd('XGROUP').arg('CREATE').key(key).arg(group).arg(id).arg('MKSTREAM'), as.none),
571
+ /** Deletes a consumer group. `false` if there was none. */
572
+ xgroupDestroy: write((key, group) => cmd('XGROUP').arg('DESTROY').key(key).arg(group), as.bool),
573
+ /**
574
+ * Reads entries as `consumer` of a group: `">"` as the id for the ones no
575
+ * consumer has been given yet. With a `count`, at most that many per
576
+ * stream. A write: it records them as given to the consumer. Read it with
577
+ * {@link Reply.streams}.
578
+ */
579
+ xreadGroup: write((group, consumer, keys, ids, count) => cmd('XREADGROUP')
580
+ .arg('GROUP')
581
+ .arg(group)
582
+ .arg(consumer)
583
+ .argsOf(count === undefined ? [] : ['COUNT', count])
584
+ .arg('STREAMS')
585
+ .keys(keys)
586
+ .argsOf(ids), as.reply),
587
+ /**
588
+ * Acknowledges entries a consumer group was given, returning how many were
589
+ * pending.
590
+ */
591
+ xack: write((key, group, ...ids) => cmd('XACK').key(key).arg(group).argsOf(ids), as.number),
592
+ /**
593
+ * Takes over pending entries that have been idle for `minIdleMs`, for
594
+ * `consumer`: read it with {@link Reply.streamEntries}.
595
+ */
596
+ xclaim: write((key, group, consumer, minIdleMs, ...ids) => cmd('XCLAIM')
597
+ .key(key)
598
+ .arg(group)
599
+ .arg(consumer)
600
+ .arg(minIdleMs)
601
+ .argsOf(ids), as.reply),
602
+ /**
603
+ * Takes over the pending entries from id `start` that have been idle for
604
+ * `minIdleMs`, for `consumer`: read it with {@link Reply.streamAutoClaim}.
605
+ */
606
+ xautoclaim: write((key, group, consumer, minIdleMs, start) => cmd('XAUTOCLAIM')
607
+ .key(key)
608
+ .arg(group)
609
+ .arg(consumer)
610
+ .arg(minIdleMs)
611
+ .arg(start), as.reply),
612
+ /**
613
+ * `xread`, waiting up to `blockMs` milliseconds for an
614
+ * entry if there is none yet: 0 waits for ever. With a `count`, at most that
615
+ * many per stream. A nil reply once the wait passes.
616
+ */
617
+ xreadBlock: readBlocking((keys, ids, blockMs, count) => cmd('XREAD')
618
+ .argsOf(count === undefined ? [] : ['COUNT', count])
619
+ .arg('BLOCK')
620
+ .arg(blockMs)
621
+ .arg('STREAMS')
622
+ .keys(keys)
623
+ .argsOf(ids), as.reply),
624
+ /**
625
+ * `xreadGroup`, waiting up to `blockMs` milliseconds
626
+ * for an entry if there is none yet: 0 waits for ever. A nil reply once the
627
+ * wait passes.
628
+ */
629
+ xreadGroupBlock: writeBlocking((group, consumer, keys, ids, blockMs, count) => cmd('XREADGROUP')
630
+ .arg('GROUP')
631
+ .arg(group)
632
+ .arg(consumer)
633
+ .argsOf(count === undefined ? [] : ['COUNT', count])
634
+ .arg('BLOCK')
635
+ .arg(blockMs)
636
+ .arg('STREAMS')
637
+ .keys(keys)
638
+ .argsOf(ids), as.reply),
639
+ };
640
+ const hyperloglog = {
641
+ /**
642
+ * The estimated number of distinct elements added to the keys, counted as
643
+ * their union.
644
+ */
645
+ pfcount: read((...keys) => cmd('PFCOUNT').keys(keys), as.number),
646
+ /** Adds the elements, returning whether the estimate changed. */
647
+ pfadd: write((key, ...elements) => cmd('PFADD').key(key).argsOf(elements), as.bool),
648
+ /** Stores at `destination` the union of itself and the sources. */
649
+ pfmerge: write((destination, ...sources) => cmd('PFMERGE').key(destination).keys(sources), as.none),
650
+ };
651
+ const pubsub = {
652
+ /** Subscribes to one or more channels, on a connection of its own. */
653
+ subscribe: readRun((t, ...channels) => subscribe(t, channels, [])),
654
+ /**
655
+ * Subscribes to the channels matching one or more glob-style patterns, on a
656
+ * connection of its own.
657
+ */
658
+ psubscribe: readRun((t, ...patterns) => subscribe(t, [], patterns)),
659
+ /**
660
+ * Publishes a message to a channel, returning how many subscribers received
661
+ * it. A channel is prefixed like a key, so only this database's subscribers
662
+ * hear it.
663
+ */
664
+ publish: write((channel, message) => cmd('PUBLISH').key(channel).arg(message), as.number),
665
+ };
666
+ /** Every group, by the name it has on a database. */
667
+ const groups = {
668
+ generic,
669
+ string,
670
+ bitmap,
671
+ hash,
672
+ list,
673
+ set,
674
+ sortedSet,
675
+ geo,
676
+ stream,
677
+ hyperloglog,
678
+ pubsub,
679
+ };
680
+ /** `setEx` as a trace names it, after the Rust SDK: `set_ex`. */
681
+ function operation(name) {
682
+ return name.replace(/[A-Z]/g, c => `_${c.toLowerCase()}`);
683
+ }
684
+ /** The command `def` builds from `args`, named and marked as it is. */
685
+ function built(op, def, args) {
686
+ const c = def.build(...args);
687
+ const out = new Cmd(op, c.name, def.write);
688
+ out.args.push(...c.args);
689
+ return out;
690
+ }
691
+ function runForms(t, readOnly) {
692
+ const out = {};
693
+ for (const [groupName, group] of Object.entries(groups)) {
694
+ const forms = {};
695
+ for (const [name, def] of Object.entries(group)) {
696
+ if (readOnly && def.write)
697
+ continue;
698
+ if ('run' in def) {
699
+ forms[name] = (...args) => def.run(t, ...args);
700
+ continue;
701
+ }
702
+ const op = operation(name);
703
+ if ('start' in def) {
704
+ forms[name] = (...args) => def.start(t, built(op, def, args));
705
+ continue;
706
+ }
707
+ if (def.reply === as.reply) {
708
+ // Any error, the command's or that of sending it, is the reply's to
709
+ // report when read.
710
+ forms[name] = (...args) => new ReplyPromise((async () => {
711
+ try {
712
+ return new Reply(await t.run(built(op, def, args)));
713
+ }
714
+ catch (err) {
715
+ return Reply.failed(err);
716
+ }
717
+ })());
718
+ }
719
+ else {
720
+ forms[name] = async (...args) => def.reply(await t.run(built(op, def, args)));
721
+ }
722
+ }
723
+ out[groupName] = Object.freeze(forms);
724
+ }
725
+ return Object.freeze(out);
726
+ }
727
+ /** The command groups of `t`, each running its commands as they are called. */
728
+ export function commandGroups(t) {
729
+ return runForms(t, false);
730
+ }
731
+ /** The command groups of `t` that only read. */
732
+ export function readCommandGroups(t) {
733
+ return runForms(t, true);
734
+ }
735
+ /** The command groups of a pipeline or a transaction, queueing on `queue`. */
736
+ export function queueGroups(queue) {
737
+ const out = {};
738
+ for (const [groupName, group] of Object.entries(groups)) {
739
+ const forms = {};
740
+ for (const [name, def] of Object.entries(group)) {
741
+ if (!('build' in def))
742
+ continue;
743
+ const op = operation(name);
744
+ if ('queued' in def) {
745
+ forms[name] = (...args) => def.queued(queue, built(op, def, args));
746
+ continue;
747
+ }
748
+ if (def.blocking)
749
+ continue;
750
+ forms[name] = (...args) => {
751
+ queue.push(built(op, def, args));
752
+ return forms;
753
+ };
754
+ }
755
+ out[groupName] = Object.freeze(forms);
756
+ }
757
+ return Object.freeze(out);
758
+ }
759
+ //# sourceMappingURL=commands.js.map