@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.
- 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 +7 -0
- package/dist/services/index.js +17 -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 +16 -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
package/config/config.ts
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import * as runtime from '../internal/runtime/mod';
|
|
2
|
+
import {secretOfField} from './secrets';
|
|
3
|
+
import {build} from './value';
|
|
4
|
+
|
|
5
|
+
export {Duration} from './value';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A config: a typed value a service reads, written in files beside the code
|
|
9
|
+
* and changed while the app runs. Calling it reads the value now.
|
|
10
|
+
*
|
|
11
|
+
* Declare one with {@link config}, {@link sharedConfig} or
|
|
12
|
+
* {@link globalConfig}, giving the value's type as the type argument. Encore
|
|
13
|
+
* reads that type to know what the config's files may hold, and checks them
|
|
14
|
+
* against it before the value reaches the code.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* import { config, type Min, type Max, type Duration } from "@encore.dev/sdk/config";
|
|
18
|
+
*
|
|
19
|
+
* interface Checkout {
|
|
20
|
+
* // Most items one order may hold.
|
|
21
|
+
* maxItems: number & Int & Min<1> & Max<500>;
|
|
22
|
+
* currencies?: string[];
|
|
23
|
+
* paymentTimeout: Duration;
|
|
24
|
+
* }
|
|
25
|
+
*
|
|
26
|
+
* export const checkout = config<Checkout>("checkout");
|
|
27
|
+
*
|
|
28
|
+
* if (items.length > checkout().maxItems) { ... }
|
|
29
|
+
*
|
|
30
|
+
* # Values
|
|
31
|
+
*
|
|
32
|
+
* A config's value is written in a file named after it — `checkout.config.toml`,
|
|
33
|
+
* or `.json` — beside the declaring service's `encore.service.json`, or beside
|
|
34
|
+
* `encore.app.json` for a shared or global config. Files over it change it for some
|
|
35
|
+
* environments only: `checkout.production.config.toml` for environments of a
|
|
36
|
+
* type, `checkout.@prod-eu.config.toml` for one environment, and
|
|
37
|
+
* `checkout.user.config.toml` — gitignored, the user override — for a
|
|
38
|
+
* developer's own `encore run`, never in tests.
|
|
39
|
+
*
|
|
40
|
+
* Calling the config returns a snapshot: the same object until the value
|
|
41
|
+
* changes, which it may while the app runs, without a restart. Read it where
|
|
42
|
+
* it is used rather than keeping it, or use {@link Config.onChange}.
|
|
43
|
+
*/
|
|
44
|
+
export interface Config<T> {
|
|
45
|
+
/** The config's value now. */
|
|
46
|
+
(): T;
|
|
47
|
+
|
|
48
|
+
/** The name the config was declared with. */
|
|
49
|
+
readonly name: string;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Calls `listener` with each new value the config is given from now on,
|
|
53
|
+
* while the app runs, until the returned function is called, whether or
|
|
54
|
+
* not it is kept. Values that come faster than `listener` is called are
|
|
55
|
+
* coalesced: it gets the latest, once. Does not keep the process alive.
|
|
56
|
+
*/
|
|
57
|
+
onChange(listener: (value: T) => void): () => void;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* config declares a {@link Config} belonging to the service that declares it,
|
|
62
|
+
* which holds its own value for it. Two services may each declare a config of
|
|
63
|
+
* the same name. The declaration must live inside a service, as a module-level
|
|
64
|
+
* `export const`, with the name a string literal.
|
|
65
|
+
*/
|
|
66
|
+
export function config<T>(name: string): Config<T> {
|
|
67
|
+
return makeConfig<T>(name, runtime.RT.config(name));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* sharedConfig declares a {@link Config} with one value for the whole app. A
|
|
72
|
+
* service that reads it is recorded as using it. Unlike {@link config} it may
|
|
73
|
+
* be declared outside a service.
|
|
74
|
+
*/
|
|
75
|
+
export function sharedConfig<T>(name: string): Config<T> {
|
|
76
|
+
return makeConfig<T>(name, runtime.RT.sharedConfig(name));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* globalConfig declares a {@link Config} with one value for the whole app,
|
|
81
|
+
* available to every service without being recorded as used.
|
|
82
|
+
*/
|
|
83
|
+
export function globalConfig<T>(name: string): Config<T> {
|
|
84
|
+
return makeConfig<T>(name, runtime.RT.sharedConfig(name));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** The native handle to a config, when the runtime config has it. */
|
|
88
|
+
type Impl = NonNullable<ReturnType<typeof runtime.RT.config>>;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The native watches not yet stopped. A watch stops when it is collected, and
|
|
92
|
+
* a caller that drops the function `onChange` returns would otherwise leave
|
|
93
|
+
* nothing that is sure to hold it: its calls could end at any collection.
|
|
94
|
+
*/
|
|
95
|
+
const watches = new Set<ReturnType<Impl['onChange']>>();
|
|
96
|
+
|
|
97
|
+
function makeConfig<T>(name: string, impl: Impl | null): Config<T> {
|
|
98
|
+
let schema: Record<string, any> | undefined;
|
|
99
|
+
let cached: {revision: number; value: T} | undefined;
|
|
100
|
+
|
|
101
|
+
/** The value of one revision, built once for it. */
|
|
102
|
+
const valueOf = (impl: Impl, revision: runtime.ConfigRevision): T => {
|
|
103
|
+
if (cached?.revision === revision.number) return cached.value;
|
|
104
|
+
schema ??= JSON.parse(impl.schema());
|
|
105
|
+
const value = build(
|
|
106
|
+
schema!,
|
|
107
|
+
JSON.parse(revision.value),
|
|
108
|
+
secretOfField,
|
|
109
|
+
) as T;
|
|
110
|
+
// Only a newer revision replaces the snapshot: a listener may build one
|
|
111
|
+
// that the value has since moved on from.
|
|
112
|
+
if (cached === undefined || cached.revision < revision.number) {
|
|
113
|
+
cached = {revision: revision.number, value};
|
|
114
|
+
}
|
|
115
|
+
return value;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const read = (): T => {
|
|
119
|
+
if (impl === null) {
|
|
120
|
+
// No value at all: every field takes its default, which in TypeScript is
|
|
121
|
+
// none. The runtime config has every config the app declares, so this
|
|
122
|
+
// is an app run outside Encore.
|
|
123
|
+
if (cached === undefined) cached = {revision: -1, value: {} as T};
|
|
124
|
+
return cached.value;
|
|
125
|
+
}
|
|
126
|
+
if (cached === undefined || cached.revision !== impl.revision()) {
|
|
127
|
+
return valueOf(impl, impl.current());
|
|
128
|
+
}
|
|
129
|
+
return cached.value;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const handle = (() => read()) as Config<T>;
|
|
133
|
+
Object.defineProperty(handle, 'name', {value: name});
|
|
134
|
+
handle.onChange = (listener: (value: T) => void) => {
|
|
135
|
+
if (impl === null) return () => {};
|
|
136
|
+
const watch = impl.onChange(revision => {
|
|
137
|
+
// A later revision is on its way to this listener too: the latest is
|
|
138
|
+
// the one it gets, once.
|
|
139
|
+
if (revision.number < impl.revision()) return;
|
|
140
|
+
// The revision it was told of, not the value now, which may have moved
|
|
141
|
+
// on since.
|
|
142
|
+
listener(valueOf(impl, revision));
|
|
143
|
+
});
|
|
144
|
+
watches.add(watch);
|
|
145
|
+
return () => {
|
|
146
|
+
if (watches.delete(watch)) watch.stop();
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
return handle;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* The value is at least `N`. A constraint on a `number` field of a config's
|
|
154
|
+
* type, written as an intersection: `number & Min<1>`. Encore checks the
|
|
155
|
+
* config's files against it; at runtime the field is a plain `number`.
|
|
156
|
+
*/
|
|
157
|
+
export type Min<N extends number> = {readonly '~encore.min'?: N};
|
|
158
|
+
|
|
159
|
+
/** The value is at most `N`: `number & Max<500>`. See {@link Min}. */
|
|
160
|
+
export type Max<N extends number> = {readonly '~encore.max'?: N};
|
|
161
|
+
|
|
162
|
+
/** The value is a whole number: `number & Int`. See {@link Min}. */
|
|
163
|
+
export type Int = {readonly '~encore.int'?: true};
|
|
164
|
+
|
|
165
|
+
/** The string is at least `N` characters long: `string & MinLen<3>`. */
|
|
166
|
+
export type MinLen<N extends number> = {readonly '~encore.min_len'?: N};
|
|
167
|
+
|
|
168
|
+
/** The string is at most `N` characters long: `string & MaxLen<64>`. */
|
|
169
|
+
export type MaxLen<N extends number> = {readonly '~encore.max_len'?: N};
|
|
170
|
+
|
|
171
|
+
/** The string matches the regular expression `S`: `string & Pattern<"^[A-Z]+$">`. */
|
|
172
|
+
export type Pattern<S extends string> = {readonly '~encore.pattern'?: S};
|
|
173
|
+
|
|
174
|
+
/** The array has at least `N` items: `string[] & MinItems<1>`. */
|
|
175
|
+
export type MinItems<N extends number> = {readonly '~encore.min_items'?: N};
|
|
176
|
+
|
|
177
|
+
/** The array has at most `N` items: `string[] & MaxItems<10>`. */
|
|
178
|
+
export type MaxItems<N extends number> = {readonly '~encore.max_items'?: N};
|
package/config/mod.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type {Secret, AnySecret} from './secrets';
|
|
2
|
+
export {secret, sharedSecret, globalSecret} from './secrets';
|
|
3
|
+
export type {
|
|
4
|
+
Config,
|
|
5
|
+
Min,
|
|
6
|
+
Max,
|
|
7
|
+
Int,
|
|
8
|
+
MinLen,
|
|
9
|
+
MaxLen,
|
|
10
|
+
Pattern,
|
|
11
|
+
MinItems,
|
|
12
|
+
MaxItems,
|
|
13
|
+
} from './config';
|
|
14
|
+
export {config, sharedConfig, globalConfig, Duration} from './config';
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import * as runtime from '../internal/runtime/mod';
|
|
2
|
+
import {StringLiteral} from '../internal/utils/constraints';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Secret represents a single secret value that is loaded
|
|
6
|
+
* into the application. It is strongly typed for that secret,
|
|
7
|
+
* so that you can write functions which expect a specific one.
|
|
8
|
+
*
|
|
9
|
+
* You can use {@link AnySecret} to represent any secret without knowing
|
|
10
|
+
* it's name.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
*
|
|
14
|
+
* function doFoo(s: Secret<"foo">): void {
|
|
15
|
+
* const foo = s();
|
|
16
|
+
* }
|
|
17
|
+
*/
|
|
18
|
+
export interface Secret<Name extends string> {
|
|
19
|
+
/**
|
|
20
|
+
* Returns the current value of the secret.
|
|
21
|
+
*
|
|
22
|
+
* Encore will periodically refresh the value of the secret, so this
|
|
23
|
+
* value may change over time and could be stale for upto a couple of
|
|
24
|
+
* minutes. If you need to ensure you have the latest value, use
|
|
25
|
+
* `latest`.
|
|
26
|
+
*/
|
|
27
|
+
(): string;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The name of the secret.
|
|
31
|
+
*/
|
|
32
|
+
readonly name: Name;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Marks the type as an Encore secret, for Encore's parser, which reads a
|
|
36
|
+
* config's type to know which of its fields read a secret. Never set.
|
|
37
|
+
*
|
|
38
|
+
* As a field of a config's type, `apiKey: Secret<"StripeKey">` reads the
|
|
39
|
+
* secret of that name in the config's own scope: the declaring service's
|
|
40
|
+
* own for `config()`, the app's for `sharedConfig()` and `globalConfig()`.
|
|
41
|
+
* The secret is declared as any other is, with {@link secret},
|
|
42
|
+
* {@link sharedSecret} or {@link globalSecret}.
|
|
43
|
+
*/
|
|
44
|
+
readonly '~encore.secret'?: true;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* AnySecret is a type which can be used to represent any {@link Secret}
|
|
49
|
+
* without knowing its name.
|
|
50
|
+
*/
|
|
51
|
+
export type AnySecret = Secret<string>;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* secret declares a {@link Secret} belonging to the service that declares it.
|
|
55
|
+
*
|
|
56
|
+
* Two services may each declare a secret of the same name and hold different
|
|
57
|
+
* values in them, so adding a secret to one service can never collide with — or
|
|
58
|
+
* silently reuse — a name another service already took. The declaration must
|
|
59
|
+
* therefore live inside a service; Encore reports an error otherwise.
|
|
60
|
+
*
|
|
61
|
+
* For a value several services genuinely share, use {@link sharedSecret}.
|
|
62
|
+
*
|
|
63
|
+
* @example loading a single secret
|
|
64
|
+
* import {secret} from "@encore.dev/sdk/config";
|
|
65
|
+
* const foo = secret("foo");
|
|
66
|
+
*/
|
|
67
|
+
export function secret<Name extends string>(
|
|
68
|
+
name: StringLiteral<Name>,
|
|
69
|
+
): Secret<Name> {
|
|
70
|
+
return makeSecret<Secret<Name>>(name, runtime.RT.secret(name));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* sharedSecret declares a {@link Secret} shared by the whole app, readable from
|
|
75
|
+
* any service. Unlike {@link secret} it may be declared outside a service.
|
|
76
|
+
*
|
|
77
|
+
* Use it only for a value several services genuinely share: a shared secret
|
|
78
|
+
* couples every service that reads it, and widening a secret's scope later is
|
|
79
|
+
* easier than narrowing it.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* import {sharedSecret} from "@encore.dev/sdk/config";
|
|
83
|
+
* const signingKey = sharedSecret("SigningKey");
|
|
84
|
+
*/
|
|
85
|
+
export function sharedSecret<Name extends string>(
|
|
86
|
+
name: StringLiteral<Name>,
|
|
87
|
+
): Secret<Name> {
|
|
88
|
+
return makeSecret<Secret<Name>>(name, runtime.RT.secret(name));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* globalSecret declares a {@link Secret} with one value for the whole app,
|
|
93
|
+
* available to every service without being granted. Like
|
|
94
|
+
* {@link sharedSecret} it may be declared outside a service.
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* import {globalSecret} from "@encore.dev/sdk/config";
|
|
98
|
+
* const telemetryKey = globalSecret("TelemetryKey");
|
|
99
|
+
*/
|
|
100
|
+
export function globalSecret<Name extends string>(
|
|
101
|
+
name: StringLiteral<Name>,
|
|
102
|
+
): Secret<Name> {
|
|
103
|
+
return makeSecret<Secret<Name>>(name, runtime.RT.secret(name));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* The secret a config's secret field reads: what the runtime's placeholder
|
|
108
|
+
* for the field stands for. A secret name has one scope across the app, so it
|
|
109
|
+
* is read by name whatever the config's scope. Internal to the config module.
|
|
110
|
+
*
|
|
111
|
+
* @internal
|
|
112
|
+
*/
|
|
113
|
+
export function secretOfField(name: string): AnySecret {
|
|
114
|
+
return makeSecret<AnySecret>(name, runtime.RT.secret(name));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Builds the secret handle around an already-resolved implementation. `impl`
|
|
119
|
+
* is null when the runtime config gives the service no secret of that name.
|
|
120
|
+
*/
|
|
121
|
+
function makeSecret<S extends AnySecret>(
|
|
122
|
+
name: string,
|
|
123
|
+
impl: ReturnType<typeof runtime.RT.secret>,
|
|
124
|
+
): S {
|
|
125
|
+
const secretObj = () => {
|
|
126
|
+
if (impl === null) {
|
|
127
|
+
// During local development we don't consider missing secrets a fatal error.
|
|
128
|
+
if (
|
|
129
|
+
runtime.RT.appMeta().environment.cloud === runtime.CloudProvider.Local
|
|
130
|
+
) {
|
|
131
|
+
return '';
|
|
132
|
+
}
|
|
133
|
+
throw new Error(`secret ${name} is not set`);
|
|
134
|
+
}
|
|
135
|
+
return impl.cached();
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
secretObj.toString = () => {
|
|
139
|
+
if (impl === null) {
|
|
140
|
+
return `Secret<${name}>(not set)`;
|
|
141
|
+
}
|
|
142
|
+
return `Secret<${name}>(*********)`;
|
|
143
|
+
};
|
|
144
|
+
Object.defineProperty(secretObj, 'name', {value: name});
|
|
145
|
+
|
|
146
|
+
return secretObj as unknown as S;
|
|
147
|
+
}
|
package/config/value.ts
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a config's value is built from: the JSON the runtime hands over,
|
|
3
|
+
* turned into what the declared type says, guided by the config's schema.
|
|
4
|
+
* Durations become {@link Duration}s, and the runtime's placeholder for each
|
|
5
|
+
* secret field becomes the secret itself. Kept apart from the runtime, so it
|
|
6
|
+
* can be tested without one.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** What a duration string looks like: one or more numbers, each with a unit. */
|
|
10
|
+
const DURATION = /^([0-9]+(\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$/;
|
|
11
|
+
const UNIT_MS: Record<string, number> = {
|
|
12
|
+
ns: 1e-6,
|
|
13
|
+
us: 1e-3,
|
|
14
|
+
µs: 1e-3,
|
|
15
|
+
ms: 1,
|
|
16
|
+
s: 1000,
|
|
17
|
+
m: 60_000,
|
|
18
|
+
h: 3_600_000,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* A length of time, written in config files as a number with a unit, or
|
|
23
|
+
* several: `"30s"`, `"250ms"`, `"1h30m"` (units `ns`, `us`, `ms`, `s`, `m`,
|
|
24
|
+
* `h`, as Go's `time.ParseDuration` reads them, without a sign).
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* interface Checkout { paymentTimeout: Duration }
|
|
28
|
+
* setTimeout(retry, checkout().paymentTimeout.milliseconds);
|
|
29
|
+
*/
|
|
30
|
+
export class Duration {
|
|
31
|
+
/**
|
|
32
|
+
* Marks the type as Encore's duration, for Encore's parser, which reads a
|
|
33
|
+
* config's type to know what its files may hold. Never set.
|
|
34
|
+
*/
|
|
35
|
+
declare readonly '~encore.duration'?: true;
|
|
36
|
+
|
|
37
|
+
private readonly ms: number;
|
|
38
|
+
|
|
39
|
+
private constructor(ms: number) {
|
|
40
|
+
this.ms = ms;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Reads a duration string; throws on anything else. */
|
|
44
|
+
static parse(text: string): Duration {
|
|
45
|
+
if (!DURATION.test(text)) {
|
|
46
|
+
throw new Error(
|
|
47
|
+
`${JSON.stringify(text)} is not a duration, such as "30s", "250ms" or "1h30m"`,
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
let ms = 0;
|
|
51
|
+
for (const m of text.matchAll(
|
|
52
|
+
/([0-9]+(?:\.[0-9]+)?)(ns|us|µs|ms|s|m|h)/g,
|
|
53
|
+
)) {
|
|
54
|
+
ms += parseFloat(m[1]!) * UNIT_MS[m[2]!]!;
|
|
55
|
+
}
|
|
56
|
+
// Whole nanoseconds, so that "0.1s" is 100ms rather than 100.00000000000001.
|
|
57
|
+
return new Duration(Math.round(ms * 1e6) / 1e6);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** A duration of `ms` milliseconds. */
|
|
61
|
+
static ofMilliseconds(ms: number): Duration {
|
|
62
|
+
if (!(ms >= 0)) {
|
|
63
|
+
throw new Error('a duration is not negative');
|
|
64
|
+
}
|
|
65
|
+
return new Duration(ms);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** The duration in milliseconds: what `setTimeout` takes. */
|
|
69
|
+
get milliseconds(): number {
|
|
70
|
+
return this.ms;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** The duration in seconds. */
|
|
74
|
+
get seconds(): number {
|
|
75
|
+
return this.ms / 1000;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** As a config file writes it: `"1h30m"`, `"250ms"`, `"0s"`. */
|
|
79
|
+
toString(): string {
|
|
80
|
+
let ms = this.ms;
|
|
81
|
+
if (ms === 0) return '0s';
|
|
82
|
+
let out = '';
|
|
83
|
+
for (const [unit, size] of [
|
|
84
|
+
['h', 3_600_000],
|
|
85
|
+
['m', 60_000],
|
|
86
|
+
['s', 1000],
|
|
87
|
+
] as const) {
|
|
88
|
+
const n = Math.floor(ms / size);
|
|
89
|
+
if (n > 0) {
|
|
90
|
+
out += `${n}${unit}`;
|
|
91
|
+
ms -= n * size;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (ms > 0) {
|
|
95
|
+
// What is left is under a second.
|
|
96
|
+
out += Number.isInteger(ms) ? `${ms}ms` : `${Math.round(ms * 1e6)}ns`;
|
|
97
|
+
}
|
|
98
|
+
return out;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
toJSON(): string {
|
|
102
|
+
return this.toString();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** The key of the runtime's placeholder for a secret field. */
|
|
107
|
+
export const PLACEHOLDER_KEY = '$encore_secret';
|
|
108
|
+
|
|
109
|
+
/** A secret's scope, as a placeholder names it. */
|
|
110
|
+
export type SecretScope = 'service' | 'shared' | 'global';
|
|
111
|
+
|
|
112
|
+
/** Builds the secret a placeholder stands for. */
|
|
113
|
+
export type SecretOf = (name: string, scope: SecretScope) => unknown;
|
|
114
|
+
|
|
115
|
+
type Schema = Record<string, any>;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* `value`, as the declared type has it: the JSON the runtime hands over, with
|
|
119
|
+
* each duration string `schema` marks made a {@link Duration}, and the
|
|
120
|
+
* runtime's placeholder at each secret field `schema` marks made the secret
|
|
121
|
+
* `secretOf` builds.
|
|
122
|
+
*/
|
|
123
|
+
export function build(
|
|
124
|
+
schema: Schema,
|
|
125
|
+
value: unknown,
|
|
126
|
+
secretOf: SecretOf,
|
|
127
|
+
): unknown {
|
|
128
|
+
return convert(schema, schema, value, secretOf, 0);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function resolve(root: Schema, schema: Schema): Schema {
|
|
132
|
+
const ref = schema?.['$ref'];
|
|
133
|
+
if (typeof ref === 'string' && ref.startsWith('#/')) {
|
|
134
|
+
let node: any = root;
|
|
135
|
+
for (const token of ref.slice(2).split('/')) {
|
|
136
|
+
node = node?.[token.replace(/~1/g, '/').replace(/~0/g, '~')];
|
|
137
|
+
}
|
|
138
|
+
if (node && typeof node === 'object') return node;
|
|
139
|
+
}
|
|
140
|
+
return schema;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function convert(
|
|
144
|
+
root: Schema,
|
|
145
|
+
schema: Schema | undefined,
|
|
146
|
+
value: unknown,
|
|
147
|
+
secretOf: SecretOf,
|
|
148
|
+
depth: number,
|
|
149
|
+
): unknown {
|
|
150
|
+
if (!schema || typeof schema !== 'object' || depth > 128) {
|
|
151
|
+
return value;
|
|
152
|
+
}
|
|
153
|
+
schema = resolve(root, schema);
|
|
154
|
+
|
|
155
|
+
// Only a field the schema says reads a secret is one: anywhere else, a
|
|
156
|
+
// value shaped like a placeholder is just data, and must not reach a secret.
|
|
157
|
+
const secret = schema['x-encore-secret'];
|
|
158
|
+
if (secret) {
|
|
159
|
+
if (
|
|
160
|
+
!isPlaceholder(value) ||
|
|
161
|
+
value[PLACEHOLDER_KEY].name !== secret.name ||
|
|
162
|
+
value[PLACEHOLDER_KEY].scope !== secret.scope
|
|
163
|
+
) {
|
|
164
|
+
// Never say what the value is: it may be a pasted secret.
|
|
165
|
+
throw new Error(
|
|
166
|
+
`a secret field reads the secret ${secret.name}, and is not set in config`,
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
return secretOf(secret.name, secret.scope);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (schema['x-encore-format'] === 'duration' && typeof value === 'string') {
|
|
173
|
+
return Duration.parse(value);
|
|
174
|
+
}
|
|
175
|
+
if (Array.isArray(schema.anyOf) && value !== null) {
|
|
176
|
+
// `T | null`: the value is a `T`.
|
|
177
|
+
const branch = schema.anyOf.find((b: Schema) => b?.type !== 'null');
|
|
178
|
+
return convert(root, branch, value, secretOf, depth + 1);
|
|
179
|
+
}
|
|
180
|
+
if (Array.isArray(schema.oneOf)) {
|
|
181
|
+
return convert(
|
|
182
|
+
root,
|
|
183
|
+
branchOf(root, schema.oneOf, value),
|
|
184
|
+
value,
|
|
185
|
+
secretOf,
|
|
186
|
+
depth + 1,
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
if (Array.isArray(value)) {
|
|
190
|
+
return value.map(item =>
|
|
191
|
+
convert(root, schema!.items, item, secretOf, depth + 1),
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
if (value !== null && typeof value === 'object') {
|
|
195
|
+
const props: Schema = schema.properties ?? {};
|
|
196
|
+
const extra =
|
|
197
|
+
typeof schema.additionalProperties === 'object'
|
|
198
|
+
? schema.additionalProperties
|
|
199
|
+
: undefined;
|
|
200
|
+
const out: Record<string, unknown> = {};
|
|
201
|
+
for (const [k, v] of Object.entries(value)) {
|
|
202
|
+
out[k] = convert(root, props[k] ?? extra, v, secretOf, depth + 1);
|
|
203
|
+
}
|
|
204
|
+
return out;
|
|
205
|
+
}
|
|
206
|
+
return value;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** The branch of a `oneOf` a value is: the one whose constant tag it has. */
|
|
210
|
+
function branchOf(
|
|
211
|
+
root: Schema,
|
|
212
|
+
branches: Schema[],
|
|
213
|
+
value: unknown,
|
|
214
|
+
): Schema | undefined {
|
|
215
|
+
const resolved = branches.map(b => resolve(root, b));
|
|
216
|
+
if (value !== null && typeof value === 'object' && !Array.isArray(value)) {
|
|
217
|
+
for (const b of resolved) {
|
|
218
|
+
const props = b?.properties;
|
|
219
|
+
if (!props) continue;
|
|
220
|
+
const tagged = Object.entries(props).every(
|
|
221
|
+
([k, p]: [string, any]) =>
|
|
222
|
+
!('const' in (p ?? {})) ||
|
|
223
|
+
(value as Record<string, unknown>)[k] === p.const,
|
|
224
|
+
);
|
|
225
|
+
if (
|
|
226
|
+
tagged &&
|
|
227
|
+
Object.values(props).some((p: any) => 'const' in (p ?? {}))
|
|
228
|
+
) {
|
|
229
|
+
return b;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return undefined;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function isPlaceholder(
|
|
237
|
+
value: unknown,
|
|
238
|
+
): value is {[PLACEHOLDER_KEY]: {name: string; scope: SecretScope}} {
|
|
239
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value))
|
|
240
|
+
return false;
|
|
241
|
+
const keys = Object.keys(value);
|
|
242
|
+
return keys.length === 1 && keys[0] === PLACEHOLDER_KEY;
|
|
243
|
+
}
|
package/cron/mod.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {DurationString} from '../types/mod';
|
|
2
|
+
|
|
3
|
+
export class CronJob {
|
|
4
|
+
readonly name: string;
|
|
5
|
+
readonly cfg: CronJobConfig;
|
|
6
|
+
constructor(name: string, cfg: CronJobConfig) {
|
|
7
|
+
this.name = name;
|
|
8
|
+
this.cfg = cfg;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The configuration of a cron job: the path it requests and when.
|
|
14
|
+
*
|
|
15
|
+
* When the job is due, Encore sends a `POST` request for `path` to the service
|
|
16
|
+
* that declares the job. The fields must be literals: Encore reads them from
|
|
17
|
+
* the source.
|
|
18
|
+
*/
|
|
19
|
+
export type CronJobConfig = {
|
|
20
|
+
/** The path the job requests of its service, starting with `/`. */
|
|
21
|
+
path: string;
|
|
22
|
+
title?: string;
|
|
23
|
+
} & ({every: DurationString} | {schedule: string});
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/** Describes the running Encore application. */
|
|
2
|
+
export interface AppMeta {
|
|
3
|
+
/**
|
|
4
|
+
* The Encore application ID. If the application is not linked to the Encore platform this will be an empty string.
|
|
5
|
+
* To link to the Encore platform run `encore app link` from your terminal in the root directory of the Encore app.
|
|
6
|
+
*/
|
|
7
|
+
appId: string;
|
|
8
|
+
/**
|
|
9
|
+
* The Encore application slug — the human-readable identifier shown in the Encore
|
|
10
|
+
* Cloud dashboard and used by the CLI. If the application is not linked to the
|
|
11
|
+
* Encore platform this will be an empty string.
|
|
12
|
+
*
|
|
13
|
+
* Distinct from `appId`: the id is opaque and stable, the slug is readable and may
|
|
14
|
+
* be renamed. Locally the two are the same.
|
|
15
|
+
*/
|
|
16
|
+
appSlug: string;
|
|
17
|
+
/**
|
|
18
|
+
* The API gateways that serve this application, keyed by gateway name.
|
|
19
|
+
*
|
|
20
|
+
* An application can declare several gateways, so there is no single base URL for
|
|
21
|
+
* the API — look up the gateway you mean by name. A process that serves no gateway
|
|
22
|
+
* (a worker) reports an empty object.
|
|
23
|
+
*/
|
|
24
|
+
gateways: Record<string, GatewayMeta>;
|
|
25
|
+
/** Information about the environment the app is running in. */
|
|
26
|
+
environment: EnvironmentMeta;
|
|
27
|
+
/** Information about the build. */
|
|
28
|
+
build: BuildMeta;
|
|
29
|
+
/** Information about the deployment. */
|
|
30
|
+
deploy: DeployMeta;
|
|
31
|
+
}
|
|
32
|
+
/** Describes an API gateway serving the application. */
|
|
33
|
+
export interface GatewayMeta {
|
|
34
|
+
/** The name of the gateway, as declared by the application. */
|
|
35
|
+
name: string;
|
|
36
|
+
/**
|
|
37
|
+
* The base URL which can be used to call the API of this running application
|
|
38
|
+
* through this gateway.
|
|
39
|
+
*
|
|
40
|
+
* For local development it is "http://localhost:<port>", typically "http://localhost:4000".
|
|
41
|
+
*
|
|
42
|
+
* If a custom domain is used for this environment it is returned here, but note that
|
|
43
|
+
* changes only take effect at the time of deployment while custom domains can be updated at any time.
|
|
44
|
+
*/
|
|
45
|
+
baseUrl: string;
|
|
46
|
+
}
|
|
47
|
+
/** Describes the environment the Encore application is running in. */
|
|
48
|
+
export interface EnvironmentMeta {
|
|
49
|
+
/**
|
|
50
|
+
* The name of environment that this application.
|
|
51
|
+
* For local development it is "local".
|
|
52
|
+
*/
|
|
53
|
+
name: string;
|
|
54
|
+
/**
|
|
55
|
+
* The type of environment is this application running in.
|
|
56
|
+
* For local development it is "development".
|
|
57
|
+
*/
|
|
58
|
+
type: EnvironmentType;
|
|
59
|
+
/**
|
|
60
|
+
* The cloud this is running in.
|
|
61
|
+
* For local development it is "local".
|
|
62
|
+
*/
|
|
63
|
+
cloud: CloudProvider;
|
|
64
|
+
}
|
|
65
|
+
/** Describes what type of environment the application is running in. */
|
|
66
|
+
export type EnvironmentType = 'production' | 'development' | 'ephemeral' | 'test';
|
|
67
|
+
/** Describes what cloud provider the application is running in. */
|
|
68
|
+
export type CloudProvider = 'aws' | 'gcp' | 'azure' | 'encore' | 'local';
|
|
69
|
+
/** Information about the build that formed the running application. */
|
|
70
|
+
export interface BuildMeta {
|
|
71
|
+
/** The VCS revision the deployed application was built from. */
|
|
72
|
+
revision: string;
|
|
73
|
+
}
|
|
74
|
+
/** Information about the deployment of the running application. */
|
|
75
|
+
export interface DeployMeta {
|
|
76
|
+
/** The unique id of the deployment. Generated by the Encore Platform. */
|
|
77
|
+
id: string;
|
|
78
|
+
/** The time the Encore Platform deployed this build to the environment. */
|
|
79
|
+
time: Date;
|
|
80
|
+
/** The services hosted by this deployment, keyed by the service name. */
|
|
81
|
+
hostedServices: Record<string, HostedService>;
|
|
82
|
+
}
|
|
83
|
+
export interface HostedService {
|
|
84
|
+
/** The name of the service */
|
|
85
|
+
name: string;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Returns metadata about the running Encore application.
|
|
89
|
+
*
|
|
90
|
+
* The metadata is cached and is the same object each call,
|
|
91
|
+
* and therefore must not be modified by the caller.
|
|
92
|
+
*/
|
|
93
|
+
export declare function appMeta(): AppMeta;
|