@ericminassian/platform-core 0.3.0 → 0.4.1
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/dist/api.d.ts +1225 -45
- package/dist/api.js +471 -13
- package/dist/api.js.map +1 -1
- package/dist/auth.js +5 -2
- package/dist/auth.js.map +1 -1
- package/dist/base64url.d.ts +3 -0
- package/dist/base64url.js +15 -0
- package/dist/base64url.js.map +1 -0
- package/dist/bindings.d.ts +62 -12
- package/dist/bindings.js +1 -1
- package/dist/bindings.js.map +1 -1
- package/dist/cloudfront-function.d.ts +5 -1
- package/dist/cloudfront-function.js +64 -2
- package/dist/cloudfront-function.js.map +1 -1
- package/dist/compute.d.ts +52 -0
- package/dist/compute.js +65 -0
- package/dist/compute.js.map +1 -0
- package/dist/config.d.ts +18 -0
- package/dist/config.js +9 -0
- package/dist/config.js.map +1 -1
- package/dist/constants.d.ts +56 -1
- package/dist/constants.js +56 -1
- package/dist/constants.js.map +1 -1
- package/dist/email.d.ts +84 -0
- package/dist/email.js +111 -0
- package/dist/email.js.map +1 -0
- package/dist/explore.d.ts +365 -0
- package/dist/explore.js +440 -0
- package/dist/explore.js.map +1 -0
- package/dist/fingerprint.d.ts +9 -0
- package/dist/fingerprint.js +19 -0
- package/dist/fingerprint.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/jobs.d.ts +111 -0
- package/dist/jobs.js +214 -0
- package/dist/jobs.js.map +1 -0
- package/dist/manifest.d.ts +270 -29
- package/dist/manifest.js +190 -22
- package/dist/manifest.js.map +1 -1
- package/dist/naming.d.ts +83 -7
- package/dist/naming.js +89 -8
- package/dist/naming.js.map +1 -1
- package/dist/platform-api.d.ts +5897 -1672
- package/dist/platform-api.js +218 -8
- package/dist/platform-api.js.map +1 -1
- package/dist/realtime.d.ts +139 -0
- package/dist/realtime.js +201 -0
- package/dist/realtime.js.map +1 -0
- package/dist/router/decide.d.ts +2 -0
- package/dist/router/decide.js +38 -6
- package/dist/router.d.ts +35 -13
- package/dist/router.js +36 -0
- package/dist/router.js.map +1 -1
- package/dist/runtime-config.d.ts +57 -0
- package/dist/runtime-config.js +12 -0
- package/dist/runtime-config.js.map +1 -1
- package/dist/storage.d.ts +65 -0
- package/dist/storage.js +122 -0
- package/dist/storage.js.map +1 -0
- package/dist/telemetry.d.ts +135 -20
- package/dist/telemetry.js +108 -22
- package/dist/telemetry.js.map +1 -1
- package/dist/web-compute.d.ts +191 -0
- package/dist/web-compute.js +257 -0
- package/dist/web-compute.js.map +1 -0
- package/package.json +19 -7
- package/src/api.ts +564 -15
- package/src/auth.ts +6 -2
- package/src/base64url.ts +13 -0
- package/src/bindings.ts +67 -6
- package/src/cloudfront-function.ts +64 -2
- package/src/compute.ts +86 -0
- package/src/config.ts +31 -1
- package/src/constants.ts +64 -1
- package/src/email.ts +168 -0
- package/src/explore.ts +504 -0
- package/src/fingerprint.ts +20 -0
- package/src/index.ts +7 -0
- package/src/jobs.ts +281 -0
- package/src/manifest.ts +415 -45
- package/src/naming.ts +93 -9
- package/src/platform-api.ts +249 -8
- package/src/realtime.ts +298 -0
- package/src/router/decide.d.ts +2 -0
- package/src/router/decide.js +38 -6
- package/src/router.ts +33 -13
- package/src/runtime-config.ts +70 -0
- package/src/storage.ts +131 -0
- package/src/telemetry.ts +115 -22
- package/src/web-compute.ts +342 -0
package/dist/jobs.js
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Jobs: queue messages, events and cron runs. They are pushed, never polled:
|
|
3
|
+
* a queue send is an async Lambda invoke of the function its handler runs in,
|
|
4
|
+
* events arrive from EventBridge and crons from EventBridge Scheduler, and a
|
|
5
|
+
* failed run is retried through a one-shot Scheduler schedule. A stage with
|
|
6
|
+
* jobs costs nothing until one runs (an SQS queue with a Lambda event source
|
|
7
|
+
* mapping costs ~$0.26 a month in empty polls).
|
|
8
|
+
*
|
|
9
|
+
* After its last attempt a job goes to the stage's dead-letter queue, an SQS
|
|
10
|
+
* queue nothing polls. Four writers share it: the SDK (a handler that failed
|
|
11
|
+
* every attempt, `DeadLetter`), Lambda's on-failure destination (a crash or
|
|
12
|
+
* timeout retried twice, or an event older than six hours), Scheduler's
|
|
13
|
+
* dead-letter queue (a retry or cron it couldn't deliver) and EventBridge's (an
|
|
14
|
+
* event it couldn't deliver). `readDeadLetter` reads all four.
|
|
15
|
+
*/
|
|
16
|
+
import { fingerprint } from './fingerprint.js';
|
|
17
|
+
/** Marker on every job payload the platform sends to a worker function. */
|
|
18
|
+
export const JOB_MARKER = 'job';
|
|
19
|
+
/**
|
|
20
|
+
* The largest job payload, in bytes of JSON. Retries and delayed sends go
|
|
21
|
+
* through a Scheduler schedule, whose input is capped at 256 KB, and a dead
|
|
22
|
+
* letter wraps the payload with its error, so this leaves room for both.
|
|
23
|
+
*/
|
|
24
|
+
export const JOB_PAYLOAD_MAX_BYTES = 240 * 1024;
|
|
25
|
+
/** Attempts per kind when a handler sets none. Lambda retried events and crons twice before. */
|
|
26
|
+
export const DEFAULT_ATTEMPTS = { queue: 5, event: 3, cron: 3 };
|
|
27
|
+
export const MAX_ATTEMPTS = 100;
|
|
28
|
+
/** The longest delay `send` takes: a one-shot schedule can be any time ahead, a year is plenty. */
|
|
29
|
+
export const MAX_JOB_DELAY_SECONDS = 365 * 86_400;
|
|
30
|
+
/**
|
|
31
|
+
* Scheduler fires a one-shot schedule within about a minute of its time, and
|
|
32
|
+
* refuses times in the past, so a delayed send or retry is scheduled at least
|
|
33
|
+
* this far ahead.
|
|
34
|
+
*/
|
|
35
|
+
export const MIN_SCHEDULE_LEAD_SECONDS = 60;
|
|
36
|
+
/** Seconds before attempt `failed + 1`: 1, 2, 4 … minutes, at most an hour. */
|
|
37
|
+
export function retryDelaySeconds(failed) {
|
|
38
|
+
return Math.min(60 * 2 ** Math.max(0, failed - 1), 3600);
|
|
39
|
+
}
|
|
40
|
+
/** `kind:name`, the key bindings use for a handler. */
|
|
41
|
+
export const handlerKey = (kind, name) => `${kind}:${name}`;
|
|
42
|
+
/**
|
|
43
|
+
* Name of the one-shot schedule for a retry or delayed send (≤ 64 chars of
|
|
44
|
+
* Scheduler's alphabet). It leads with `_`, which no cron key (a cron's own
|
|
45
|
+
* schedule) or service stop schedule (`<key>--stop`) starts with, then the
|
|
46
|
+
* kind and queue or cron key, so the console can count what's waiting per
|
|
47
|
+
* queue with a name prefix. Event types can be long and contain `:`, so they
|
|
48
|
+
* are hashed.
|
|
49
|
+
*/
|
|
50
|
+
export function jobScheduleName(kind, name, id) {
|
|
51
|
+
return `${jobSchedulePrefix(kind, name)}${id}`.slice(0, 64);
|
|
52
|
+
}
|
|
53
|
+
export function jobSchedulePrefix(kind, name) {
|
|
54
|
+
if (kind === 'queue')
|
|
55
|
+
return `_q-${name}-`;
|
|
56
|
+
if (kind === 'cron')
|
|
57
|
+
return `_c-${name}-`;
|
|
58
|
+
return `_e-${fingerprint([name])}-`;
|
|
59
|
+
}
|
|
60
|
+
export const isJobSchedule = (name) => name.startsWith('_');
|
|
61
|
+
/** One-shot schedule expression for `at` (UTC, whole seconds). */
|
|
62
|
+
export function atExpression(at) {
|
|
63
|
+
return `at(${at.toISOString().slice(0, 19)})`;
|
|
64
|
+
}
|
|
65
|
+
const isObject = (v) => typeof v === 'object' && v !== null;
|
|
66
|
+
/**
|
|
67
|
+
* Normalizes anything a worker function can receive into the job it stands
|
|
68
|
+
* for: a job payload as is, an EventBridge event, or a cron firing. `id` is
|
|
69
|
+
* used when the input carries none (a cron firing). Undefined for anything
|
|
70
|
+
* else, such as a direct `invoke`.
|
|
71
|
+
*/
|
|
72
|
+
export function toJob(input, id, now) {
|
|
73
|
+
if (!isObject(input))
|
|
74
|
+
return undefined;
|
|
75
|
+
if (input.__platform === JOB_MARKER && typeof input.kind === 'string' && typeof input.name === 'string') {
|
|
76
|
+
return input;
|
|
77
|
+
}
|
|
78
|
+
if (input.__platform === 'cron' && typeof input.name === 'string') {
|
|
79
|
+
return {
|
|
80
|
+
__platform: JOB_MARKER,
|
|
81
|
+
kind: 'cron',
|
|
82
|
+
name: input.name,
|
|
83
|
+
id,
|
|
84
|
+
attempt: 1,
|
|
85
|
+
sentAt: now,
|
|
86
|
+
...(typeof input.trace === 'string' ? { trace: input.trace } : {}),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
if (typeof input['detail-type'] === 'string') {
|
|
90
|
+
// The SDK publishes `{ data, trace }` as an event's detail; events from elsewhere are bare.
|
|
91
|
+
const detail = input.detail;
|
|
92
|
+
const envelope = isObject(detail) && 'data' in detail ? detail : undefined;
|
|
93
|
+
return {
|
|
94
|
+
__platform: JOB_MARKER,
|
|
95
|
+
kind: 'event',
|
|
96
|
+
name: input['detail-type'],
|
|
97
|
+
id: typeof input.id === 'string' ? input.id : id,
|
|
98
|
+
attempt: 1,
|
|
99
|
+
sentAt: typeof input.time === 'string' ? Date.parse(input.time) || now : now,
|
|
100
|
+
detail: envelope ? envelope.data : detail,
|
|
101
|
+
...(envelope && typeof envelope.trace === 'string' ? { trace: envelope.trace } : {}),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
/** Reads a dead-letter queue message; null for one the platform didn't write. */
|
|
107
|
+
export function readDeadLetter(body, attributes = {}) {
|
|
108
|
+
let parsed;
|
|
109
|
+
try {
|
|
110
|
+
parsed = JSON.parse(body);
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
if (!isObject(parsed))
|
|
116
|
+
return null;
|
|
117
|
+
const attr = (name) => attributes[name]?.StringValue;
|
|
118
|
+
// The SDK's own.
|
|
119
|
+
if (parsed.v === 1 && isObject(parsed.job) && isObject(parsed.error)) {
|
|
120
|
+
const d = parsed;
|
|
121
|
+
return {
|
|
122
|
+
kind: d.job.kind,
|
|
123
|
+
name: d.job.name,
|
|
124
|
+
attempts: d.job.attempt,
|
|
125
|
+
error: d.error,
|
|
126
|
+
failedAt: d.failedAt,
|
|
127
|
+
source: 'sdk',
|
|
128
|
+
redrive: { ...d.job, attempt: 1 },
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
// Lambda's on-failure destination record.
|
|
132
|
+
if (isObject(parsed.requestContext) && 'requestPayload' in parsed) {
|
|
133
|
+
const ctx = parsed.requestContext;
|
|
134
|
+
const response = isObject(parsed.responsePayload) ? parsed.responsePayload : {};
|
|
135
|
+
const condition = typeof ctx.condition === 'string' ? ctx.condition : 'RetriesExhausted';
|
|
136
|
+
const error = {
|
|
137
|
+
name: typeof response.errorType === 'string'
|
|
138
|
+
? response.errorType
|
|
139
|
+
: condition === 'EventAgeExceeded'
|
|
140
|
+
? 'EventAgeExceeded'
|
|
141
|
+
: 'FunctionError',
|
|
142
|
+
message: typeof response.errorMessage === 'string'
|
|
143
|
+
? response.errorMessage
|
|
144
|
+
: condition === 'EventAgeExceeded'
|
|
145
|
+
? 'the event waited longer than six hours (throttled)'
|
|
146
|
+
: condition,
|
|
147
|
+
};
|
|
148
|
+
const failedAt = typeof parsed.timestamp === 'string' ? Date.parse(parsed.timestamp) || null : null;
|
|
149
|
+
const attempts = typeof ctx.approximateInvokeCount === 'number' ? ctx.approximateInvokeCount : null;
|
|
150
|
+
return fromPayload(parsed.requestPayload, error, failedAt, 'lambda', attempts);
|
|
151
|
+
}
|
|
152
|
+
// Scheduler (a retry, delayed send or cron it couldn't deliver) and EventBridge (an event it
|
|
153
|
+
// couldn't deliver) put the input they meant to deliver in the body and the error in attributes.
|
|
154
|
+
const error = {
|
|
155
|
+
name: attr('ERROR_CODE') ?? 'DeliveryFailed',
|
|
156
|
+
message: attr('ERROR_MESSAGE') ?? 'the target could not be invoked',
|
|
157
|
+
};
|
|
158
|
+
const source = attr('RULE_ARN') ? 'eventbridge' : 'scheduler';
|
|
159
|
+
return fromPayload(parsed, error, null, source, null);
|
|
160
|
+
}
|
|
161
|
+
function fromPayload(payload, error, failedAt, source, attempts) {
|
|
162
|
+
const job = toJob(payload, `r${fingerprint([JSON.stringify(payload ?? null)])}`, failedAt ?? Date.now());
|
|
163
|
+
if (job) {
|
|
164
|
+
return {
|
|
165
|
+
kind: job.kind,
|
|
166
|
+
name: job.name,
|
|
167
|
+
attempts: attempts ?? job.attempt,
|
|
168
|
+
error,
|
|
169
|
+
failedAt,
|
|
170
|
+
source,
|
|
171
|
+
redrive: { ...job, attempt: 1 },
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
if (isObject(payload) && payload.__platform === 'invoke' && typeof payload.name === 'string') {
|
|
175
|
+
return {
|
|
176
|
+
kind: 'invoke',
|
|
177
|
+
name: payload.name,
|
|
178
|
+
attempts,
|
|
179
|
+
error,
|
|
180
|
+
failedAt,
|
|
181
|
+
source,
|
|
182
|
+
redrive: {
|
|
183
|
+
__platform: 'invoke',
|
|
184
|
+
name: payload.name,
|
|
185
|
+
payload: payload.payload,
|
|
186
|
+
...(typeof payload.trace === 'string' ? { trace: payload.trace } : {}),
|
|
187
|
+
},
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* The oldest `@ericminassian/platform` whose bundles this platform deploys:
|
|
194
|
+
* jobs became pushed (bindings v2) in 0.4.0, and an older worker can't read
|
|
195
|
+
* them.
|
|
196
|
+
*/
|
|
197
|
+
export const MIN_SDK_VERSION = '0.4.0';
|
|
198
|
+
/** Whether bundles built with SDK `version` can be deployed (undefined: a CLI older than 0.4.0 sent none). */
|
|
199
|
+
export function sdkSupported(version) {
|
|
200
|
+
if (!version)
|
|
201
|
+
return false;
|
|
202
|
+
const parse = (v) => v
|
|
203
|
+
.split('-')[0]
|
|
204
|
+
.split('.')
|
|
205
|
+
.map((n) => Number(n));
|
|
206
|
+
const [a, b] = [parse(version), parse(MIN_SDK_VERSION)];
|
|
207
|
+
if (a.length !== 3 || a.some((n) => !Number.isInteger(n)))
|
|
208
|
+
return false;
|
|
209
|
+
for (let i = 0; i < 3; i++)
|
|
210
|
+
if (a[i] !== b[i])
|
|
211
|
+
return a[i] > b[i];
|
|
212
|
+
return true;
|
|
213
|
+
}
|
|
214
|
+
//# sourceMappingURL=jobs.js.map
|
package/dist/jobs.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jobs.js","sourceRoot":"","sources":["../src/jobs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAG/C,2EAA2E;AAC3E,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,CAAC;AAqBhC;;;;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAG,GAAG,IAAI,CAAC;AAEhD,gGAAgG;AAChG,MAAM,CAAC,MAAM,gBAAgB,GAA0C,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;AACvG,MAAM,CAAC,MAAM,YAAY,GAAG,GAAG,CAAC;AAEhC,mGAAmG;AACnG,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAG,GAAG,MAAM,CAAC;AAElD;;;;GAIG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,CAAC;AAE5C,+EAA+E;AAC/E,MAAM,UAAU,iBAAiB,CAAC,MAAc;IAC9C,OAAO,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;AAC3D,CAAC;AAED,uDAAuD;AACvD,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAiB,EAAE,IAAY,EAAU,EAAE,CAAC,GAAG,IAAI,IAAI,IAAI,EAAE,CAAC;AAEzF;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAAC,IAAiB,E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C;aACvE;SACF,CAAC;IACJ,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,OAAO,CAAC;AAEvC,8GAA8G;AAC9G,MAAM,UAAU,YAAY,CAAC,OAA2B;IACtD,IAAI,CAAC,OAAO;QAAE,OAAO,KAAK,CAAC;IAC3B,MAAM,KAAK,GAAG,CAAC,CAAS,EAAE,EAAE,CAC1B,CAAC;SACE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAE;SACd,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3B,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC;IACxD,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QAAE,OAAO,KAAK,CAAC;IACxE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE;QAAE,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAAE,OAAO,CAAC,CAAC,CAAC,CAAE,GAAG,CAAC,CAAC,CAAC,CAAE,CAAC;IACpE,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/manifest.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { Schema } from 'effect';
|
|
2
|
+
import { type FargateCpu } from './compute.ts';
|
|
3
|
+
import { type WebComputeSetting } from './web-compute.ts';
|
|
2
4
|
/**
|
|
3
5
|
* The app's config file, at the app root. `plat` evaluates it and sends the
|
|
4
6
|
* result to the platform as JSON; the control plane never runs app code.
|
|
@@ -19,6 +21,9 @@ export declare const ManifestSchema: Schema.Struct<{
|
|
|
19
21
|
readonly serverRoutes: Schema.withDecodingDefault<Schema.$Array<Schema.String>, never>;
|
|
20
22
|
readonly timeoutSeconds: Schema.withDecodingDefault<Schema.Int, never>;
|
|
21
23
|
readonly concurrency: Schema.withDecodingDefault<Schema.Int, never>;
|
|
24
|
+
readonly compute: Schema.withDecodingDefault<Schema.Literals<readonly ["auto", "request", "instance"]>, never>;
|
|
25
|
+
readonly memoryMb: Schema.withDecodingDefault<Schema.Int, never>;
|
|
26
|
+
readonly maxEnvironments: Schema.optional<Schema.Int>;
|
|
22
27
|
}>>;
|
|
23
28
|
readonly worker: Schema.optional<Schema.Struct<{
|
|
24
29
|
readonly entry: Schema.withDecodingDefault<Schema.String, never>;
|
|
@@ -30,19 +35,47 @@ export declare const ManifestSchema: Schema.Struct<{
|
|
|
30
35
|
}>]>, never>;
|
|
31
36
|
readonly db: Schema.withDecodingDefault<Schema.Boolean, never>;
|
|
32
37
|
readonly queues: Schema.withDecodingDefault<Schema.$Record<Schema.String, Schema.Struct<{
|
|
33
|
-
readonly
|
|
34
|
-
readonly
|
|
35
|
-
readonly
|
|
38
|
+
readonly timeoutSeconds: Schema.optional<Schema.Int>;
|
|
39
|
+
readonly memoryMb: Schema.optional<Schema.Int>;
|
|
40
|
+
readonly maxAttempts: Schema.withDecodingDefault<Schema.Int, never>;
|
|
36
41
|
readonly concurrency: Schema.optional<Schema.Int>;
|
|
42
|
+
readonly batchSize: Schema.optional<Schema.Unknown>;
|
|
43
|
+
readonly visibilityTimeoutSeconds: Schema.optional<Schema.Unknown>;
|
|
44
|
+
readonly maxReceiveCount: Schema.optional<Schema.Unknown>;
|
|
37
45
|
}>>, never>;
|
|
38
|
-
readonly events: Schema.withDecodingDefault<Schema.Union<readonly [Schema.$Array<Schema.String>, Schema.$Record<Schema.String, Schema.Struct<{
|
|
46
|
+
readonly events: Schema.withDecodingDefault<Schema.Union<readonly [Schema.$Array<Schema.String>, Schema.$Record<Schema.String, Schema.Struct<{
|
|
47
|
+
readonly timeoutSeconds: Schema.optional<Schema.Int>;
|
|
48
|
+
readonly memoryMb: Schema.optional<Schema.Int>;
|
|
49
|
+
readonly maxAttempts: Schema.optional<Schema.Int>;
|
|
50
|
+
}>>]>, never>;
|
|
39
51
|
readonly crons: Schema.withDecodingDefault<Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Struct<{
|
|
52
|
+
readonly timeoutSeconds: Schema.optional<Schema.Int>;
|
|
53
|
+
readonly memoryMb: Schema.optional<Schema.Int>;
|
|
40
54
|
readonly schedule: Schema.String;
|
|
41
55
|
readonly timezone: Schema.optional<Schema.String>;
|
|
56
|
+
readonly maxAttempts: Schema.optional<Schema.Int>;
|
|
42
57
|
}>]>>, never>;
|
|
43
|
-
readonly storage: Schema.withDecodingDefault<Schema.$Array<Schema.String>,
|
|
58
|
+
readonly storage: Schema.withDecodingDefault<Schema.Union<readonly [Schema.$Array<Schema.String>, Schema.$Record<Schema.String, Schema.Struct<{
|
|
59
|
+
readonly public: Schema.withDecodingDefault<Schema.Boolean, never>;
|
|
60
|
+
readonly expireAfterDays: Schema.optional<Schema.Int>;
|
|
61
|
+
}>>]>, never>;
|
|
44
62
|
readonly secrets: Schema.withDecodingDefault<Schema.$Array<Schema.String>, never>;
|
|
45
63
|
readonly env: Schema.withDecodingDefault<Schema.$Record<Schema.String, Schema.String>, never>;
|
|
64
|
+
readonly realtime: Schema.optional<Schema.Struct<{
|
|
65
|
+
readonly subscribe: Schema.withDecodingDefault<Schema.Literals<readonly ["public", "signed-in"]>, never>;
|
|
66
|
+
readonly channels: Schema.$Record<Schema.String, Schema.Struct<{}>>;
|
|
67
|
+
}>>;
|
|
68
|
+
readonly email: Schema.withDecodingDefault<Schema.Union<readonly [Schema.Boolean, Schema.Struct<{
|
|
69
|
+
readonly name: Schema.optional<Schema.String>;
|
|
70
|
+
readonly dailyLimit: Schema.optional<Schema.Int>;
|
|
71
|
+
}>]>, never>;
|
|
72
|
+
readonly services: Schema.withDecodingDefault<Schema.$Record<Schema.String, Schema.Struct<{
|
|
73
|
+
readonly entry: Schema.String;
|
|
74
|
+
readonly cpu: Schema.withDecodingDefault<Schema.Literals<readonly [0.25, 0.5, 1, 2, 4]>, never>;
|
|
75
|
+
readonly memoryMb: Schema.withDecodingDefault<Schema.Int, never>;
|
|
76
|
+
readonly spot: Schema.withDecodingDefault<Schema.Boolean, never>;
|
|
77
|
+
readonly previewMinutes: Schema.withDecodingDefault<Schema.Int, never>;
|
|
78
|
+
}>>, never>;
|
|
46
79
|
}>;
|
|
47
80
|
/** The evaluated config as JSON: what the CLI sends and deployments store. */
|
|
48
81
|
export type ManifestInput = typeof ManifestSchema.Encoded;
|
|
@@ -76,35 +109,152 @@ export interface WebConfig {
|
|
|
76
109
|
serverRoutes?: readonly string[];
|
|
77
110
|
/** 3-900. Default 30. */
|
|
78
111
|
timeoutSeconds?: number;
|
|
79
|
-
/** Max concurrent requests per Web Function environment, 1-128. Default 64. */
|
|
112
|
+
/** Max concurrent requests per Web Function environment (instance mode), 1-128. Default 64. */
|
|
80
113
|
concurrency?: number;
|
|
114
|
+
/**
|
|
115
|
+
* How the server runs. `request`: one invocation per request, billed by the
|
|
116
|
+
* millisecond and nothing while idle. `instance`: a Web Function, whose
|
|
117
|
+
* environments serve many requests at once and are billed for their memory
|
|
118
|
+
* while they live (until about five minutes after the last request).
|
|
119
|
+
* `auto` (default): previews run `request`; prod starts on `request` and
|
|
120
|
+
* moves to whichever mode its traffic makes cheaper, checked daily.
|
|
121
|
+
*/
|
|
122
|
+
compute?: WebComputeSetting;
|
|
123
|
+
/** Memory of the server in request mode, 128-10240 MB (CPU grows with it). Default 1024. */
|
|
124
|
+
memoryMb?: number;
|
|
125
|
+
/** Most environments prod's Web Function (instance mode) runs at once, 2-10000. Default 10; previews 2. */
|
|
126
|
+
maxEnvironments?: number;
|
|
81
127
|
}
|
|
82
128
|
export interface WorkerConfig {
|
|
83
129
|
/** Module whose default export is `defineWorker(...)`. Default `src/worker.ts`. */
|
|
84
130
|
entry?: string;
|
|
85
|
-
/** 1-900. Default 60. */
|
|
131
|
+
/** 1-900. Default 60. Handlers can set their own (`HandlerConfig`). */
|
|
132
|
+
timeoutSeconds?: number;
|
|
133
|
+
/** 128-10240. Default 512. Handlers can set their own (`HandlerConfig`). */
|
|
134
|
+
memoryMb?: number;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* A queue, event or cron handler's own Lambda settings, for handlers whose
|
|
138
|
+
* needs differ from the rest (a big parse, a long idle wait). A handler that
|
|
139
|
+
* sets either runs in a function of its own, from the same worker bundle;
|
|
140
|
+
* the one it doesn't set is the worker's.
|
|
141
|
+
*/
|
|
142
|
+
export interface HandlerConfig {
|
|
143
|
+
/** 1-900. Default: the worker's `timeoutSeconds`. */
|
|
86
144
|
timeoutSeconds?: number;
|
|
87
|
-
/** 128-10240. Default
|
|
145
|
+
/** 128-10240. Default: the worker's `memoryMb`. */
|
|
88
146
|
memoryMb?: number;
|
|
89
147
|
}
|
|
90
|
-
/**
|
|
91
|
-
export interface
|
|
92
|
-
/**
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
148
|
+
/** How often a failed run is tried again, for every kind of handler. */
|
|
149
|
+
export interface RetryConfig {
|
|
150
|
+
/**
|
|
151
|
+
* Runs before the job goes to the stage's dead-letter queue, 1-100: the
|
|
152
|
+
* first, then retries 1, 2, 4 … minutes apart (at most an hour). Default 5
|
|
153
|
+
* for queues, 3 for events and crons.
|
|
154
|
+
*/
|
|
155
|
+
maxAttempts?: number;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Declare one with `queue<Body>({ ... })` to type what is sent and received.
|
|
159
|
+
* Each message is one run of its handler, at least once and in no set order.
|
|
160
|
+
*/
|
|
161
|
+
export interface QueueConfig<Body = unknown> extends Payload<Body>, HandlerConfig, RetryConfig {
|
|
162
|
+
/**
|
|
163
|
+
* At most this many runs at once, 1-1000. Setting it runs the handler in a
|
|
164
|
+
* function of its own with that much reserved Lambda concurrency; messages
|
|
165
|
+
* past it wait (up to six hours) instead of failing.
|
|
166
|
+
*/
|
|
99
167
|
concurrency?: number;
|
|
100
168
|
}
|
|
169
|
+
/** Event handler options. */
|
|
170
|
+
export type EventOptions = HandlerConfig & RetryConfig;
|
|
101
171
|
/** Declare one with `event<Detail>()` to type what is published and handled. */
|
|
102
|
-
export type EventConfig<Detail = unknown> = Payload<Detail
|
|
103
|
-
/**
|
|
104
|
-
|
|
172
|
+
export type EventConfig<Detail = unknown> = Payload<Detail> & EventOptions;
|
|
173
|
+
/**
|
|
174
|
+
* 5-field cron in UTC (`0 3 * * *`) or `rate(5 minutes)`; the object form adds
|
|
175
|
+
* a timezone or the handler's own settings.
|
|
176
|
+
*/
|
|
177
|
+
export type CronConfig = string | CronSchedule;
|
|
178
|
+
export interface CronSchedule extends HandlerConfig, RetryConfig {
|
|
105
179
|
schedule: string;
|
|
180
|
+
/** IANA name, e.g. `America/Los_Angeles`. Default UTC. */
|
|
106
181
|
timezone?: string;
|
|
107
|
-
}
|
|
182
|
+
}
|
|
183
|
+
/** Declare one with `channel<Event>()` to type what is published and received. */
|
|
184
|
+
export type ChannelConfig<Event = unknown> = Payload<Event>;
|
|
185
|
+
/** A file store. `{}` is a private store whose files are kept until deleted. */
|
|
186
|
+
export interface StoreConfig {
|
|
187
|
+
/**
|
|
188
|
+
* Serve the store's files from the edge at `/__platform/storage/<store>/<key>`
|
|
189
|
+
* on the app's host, to anyone with the URL (`auth.required` doesn't cover
|
|
190
|
+
* it), with no server in the path. Files are cached as their `cacheControl`
|
|
191
|
+
* says; without one, browsers revalidate on each use. Default `false`.
|
|
192
|
+
*/
|
|
193
|
+
public?: boolean;
|
|
194
|
+
/** Delete files not written for this many days, 1-3650. Checked daily. Default: kept until deleted. */
|
|
195
|
+
expireAfterDays?: number;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* A long-running process: it holds connections open (WebSocket or
|
|
199
|
+
* server-sent-event sources) and writes what it receives to the db, storage,
|
|
200
|
+
* queues or realtime. One instance per stage, restarted when it crashes and
|
|
201
|
+
* replaced on each deploy. Unlike everything else it is billed while it runs:
|
|
202
|
+
* about $6 a month at the default size on Spot.
|
|
203
|
+
*/
|
|
204
|
+
export interface ServiceConfig {
|
|
205
|
+
/** Module whose default export is `defineService(...)` from `@ericminassian/platform`. */
|
|
206
|
+
entry: string;
|
|
207
|
+
/** vCPUs: 0.25 (default), 0.5, 1, 2 or 4. */
|
|
208
|
+
cpu?: FargateCpu;
|
|
209
|
+
/**
|
|
210
|
+
* Memory in MB, one of the sizes Fargate pairs with `cpu`: 512, 1024 or
|
|
211
|
+
* 2048 for 0.25 vCPU; 1024-4096 for 0.5; 2048-8192 for 1; 4096-16384 for 2;
|
|
212
|
+
* 8192-30720 for 4 (steps of 1024). Default 512.
|
|
213
|
+
*/
|
|
214
|
+
memoryMb?: number;
|
|
215
|
+
/**
|
|
216
|
+
* Run on Fargate Spot, about 70% cheaper. AWS may reclaim it with two
|
|
217
|
+
* minutes' notice (the service gets SIGTERM) and the platform starts a
|
|
218
|
+
* replacement. Default `true`.
|
|
219
|
+
*/
|
|
220
|
+
spot?: boolean;
|
|
221
|
+
/** Minutes a preview stage runs it after each deploy before stopping it; 0 means never. Default 30. */
|
|
222
|
+
previewMinutes?: number;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Live updates pushed to browsers. The server and worker publish; browsers
|
|
226
|
+
* subscribe (they never publish). Events aren't stored: a browser that was
|
|
227
|
+
* away re-reads what it shows after reconnecting.
|
|
228
|
+
*/
|
|
229
|
+
export interface RealtimeConfig {
|
|
230
|
+
/**
|
|
231
|
+
* Who may subscribe: anyone (`public`, the default), or signed-in users of
|
|
232
|
+
* this app (`signed-in`, needs `auth` and `web.server`).
|
|
233
|
+
*/
|
|
234
|
+
subscribe?: 'public' | 'signed-in';
|
|
235
|
+
/**
|
|
236
|
+
* Channels and their event types: `board: channel<BoardEvent>()`, or
|
|
237
|
+
* `'boards/*': channel<BoardEvent>()` for every channel below `boards/`.
|
|
238
|
+
* Names are 1-4 segments of a-z, 0-9 and hyphens. `'user/*'` channels
|
|
239
|
+
* (`user/<user id>/...`) are private to that user (`signed-in` only).
|
|
240
|
+
*/
|
|
241
|
+
channels: {
|
|
242
|
+
readonly [pattern: string]: ChannelConfig;
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Transactional email, sent from `<app>@mail.<platform zone>` (previews from
|
|
247
|
+
* `<app>--<stage>@…`). Replies need `replyTo`: the sending address takes no mail.
|
|
248
|
+
*/
|
|
249
|
+
export interface EmailConfig {
|
|
250
|
+
/** Display name recipients see, e.g. `Todo` → `"Todo" <todo@mail…>`. */
|
|
251
|
+
name?: string;
|
|
252
|
+
/**
|
|
253
|
+
* Recipients per UTC day (default 200), up to the platform's
|
|
254
|
+
* `limits.emailsPerDay`. Previews and `plat dev` get at most 50.
|
|
255
|
+
*/
|
|
256
|
+
dailyLimit?: number;
|
|
257
|
+
}
|
|
108
258
|
export interface AppConfig {
|
|
109
259
|
/** 3-30 chars of a-z, 0-9 and single hyphens; also the app's host name. */
|
|
110
260
|
name: string;
|
|
@@ -130,14 +280,29 @@ export interface AppConfig {
|
|
|
130
280
|
crons?: {
|
|
131
281
|
readonly [name: string]: CronConfig;
|
|
132
282
|
};
|
|
133
|
-
/**
|
|
134
|
-
|
|
283
|
+
/**
|
|
284
|
+
* Named file stores: `{ uploads: {}, snapshots: { public: true, expireAfterDays: 7 } }`.
|
|
285
|
+
* A list of names (`['uploads']`) declares private stores. Keys are 1-20
|
|
286
|
+
* chars of a-z, 0-9 and hyphens. A store can't switch between public and
|
|
287
|
+
* private once it has files: declare a new one instead.
|
|
288
|
+
*/
|
|
289
|
+
storage?: readonly string[] | {
|
|
290
|
+
readonly [name: string]: StoreConfig;
|
|
291
|
+
};
|
|
135
292
|
/** Secret names like `STRIPE_KEY`; values are set with `plat secrets set`. */
|
|
136
293
|
secrets?: readonly string[];
|
|
137
294
|
/** Plain, non-secret configuration exposed as environment variables. */
|
|
138
295
|
env?: {
|
|
139
296
|
readonly [name: string]: string;
|
|
140
297
|
};
|
|
298
|
+
/** Live updates pushed to browsers on typed channels. */
|
|
299
|
+
realtime?: RealtimeConfig;
|
|
300
|
+
/** Send email with the SDK's `Email` service: `true`, or `{ name, dailyLimit }`. */
|
|
301
|
+
email?: boolean | EmailConfig;
|
|
302
|
+
/** Long-running processes, e.g. stream ingest. Keys are 1-20 chars of a-z, 0-9 and hyphens. */
|
|
303
|
+
services?: {
|
|
304
|
+
readonly [name: string]: ServiceConfig;
|
|
305
|
+
};
|
|
141
306
|
}
|
|
142
307
|
/**
|
|
143
308
|
* Maps every key `T` has but `Shape` doesn't to `never`, recursively, so a
|
|
@@ -153,10 +318,12 @@ type Exact<T, Shape> = Shape extends readonly (infer S)[] ? T extends readonly (
|
|
|
153
318
|
* store and secret names (and payload types) are checked in app code.
|
|
154
319
|
*/
|
|
155
320
|
export declare function defineApp<const T extends AppConfig>(config: T & Exact<T, AppConfig>): T;
|
|
156
|
-
/** A queue whose messages are `Body`: `queues: { emails: queue<EmailJob>({
|
|
321
|
+
/** A queue whose messages are `Body`: `queues: { emails: queue<EmailJob>({ maxAttempts: 3 }) }`. */
|
|
157
322
|
export declare function queue<Body>(options?: QueueConfig): QueueConfig<Body>;
|
|
158
323
|
/** An event subscription whose detail is `Detail`: `events: { 'todo.created': event<TodoCreated>() }`. */
|
|
159
|
-
export declare function event<Detail>(): EventConfig<Detail>;
|
|
324
|
+
export declare function event<Detail>(options?: EventOptions): EventConfig<Detail>;
|
|
325
|
+
/** A realtime channel whose events are `Event`: `realtime: { channels: { board: channel<BoardEvent>() } }`. */
|
|
326
|
+
export declare function channel<Event>(): ChannelConfig<Event>;
|
|
160
327
|
/**
|
|
161
328
|
* Manifest with defaults applied and derived fields normalized: what
|
|
162
329
|
* deployments store. Decoding fills defaults for fields added since a stored
|
|
@@ -177,6 +344,9 @@ export declare const ResolvedManifest: Schema.Struct<{
|
|
|
177
344
|
readonly serverRoutes: Schema.withDecodingDefault<Schema.$Array<Schema.String>, never>;
|
|
178
345
|
readonly timeoutSeconds: Schema.withDecodingDefault<Schema.Int, never>;
|
|
179
346
|
readonly concurrency: Schema.withDecodingDefault<Schema.Int, never>;
|
|
347
|
+
readonly compute: Schema.withDecodingDefault<Schema.Literals<readonly ["auto", "request", "instance"]>, never>;
|
|
348
|
+
readonly memoryMb: Schema.withDecodingDefault<Schema.Int, never>;
|
|
349
|
+
readonly maxEnvironments: Schema.optional<Schema.Int>;
|
|
180
350
|
}>>;
|
|
181
351
|
/** Present when any queue, event subscription or cron exists. */
|
|
182
352
|
readonly worker: Schema.optional<Schema.Struct<{
|
|
@@ -190,19 +360,60 @@ export declare const ResolvedManifest: Schema.Struct<{
|
|
|
190
360
|
}>;
|
|
191
361
|
readonly db: Schema.Boolean;
|
|
192
362
|
readonly queues: Schema.$Record<Schema.String, Schema.Struct<{
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
363
|
+
timeoutSeconds: Schema.optional<Schema.Int>;
|
|
364
|
+
memoryMb: Schema.optional<Schema.Int>;
|
|
365
|
+
maxAttempts: Schema.withDecodingDefault<Schema.Int, never>;
|
|
366
|
+
concurrency: Schema.optional<Schema.Int>;
|
|
197
367
|
}>>;
|
|
198
368
|
readonly events: Schema.$Array<Schema.String>;
|
|
369
|
+
/**
|
|
370
|
+
* Each event handler's own settings, by type. Absent from deployments
|
|
371
|
+
* recorded before handlers had any. A field of its own, so clients that
|
|
372
|
+
* know only `events` keep decoding manifests.
|
|
373
|
+
*/
|
|
374
|
+
readonly eventOptions: Schema.withDecodingDefault<Schema.$Record<Schema.String, Schema.Struct<{
|
|
375
|
+
readonly timeoutSeconds: Schema.optional<Schema.Int>;
|
|
376
|
+
readonly memoryMb: Schema.optional<Schema.Int>;
|
|
377
|
+
readonly maxAttempts: Schema.optional<Schema.Int>;
|
|
378
|
+
}>>, never>;
|
|
199
379
|
readonly crons: Schema.$Record<Schema.String, Schema.Struct<{
|
|
380
|
+
readonly timeoutSeconds: Schema.optional<Schema.Int>;
|
|
381
|
+
readonly memoryMb: Schema.optional<Schema.Int>;
|
|
200
382
|
readonly schedule: Schema.String;
|
|
201
383
|
readonly timezone: Schema.optional<Schema.String>;
|
|
384
|
+
readonly maxAttempts: Schema.optional<Schema.Int>;
|
|
202
385
|
}>>;
|
|
386
|
+
/** Every store's name. */
|
|
203
387
|
readonly storage: Schema.$Array<Schema.String>;
|
|
388
|
+
/**
|
|
389
|
+
* Each store's options, by name. Absent from deployments recorded before
|
|
390
|
+
* stores had any: those stores are private and kept until deleted. A field
|
|
391
|
+
* of its own, so clients that know only `storage` keep decoding manifests.
|
|
392
|
+
*/
|
|
393
|
+
readonly storageOptions: Schema.withDecodingDefault<Schema.$Record<Schema.String, Schema.Struct<{
|
|
394
|
+
readonly public: Schema.Boolean;
|
|
395
|
+
readonly expireAfterDays: Schema.optional<Schema.Finite>;
|
|
396
|
+
}>>, never>;
|
|
204
397
|
readonly secrets: Schema.$Array<Schema.String>;
|
|
205
398
|
readonly env: Schema.$Record<Schema.String, Schema.String>;
|
|
399
|
+
/** Present when the stage has a channel namespace. `channels` are the declared patterns. */
|
|
400
|
+
readonly realtime: Schema.optional<Schema.Struct<{
|
|
401
|
+
readonly subscribe: Schema.Literals<readonly ["public", "signed-in"]>;
|
|
402
|
+
readonly channels: Schema.$Array<Schema.String>;
|
|
403
|
+
}>>;
|
|
404
|
+
/** Present when the stage sends email. `dailyLimit` is the declared one (prod's). */
|
|
405
|
+
readonly email: Schema.optional<Schema.Struct<{
|
|
406
|
+
readonly name: Schema.optional<Schema.String>;
|
|
407
|
+
readonly dailyLimit: Schema.Finite;
|
|
408
|
+
}>>;
|
|
409
|
+
/** Long-running services, with defaults applied. */
|
|
410
|
+
readonly services: Schema.withDecodingDefault<Schema.$Record<Schema.String, Schema.Struct<{
|
|
411
|
+
readonly entry: Schema.String;
|
|
412
|
+
readonly cpu: Schema.withDecodingDefault<Schema.Literals<readonly [0.25, 0.5, 1, 2, 4]>, never>;
|
|
413
|
+
readonly memoryMb: Schema.withDecodingDefault<Schema.Int, never>;
|
|
414
|
+
readonly spot: Schema.withDecodingDefault<Schema.Boolean, never>;
|
|
415
|
+
readonly previewMinutes: Schema.withDecodingDefault<Schema.Int, never>;
|
|
416
|
+
}>>, never>;
|
|
206
417
|
}>;
|
|
207
418
|
export type ResolvedManifest = typeof ResolvedManifest.Type;
|
|
208
419
|
export declare class ManifestError extends Error {
|
|
@@ -211,4 +422,34 @@ export declare class ManifestError extends Error {
|
|
|
211
422
|
}
|
|
212
423
|
export declare function parseManifest(input: unknown): ResolvedManifest;
|
|
213
424
|
export declare function resolveManifest(m: Manifest): ResolvedManifest;
|
|
425
|
+
/** The stores the edge serves (`public: true`). */
|
|
426
|
+
export declare function publicStores(m: Pick<ResolvedManifest, 'storage' | 'storageOptions'>): string[];
|
|
427
|
+
declare const HANDLER_KINDS: readonly ['queue', 'event', 'cron'];
|
|
428
|
+
export type HandlerKind = (typeof HANDLER_KINDS)[number];
|
|
429
|
+
/** A queue, event or cron handler and the settings it runs with. */
|
|
430
|
+
export interface HandlerSettings {
|
|
431
|
+
kind: HandlerKind;
|
|
432
|
+
/** The queue or cron key, or the event type. */
|
|
433
|
+
name: string;
|
|
434
|
+
timeoutSeconds: number;
|
|
435
|
+
memoryMb: number;
|
|
436
|
+
/** Runs before its job is dead-lettered. */
|
|
437
|
+
maxAttempts: number;
|
|
438
|
+
/** Reserved concurrency of its function (queues that set `concurrency`). */
|
|
439
|
+
concurrency?: number;
|
|
440
|
+
/**
|
|
441
|
+
* It sets its own memory, timeout or (a queue) concurrency, so it runs in a
|
|
442
|
+
* function of its own (`names.handlerFunction`).
|
|
443
|
+
*/
|
|
444
|
+
own: boolean;
|
|
445
|
+
}
|
|
446
|
+
type WorkerManifest = Pick<ResolvedManifest, 'worker' | 'queues' | 'eventOptions' | 'crons'>;
|
|
447
|
+
/** A handler's settings: its own, and the worker's for any it doesn't set. */
|
|
448
|
+
export declare function handlerSettings(m: WorkerManifest, kind: HandlerKind, name: string): HandlerSettings;
|
|
449
|
+
/** Every queue, event and cron handler with its settings. */
|
|
450
|
+
export declare function workerHandlers(m: WorkerManifest): HandlerSettings[];
|
|
451
|
+
/** The handlers that run in functions of their own. The worker's function runs the rest. */
|
|
452
|
+
export declare function ownFunctionHandlers(m: WorkerManifest): HandlerSettings[];
|
|
453
|
+
/** The Lambda function a handler runs in: its own, or the worker's. */
|
|
454
|
+
export declare function handlerFunctionName(app: string, stage: string, m: WorkerManifest, kind: HandlerKind, name: string): string;
|
|
214
455
|
export {};
|