@ericminassian/platform-core 0.1.0 → 0.3.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.
- package/dist/api.d.ts +947 -209
- package/dist/api.js +335 -1
- package/dist/api.js.map +1 -1
- package/dist/auth.d.ts +19 -0
- package/dist/auth.js +29 -0
- package/dist/auth.js.map +1 -1
- package/dist/bindings.d.ts +8 -2
- package/dist/bindings.js.map +1 -1
- package/dist/cloudfront-function.js +6 -0
- package/dist/cloudfront-function.js.map +1 -1
- package/dist/config.d.ts +11 -1
- package/dist/config.js +7 -0
- package/dist/config.js.map +1 -1
- package/dist/constants.d.ts +11 -0
- package/dist/constants.js.map +1 -1
- package/dist/manifest.d.ts +203 -90
- package/dist/manifest.js +129 -93
- package/dist/manifest.js.map +1 -1
- package/dist/naming.d.ts +13 -2
- package/dist/naming.js +12 -1
- package/dist/naming.js.map +1 -1
- package/dist/platform-api.d.ts +5337 -0
- package/dist/platform-api.js +343 -0
- package/dist/platform-api.js.map +1 -0
- package/dist/router/decide.d.ts +5 -1
- package/dist/router/decide.js +7 -2
- package/dist/router.d.ts +1 -1
- package/dist/telemetry.d.ts +236 -74
- package/dist/telemetry.js +97 -0
- package/dist/telemetry.js.map +1 -1
- package/package.json +12 -6
- package/src/api.ts +427 -231
- package/src/auth.ts +33 -0
- package/src/bindings.ts +8 -2
- package/src/cloudfront-function.ts +6 -0
- package/src/config.ts +10 -2
- package/src/constants.ts +12 -0
- package/src/manifest.ts +280 -113
- package/src/naming.ts +13 -2
- package/src/platform-api.ts +504 -0
- package/src/router/decide.d.ts +5 -1
- package/src/router/decide.js +7 -2
- package/src/router.ts +1 -1
- package/src/telemetry.ts +107 -85
- package/platform.schema.json +0 -213
package/dist/manifest.d.ts
CHANGED
|
@@ -1,101 +1,214 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
1
|
+
import { Schema } from 'effect';
|
|
2
|
+
/**
|
|
3
|
+
* The app's config file, at the app root. `plat` evaluates it and sends the
|
|
4
|
+
* result to the platform as JSON; the control plane never runs app code.
|
|
5
|
+
*/
|
|
6
|
+
export declare const APP_CONFIG_FILE = "plat.config.ts";
|
|
7
|
+
export declare const ManifestSchema: Schema.Struct<{
|
|
8
|
+
readonly name: Schema.String;
|
|
9
|
+
readonly description: Schema.optional<Schema.String>;
|
|
10
|
+
readonly web: Schema.optional<Schema.Struct<{
|
|
11
|
+
readonly server: Schema.optional<Schema.String>;
|
|
12
|
+
readonly static: Schema.optional<Schema.String>;
|
|
13
|
+
readonly build: Schema.optional<Schema.String>;
|
|
14
|
+
readonly dev: Schema.optional<Schema.Struct<{
|
|
15
|
+
readonly command: Schema.String;
|
|
16
|
+
readonly port: Schema.optional<Schema.Int>;
|
|
17
|
+
}>>;
|
|
18
|
+
readonly spa: Schema.withDecodingDefault<Schema.Boolean, never>;
|
|
19
|
+
readonly serverRoutes: Schema.withDecodingDefault<Schema.$Array<Schema.String>, never>;
|
|
20
|
+
readonly timeoutSeconds: Schema.withDecodingDefault<Schema.Int, never>;
|
|
21
|
+
readonly concurrency: Schema.withDecodingDefault<Schema.Int, never>;
|
|
22
|
+
}>>;
|
|
23
|
+
readonly worker: Schema.optional<Schema.Struct<{
|
|
24
|
+
readonly entry: Schema.withDecodingDefault<Schema.String, never>;
|
|
25
|
+
readonly timeoutSeconds: Schema.withDecodingDefault<Schema.Int, never>;
|
|
26
|
+
readonly memoryMb: Schema.withDecodingDefault<Schema.Int, never>;
|
|
27
|
+
}>>;
|
|
28
|
+
readonly auth: Schema.withDecodingDefault<Schema.Union<readonly [Schema.Boolean, Schema.Struct<{
|
|
29
|
+
readonly required: Schema.withDecodingDefault<Schema.Boolean, never>;
|
|
30
|
+
}>]>, never>;
|
|
31
|
+
readonly db: Schema.withDecodingDefault<Schema.Boolean, never>;
|
|
32
|
+
readonly queues: Schema.withDecodingDefault<Schema.$Record<Schema.String, Schema.Struct<{
|
|
33
|
+
readonly batchSize: Schema.withDecodingDefault<Schema.Int, never>;
|
|
34
|
+
readonly visibilityTimeoutSeconds: Schema.optional<Schema.Int>;
|
|
35
|
+
readonly maxReceiveCount: Schema.withDecodingDefault<Schema.Int, never>;
|
|
36
|
+
readonly concurrency: Schema.optional<Schema.Int>;
|
|
37
|
+
}>>, never>;
|
|
38
|
+
readonly events: Schema.withDecodingDefault<Schema.Union<readonly [Schema.$Array<Schema.String>, Schema.$Record<Schema.String, Schema.Struct<{}>>]>, never>;
|
|
39
|
+
readonly crons: Schema.withDecodingDefault<Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Struct<{
|
|
40
|
+
readonly schedule: Schema.String;
|
|
41
|
+
readonly timezone: Schema.optional<Schema.String>;
|
|
42
|
+
}>]>>, never>;
|
|
43
|
+
readonly storage: Schema.withDecodingDefault<Schema.$Array<Schema.String>, never>;
|
|
44
|
+
readonly secrets: Schema.withDecodingDefault<Schema.$Array<Schema.String>, never>;
|
|
45
|
+
readonly env: Schema.withDecodingDefault<Schema.$Record<Schema.String, Schema.String>, never>;
|
|
46
|
+
}>;
|
|
47
|
+
/** The evaluated config as JSON: what the CLI sends and deployments store. */
|
|
48
|
+
export type ManifestInput = typeof ManifestSchema.Encoded;
|
|
49
|
+
export type Manifest = typeof ManifestSchema.Type;
|
|
50
|
+
/** Type-only marker for a queue's message body or an event's detail. Never set at runtime. */
|
|
51
|
+
declare const payloadType: unique symbol;
|
|
52
|
+
type Payload<T> = {
|
|
53
|
+
readonly [payloadType]?: T;
|
|
54
|
+
};
|
|
55
|
+
/** The message or detail type declared with `queue<T>()` / `event<T>()`; `unknown` if none. */
|
|
56
|
+
export type PayloadOf<D> = D extends Payload<infer T> ? (unknown extends T ? unknown : T) : unknown;
|
|
57
|
+
export interface WebConfig {
|
|
58
|
+
/** Entry module whose default export is `toFetchHandler(...)` from `@ericminassian/platform`. */
|
|
59
|
+
server?: string;
|
|
60
|
+
/** Directory of built static assets, served from the edge. */
|
|
61
|
+
static?: string;
|
|
62
|
+
/** Shell command that builds `static` (run by `plat build`). */
|
|
63
|
+
build?: string;
|
|
64
|
+
/**
|
|
65
|
+
* Dev server for the frontend, proxied by `plat dev` (e.g. Vite). The command
|
|
66
|
+
* listens on the port `plat dev` passes in `PLATFORM_DEV_WEB_PORT` (and `PORT`):
|
|
67
|
+
* `port` when it is free, otherwise any free port.
|
|
68
|
+
*/
|
|
69
|
+
dev?: {
|
|
70
|
+
command: string;
|
|
71
|
+
port?: number;
|
|
72
|
+
};
|
|
73
|
+
/** Serve `index.html` for unknown non-file paths (client-side routing). Default `true`. */
|
|
74
|
+
spa?: boolean;
|
|
75
|
+
/** When both `server` and `static` exist, path prefixes handled by the server. Default `['/api/']`. */
|
|
76
|
+
serverRoutes?: readonly string[];
|
|
77
|
+
/** 3-900. Default 30. */
|
|
78
|
+
timeoutSeconds?: number;
|
|
79
|
+
/** Max concurrent requests per Web Function environment, 1-128. Default 64. */
|
|
80
|
+
concurrency?: number;
|
|
81
|
+
}
|
|
82
|
+
export interface WorkerConfig {
|
|
83
|
+
/** Module whose default export is `defineWorker(...)`. Default `src/worker.ts`. */
|
|
84
|
+
entry?: string;
|
|
85
|
+
/** 1-900. Default 60. */
|
|
86
|
+
timeoutSeconds?: number;
|
|
87
|
+
/** 128-10240. Default 512. */
|
|
88
|
+
memoryMb?: number;
|
|
89
|
+
}
|
|
90
|
+
/** Declare one with `queue<Body>({ ... })` to type what is sent and received. */
|
|
91
|
+
export interface QueueConfig<Body = unknown> extends Payload<Body> {
|
|
92
|
+
/** Messages per worker invocation, 1-10. Default 10. */
|
|
93
|
+
batchSize?: number;
|
|
94
|
+
/** Defaults to 6x the worker timeout, as AWS recommends for Lambda consumers. */
|
|
95
|
+
visibilityTimeoutSeconds?: number;
|
|
96
|
+
/** Deliveries before a message moves to the dead-letter queue, 1-1000. Default 5. */
|
|
97
|
+
maxReceiveCount?: number;
|
|
98
|
+
/** Max concurrent worker invocations draining this queue, 2-1000. */
|
|
99
|
+
concurrency?: number;
|
|
100
|
+
}
|
|
101
|
+
/** Declare one with `event<Detail>()` to type what is published and handled. */
|
|
102
|
+
export type EventConfig<Detail = unknown> = Payload<Detail>;
|
|
103
|
+
/** 5-field cron in UTC (`0 3 * * *`) or `rate(5 minutes)`. */
|
|
104
|
+
export type CronConfig = string | {
|
|
105
|
+
schedule: string;
|
|
106
|
+
timezone?: string;
|
|
107
|
+
};
|
|
108
|
+
export interface AppConfig {
|
|
109
|
+
/** 3-30 chars of a-z, 0-9 and single hyphens; also the app's host name. */
|
|
71
110
|
name: string;
|
|
72
111
|
description?: string;
|
|
73
|
-
web?:
|
|
74
|
-
/** Present when any queue, event
|
|
75
|
-
worker?:
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
required
|
|
112
|
+
web?: WebConfig;
|
|
113
|
+
/** Present automatically when any queue, event or cron exists. */
|
|
114
|
+
worker?: WorkerConfig;
|
|
115
|
+
/** Sign-in with the shared user pool. `{ required: true }` guards every non-platform route. */
|
|
116
|
+
auth?: boolean | {
|
|
117
|
+
required?: boolean;
|
|
118
|
+
};
|
|
119
|
+
/** One document database per stage; collections are declared in code. */
|
|
120
|
+
db?: boolean;
|
|
121
|
+
/** Keys are 1-20 chars of a-z, 0-9 and hyphens. Each needs a handler in the worker. */
|
|
122
|
+
queues?: {
|
|
123
|
+
readonly [name: string]: QueueConfig;
|
|
124
|
+
};
|
|
125
|
+
/** Event types the worker subscribes to, e.g. `order.created`. Each needs a handler in the worker. */
|
|
126
|
+
events?: readonly string[] | {
|
|
127
|
+
readonly [type: string]: EventConfig;
|
|
128
|
+
};
|
|
129
|
+
/** Scheduled jobs. Each needs a handler in the worker. */
|
|
130
|
+
crons?: {
|
|
131
|
+
readonly [name: string]: CronConfig;
|
|
132
|
+
};
|
|
133
|
+
/** Named file stores. */
|
|
134
|
+
storage?: readonly string[];
|
|
135
|
+
/** Secret names like `STRIPE_KEY`; values are set with `plat secrets set`. */
|
|
136
|
+
secrets?: readonly string[];
|
|
137
|
+
/** Plain, non-secret configuration exposed as environment variables. */
|
|
138
|
+
env?: {
|
|
139
|
+
readonly [name: string]: string;
|
|
79
140
|
};
|
|
80
|
-
db: boolean;
|
|
81
|
-
queues: Record<string, z.output<typeof QueueSchema> & {
|
|
82
|
-
visibilityTimeoutSeconds: number;
|
|
83
|
-
}>;
|
|
84
|
-
events: string[];
|
|
85
|
-
crons: Record<string, {
|
|
86
|
-
schedule: string;
|
|
87
|
-
timezone?: string;
|
|
88
|
-
}>;
|
|
89
|
-
storage: string[];
|
|
90
|
-
secrets: string[];
|
|
91
|
-
env: Record<string, string>;
|
|
92
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* Maps every key `T` has but `Shape` doesn't to `never`, recursively, so a
|
|
144
|
+
* misspelled field is a type error. `defineApp` needs this because a generic
|
|
145
|
+
* parameter (which keeps the literal names) skips excess-property checks.
|
|
146
|
+
*/
|
|
147
|
+
type Exact<T, Shape> = Shape extends readonly (infer S)[] ? T extends readonly (infer E)[] ? readonly Exact<E, S>[] : Shape : Shape extends object ? T extends object ? {
|
|
148
|
+
[K in keyof T]: K extends keyof Shape ? Exact<T[K], Shape[K]> : never;
|
|
149
|
+
} : Shape : Shape;
|
|
150
|
+
/**
|
|
151
|
+
* The default export of `plat.config.ts`. Returns the config unchanged with
|
|
152
|
+
* its literal names, which `Register` hands to the SDK so queue, event, cron,
|
|
153
|
+
* store and secret names (and payload types) are checked in app code.
|
|
154
|
+
*/
|
|
155
|
+
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>({ batchSize: 5 }) }`. */
|
|
157
|
+
export declare function queue<Body>(options?: QueueConfig): QueueConfig<Body>;
|
|
158
|
+
/** An event subscription whose detail is `Detail`: `events: { 'todo.created': event<TodoCreated>() }`. */
|
|
159
|
+
export declare function event<Detail>(): EventConfig<Detail>;
|
|
160
|
+
/**
|
|
161
|
+
* Manifest with defaults applied and derived fields normalized: what
|
|
162
|
+
* deployments store. Decoding fills defaults for fields added since a stored
|
|
163
|
+
* manifest was written, so earlier deployments keep decoding.
|
|
164
|
+
*/
|
|
165
|
+
export declare const ResolvedManifest: Schema.Struct<{
|
|
166
|
+
readonly name: Schema.String;
|
|
167
|
+
readonly description: Schema.optional<Schema.String>;
|
|
168
|
+
readonly web: Schema.optional<Schema.Struct<{
|
|
169
|
+
readonly server: Schema.optional<Schema.String>;
|
|
170
|
+
readonly static: Schema.optional<Schema.String>;
|
|
171
|
+
readonly build: Schema.optional<Schema.String>;
|
|
172
|
+
readonly dev: Schema.optional<Schema.Struct<{
|
|
173
|
+
readonly command: Schema.String;
|
|
174
|
+
readonly port: Schema.optional<Schema.Int>;
|
|
175
|
+
}>>;
|
|
176
|
+
readonly spa: Schema.withDecodingDefault<Schema.Boolean, never>;
|
|
177
|
+
readonly serverRoutes: Schema.withDecodingDefault<Schema.$Array<Schema.String>, never>;
|
|
178
|
+
readonly timeoutSeconds: Schema.withDecodingDefault<Schema.Int, never>;
|
|
179
|
+
readonly concurrency: Schema.withDecodingDefault<Schema.Int, never>;
|
|
180
|
+
}>>;
|
|
181
|
+
/** Present when any queue, event subscription or cron exists. */
|
|
182
|
+
readonly worker: Schema.optional<Schema.Struct<{
|
|
183
|
+
readonly entry: Schema.withDecodingDefault<Schema.String, never>;
|
|
184
|
+
readonly timeoutSeconds: Schema.withDecodingDefault<Schema.Int, never>;
|
|
185
|
+
readonly memoryMb: Schema.withDecodingDefault<Schema.Int, never>;
|
|
186
|
+
}>>;
|
|
187
|
+
readonly auth: Schema.Struct<{
|
|
188
|
+
readonly enabled: Schema.Boolean;
|
|
189
|
+
readonly required: Schema.Boolean;
|
|
190
|
+
}>;
|
|
191
|
+
readonly db: Schema.Boolean;
|
|
192
|
+
readonly queues: Schema.$Record<Schema.String, Schema.Struct<{
|
|
193
|
+
readonly batchSize: Schema.withDecodingDefault<Schema.Int, never>;
|
|
194
|
+
readonly maxReceiveCount: Schema.withDecodingDefault<Schema.Int, never>;
|
|
195
|
+
readonly concurrency: Schema.optional<Schema.Int>;
|
|
196
|
+
readonly visibilityTimeoutSeconds: Schema.Finite;
|
|
197
|
+
}>>;
|
|
198
|
+
readonly events: Schema.$Array<Schema.String>;
|
|
199
|
+
readonly crons: Schema.$Record<Schema.String, Schema.Struct<{
|
|
200
|
+
readonly schedule: Schema.String;
|
|
201
|
+
readonly timezone: Schema.optional<Schema.String>;
|
|
202
|
+
}>>;
|
|
203
|
+
readonly storage: Schema.$Array<Schema.String>;
|
|
204
|
+
readonly secrets: Schema.$Array<Schema.String>;
|
|
205
|
+
readonly env: Schema.$Record<Schema.String, Schema.String>;
|
|
206
|
+
}>;
|
|
207
|
+
export type ResolvedManifest = typeof ResolvedManifest.Type;
|
|
93
208
|
export declare class ManifestError extends Error {
|
|
94
209
|
readonly issues: string[];
|
|
95
210
|
constructor(issues: string[]);
|
|
96
211
|
}
|
|
97
212
|
export declare function parseManifest(input: unknown): ResolvedManifest;
|
|
98
213
|
export declare function resolveManifest(m: Manifest): ResolvedManifest;
|
|
99
|
-
/** JSON Schema URL apps reference for editor completion. */
|
|
100
|
-
export declare const MANIFEST_SCHEMA_URL = "https://raw.githubusercontent.com/eric-minassian/platform/main/packages/core/platform.schema.json";
|
|
101
214
|
export {};
|
package/dist/manifest.js
CHANGED
|
@@ -1,114 +1,152 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Effect, Schema } from 'effect';
|
|
2
2
|
import { validateCron } from './cron.js';
|
|
3
3
|
import { APP_NAME_PATTERN, ENV_NAME_PATTERN, EVENT_TYPE_PATTERN, RESOURCE_KEY_PATTERN } from './naming.js';
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* infrastructure code. Keep this schema small and stable.
|
|
5
|
+
* The app's config file, at the app root. `plat` evaluates it and sends the
|
|
6
|
+
* result to the platform as JSON; the control plane never runs app code.
|
|
8
7
|
*/
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
8
|
+
export const APP_CONFIG_FILE = 'plat.config.ts';
|
|
9
|
+
/**
|
|
10
|
+
* What `plat.config.ts` declares: everything an app needs, in cloud-neutral
|
|
11
|
+
* terms. This is the whole contract between an app repo and the platform;
|
|
12
|
+
* apps contain no infrastructure code. Keep this schema small and stable.
|
|
13
|
+
*
|
|
14
|
+
* `ManifestSchema` validates the evaluated config (CLI and API); `AppConfig`
|
|
15
|
+
* below is the same shape written for authors. `test/manifest-types.test.ts`
|
|
16
|
+
* keeps the two in step.
|
|
17
|
+
*/
|
|
18
|
+
const RESOURCE_KEY_MESSAGE = 'must be 1-20 chars of a-z, 0-9, hyphens';
|
|
19
|
+
const resourceKey = Schema.String.check(Schema.isPattern(RESOURCE_KEY_PATTERN, { message: RESOURCE_KEY_MESSAGE }));
|
|
20
|
+
const eventType = Schema.String.check(Schema.isPattern(EVENT_TYPE_PATTERN));
|
|
21
|
+
const envName = Schema.String.check(Schema.isPattern(ENV_NAME_PATTERN));
|
|
22
|
+
/**
|
|
23
|
+
* A record whose keys must match `pattern`. `Schema.Record` drops keys that fail
|
|
24
|
+
* its key schema, which would make a misnamed queue silently disappear, so
|
|
25
|
+
* keys are checked here and reported at their path instead.
|
|
26
|
+
*/
|
|
27
|
+
const recordOf = (pattern, value, message = `must match ${pattern}`) => Schema.Record(Schema.String, value).check(Schema.makeFilter((record) => Object.keys(record)
|
|
28
|
+
.filter((key) => !pattern.test(key))
|
|
29
|
+
.map((key) => ({ path: [key], issue: message }))));
|
|
30
|
+
const intBetween = (minimum, maximum) => Schema.Int.check(Schema.isBetween({ minimum, maximum }));
|
|
31
|
+
/** Absent (or `undefined`) decodes to `value`. */
|
|
32
|
+
const orElse = (value) => (schema) => schema.pipe(Schema.withDecodingDefault(Effect.succeed(value)));
|
|
33
|
+
const WebSchema = Schema.Struct({
|
|
34
|
+
server: Schema.optional(Schema.String),
|
|
35
|
+
static: Schema.optional(Schema.String),
|
|
36
|
+
build: Schema.optional(Schema.String),
|
|
37
|
+
dev: Schema.optional(Schema.Struct({ command: Schema.String, port: Schema.optional(intBetween(1, 65535)) })),
|
|
38
|
+
spa: Schema.Boolean.pipe(orElse(true)),
|
|
39
|
+
serverRoutes: Schema.Array(Schema.String.check(Schema.isStartingWith('/'))).pipe(orElse(['/api/'])),
|
|
40
|
+
timeoutSeconds: intBetween(3, 900).pipe(orElse(30)),
|
|
41
|
+
concurrency: intBetween(1, 128).pipe(orElse(64)),
|
|
42
|
+
}).check(Schema.makeFilter((w) => w.server || w.static ? undefined : 'web needs a server, a static directory, or both'));
|
|
43
|
+
const WorkerSchema = Schema.Struct({
|
|
44
|
+
entry: Schema.String.pipe(orElse('src/worker.ts')),
|
|
45
|
+
timeoutSeconds: intBetween(1, 900).pipe(orElse(60)),
|
|
46
|
+
memoryMb: intBetween(128, 10240).pipe(orElse(512)),
|
|
33
47
|
});
|
|
34
|
-
const QueueSchema =
|
|
35
|
-
batchSize:
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
/** Max concurrent worker invocations draining this queue. */
|
|
40
|
-
concurrency: z.number().int().min(2).max(1000).optional(),
|
|
48
|
+
const QueueSchema = Schema.Struct({
|
|
49
|
+
batchSize: intBetween(1, 10).pipe(orElse(10)),
|
|
50
|
+
visibilityTimeoutSeconds: Schema.optional(intBetween(0, 43200)),
|
|
51
|
+
maxReceiveCount: intBetween(1, 1000).pipe(orElse(5)),
|
|
52
|
+
concurrency: Schema.optional(intBetween(2, 1000)),
|
|
41
53
|
});
|
|
42
|
-
const CronSchema =
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}),
|
|
54
|
+
const CronSchema = Schema.Union([
|
|
55
|
+
Schema.String,
|
|
56
|
+
Schema.Struct({ schedule: Schema.String, timezone: Schema.optional(Schema.String) }),
|
|
57
|
+
]).check(Schema.makeFilter((cron) => validateCron(typeof cron === 'string' ? cron : cron.schedule) ?? undefined));
|
|
58
|
+
const AuthSchema = Schema.Union([
|
|
59
|
+
Schema.Boolean,
|
|
60
|
+
Schema.Struct({ required: Schema.Boolean.pipe(orElse(false)) }),
|
|
49
61
|
]);
|
|
50
|
-
export const ManifestSchema =
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
name: z
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
62
|
+
export const ManifestSchema = Schema.Struct({
|
|
63
|
+
// Reserved names are enforced when an app is registered (API), not here:
|
|
64
|
+
// the control plane itself is the app named `platform`.
|
|
65
|
+
name: Schema.String.check(Schema.isPattern(APP_NAME_PATTERN, { message: 'must be 3-30 chars of a-z, 0-9, single hyphens' })),
|
|
66
|
+
description: Schema.optional(Schema.String.check(Schema.isMaxLength(200))),
|
|
67
|
+
web: Schema.optional(WebSchema),
|
|
68
|
+
worker: Schema.optional(WorkerSchema),
|
|
69
|
+
auth: AuthSchema.pipe(orElse(false)),
|
|
70
|
+
db: Schema.Boolean.pipe(orElse(false)),
|
|
71
|
+
queues: recordOf(RESOURCE_KEY_PATTERN, QueueSchema, RESOURCE_KEY_MESSAGE).pipe(orElse({})),
|
|
72
|
+
// The array form predates typed event payloads; deployments recorded
|
|
73
|
+
// before then still store it.
|
|
74
|
+
events: Schema.Union([Schema.Array(eventType), recordOf(EVENT_TYPE_PATTERN, Schema.Struct({}))]).pipe(orElse([])),
|
|
75
|
+
crons: recordOf(RESOURCE_KEY_PATTERN, CronSchema, RESOURCE_KEY_MESSAGE).pipe(orElse({})),
|
|
76
|
+
storage: Schema.Array(resourceKey).pipe(orElse([])),
|
|
77
|
+
secrets: Schema.Array(envName).pipe(orElse([])),
|
|
78
|
+
env: recordOf(ENV_NAME_PATTERN, Schema.String).pipe(orElse({})),
|
|
79
|
+
});
|
|
80
|
+
/**
|
|
81
|
+
* The default export of `plat.config.ts`. Returns the config unchanged with
|
|
82
|
+
* its literal names, which `Register` hands to the SDK so queue, event, cron,
|
|
83
|
+
* store and secret names (and payload types) are checked in app code.
|
|
84
|
+
*/
|
|
85
|
+
export function defineApp(config) {
|
|
86
|
+
return config;
|
|
87
|
+
}
|
|
88
|
+
/** A queue whose messages are `Body`: `queues: { emails: queue<EmailJob>({ batchSize: 5 }) }`. */
|
|
89
|
+
export function queue(options = {}) {
|
|
90
|
+
return options;
|
|
91
|
+
}
|
|
92
|
+
/** An event subscription whose detail is `Detail`: `events: { 'todo.created': event<TodoCreated>() }`. */
|
|
93
|
+
export function event() {
|
|
94
|
+
return {};
|
|
95
|
+
}
|
|
96
|
+
// ---------------------------------------------------------------------------
|
|
97
|
+
/**
|
|
98
|
+
* Manifest with defaults applied and derived fields normalized: what
|
|
99
|
+
* deployments store. Decoding fills defaults for fields added since a stored
|
|
100
|
+
* manifest was written, so earlier deployments keep decoding.
|
|
101
|
+
*/
|
|
102
|
+
export const ResolvedManifest = Schema.Struct({
|
|
103
|
+
name: Schema.String,
|
|
104
|
+
description: Schema.optional(Schema.String),
|
|
105
|
+
web: Schema.optional(WebSchema),
|
|
106
|
+
/** Present when any queue, event subscription or cron exists. */
|
|
107
|
+
worker: Schema.optional(WorkerSchema),
|
|
108
|
+
auth: Schema.Struct({ enabled: Schema.Boolean, required: Schema.Boolean }),
|
|
109
|
+
db: Schema.Boolean,
|
|
110
|
+
queues: Schema.Record(Schema.String, Schema.Struct({ ...QueueSchema.fields, visibilityTimeoutSeconds: Schema.Finite })),
|
|
111
|
+
events: Schema.Array(Schema.String),
|
|
112
|
+
crons: Schema.Record(Schema.String, Schema.Struct({ schedule: Schema.String, timezone: Schema.optional(Schema.String) })),
|
|
113
|
+
storage: Schema.Array(Schema.String),
|
|
114
|
+
secrets: Schema.Array(Schema.String),
|
|
115
|
+
env: Schema.Record(Schema.String, Schema.String),
|
|
81
116
|
});
|
|
82
117
|
export class ManifestError extends Error {
|
|
83
118
|
issues;
|
|
84
119
|
constructor(issues) {
|
|
85
|
-
super(`Invalid
|
|
120
|
+
super(`Invalid ${APP_CONFIG_FILE}:\n - ${issues.join('\n - ')}`);
|
|
86
121
|
this.issues = issues;
|
|
87
122
|
}
|
|
88
123
|
}
|
|
124
|
+
const validateManifest = Schema.toStandardSchemaV1(ManifestSchema, { parseOptions: { errors: 'all' } })['~standard'].validate;
|
|
89
125
|
export function parseManifest(input) {
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
126
|
+
const result = validateManifest(input);
|
|
127
|
+
// The schema has no asynchronous checks, so validation is synchronous.
|
|
128
|
+
if (result instanceof Promise)
|
|
129
|
+
throw new Error('manifest validation must be synchronous');
|
|
130
|
+
if (result.issues) {
|
|
131
|
+
throw new ManifestError(result.issues.map((i) => {
|
|
132
|
+
const path = (i.path ?? []).map((p) => String(typeof p === 'object' ? p.key : p)).join('.');
|
|
133
|
+
return `${path || '(root)'}: ${i.message}`;
|
|
134
|
+
}));
|
|
93
135
|
}
|
|
94
|
-
return resolveManifest(
|
|
136
|
+
return resolveManifest(result.value);
|
|
95
137
|
}
|
|
96
138
|
export function resolveManifest(m) {
|
|
97
|
-
const
|
|
98
|
-
const
|
|
139
|
+
const events = Array.isArray(m.events) ? m.events : Object.keys(m.events);
|
|
140
|
+
const needsWorker = Object.keys(m.queues).length > 0 || events.length > 0 || Object.keys(m.crons).length > 0;
|
|
141
|
+
const worker = m.worker ?? (needsWorker ? Schema.decodeUnknownSync(WorkerSchema)({}) : undefined);
|
|
99
142
|
const auth = typeof m.auth === 'boolean'
|
|
100
143
|
? { enabled: m.auth, required: false }
|
|
101
144
|
: { enabled: true, required: m.auth.required };
|
|
102
|
-
const queues =
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
const crons = {};
|
|
110
|
-
for (const [key, c] of Object.entries(m.crons))
|
|
111
|
-
crons[key] = typeof c === 'string' ? { schedule: c } : c;
|
|
145
|
+
const queues = Object.fromEntries(Object.entries(m.queues).map(([key, q]) => [
|
|
146
|
+
key,
|
|
147
|
+
{ ...q, visibilityTimeoutSeconds: q.visibilityTimeoutSeconds ?? (worker?.timeoutSeconds ?? 60) * 6 },
|
|
148
|
+
]));
|
|
149
|
+
const crons = Object.fromEntries(Object.entries(m.crons).map(([key, c]) => [key, typeof c === 'string' ? { schedule: c } : c]));
|
|
112
150
|
return {
|
|
113
151
|
name: m.name,
|
|
114
152
|
...(m.description ? { description: m.description } : {}),
|
|
@@ -117,13 +155,11 @@ export function resolveManifest(m) {
|
|
|
117
155
|
auth,
|
|
118
156
|
db: m.db,
|
|
119
157
|
queues,
|
|
120
|
-
events: [...new Set(
|
|
158
|
+
events: [...new Set(events)],
|
|
121
159
|
crons,
|
|
122
160
|
storage: [...new Set(m.storage)],
|
|
123
161
|
secrets: [...new Set(m.secrets)],
|
|
124
162
|
env: m.env,
|
|
125
163
|
};
|
|
126
164
|
}
|
|
127
|
-
/** JSON Schema URL apps reference for editor completion. */
|
|
128
|
-
export const MANIFEST_SCHEMA_URL = 'https://raw.githubusercontent.com/eric-minassian/platform/main/packages/core/platform.schema.json';
|
|
129
165
|
//# sourceMappingURL=manifest.js.map
|