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

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 (250) hide show
  1. package/LICENSE +362 -0
  2. package/README.md +122 -2
  3. package/app_meta.test.ts +134 -0
  4. package/app_meta.ts +186 -0
  5. package/config/config.test.ts +381 -0
  6. package/config/config.ts +178 -0
  7. package/config/mod.ts +14 -0
  8. package/config/secrets.ts +147 -0
  9. package/config/value.ts +243 -0
  10. package/cron/mod.ts +23 -0
  11. package/dist/app_meta.d.ts +93 -0
  12. package/dist/app_meta.js +65 -0
  13. package/dist/app_meta.js.map +1 -0
  14. package/dist/config/config.d.ts +105 -0
  15. package/dist/config/config.js +87 -0
  16. package/dist/config/config.js.map +1 -0
  17. package/dist/config/mod.d.ts +4 -0
  18. package/dist/config/mod.js +3 -0
  19. package/dist/config/mod.js.map +1 -0
  20. package/dist/config/secrets.d.ts +92 -0
  21. package/dist/config/secrets.js +80 -0
  22. package/dist/config/secrets.js.map +1 -0
  23. package/dist/config/value.d.ts +51 -0
  24. package/dist/config/value.js +178 -0
  25. package/dist/config/value.js.map +1 -0
  26. package/dist/cron/mod.d.ts +22 -0
  27. package/dist/cron/mod.js +9 -0
  28. package/dist/cron/mod.js.map +1 -0
  29. package/dist/internal/otel/backend.d.ts +50 -0
  30. package/dist/internal/otel/backend.js +2 -0
  31. package/dist/internal/otel/backend.js.map +1 -0
  32. package/dist/internal/otel/context.d.ts +10 -0
  33. package/dist/internal/otel/context.js +34 -0
  34. package/dist/internal/otel/context.js.map +1 -0
  35. package/dist/internal/otel/context_manager.d.ts +22 -0
  36. package/dist/internal/otel/context_manager.js +120 -0
  37. package/dist/internal/otel/context_manager.js.map +1 -0
  38. package/dist/internal/otel/encode.d.ts +112 -0
  39. package/dist/internal/otel/encode.js +290 -0
  40. package/dist/internal/otel/encode.js.map +1 -0
  41. package/dist/internal/otel/index.d.ts +9 -0
  42. package/dist/internal/otel/index.js +9 -0
  43. package/dist/internal/otel/index.js.map +1 -0
  44. package/dist/internal/otel/meter.d.ts +73 -0
  45. package/dist/internal/otel/meter.js +265 -0
  46. package/dist/internal/otel/meter.js.map +1 -0
  47. package/dist/internal/otel/propagator.d.ts +14 -0
  48. package/dist/internal/otel/propagator.js +61 -0
  49. package/dist/internal/otel/propagator.js.map +1 -0
  50. package/dist/internal/otel/provider.d.ts +9 -0
  51. package/dist/internal/otel/provider.js +19 -0
  52. package/dist/internal/otel/provider.js.map +1 -0
  53. package/dist/internal/otel/request_context.d.ts +11 -0
  54. package/dist/internal/otel/request_context.js +20 -0
  55. package/dist/internal/otel/request_context.js.map +1 -0
  56. package/dist/internal/otel/span.d.ts +61 -0
  57. package/dist/internal/otel/span.js +206 -0
  58. package/dist/internal/otel/span.js.map +1 -0
  59. package/dist/internal/otel/tracer.d.ts +15 -0
  60. package/dist/internal/otel/tracer.js +65 -0
  61. package/dist/internal/otel/tracer.js.map +1 -0
  62. package/dist/internal/reqtrack/mod.d.ts +6 -0
  63. package/dist/internal/reqtrack/mod.js +28 -0
  64. package/dist/internal/reqtrack/mod.js.map +1 -0
  65. package/dist/internal/runtime/meter.d.ts +11 -0
  66. package/dist/internal/runtime/meter.js +22 -0
  67. package/dist/internal/runtime/meter.js.map +1 -0
  68. package/dist/internal/runtime/mod.d.ts +12 -0
  69. package/dist/internal/runtime/mod.js +28 -0
  70. package/dist/internal/runtime/mod.js.map +1 -0
  71. package/dist/internal/runtime/napi/napi.cjs +122 -0
  72. package/dist/internal/runtime/napi/napi.d.cts +601 -0
  73. package/dist/internal/runtime/shutdown.d.ts +13 -0
  74. package/dist/internal/runtime/shutdown.js +56 -0
  75. package/dist/internal/runtime/shutdown.js.map +1 -0
  76. package/dist/internal/utils/constraints.d.ts +9 -0
  77. package/dist/internal/utils/constraints.js +2 -0
  78. package/dist/internal/utils/constraints.js.map +1 -0
  79. package/dist/log/index.d.ts +39 -0
  80. package/dist/log/index.js +44 -0
  81. package/dist/log/index.js.map +1 -0
  82. package/dist/log/logger.d.ts +123 -0
  83. package/dist/log/logger.js +203 -0
  84. package/dist/log/logger.js.map +1 -0
  85. package/dist/log/runtime.d.ts +19 -0
  86. package/dist/log/runtime.js +22 -0
  87. package/dist/log/runtime.js.map +1 -0
  88. package/dist/log/stderr.d.ts +9 -0
  89. package/dist/log/stderr.js +25 -0
  90. package/dist/log/stderr.js.map +1 -0
  91. package/dist/metrics/mod.d.ts +315 -0
  92. package/dist/metrics/mod.js +488 -0
  93. package/dist/metrics/mod.js.map +1 -0
  94. package/dist/mod.d.ts +6 -0
  95. package/dist/mod.js +4 -0
  96. package/dist/mod.js.map +1 -0
  97. package/dist/otel.d.ts +9 -0
  98. package/dist/otel.js +13 -0
  99. package/dist/otel.js.map +1 -0
  100. package/dist/pubsub/encoding.d.ts +3 -0
  101. package/dist/pubsub/encoding.js +10 -0
  102. package/dist/pubsub/encoding.js.map +1 -0
  103. package/dist/pubsub/mod.d.ts +6 -0
  104. package/dist/pubsub/mod.js +3 -0
  105. package/dist/pubsub/mod.js.map +1 -0
  106. package/dist/pubsub/refs.d.ts +12 -0
  107. package/dist/pubsub/refs.js +11 -0
  108. package/dist/pubsub/refs.js.map +1 -0
  109. package/dist/pubsub/subscription.d.ts +128 -0
  110. package/dist/pubsub/subscription.js +39 -0
  111. package/dist/pubsub/subscription.js.map +1 -0
  112. package/dist/pubsub/topic.d.ts +148 -0
  113. package/dist/pubsub/topic.js +164 -0
  114. package/dist/pubsub/topic.js.map +1 -0
  115. package/dist/req_meta.d.ts +47 -0
  116. package/dist/req_meta.js +26 -0
  117. package/dist/req_meta.js.map +1 -0
  118. package/dist/services/index.d.ts +7 -0
  119. package/dist/services/index.js +17 -0
  120. package/dist/services/index.js.map +1 -0
  121. package/dist/shutdown/mod.d.ts +23 -0
  122. package/dist/shutdown/mod.js +24 -0
  123. package/dist/shutdown/mod.js.map +1 -0
  124. package/dist/storage/objects/bucket.d.ts +216 -0
  125. package/dist/storage/objects/bucket.js +123 -0
  126. package/dist/storage/objects/bucket.js.map +1 -0
  127. package/dist/storage/objects/error.d.ts +14 -0
  128. package/dist/storage/objects/error.js +81 -0
  129. package/dist/storage/objects/error.js.map +1 -0
  130. package/dist/storage/objects/mod.d.ts +4 -0
  131. package/dist/storage/objects/mod.js +3 -0
  132. package/dist/storage/objects/mod.js.map +1 -0
  133. package/dist/storage/objects/refs.d.ts +31 -0
  134. package/dist/storage/objects/refs.js +20 -0
  135. package/dist/storage/objects/refs.js.map +1 -0
  136. package/dist/storage/postgres/database.d.ts +295 -0
  137. package/dist/storage/postgres/database.js +378 -0
  138. package/dist/storage/postgres/database.js.map +1 -0
  139. package/dist/storage/postgres/mod.d.ts +2 -0
  140. package/dist/storage/postgres/mod.js +2 -0
  141. package/dist/storage/postgres/mod.js.map +1 -0
  142. package/dist/storage/redis/commands.d.ts +573 -0
  143. package/dist/storage/redis/commands.js +637 -0
  144. package/dist/storage/redis/commands.js.map +1 -0
  145. package/dist/storage/redis/database.d.ts +302 -0
  146. package/dist/storage/redis/database.js +336 -0
  147. package/dist/storage/redis/database.js.map +1 -0
  148. package/dist/storage/redis/mod.d.ts +88 -0
  149. package/dist/storage/redis/mod.js +84 -0
  150. package/dist/storage/redis/mod.js.map +1 -0
  151. package/dist/storage/redis/native.d.ts +8 -0
  152. package/dist/storage/redis/native.js +11 -0
  153. package/dist/storage/redis/native.js.map +1 -0
  154. package/dist/storage/redis/options.d.ts +89 -0
  155. package/dist/storage/redis/options.js +53 -0
  156. package/dist/storage/redis/options.js.map +1 -0
  157. package/dist/storage/redis/pubsub.d.ts +53 -0
  158. package/dist/storage/redis/pubsub.js +88 -0
  159. package/dist/storage/redis/pubsub.js.map +1 -0
  160. package/dist/storage/redis/reply.d.ts +256 -0
  161. package/dist/storage/redis/reply.js +572 -0
  162. package/dist/storage/redis/reply.js.map +1 -0
  163. package/dist/storage/redis/scan.d.ts +11 -0
  164. package/dist/storage/redis/scan.js +76 -0
  165. package/dist/storage/redis/scan.js.map +1 -0
  166. package/dist/storage/redis/script.d.ts +91 -0
  167. package/dist/storage/redis/script.js +143 -0
  168. package/dist/storage/redis/script.js.map +1 -0
  169. package/dist/storage/redis/target.d.ts +47 -0
  170. package/dist/storage/redis/target.js +82 -0
  171. package/dist/storage/redis/target.js.map +1 -0
  172. package/dist/storage/redis/wire.d.ts +105 -0
  173. package/dist/storage/redis/wire.js +333 -0
  174. package/dist/storage/redis/wire.js.map +1 -0
  175. package/dist/tsconfig.build.tsbuildinfo +1 -0
  176. package/dist/types/mod.d.ts +42 -0
  177. package/dist/types/mod.js +65 -0
  178. package/dist/types/mod.js.map +1 -0
  179. package/internal/otel/backend.ts +60 -0
  180. package/internal/otel/context.test.ts +70 -0
  181. package/internal/otel/context.ts +48 -0
  182. package/internal/otel/context_manager.test.ts +154 -0
  183. package/internal/otel/context_manager.ts +141 -0
  184. package/internal/otel/encode.test.ts +266 -0
  185. package/internal/otel/encode.ts +408 -0
  186. package/internal/otel/index.ts +20 -0
  187. package/internal/otel/meter.test.ts +231 -0
  188. package/internal/otel/meter.ts +332 -0
  189. package/internal/otel/propagator.test.ts +105 -0
  190. package/internal/otel/propagator.ts +68 -0
  191. package/internal/otel/provider.ts +23 -0
  192. package/internal/otel/request_context.ts +32 -0
  193. package/internal/otel/span.ts +252 -0
  194. package/internal/otel/tracer.test.ts +352 -0
  195. package/internal/otel/tracer.ts +104 -0
  196. package/internal/reqtrack/mod.ts +39 -0
  197. package/internal/runtime/meter.ts +26 -0
  198. package/internal/runtime/mod.ts +41 -0
  199. package/internal/runtime/napi/napi.cjs +122 -0
  200. package/internal/runtime/napi/napi.d.cts +601 -0
  201. package/internal/runtime/shutdown.test.ts +248 -0
  202. package/internal/runtime/shutdown.ts +64 -0
  203. package/internal/utils/constraints.ts +12 -0
  204. package/log/index.ts +107 -0
  205. package/log/logger.test.ts +194 -0
  206. package/log/logger.ts +308 -0
  207. package/log/runtime.test.ts +65 -0
  208. package/log/runtime.ts +40 -0
  209. package/log/stderr.test.ts +23 -0
  210. package/log/stderr.ts +24 -0
  211. package/metrics/export.test.ts +337 -0
  212. package/metrics/mod.test.ts +180 -0
  213. package/metrics/mod.ts +619 -0
  214. package/mod.ts +22 -0
  215. package/otel.test.ts +84 -0
  216. package/otel.ts +17 -0
  217. package/package.json +121 -5
  218. package/pubsub/encoding.ts +8 -0
  219. package/pubsub/mod.ts +14 -0
  220. package/pubsub/pubsub.test.ts +186 -0
  221. package/pubsub/refs.ts +22 -0
  222. package/pubsub/subscription.ts +180 -0
  223. package/pubsub/topic.test.ts +121 -0
  224. package/pubsub/topic.ts +212 -0
  225. package/req_meta.ts +75 -0
  226. package/services/index.test.ts +30 -0
  227. package/services/index.ts +16 -0
  228. package/shutdown/mod.ts +24 -0
  229. package/storage/objects/bucket.ts +338 -0
  230. package/storage/objects/error.ts +94 -0
  231. package/storage/objects/mod.ts +35 -0
  232. package/storage/objects/refs.ts +69 -0
  233. package/storage/postgres/database.integration.test.ts +175 -0
  234. package/storage/postgres/database.test.ts +241 -0
  235. package/storage/postgres/database.ts +497 -0
  236. package/storage/postgres/mod.ts +15 -0
  237. package/storage/redis/commands.ts +1221 -0
  238. package/storage/redis/database.ts +466 -0
  239. package/storage/redis/mod.ts +135 -0
  240. package/storage/redis/native.ts +11 -0
  241. package/storage/redis/options.ts +119 -0
  242. package/storage/redis/pubsub.ts +92 -0
  243. package/storage/redis/redis.test.ts +706 -0
  244. package/storage/redis/reply.ts +705 -0
  245. package/storage/redis/runtime.test.ts +233 -0
  246. package/storage/redis/scan.ts +125 -0
  247. package/storage/redis/script.ts +162 -0
  248. package/storage/redis/target.ts +131 -0
  249. package/storage/redis/wire.ts +369 -0
  250. package/types/mod.ts +92 -0
@@ -0,0 +1,53 @@
1
+ /** @internal */
2
+ export function expiryArgs(expiry) {
3
+ if ('ex' in expiry)
4
+ return ['EX', expiry.ex];
5
+ if ('px' in expiry)
6
+ return ['PX', expiry.px];
7
+ if ('exAt' in expiry)
8
+ return ['EXAT', expiry.exAt];
9
+ if ('pxAt' in expiry)
10
+ return ['PXAT', expiry.pxAt];
11
+ if ('keepTtl' in expiry)
12
+ return ['KEEPTTL'];
13
+ return ['PERSIST'];
14
+ }
15
+ /** @internal */
16
+ export function setArgs(options) {
17
+ const out = [];
18
+ if (options.condition === 'nx')
19
+ out.push('NX');
20
+ if (options.condition === 'xx')
21
+ out.push('XX');
22
+ if (options.get)
23
+ out.push('GET');
24
+ if (options.expiry)
25
+ out.push(...expiryArgs(options.expiry));
26
+ return out;
27
+ }
28
+ /** @internal */
29
+ export function directionArg(d) {
30
+ return d === 'right' ? 'RIGHT' : 'LEFT';
31
+ }
32
+ /** @internal */
33
+ export function radiusArgs(options = {}) {
34
+ const out = [];
35
+ if (options.withCoord)
36
+ out.push('WITHCOORD');
37
+ if (options.withDist)
38
+ out.push('WITHDIST');
39
+ if (options.withHash)
40
+ out.push('WITHHASH');
41
+ if (options.count)
42
+ out.push('COUNT', options.count);
43
+ if (options.order === 'asc')
44
+ out.push('ASC');
45
+ if (options.order === 'desc')
46
+ out.push('DESC');
47
+ return out;
48
+ }
49
+ /** @internal */
50
+ export function maxlenArgs(m) {
51
+ return ['MAXLEN', m.approx ? '~' : '=', m.maxlen];
52
+ }
53
+ //# sourceMappingURL=options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.js","sourceRoot":"","sources":["../../../storage/redis/options.ts"],"names":[],"mappings":"AA8EA,gBAAgB;AAChB,MAAM,UAAU,UAAU,CAAC,MAA0B;IACnD,IAAI,IAAI,IAAI,MAAM;QAAE,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC;IAC7C,IAAI,IAAI,IAAI,MAAM;QAAE,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC;IAC7C,IAAI,MAAM,IAAI,MAAM;QAAE,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;IACnD,IAAI,MAAM,IAAI,MAA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AAO,CAAC,KAAK,CAAC,CAAC;IACpD,IAAI,OAAO,CAAC,KAAK,KAAK,KAAK;QAAE,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC7C,IAAI,OAAO,CAAC,KAAK,KAAK,MAAM;QAAE,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC/C,OAAO,GAAG,CAAC;AACb,CAAC;AAED,gBAAgB;AAChB,MAAM,UAAU,UAAU,CAAC,CAAe;IACxC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC;AACpD,CAAC"}
@@ -0,0 +1,53 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import type * as runtime from '../../internal/runtime/mod.js';
4
+ import type { Target } from './target.js';
5
+ /**
6
+ * A message received on a {@link Subscription}.
7
+ */
8
+ export declare class Message {
9
+ /** The channel it was published to. */
10
+ readonly channel: string;
11
+ /** What was published, as it was sent. */
12
+ readonly payload: Buffer;
13
+ /** @internal */
14
+ constructor(
15
+ /** The channel it was published to. */
16
+ channel: string,
17
+ /** What was published, as it was sent. */
18
+ payload: Buffer);
19
+ /** The payload as UTF-8 text. */
20
+ text(): string;
21
+ /** The payload's text, parsed as JSON. */
22
+ json<T = unknown>(): T;
23
+ }
24
+ /**
25
+ * An open subscription, on a connection of its own: Redis's own channel
26
+ * messaging, where a message reaches whoever is subscribed at that moment and
27
+ * nobody else. For messages that are kept until they are handled, use
28
+ * `@encore.dev/sdk/pubsub`.
29
+ *
30
+ * Iterate over it for its messages. Close it when done with it, which closes
31
+ * its connection and unsubscribes; leaving a `for await` loop over it early
32
+ * closes it too.
33
+ *
34
+ * ```ts
35
+ * const sub = await EVENTS.pubsub.subscribe("orders");
36
+ * for await (const message of sub) {
37
+ * console.log(message.channel, message.text());
38
+ * }
39
+ * ```
40
+ */
41
+ export declare class Subscription implements AsyncIterable<Message>, AsyncDisposable {
42
+ private readonly impl;
43
+ /** @internal */
44
+ constructor(impl: runtime.RedisSubscription);
45
+ /** The next message, or `null` once the subscription is closed. */
46
+ next(): Promise<Message | null>;
47
+ [Symbol.asyncIterator](): AsyncGenerator<Message>;
48
+ /** Closes the subscription. Safe to call more than once. */
49
+ close(): Promise<void>;
50
+ [Symbol.asyncDispose](): Promise<void>;
51
+ }
52
+ /** Subscribes to `channels` and to the channels matching `patterns`. */
53
+ export declare function subscribe(t: Target, channels: string[], patterns: string[]): Promise<Subscription>;
@@ -0,0 +1,88 @@
1
+ import { activeCtxBytes } from '../../internal/otel/index.js';
2
+ import { encodeList } from './wire.js';
3
+ /**
4
+ * A message received on a {@link Subscription}.
5
+ */
6
+ export class Message {
7
+ channel;
8
+ payload;
9
+ /** @internal */
10
+ constructor(
11
+ /** The channel it was published to. */
12
+ channel,
13
+ /** What was published, as it was sent. */
14
+ payload) {
15
+ this.channel = channel;
16
+ this.payload = payload;
17
+ }
18
+ /** The payload as UTF-8 text. */
19
+ text() {
20
+ return this.payload.toString('utf8');
21
+ }
22
+ /** The payload's text, parsed as JSON. */
23
+ json() {
24
+ return JSON.parse(this.text());
25
+ }
26
+ }
27
+ /**
28
+ * An open subscription, on a connection of its own: Redis's own channel
29
+ * messaging, where a message reaches whoever is subscribed at that moment and
30
+ * nobody else. For messages that are kept until they are handled, use
31
+ * `@encore.dev/sdk/pubsub`.
32
+ *
33
+ * Iterate over it for its messages. Close it when done with it, which closes
34
+ * its connection and unsubscribes; leaving a `for await` loop over it early
35
+ * closes it too.
36
+ *
37
+ * ```ts
38
+ * const sub = await EVENTS.pubsub.subscribe("orders");
39
+ * for await (const message of sub) {
40
+ * console.log(message.channel, message.text());
41
+ * }
42
+ * ```
43
+ */
44
+ export class Subscription {
45
+ impl;
46
+ /** @internal */
47
+ constructor(impl) {
48
+ this.impl = impl;
49
+ }
50
+ /** The next message, or `null` once the subscription is closed. */
51
+ async next() {
52
+ const message = await this.impl.next();
53
+ if (message === null)
54
+ return null;
55
+ return new Message(message.channel.toString('utf8'), message.payload);
56
+ }
57
+ async *[Symbol.asyncIterator]() {
58
+ try {
59
+ for (;;) {
60
+ const message = await this.next();
61
+ if (message === null)
62
+ return;
63
+ yield message;
64
+ }
65
+ }
66
+ finally {
67
+ await this.close();
68
+ }
69
+ }
70
+ /** Closes the subscription. Safe to call more than once. */
71
+ async close() {
72
+ await this.impl.close();
73
+ }
74
+ async [Symbol.asyncDispose]() {
75
+ await this.close();
76
+ }
77
+ }
78
+ /** Subscribes to `channels` and to the channels matching `patterns`. */
79
+ export async function subscribe(t, channels, patterns) {
80
+ if (channels.length === 0 && patterns.length === 0) {
81
+ throw new TypeError('redis: subscribe to at least one channel or pattern');
82
+ }
83
+ const impl = await t
84
+ .database()
85
+ .subscribe(encodeList(channels), encodeList(patterns), activeCtxBytes());
86
+ return new Subscription(impl);
87
+ }
88
+ //# sourceMappingURL=pubsub.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pubsub.js","sourceRoot":"","sources":["../../../storage/redis/pubsub.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,2BAA2B,CAAC;AAGzD,OAAO,EAAC,UAAU,EAAC,MAAM,QAAQ,CAAC;AAElC;;GAEG;AACH,MAAM,OAAO,OAAO;IAIP;IAEA;IALX,gBAAgB;IAChB;IACE,uCAAuC;IAC9B,OAAe;IACxB,0CAA0C;IACjC,OAAe;QAFf,YAAO,GAAP,OAAO,CAAQ;QAEf,YAAO,GAAP,OAAO,CAAQ;IACvB,CAAC;IAEJ,iCAAiC;IACjC,IAAI;QACF,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACvC,CAAC;IAED,0CAA0C;IAC1C,IAAI;QACF,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,CAAM,CAAC;IACtC,CAAC;CACF;AAED;;;;;;;;;;;;;;;;GAgBG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;SACV,SAAS,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,UAAU,CAAC,QAAQ,CAAC,EAAE,cAAc,EAAE,CAAC,CAAC;IAC3E,OAAO,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC;AAChC,CAAC"}
@@ -0,0 +1,256 @@
1
+ /// <reference types="node" />
2
+ import { Value } from './wire.js';
3
+ /**
4
+ * A reply as plain values: what {@link Reply.value} returns. A string reply is
5
+ * text, an integer a `number` (a `bigint` past what a `number` holds exactly),
6
+ * a map an object keyed by its keys' text, with no prototype.
7
+ */
8
+ export type RedisValue = null | string | number | bigint | boolean | RedisValue[] | {
9
+ [key: string]: RedisValue;
10
+ };
11
+ /** A member of a sorted set, with its score. */
12
+ export interface ScoredMember {
13
+ member: string;
14
+ score: number;
15
+ }
16
+ /** A field of a hash, with its value. */
17
+ export interface FieldValue {
18
+ field: string;
19
+ value: string;
20
+ }
21
+ /** An entry of a stream: its id and its fields. */
22
+ export interface StreamEntry {
23
+ id: string;
24
+ fields: Record<string, string>;
25
+ }
26
+ /** The entries read from one stream. */
27
+ export interface Stream {
28
+ key: string;
29
+ entries: StreamEntry[];
30
+ }
31
+ /**
32
+ * The summary of what a consumer group has been given and not acknowledged,
33
+ * as `xpending` replies.
34
+ */
35
+ export interface StreamPending {
36
+ /** How many entries are pending. */
37
+ count: number;
38
+ /** The lowest pending id: `null` when nothing is pending. */
39
+ lowest: string | null;
40
+ /** The highest pending id: `null` when nothing is pending. */
41
+ highest: string | null;
42
+ /** The consumers with pending entries, and how many each has. */
43
+ consumers: {
44
+ name: string;
45
+ pending: number;
46
+ }[];
47
+ }
48
+ /** What the server knows about a stream, as `xinfoStream` replies. */
49
+ export interface StreamInfo {
50
+ length: number;
51
+ radixTreeKeys: number;
52
+ radixTreeNodes: number;
53
+ groups: number;
54
+ lastGeneratedId: string;
55
+ /** `null` for an empty stream. */
56
+ firstEntry: StreamEntry | null;
57
+ /** `null` for an empty stream. */
58
+ lastEntry: StreamEntry | null;
59
+ }
60
+ /** What `xautoclaim` replies. */
61
+ export interface StreamAutoClaim {
62
+ /**
63
+ * The id to pass as the next call's start, or `"0-0"` when the scan of
64
+ * pending entries is done.
65
+ */
66
+ next: string;
67
+ /** The entries now held by the consumer. */
68
+ claimed: StreamEntry[];
69
+ /** The ids of pending entries that no longer exist. */
70
+ deleted: string[];
71
+ }
72
+ /** A position on Earth. */
73
+ export interface GeoPosition {
74
+ longitude: number;
75
+ latitude: number;
76
+ }
77
+ /** A member found by a radius search, with what the search asked for of it. */
78
+ export interface GeoRadiusResult {
79
+ name: string;
80
+ /** The distance from the center, with `withDist`. */
81
+ dist?: number;
82
+ /** The member's geohash as an integer, with `withHash`. */
83
+ hash?: bigint;
84
+ /** The member's position, with `withCoord`. */
85
+ coord?: GeoPosition;
86
+ }
87
+ export declare function textOf(v: Value): string;
88
+ /** An array reply's elements; a map's keys and values in turn; none for nil. */
89
+ export declare function arrayOf(v: Value): Value[];
90
+ /** The members of a sorted set with their scores, nested in pairs or flat. */
91
+ export declare function scoredMembersOf(items: Value[]): ScoredMember[];
92
+ /**
93
+ * What Redis replied to a command, or the error the command failed with. Read
94
+ * it as what it holds: {@link Reply.text}, {@link Reply.number},
95
+ * {@link Reply.textMap}, …; each throws the command's error if it failed, and
96
+ * reads a nil reply as `null`.
97
+ */
98
+ export declare class Reply {
99
+ private readonly reply;
100
+ private readonly err?;
101
+ /** @internal */
102
+ constructor(reply: Value, err?: Error | undefined);
103
+ /** @internal A reply for a command that could not be sent. */
104
+ static failed(err: unknown): Reply;
105
+ /** The error the command failed with, if it did. A nil reply is not one. */
106
+ get error(): Error | undefined;
107
+ /** Whether the command succeeded and replied nil. */
108
+ isNull(): boolean;
109
+ /** The reply, or the error it failed with, thrown. */
110
+ private get v();
111
+ /** The reply as plain values. */
112
+ value(): RedisValue;
113
+ /** The reply as text: a string's bytes as UTF-8, or a number's digits. */
114
+ text(): string | null;
115
+ /** The reply as bytes. */
116
+ bytes(): Buffer | null;
117
+ /**
118
+ * The reply as a number, parsing a string that holds one. An integer past
119
+ * what a `number` holds exactly is rounded: read it with
120
+ * {@link Reply.bigint}.
121
+ */
122
+ number(): number | null;
123
+ /** The reply as an integer, parsing a string that holds one. */
124
+ bigint(): bigint | null;
125
+ /** The reply as a boolean: an integer is true unless 0, and `OK` is true. */
126
+ bool(): boolean | null;
127
+ /** The reply's text, parsed as JSON. */
128
+ json<T = unknown>(): T | null;
129
+ /** An array reply as each of its elements, to read each as what it holds. */
130
+ replies(): Reply[];
131
+ /**
132
+ * An array reply as text. A nil element throws; to tell missing elements
133
+ * apart, use {@link Reply.optionalTexts}.
134
+ */
135
+ texts(): string[];
136
+ /**
137
+ * An array reply as text, a nil element as `null`: what `mget` and `hmget`
138
+ * reply for a missing key or field.
139
+ */
140
+ optionalTexts(): (string | null)[];
141
+ /** An array reply as numbers. */
142
+ numbers(): number[];
143
+ /** An array reply as booleans. */
144
+ bools(): boolean[];
145
+ /**
146
+ * A map reply, or an array of keys and values in turn, as an object: what
147
+ * `hgetall` replies. The object has no prototype, so each field is its own
148
+ * key, `__proto__` too.
149
+ */
150
+ textMap(): Record<string, string>;
151
+ /**
152
+ * The members of a sorted set with their scores, as `zrangeWithscores` and
153
+ * `zpopmin` reply.
154
+ */
155
+ scoredMembers(): ScoredMember[];
156
+ /**
157
+ * The entries of a stream, as `xrange`, `xrevrange` and `xclaim` reply.
158
+ */
159
+ streamEntries(): StreamEntry[];
160
+ /**
161
+ * The entries read from each stream, as `xread` and `xreadGroup` reply. A
162
+ * read that found nothing is no streams.
163
+ */
164
+ streams(): Stream[];
165
+ /** The reply of `xpending`. */
166
+ streamPending(): StreamPending;
167
+ /** The reply of `xinfoStream`. */
168
+ streamInfo(): StreamInfo;
169
+ /** The reply of `xautoclaim`. */
170
+ streamAutoClaim(): StreamAutoClaim;
171
+ /** The position of each member, a missing one as `null`, as `geoPos` replies. */
172
+ geoPositions(): (GeoPosition | null)[];
173
+ /** The members a radius search found, as `geoRadius` replies. */
174
+ geoRadius(): GeoRadiusResult[];
175
+ }
176
+ /**
177
+ * A command's reply, on its way. Await it for the {@link Reply}, which
178
+ * rejects if the command failed; or read it as what it holds straight away:
179
+ *
180
+ * ```ts
181
+ * const name = await SESSIONS.string.get("name:1").text();
182
+ * ```
183
+ *
184
+ * The command is sent when it is called, whether or not this is awaited.
185
+ */
186
+ export declare class ReplyPromise implements PromiseLike<Reply> {
187
+ private readonly reply;
188
+ /** @internal */
189
+ constructor(reply: Promise<Reply>);
190
+ then<T = Reply, E = never>(onfulfilled?: ((value: Reply) => T | PromiseLike<T>) | null, onrejected?: ((reason: unknown) => E | PromiseLike<E>) | null): Promise<T | E>;
191
+ catch<E = never>(onrejected?: ((reason: unknown) => E | PromiseLike<E>) | null): Promise<Reply | E>;
192
+ finally(onfinally?: (() => void) | null): Promise<Reply>;
193
+ /** See {@link Reply.value}. */
194
+ value(): Promise<RedisValue>;
195
+ /** See {@link Reply.text}. */
196
+ text(): Promise<string | null>;
197
+ /** See {@link Reply.bytes}. */
198
+ bytes(): Promise<Buffer | null>;
199
+ /** See {@link Reply.number}. */
200
+ number(): Promise<number | null>;
201
+ /** See {@link Reply.bigint}. */
202
+ bigint(): Promise<bigint | null>;
203
+ /** See {@link Reply.bool}. */
204
+ bool(): Promise<boolean | null>;
205
+ /** See {@link Reply.json}. */
206
+ json<T = unknown>(): Promise<T | null>;
207
+ /** See {@link Reply.replies}. */
208
+ replies(): Promise<Reply[]>;
209
+ /** See {@link Reply.texts}. */
210
+ texts(): Promise<string[]>;
211
+ /** See {@link Reply.optionalTexts}. */
212
+ optionalTexts(): Promise<(string | null)[]>;
213
+ /** See {@link Reply.numbers}. */
214
+ numbers(): Promise<number[]>;
215
+ /** See {@link Reply.bools}. */
216
+ bools(): Promise<boolean[]>;
217
+ /** See {@link Reply.textMap}. */
218
+ textMap(): Promise<Record<string, string>>;
219
+ /** See {@link Reply.scoredMembers}. */
220
+ scoredMembers(): Promise<ScoredMember[]>;
221
+ /** See {@link Reply.streamEntries}. */
222
+ streamEntries(): Promise<StreamEntry[]>;
223
+ /** See {@link Reply.streams}. */
224
+ streams(): Promise<Stream[]>;
225
+ /** See {@link Reply.streamPending}. */
226
+ streamPending(): Promise<StreamPending>;
227
+ /** See {@link Reply.streamInfo}. */
228
+ streamInfo(): Promise<StreamInfo>;
229
+ /** See {@link Reply.streamAutoClaim}. */
230
+ streamAutoClaim(): Promise<StreamAutoClaim>;
231
+ /** See {@link Reply.geoPositions}. */
232
+ geoPositions(): Promise<(GeoPosition | null)[]>;
233
+ /** See {@link Reply.geoRadius}. */
234
+ geoRadius(): Promise<GeoRadiusResult[]>;
235
+ }
236
+ /**
237
+ * The error a pipeline or a transaction fails with when the server rejected
238
+ * some of its commands. The others ran: Redis has no rollback.
239
+ */
240
+ export declare class BatchError extends Error {
241
+ /** Every command's reply, in the order queued, each holding its own error. */
242
+ readonly replies: Reply[];
243
+ /** @internal */
244
+ constructor(replies: Reply[], first: Error);
245
+ }
246
+ /** Converters for the commands whose reply has one shape. */
247
+ export declare const as: {
248
+ /** The reply, for the caller to read. */
249
+ reply: (v: Value) => Reply;
250
+ none: (v: Value) => void;
251
+ number: (v: Value) => number;
252
+ optionalNumber: (v: Value) => number | null;
253
+ bool: (v: Value) => boolean;
254
+ text: (v: Value) => string;
255
+ bools: (v: Value) => boolean[];
256
+ };