@ericminassian/platform-core 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/dist/api.d.ts +1847 -212
  2. package/dist/api.js +694 -1
  3. package/dist/api.js.map +1 -1
  4. package/dist/auth.d.ts +19 -0
  5. package/dist/auth.js +32 -0
  6. package/dist/auth.js.map +1 -1
  7. package/dist/base64url.d.ts +3 -0
  8. package/dist/base64url.js +15 -0
  9. package/dist/base64url.js.map +1 -0
  10. package/dist/bindings.d.ts +69 -13
  11. package/dist/bindings.js +1 -1
  12. package/dist/bindings.js.map +1 -1
  13. package/dist/cloudfront-function.d.ts +5 -1
  14. package/dist/cloudfront-function.js +70 -2
  15. package/dist/cloudfront-function.js.map +1 -1
  16. package/dist/compute.d.ts +52 -0
  17. package/dist/compute.js +65 -0
  18. package/dist/compute.js.map +1 -0
  19. package/dist/config.d.ts +21 -1
  20. package/dist/config.js +16 -0
  21. package/dist/config.js.map +1 -1
  22. package/dist/constants.d.ts +67 -1
  23. package/dist/constants.js +56 -1
  24. package/dist/constants.js.map +1 -1
  25. package/dist/email.d.ts +84 -0
  26. package/dist/email.js +111 -0
  27. package/dist/email.js.map +1 -0
  28. package/dist/fingerprint.d.ts +9 -0
  29. package/dist/fingerprint.js +19 -0
  30. package/dist/fingerprint.js.map +1 -0
  31. package/dist/index.d.ts +6 -0
  32. package/dist/index.js +6 -0
  33. package/dist/index.js.map +1 -1
  34. package/dist/jobs.d.ts +111 -0
  35. package/dist/jobs.js +214 -0
  36. package/dist/jobs.js.map +1 -0
  37. package/dist/manifest.d.ts +357 -112
  38. package/dist/manifest.js +270 -72
  39. package/dist/manifest.js.map +1 -1
  40. package/dist/naming.d.ts +93 -6
  41. package/dist/naming.js +98 -6
  42. package/dist/naming.js.map +1 -1
  43. package/dist/platform-api.d.ts +7792 -0
  44. package/dist/platform-api.js +455 -0
  45. package/dist/platform-api.js.map +1 -0
  46. package/dist/realtime.d.ts +139 -0
  47. package/dist/realtime.js +201 -0
  48. package/dist/realtime.js.map +1 -0
  49. package/dist/router/decide.d.ts +7 -1
  50. package/dist/router/decide.js +42 -5
  51. package/dist/router.d.ts +35 -13
  52. package/dist/router.js +36 -0
  53. package/dist/router.js.map +1 -1
  54. package/dist/runtime-config.d.ts +57 -0
  55. package/dist/runtime-config.js +12 -0
  56. package/dist/runtime-config.js.map +1 -1
  57. package/dist/storage.d.ts +55 -0
  58. package/dist/storage.js +112 -0
  59. package/dist/storage.js.map +1 -0
  60. package/dist/telemetry.d.ts +350 -83
  61. package/dist/telemetry.js +188 -15
  62. package/dist/telemetry.js.map +1 -1
  63. package/dist/web-compute.d.ts +191 -0
  64. package/dist/web-compute.js +257 -0
  65. package/dist/web-compute.js.map +1 -0
  66. package/package.json +28 -8
  67. package/src/api.ts +864 -238
  68. package/src/auth.ts +37 -0
  69. package/src/base64url.ts +13 -0
  70. package/src/bindings.ts +74 -7
  71. package/src/cloudfront-function.ts +70 -2
  72. package/src/compute.ts +86 -0
  73. package/src/config.ts +34 -2
  74. package/src/constants.ts +76 -1
  75. package/src/email.ts +168 -0
  76. package/src/fingerprint.ts +20 -0
  77. package/src/index.ts +6 -0
  78. package/src/jobs.ts +281 -0
  79. package/src/manifest.ts +542 -114
  80. package/src/naming.ts +103 -8
  81. package/src/platform-api.ts +630 -0
  82. package/src/realtime.ts +298 -0
  83. package/src/router/decide.d.ts +7 -1
  84. package/src/router/decide.js +42 -5
  85. package/src/router.ts +33 -13
  86. package/src/runtime-config.ts +70 -0
  87. package/src/storage.ts +120 -0
  88. package/src/telemetry.ts +198 -93
  89. package/src/web-compute.ts +342 -0
@@ -1,76 +1,85 @@
1
- import { z } from 'zod';
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.
5
7
  */
6
8
  export declare const APP_CONFIG_FILE = "plat.config.ts";
7
- declare const WebSchema: z.ZodObject<{
8
- server: z.ZodOptional<z.ZodString>;
9
- static: z.ZodOptional<z.ZodString>;
10
- build: z.ZodOptional<z.ZodString>;
11
- dev: z.ZodOptional<z.ZodObject<{
12
- command: z.ZodString;
13
- port: z.ZodNumber;
14
- }, z.core.$strip>>;
15
- spa: z.ZodDefault<z.ZodBoolean>;
16
- serverRoutes: z.ZodDefault<z.ZodArray<z.ZodString>>;
17
- timeoutSeconds: z.ZodDefault<z.ZodNumber>;
18
- concurrency: z.ZodDefault<z.ZodNumber>;
19
- }, z.core.$strip>;
20
- declare const WorkerSchema: z.ZodObject<{
21
- entry: z.ZodDefault<z.ZodString>;
22
- timeoutSeconds: z.ZodDefault<z.ZodNumber>;
23
- memoryMb: z.ZodDefault<z.ZodNumber>;
24
- }, z.core.$strip>;
25
- declare const QueueSchema: z.ZodObject<{
26
- batchSize: z.ZodDefault<z.ZodNumber>;
27
- visibilityTimeoutSeconds: z.ZodOptional<z.ZodNumber>;
28
- maxReceiveCount: z.ZodDefault<z.ZodNumber>;
29
- concurrency: z.ZodOptional<z.ZodNumber>;
30
- }, z.core.$strip>;
31
- export declare const ManifestSchema: z.ZodObject<{
32
- name: z.ZodString;
33
- description: z.ZodOptional<z.ZodString>;
34
- web: z.ZodOptional<z.ZodObject<{
35
- server: z.ZodOptional<z.ZodString>;
36
- static: z.ZodOptional<z.ZodString>;
37
- build: z.ZodOptional<z.ZodString>;
38
- dev: z.ZodOptional<z.ZodObject<{
39
- command: z.ZodString;
40
- port: z.ZodNumber;
41
- }, z.core.$strip>>;
42
- spa: z.ZodDefault<z.ZodBoolean>;
43
- serverRoutes: z.ZodDefault<z.ZodArray<z.ZodString>>;
44
- timeoutSeconds: z.ZodDefault<z.ZodNumber>;
45
- concurrency: z.ZodDefault<z.ZodNumber>;
46
- }, z.core.$strip>>;
47
- worker: z.ZodOptional<z.ZodObject<{
48
- entry: z.ZodDefault<z.ZodString>;
49
- timeoutSeconds: z.ZodDefault<z.ZodNumber>;
50
- memoryMb: z.ZodDefault<z.ZodNumber>;
51
- }, z.core.$strip>>;
52
- auth: z.ZodDefault<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
53
- required: z.ZodDefault<z.ZodBoolean>;
54
- }, z.core.$strip>]>>;
55
- db: z.ZodDefault<z.ZodBoolean>;
56
- queues: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
57
- batchSize: z.ZodDefault<z.ZodNumber>;
58
- visibilityTimeoutSeconds: z.ZodOptional<z.ZodNumber>;
59
- maxReceiveCount: z.ZodDefault<z.ZodNumber>;
60
- concurrency: z.ZodOptional<z.ZodNumber>;
61
- }, z.core.$strip>>>;
62
- events: z.ZodDefault<z.ZodUnion<readonly [z.ZodArray<z.ZodString>, z.ZodRecord<z.ZodString, z.ZodObject<{}, z.core.$strip>>]>>;
63
- crons: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
64
- schedule: z.ZodString;
65
- timezone: z.ZodOptional<z.ZodString>;
66
- }, z.core.$strip>]>>>;
67
- storage: z.ZodDefault<z.ZodArray<z.ZodString>>;
68
- secrets: z.ZodDefault<z.ZodArray<z.ZodString>>;
69
- env: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
70
- }, z.core.$strip>;
9
+ export declare const ManifestSchema: Schema.Struct<{
10
+ readonly name: Schema.String;
11
+ readonly description: Schema.optional<Schema.String>;
12
+ readonly web: Schema.optional<Schema.Struct<{
13
+ readonly server: Schema.optional<Schema.String>;
14
+ readonly static: Schema.optional<Schema.String>;
15
+ readonly build: Schema.optional<Schema.String>;
16
+ readonly dev: Schema.optional<Schema.Struct<{
17
+ readonly command: Schema.String;
18
+ readonly port: Schema.optional<Schema.Int>;
19
+ }>>;
20
+ readonly spa: Schema.withDecodingDefault<Schema.Boolean, never>;
21
+ readonly serverRoutes: Schema.withDecodingDefault<Schema.$Array<Schema.String>, never>;
22
+ readonly timeoutSeconds: Schema.withDecodingDefault<Schema.Int, never>;
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>;
27
+ }>>;
28
+ readonly worker: Schema.optional<Schema.Struct<{
29
+ readonly entry: Schema.withDecodingDefault<Schema.String, never>;
30
+ readonly timeoutSeconds: Schema.withDecodingDefault<Schema.Int, never>;
31
+ readonly memoryMb: Schema.withDecodingDefault<Schema.Int, never>;
32
+ }>>;
33
+ readonly auth: Schema.withDecodingDefault<Schema.Union<readonly [Schema.Boolean, Schema.Struct<{
34
+ readonly required: Schema.withDecodingDefault<Schema.Boolean, never>;
35
+ }>]>, never>;
36
+ readonly db: Schema.withDecodingDefault<Schema.Boolean, never>;
37
+ readonly queues: Schema.withDecodingDefault<Schema.$Record<Schema.String, Schema.Struct<{
38
+ readonly timeoutSeconds: Schema.optional<Schema.Int>;
39
+ readonly memoryMb: Schema.optional<Schema.Int>;
40
+ readonly maxAttempts: Schema.withDecodingDefault<Schema.Int, never>;
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>;
45
+ }>>, never>;
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>;
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>;
54
+ readonly schedule: Schema.String;
55
+ readonly timezone: Schema.optional<Schema.String>;
56
+ readonly maxAttempts: Schema.optional<Schema.Int>;
57
+ }>]>>, never>;
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>;
62
+ readonly secrets: Schema.withDecodingDefault<Schema.$Array<Schema.String>, never>;
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>;
79
+ }>;
71
80
  /** The evaluated config as JSON: what the CLI sends and deployments store. */
72
- export type ManifestInput = z.input<typeof ManifestSchema>;
73
- export type Manifest = z.output<typeof ManifestSchema>;
81
+ export type ManifestInput = typeof ManifestSchema.Encoded;
82
+ export type Manifest = typeof ManifestSchema.Type;
74
83
  /** Type-only marker for a queue's message body or an event's detail. Never set at runtime. */
75
84
  declare const payloadType: unique symbol;
76
85
  type Payload<T> = {
@@ -79,16 +88,20 @@ type Payload<T> = {
79
88
  /** The message or detail type declared with `queue<T>()` / `event<T>()`; `unknown` if none. */
80
89
  export type PayloadOf<D> = D extends Payload<infer T> ? (unknown extends T ? unknown : T) : unknown;
81
90
  export interface WebConfig {
82
- /** Entry module whose default export is a fetch handler (`{ fetch }`, a function, or a Hono app). */
91
+ /** Entry module whose default export is `toFetchHandler(...)` from `@ericminassian/platform`. */
83
92
  server?: string;
84
93
  /** Directory of built static assets, served from the edge. */
85
94
  static?: string;
86
95
  /** Shell command that builds `static` (run by `plat build`). */
87
96
  build?: string;
88
- /** Dev server for the frontend, proxied by `plat dev` (e.g. Vite). */
97
+ /**
98
+ * Dev server for the frontend, proxied by `plat dev` (e.g. Vite). The command
99
+ * listens on the port `plat dev` passes in `PLATFORM_DEV_WEB_PORT` (and `PORT`):
100
+ * `port` when it is free, otherwise any free port.
101
+ */
89
102
  dev?: {
90
103
  command: string;
91
- port: number;
104
+ port?: number;
92
105
  };
93
106
  /** Serve `index.html` for unknown non-file paths (client-side routing). Default `true`. */
94
107
  spa?: boolean;
@@ -96,35 +109,152 @@ export interface WebConfig {
96
109
  serverRoutes?: readonly string[];
97
110
  /** 3-900. Default 30. */
98
111
  timeoutSeconds?: number;
99
- /** 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. */
100
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;
101
127
  }
102
128
  export interface WorkerConfig {
103
129
  /** Module whose default export is `defineWorker(...)`. Default `src/worker.ts`. */
104
130
  entry?: string;
105
- /** 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`. */
106
144
  timeoutSeconds?: number;
107
- /** 128-10240. Default 512. */
145
+ /** 128-10240. Default: the worker's `memoryMb`. */
108
146
  memoryMb?: number;
109
147
  }
110
- /** Declare one with `queue<Body>({ ... })` to type what is sent and received. */
111
- export interface QueueConfig<Body = unknown> extends Payload<Body> {
112
- /** Messages per worker invocation, 1-10. Default 10. */
113
- batchSize?: number;
114
- /** Defaults to 6x the worker timeout, as AWS recommends for Lambda consumers. */
115
- visibilityTimeoutSeconds?: number;
116
- /** Deliveries before a message moves to the dead-letter queue, 1-1000. Default 5. */
117
- maxReceiveCount?: number;
118
- /** Max concurrent worker invocations draining this queue, 2-1000. */
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
+ */
119
167
  concurrency?: number;
120
168
  }
169
+ /** Event handler options. */
170
+ export type EventOptions = HandlerConfig & RetryConfig;
121
171
  /** Declare one with `event<Detail>()` to type what is published and handled. */
122
- export type EventConfig<Detail = unknown> = Payload<Detail>;
123
- /** 5-field cron in UTC (`0 3 * * *`) or `rate(5 minutes)`. */
124
- export type CronConfig = string | {
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 {
125
179
  schedule: string;
180
+ /** IANA name, e.g. `America/Los_Angeles`. Default UTC. */
126
181
  timezone?: string;
127
- };
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
+ }
128
258
  export interface AppConfig {
129
259
  /** 3-30 chars of a-z, 0-9 and single hyphens; also the app's host name. */
130
260
  name: string;
@@ -150,14 +280,29 @@ export interface AppConfig {
150
280
  crons?: {
151
281
  readonly [name: string]: CronConfig;
152
282
  };
153
- /** Named file stores. */
154
- storage?: readonly string[];
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
+ };
155
292
  /** Secret names like `STRIPE_KEY`; values are set with `plat secrets set`. */
156
293
  secrets?: readonly string[];
157
294
  /** Plain, non-secret configuration exposed as environment variables. */
158
295
  env?: {
159
296
  readonly [name: string]: string;
160
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
+ };
161
306
  }
162
307
  /**
163
308
  * Maps every key `T` has but `Shape` doesn't to `never`, recursively, so a
@@ -173,38 +318,138 @@ type Exact<T, Shape> = Shape extends readonly (infer S)[] ? T extends readonly (
173
318
  * store and secret names (and payload types) are checked in app code.
174
319
  */
175
320
  export declare function defineApp<const T extends AppConfig>(config: T & Exact<T, AppConfig>): T;
176
- /** A queue whose messages are `Body`: `queues: { emails: queue<EmailJob>({ batchSize: 5 }) }`. */
321
+ /** A queue whose messages are `Body`: `queues: { emails: queue<EmailJob>({ maxAttempts: 3 }) }`. */
177
322
  export declare function queue<Body>(options?: QueueConfig): QueueConfig<Body>;
178
323
  /** An event subscription whose detail is `Detail`: `events: { 'todo.created': event<TodoCreated>() }`. */
179
- export declare function event<Detail>(): EventConfig<Detail>;
180
- /** Manifest with defaults applied and derived fields normalized. */
181
- export interface ResolvedManifest {
182
- name: string;
183
- description?: string;
184
- web?: z.output<typeof WebSchema>;
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>;
327
+ /**
328
+ * Manifest with defaults applied and derived fields normalized: what
329
+ * deployments store. Decoding fills defaults for fields added since a stored
330
+ * manifest was written, so earlier deployments keep decoding.
331
+ */
332
+ export declare const ResolvedManifest: Schema.Struct<{
333
+ readonly name: Schema.String;
334
+ readonly description: Schema.optional<Schema.String>;
335
+ readonly web: Schema.optional<Schema.Struct<{
336
+ readonly server: Schema.optional<Schema.String>;
337
+ readonly static: Schema.optional<Schema.String>;
338
+ readonly build: Schema.optional<Schema.String>;
339
+ readonly dev: Schema.optional<Schema.Struct<{
340
+ readonly command: Schema.String;
341
+ readonly port: Schema.optional<Schema.Int>;
342
+ }>>;
343
+ readonly spa: Schema.withDecodingDefault<Schema.Boolean, never>;
344
+ readonly serverRoutes: Schema.withDecodingDefault<Schema.$Array<Schema.String>, never>;
345
+ readonly timeoutSeconds: Schema.withDecodingDefault<Schema.Int, never>;
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>;
350
+ }>>;
185
351
  /** Present when any queue, event subscription or cron exists. */
186
- worker?: z.output<typeof WorkerSchema>;
187
- auth: {
188
- enabled: boolean;
189
- required: boolean;
190
- };
191
- db: boolean;
192
- queues: Record<string, z.output<typeof QueueSchema> & {
193
- visibilityTimeoutSeconds: number;
194
- }>;
195
- events: string[];
196
- crons: Record<string, {
197
- schedule: string;
198
- timezone?: string;
352
+ readonly worker: Schema.optional<Schema.Struct<{
353
+ readonly entry: Schema.withDecodingDefault<Schema.String, never>;
354
+ readonly timeoutSeconds: Schema.withDecodingDefault<Schema.Int, never>;
355
+ readonly memoryMb: Schema.withDecodingDefault<Schema.Int, never>;
356
+ }>>;
357
+ readonly auth: Schema.Struct<{
358
+ readonly enabled: Schema.Boolean;
359
+ readonly required: Schema.Boolean;
199
360
  }>;
200
- storage: string[];
201
- secrets: string[];
202
- env: Record<string, string>;
203
- }
361
+ readonly db: Schema.Boolean;
362
+ readonly queues: Schema.$Record<Schema.String, Schema.Struct<{
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>;
367
+ }>>;
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>;
379
+ readonly crons: Schema.$Record<Schema.String, Schema.Struct<{
380
+ readonly timeoutSeconds: Schema.optional<Schema.Int>;
381
+ readonly memoryMb: Schema.optional<Schema.Int>;
382
+ readonly schedule: Schema.String;
383
+ readonly timezone: Schema.optional<Schema.String>;
384
+ readonly maxAttempts: Schema.optional<Schema.Int>;
385
+ }>>;
386
+ /** Every store's name. */
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>;
397
+ readonly secrets: Schema.$Array<Schema.String>;
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>;
417
+ }>;
418
+ export type ResolvedManifest = typeof ResolvedManifest.Type;
204
419
  export declare class ManifestError extends Error {
205
420
  readonly issues: string[];
206
421
  constructor(issues: string[]);
207
422
  }
208
423
  export declare function parseManifest(input: unknown): ResolvedManifest;
209
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;
210
455
  export {};