@encore.dev/sdk 0.0.0 → 2.0.0-beta.5
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.
- package/LICENSE +362 -0
- package/README.md +122 -2
- package/app_meta.test.ts +134 -0
- package/app_meta.ts +186 -0
- package/config/config.test.ts +381 -0
- package/config/config.ts +178 -0
- package/config/mod.ts +14 -0
- package/config/secrets.ts +147 -0
- package/config/value.ts +243 -0
- package/cron/mod.ts +23 -0
- package/dist/app_meta.d.ts +93 -0
- package/dist/app_meta.js +65 -0
- package/dist/app_meta.js.map +1 -0
- package/dist/config/config.d.ts +105 -0
- package/dist/config/config.js +87 -0
- package/dist/config/config.js.map +1 -0
- package/dist/config/mod.d.ts +4 -0
- package/dist/config/mod.js +3 -0
- package/dist/config/mod.js.map +1 -0
- package/dist/config/secrets.d.ts +92 -0
- package/dist/config/secrets.js +80 -0
- package/dist/config/secrets.js.map +1 -0
- package/dist/config/value.d.ts +51 -0
- package/dist/config/value.js +178 -0
- package/dist/config/value.js.map +1 -0
- package/dist/cron/mod.d.ts +22 -0
- package/dist/cron/mod.js +9 -0
- package/dist/cron/mod.js.map +1 -0
- package/dist/internal/otel/backend.d.ts +50 -0
- package/dist/internal/otel/backend.js +2 -0
- package/dist/internal/otel/backend.js.map +1 -0
- package/dist/internal/otel/context.d.ts +10 -0
- package/dist/internal/otel/context.js +34 -0
- package/dist/internal/otel/context.js.map +1 -0
- package/dist/internal/otel/context_manager.d.ts +22 -0
- package/dist/internal/otel/context_manager.js +120 -0
- package/dist/internal/otel/context_manager.js.map +1 -0
- package/dist/internal/otel/encode.d.ts +112 -0
- package/dist/internal/otel/encode.js +290 -0
- package/dist/internal/otel/encode.js.map +1 -0
- package/dist/internal/otel/index.d.ts +9 -0
- package/dist/internal/otel/index.js +9 -0
- package/dist/internal/otel/index.js.map +1 -0
- package/dist/internal/otel/meter.d.ts +73 -0
- package/dist/internal/otel/meter.js +265 -0
- package/dist/internal/otel/meter.js.map +1 -0
- package/dist/internal/otel/propagator.d.ts +14 -0
- package/dist/internal/otel/propagator.js +61 -0
- package/dist/internal/otel/propagator.js.map +1 -0
- package/dist/internal/otel/provider.d.ts +9 -0
- package/dist/internal/otel/provider.js +19 -0
- package/dist/internal/otel/provider.js.map +1 -0
- package/dist/internal/otel/request_context.d.ts +11 -0
- package/dist/internal/otel/request_context.js +20 -0
- package/dist/internal/otel/request_context.js.map +1 -0
- package/dist/internal/otel/span.d.ts +61 -0
- package/dist/internal/otel/span.js +206 -0
- package/dist/internal/otel/span.js.map +1 -0
- package/dist/internal/otel/tracer.d.ts +15 -0
- package/dist/internal/otel/tracer.js +65 -0
- package/dist/internal/otel/tracer.js.map +1 -0
- package/dist/internal/reqtrack/mod.d.ts +6 -0
- package/dist/internal/reqtrack/mod.js +28 -0
- package/dist/internal/reqtrack/mod.js.map +1 -0
- package/dist/internal/runtime/meter.d.ts +11 -0
- package/dist/internal/runtime/meter.js +22 -0
- package/dist/internal/runtime/meter.js.map +1 -0
- package/dist/internal/runtime/mod.d.ts +12 -0
- package/dist/internal/runtime/mod.js +28 -0
- package/dist/internal/runtime/mod.js.map +1 -0
- package/dist/internal/runtime/napi/napi.cjs +122 -0
- package/dist/internal/runtime/napi/napi.d.cts +601 -0
- package/dist/internal/runtime/shutdown.d.ts +13 -0
- package/dist/internal/runtime/shutdown.js +56 -0
- package/dist/internal/runtime/shutdown.js.map +1 -0
- package/dist/internal/utils/constraints.d.ts +9 -0
- package/dist/internal/utils/constraints.js +2 -0
- package/dist/internal/utils/constraints.js.map +1 -0
- package/dist/log/index.d.ts +39 -0
- package/dist/log/index.js +44 -0
- package/dist/log/index.js.map +1 -0
- package/dist/log/logger.d.ts +123 -0
- package/dist/log/logger.js +203 -0
- package/dist/log/logger.js.map +1 -0
- package/dist/log/runtime.d.ts +19 -0
- package/dist/log/runtime.js +22 -0
- package/dist/log/runtime.js.map +1 -0
- package/dist/log/stderr.d.ts +9 -0
- package/dist/log/stderr.js +25 -0
- package/dist/log/stderr.js.map +1 -0
- package/dist/metrics/mod.d.ts +315 -0
- package/dist/metrics/mod.js +488 -0
- package/dist/metrics/mod.js.map +1 -0
- package/dist/mod.d.ts +6 -0
- package/dist/mod.js +4 -0
- package/dist/mod.js.map +1 -0
- package/dist/otel.d.ts +9 -0
- package/dist/otel.js +13 -0
- package/dist/otel.js.map +1 -0
- package/dist/pubsub/encoding.d.ts +3 -0
- package/dist/pubsub/encoding.js +10 -0
- package/dist/pubsub/encoding.js.map +1 -0
- package/dist/pubsub/mod.d.ts +6 -0
- package/dist/pubsub/mod.js +3 -0
- package/dist/pubsub/mod.js.map +1 -0
- package/dist/pubsub/refs.d.ts +12 -0
- package/dist/pubsub/refs.js +11 -0
- package/dist/pubsub/refs.js.map +1 -0
- package/dist/pubsub/subscription.d.ts +128 -0
- package/dist/pubsub/subscription.js +39 -0
- package/dist/pubsub/subscription.js.map +1 -0
- package/dist/pubsub/topic.d.ts +148 -0
- package/dist/pubsub/topic.js +164 -0
- package/dist/pubsub/topic.js.map +1 -0
- package/dist/req_meta.d.ts +47 -0
- package/dist/req_meta.js +26 -0
- package/dist/req_meta.js.map +1 -0
- package/dist/services/index.d.ts +12 -0
- package/dist/services/index.js +22 -0
- package/dist/services/index.js.map +1 -0
- package/dist/shutdown/mod.d.ts +23 -0
- package/dist/shutdown/mod.js +24 -0
- package/dist/shutdown/mod.js.map +1 -0
- package/dist/storage/objects/bucket.d.ts +216 -0
- package/dist/storage/objects/bucket.js +123 -0
- package/dist/storage/objects/bucket.js.map +1 -0
- package/dist/storage/objects/error.d.ts +14 -0
- package/dist/storage/objects/error.js +81 -0
- package/dist/storage/objects/error.js.map +1 -0
- package/dist/storage/objects/mod.d.ts +4 -0
- package/dist/storage/objects/mod.js +3 -0
- package/dist/storage/objects/mod.js.map +1 -0
- package/dist/storage/objects/refs.d.ts +31 -0
- package/dist/storage/objects/refs.js +20 -0
- package/dist/storage/objects/refs.js.map +1 -0
- package/dist/storage/postgres/database.d.ts +295 -0
- package/dist/storage/postgres/database.js +378 -0
- package/dist/storage/postgres/database.js.map +1 -0
- package/dist/storage/postgres/mod.d.ts +2 -0
- package/dist/storage/postgres/mod.js +2 -0
- package/dist/storage/postgres/mod.js.map +1 -0
- package/dist/storage/redis/commands.d.ts +573 -0
- package/dist/storage/redis/commands.js +637 -0
- package/dist/storage/redis/commands.js.map +1 -0
- package/dist/storage/redis/database.d.ts +302 -0
- package/dist/storage/redis/database.js +336 -0
- package/dist/storage/redis/database.js.map +1 -0
- package/dist/storage/redis/mod.d.ts +88 -0
- package/dist/storage/redis/mod.js +84 -0
- package/dist/storage/redis/mod.js.map +1 -0
- package/dist/storage/redis/native.d.ts +8 -0
- package/dist/storage/redis/native.js +11 -0
- package/dist/storage/redis/native.js.map +1 -0
- package/dist/storage/redis/options.d.ts +89 -0
- package/dist/storage/redis/options.js +53 -0
- package/dist/storage/redis/options.js.map +1 -0
- package/dist/storage/redis/pubsub.d.ts +53 -0
- package/dist/storage/redis/pubsub.js +88 -0
- package/dist/storage/redis/pubsub.js.map +1 -0
- package/dist/storage/redis/reply.d.ts +256 -0
- package/dist/storage/redis/reply.js +572 -0
- package/dist/storage/redis/reply.js.map +1 -0
- package/dist/storage/redis/scan.d.ts +11 -0
- package/dist/storage/redis/scan.js +76 -0
- package/dist/storage/redis/scan.js.map +1 -0
- package/dist/storage/redis/script.d.ts +91 -0
- package/dist/storage/redis/script.js +143 -0
- package/dist/storage/redis/script.js.map +1 -0
- package/dist/storage/redis/target.d.ts +47 -0
- package/dist/storage/redis/target.js +82 -0
- package/dist/storage/redis/target.js.map +1 -0
- package/dist/storage/redis/wire.d.ts +105 -0
- package/dist/storage/redis/wire.js +333 -0
- package/dist/storage/redis/wire.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/types/mod.d.ts +42 -0
- package/dist/types/mod.js +65 -0
- package/dist/types/mod.js.map +1 -0
- package/internal/otel/backend.ts +60 -0
- package/internal/otel/context.test.ts +70 -0
- package/internal/otel/context.ts +48 -0
- package/internal/otel/context_manager.test.ts +154 -0
- package/internal/otel/context_manager.ts +141 -0
- package/internal/otel/encode.test.ts +266 -0
- package/internal/otel/encode.ts +408 -0
- package/internal/otel/index.ts +20 -0
- package/internal/otel/meter.test.ts +231 -0
- package/internal/otel/meter.ts +332 -0
- package/internal/otel/propagator.test.ts +105 -0
- package/internal/otel/propagator.ts +68 -0
- package/internal/otel/provider.ts +23 -0
- package/internal/otel/request_context.ts +32 -0
- package/internal/otel/span.ts +252 -0
- package/internal/otel/tracer.test.ts +352 -0
- package/internal/otel/tracer.ts +104 -0
- package/internal/reqtrack/mod.ts +39 -0
- package/internal/runtime/meter.ts +26 -0
- package/internal/runtime/mod.ts +41 -0
- package/internal/runtime/napi/napi.cjs +122 -0
- package/internal/runtime/napi/napi.d.cts +601 -0
- package/internal/runtime/shutdown.test.ts +248 -0
- package/internal/runtime/shutdown.ts +64 -0
- package/internal/utils/constraints.ts +12 -0
- package/log/index.ts +107 -0
- package/log/logger.test.ts +194 -0
- package/log/logger.ts +308 -0
- package/log/runtime.test.ts +65 -0
- package/log/runtime.ts +40 -0
- package/log/stderr.test.ts +23 -0
- package/log/stderr.ts +24 -0
- package/metrics/export.test.ts +337 -0
- package/metrics/mod.test.ts +180 -0
- package/metrics/mod.ts +619 -0
- package/mod.ts +22 -0
- package/otel.test.ts +84 -0
- package/otel.ts +17 -0
- package/package.json +121 -5
- package/pubsub/encoding.ts +8 -0
- package/pubsub/mod.ts +14 -0
- package/pubsub/pubsub.test.ts +186 -0
- package/pubsub/refs.ts +22 -0
- package/pubsub/subscription.ts +180 -0
- package/pubsub/topic.test.ts +121 -0
- package/pubsub/topic.ts +212 -0
- package/req_meta.ts +75 -0
- package/services/index.test.ts +30 -0
- package/services/index.ts +21 -0
- package/shutdown/mod.ts +24 -0
- package/storage/objects/bucket.ts +338 -0
- package/storage/objects/error.ts +94 -0
- package/storage/objects/mod.ts +35 -0
- package/storage/objects/refs.ts +69 -0
- package/storage/postgres/database.integration.test.ts +175 -0
- package/storage/postgres/database.test.ts +241 -0
- package/storage/postgres/database.ts +497 -0
- package/storage/postgres/mod.ts +15 -0
- package/storage/redis/commands.ts +1221 -0
- package/storage/redis/database.ts +466 -0
- package/storage/redis/mod.ts +135 -0
- package/storage/redis/native.ts +11 -0
- package/storage/redis/options.ts +119 -0
- package/storage/redis/pubsub.ts +92 -0
- package/storage/redis/redis.test.ts +706 -0
- package/storage/redis/reply.ts +705 -0
- package/storage/redis/runtime.test.ts +233 -0
- package/storage/redis/scan.ts +125 -0
- package/storage/redis/script.ts +162 -0
- package/storage/redis/target.ts +131 -0
- package/storage/redis/wire.ts +369 -0
- package/types/mod.ts +92 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import type {RedisArg} from './wire';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* When a key `setOptions` sets expires: in seconds (`ex`) or milliseconds
|
|
5
|
+
* (`px`), at a Unix time in seconds (`exAt`) or milliseconds (`pxAt`), or
|
|
6
|
+
* keeping the expiry it has.
|
|
7
|
+
*/
|
|
8
|
+
export type SetExpiry =
|
|
9
|
+
| {ex: number}
|
|
10
|
+
| {px: number}
|
|
11
|
+
| {exAt: number}
|
|
12
|
+
| {pxAt: number}
|
|
13
|
+
| {keepTtl: true};
|
|
14
|
+
|
|
15
|
+
/** How `setOptions` sets a key. */
|
|
16
|
+
export interface SetOptions {
|
|
17
|
+
/**
|
|
18
|
+
* When to set the key: only if it does not exist (`"nx"`), or only if it
|
|
19
|
+
* does (`"xx"`).
|
|
20
|
+
*/
|
|
21
|
+
condition?: 'nx' | 'xx';
|
|
22
|
+
/** Reply with the key's old value, or nil if it had none. */
|
|
23
|
+
get?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* When the key expires. Without one it never does, and loses any expiry it
|
|
26
|
+
* had.
|
|
27
|
+
*/
|
|
28
|
+
expiry?: SetExpiry;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* How `getEx` changes a key's expiry: as {@link SetExpiry} says, or removing
|
|
33
|
+
* it.
|
|
34
|
+
*/
|
|
35
|
+
export type Expiry =
|
|
36
|
+
| {ex: number}
|
|
37
|
+
| {px: number}
|
|
38
|
+
| {exAt: number}
|
|
39
|
+
| {pxAt: number}
|
|
40
|
+
| {persist: true};
|
|
41
|
+
|
|
42
|
+
/** An end of a list: its head, or its tail. */
|
|
43
|
+
export type Direction = 'left' | 'right';
|
|
44
|
+
|
|
45
|
+
/** A unit of distance: meters, kilometers, miles or feet. */
|
|
46
|
+
export type Unit = 'm' | 'km' | 'mi' | 'ft';
|
|
47
|
+
|
|
48
|
+
/** What a radius search returns of each member it finds, and how many. */
|
|
49
|
+
export interface RadiusOptions {
|
|
50
|
+
/** Return each member's position. */
|
|
51
|
+
withCoord?: boolean;
|
|
52
|
+
/** Return each member's distance from the center. */
|
|
53
|
+
withDist?: boolean;
|
|
54
|
+
/** Return each member's geohash, as an integer. */
|
|
55
|
+
withHash?: boolean;
|
|
56
|
+
/** The most members to return. */
|
|
57
|
+
count?: number;
|
|
58
|
+
/** The nearest first (`"asc"`), or the farthest. In no order without. */
|
|
59
|
+
order?: 'asc' | 'desc';
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The most entries a stream is trimmed to: exactly `maxlen`, or with `approx`
|
|
64
|
+
* about that many, never fewer, which is cheaper.
|
|
65
|
+
*/
|
|
66
|
+
export interface StreamMaxlen {
|
|
67
|
+
maxlen: number;
|
|
68
|
+
approx?: boolean;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** What a scan looks through, and how much at a time. */
|
|
72
|
+
export interface ScanOptions {
|
|
73
|
+
/** Only what matches a glob-style pattern: `user:*`. */
|
|
74
|
+
pattern?: string;
|
|
75
|
+
/** A hint for how many elements to look at per round trip. */
|
|
76
|
+
count?: number;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** @internal */
|
|
80
|
+
export function expiryArgs(expiry: SetExpiry | Expiry): RedisArg[] {
|
|
81
|
+
if ('ex' in expiry) return ['EX', expiry.ex];
|
|
82
|
+
if ('px' in expiry) return ['PX', expiry.px];
|
|
83
|
+
if ('exAt' in expiry) return ['EXAT', expiry.exAt];
|
|
84
|
+
if ('pxAt' in expiry) return ['PXAT', expiry.pxAt];
|
|
85
|
+
if ('keepTtl' in expiry) return ['KEEPTTL'];
|
|
86
|
+
return ['PERSIST'];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** @internal */
|
|
90
|
+
export function setArgs(options: SetOptions): RedisArg[] {
|
|
91
|
+
const out: RedisArg[] = [];
|
|
92
|
+
if (options.condition === 'nx') out.push('NX');
|
|
93
|
+
if (options.condition === 'xx') out.push('XX');
|
|
94
|
+
if (options.get) out.push('GET');
|
|
95
|
+
if (options.expiry) out.push(...expiryArgs(options.expiry));
|
|
96
|
+
return out;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** @internal */
|
|
100
|
+
export function directionArg(d: Direction): string {
|
|
101
|
+
return d === 'right' ? 'RIGHT' : 'LEFT';
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** @internal */
|
|
105
|
+
export function radiusArgs(options: RadiusOptions = {}): RedisArg[] {
|
|
106
|
+
const out: RedisArg[] = [];
|
|
107
|
+
if (options.withCoord) out.push('WITHCOORD');
|
|
108
|
+
if (options.withDist) out.push('WITHDIST');
|
|
109
|
+
if (options.withHash) out.push('WITHHASH');
|
|
110
|
+
if (options.count) out.push('COUNT', options.count);
|
|
111
|
+
if (options.order === 'asc') out.push('ASC');
|
|
112
|
+
if (options.order === 'desc') out.push('DESC');
|
|
113
|
+
return out;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** @internal */
|
|
117
|
+
export function maxlenArgs(m: StreamMaxlen): RedisArg[] {
|
|
118
|
+
return ['MAXLEN', m.approx ? '~' : '=', m.maxlen];
|
|
119
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import {activeCtxBytes} from '../../internal/otel/index';
|
|
2
|
+
import type * as runtime from '../../internal/runtime/mod';
|
|
3
|
+
import type {Target} from './target';
|
|
4
|
+
import {encodeList} from './wire';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A message received on a {@link Subscription}.
|
|
8
|
+
*/
|
|
9
|
+
export class Message {
|
|
10
|
+
/** @internal */
|
|
11
|
+
constructor(
|
|
12
|
+
/** The channel it was published to. */
|
|
13
|
+
readonly channel: string,
|
|
14
|
+
/** What was published, as it was sent. */
|
|
15
|
+
readonly payload: Buffer,
|
|
16
|
+
) {}
|
|
17
|
+
|
|
18
|
+
/** The payload as UTF-8 text. */
|
|
19
|
+
text(): string {
|
|
20
|
+
return this.payload.toString('utf8');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** The payload's text, parsed as JSON. */
|
|
24
|
+
json<T = unknown>(): T {
|
|
25
|
+
return JSON.parse(this.text()) as T;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* An open subscription, on a connection of its own: Redis's own channel
|
|
31
|
+
* messaging, where a message reaches whoever is subscribed at that moment and
|
|
32
|
+
* nobody else. For messages that are kept until they are handled, use
|
|
33
|
+
* `@encore.dev/sdk/pubsub`.
|
|
34
|
+
*
|
|
35
|
+
* Iterate over it for its messages. Close it when done with it, which closes
|
|
36
|
+
* its connection and unsubscribes; leaving a `for await` loop over it early
|
|
37
|
+
* closes it too.
|
|
38
|
+
*
|
|
39
|
+
* ```ts
|
|
40
|
+
* const sub = await EVENTS.pubsub.subscribe("orders");
|
|
41
|
+
* for await (const message of sub) {
|
|
42
|
+
* console.log(message.channel, message.text());
|
|
43
|
+
* }
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export class Subscription implements AsyncIterable<Message>, AsyncDisposable {
|
|
47
|
+
/** @internal */
|
|
48
|
+
constructor(private readonly impl: runtime.RedisSubscription) {}
|
|
49
|
+
|
|
50
|
+
/** The next message, or `null` once the subscription is closed. */
|
|
51
|
+
async next(): Promise<Message | null> {
|
|
52
|
+
const message = await this.impl.next();
|
|
53
|
+
if (message === null) return null;
|
|
54
|
+
return new Message(message.channel.toString('utf8'), message.payload);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async *[Symbol.asyncIterator](): AsyncGenerator<Message> {
|
|
58
|
+
try {
|
|
59
|
+
for (;;) {
|
|
60
|
+
const message = await this.next();
|
|
61
|
+
if (message === null) return;
|
|
62
|
+
yield message;
|
|
63
|
+
}
|
|
64
|
+
} finally {
|
|
65
|
+
await this.close();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Closes the subscription. Safe to call more than once. */
|
|
70
|
+
async close(): Promise<void> {
|
|
71
|
+
await this.impl.close();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async [Symbol.asyncDispose](): Promise<void> {
|
|
75
|
+
await this.close();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Subscribes to `channels` and to the channels matching `patterns`. */
|
|
80
|
+
export async function subscribe(
|
|
81
|
+
t: Target,
|
|
82
|
+
channels: string[],
|
|
83
|
+
patterns: string[],
|
|
84
|
+
): Promise<Subscription> {
|
|
85
|
+
if (channels.length === 0 && patterns.length === 0) {
|
|
86
|
+
throw new TypeError('redis: subscribe to at least one channel or pattern');
|
|
87
|
+
}
|
|
88
|
+
const impl = await t
|
|
89
|
+
.database()
|
|
90
|
+
.subscribe(encodeList(channels), encodeList(patterns), activeCtxBytes());
|
|
91
|
+
return new Subscription(impl);
|
|
92
|
+
}
|