@ericminassian/platform-core 0.1.0 → 0.2.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/config.d.ts +8 -0
- package/dist/config.js.map +1 -1
- package/dist/manifest.d.ts +113 -4
- package/dist/manifest.js +37 -31
- package/dist/manifest.js.map +1 -1
- package/package.json +3 -5
- package/src/config.ts +7 -1
- package/src/manifest.ts +142 -33
- package/platform.schema.json +0 -213
package/dist/config.d.ts
CHANGED
|
@@ -18,9 +18,17 @@ export interface PlatformConfig {
|
|
|
18
18
|
edgeHost: string;
|
|
19
19
|
/** Cognito managed login custom domain for app end users. */
|
|
20
20
|
loginHost: string;
|
|
21
|
+
/**
|
|
22
|
+
* `ownerId`/`repoId` are the numeric GitHub ids (public). Repos created with
|
|
23
|
+
* GitHub's immutable OIDC subject claims sign tokens as
|
|
24
|
+
* `repo:<owner>@<ownerId>/<repo>@<repoId>:...`, so roles that trust GitHub
|
|
25
|
+
* Actions need them (see `gh api repos/<owner>/<repo>/actions/oidc/customization/sub`).
|
|
26
|
+
*/
|
|
21
27
|
github: {
|
|
22
28
|
owner: string;
|
|
23
29
|
repo: string;
|
|
30
|
+
ownerId: number;
|
|
31
|
+
repoId: number;
|
|
24
32
|
};
|
|
25
33
|
members: Member[];
|
|
26
34
|
/** Names that already exist in the root zone (delegated or static records). */
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAsCA,MAAM,UAAU,oBAAoB,CAAC,MAAsB;IACzD,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,KAAK,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QAC/B,MAAM,GAAG,GAAG,CAAC,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;QACnC,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;QACnE,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAChB,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,MAAsB,EAAE,MAAc;IAC/D,OAAO,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,EAAE,KAAK,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC;AACrF,CAAC"}
|
package/dist/manifest.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
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";
|
|
2
7
|
declare const WebSchema: z.ZodObject<{
|
|
3
8
|
server: z.ZodOptional<z.ZodString>;
|
|
4
9
|
static: z.ZodOptional<z.ZodString>;
|
|
@@ -24,7 +29,6 @@ declare const QueueSchema: z.ZodObject<{
|
|
|
24
29
|
concurrency: z.ZodOptional<z.ZodNumber>;
|
|
25
30
|
}, z.core.$strip>;
|
|
26
31
|
export declare const ManifestSchema: z.ZodObject<{
|
|
27
|
-
$schema: z.ZodOptional<z.ZodString>;
|
|
28
32
|
name: z.ZodString;
|
|
29
33
|
description: z.ZodOptional<z.ZodString>;
|
|
30
34
|
web: z.ZodOptional<z.ZodObject<{
|
|
@@ -55,7 +59,7 @@ export declare const ManifestSchema: z.ZodObject<{
|
|
|
55
59
|
maxReceiveCount: z.ZodDefault<z.ZodNumber>;
|
|
56
60
|
concurrency: z.ZodOptional<z.ZodNumber>;
|
|
57
61
|
}, z.core.$strip>>>;
|
|
58
|
-
events: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
62
|
+
events: z.ZodDefault<z.ZodUnion<readonly [z.ZodArray<z.ZodString>, z.ZodRecord<z.ZodString, z.ZodObject<{}, z.core.$strip>>]>>;
|
|
59
63
|
crons: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
60
64
|
schedule: z.ZodString;
|
|
61
65
|
timezone: z.ZodOptional<z.ZodString>;
|
|
@@ -64,8 +68,115 @@ export declare const ManifestSchema: z.ZodObject<{
|
|
|
64
68
|
secrets: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
65
69
|
env: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
66
70
|
}, z.core.$strip>;
|
|
71
|
+
/** The evaluated config as JSON: what the CLI sends and deployments store. */
|
|
67
72
|
export type ManifestInput = z.input<typeof ManifestSchema>;
|
|
68
73
|
export type Manifest = z.output<typeof ManifestSchema>;
|
|
74
|
+
/** Type-only marker for a queue's message body or an event's detail. Never set at runtime. */
|
|
75
|
+
declare const payloadType: unique symbol;
|
|
76
|
+
type Payload<T> = {
|
|
77
|
+
readonly [payloadType]?: T;
|
|
78
|
+
};
|
|
79
|
+
/** The message or detail type declared with `queue<T>()` / `event<T>()`; `unknown` if none. */
|
|
80
|
+
export type PayloadOf<D> = D extends Payload<infer T> ? (unknown extends T ? unknown : T) : unknown;
|
|
81
|
+
export interface WebConfig {
|
|
82
|
+
/** Entry module whose default export is a fetch handler (`{ fetch }`, a function, or a Hono app). */
|
|
83
|
+
server?: string;
|
|
84
|
+
/** Directory of built static assets, served from the edge. */
|
|
85
|
+
static?: string;
|
|
86
|
+
/** Shell command that builds `static` (run by `plat build`). */
|
|
87
|
+
build?: string;
|
|
88
|
+
/** Dev server for the frontend, proxied by `plat dev` (e.g. Vite). */
|
|
89
|
+
dev?: {
|
|
90
|
+
command: string;
|
|
91
|
+
port: number;
|
|
92
|
+
};
|
|
93
|
+
/** Serve `index.html` for unknown non-file paths (client-side routing). Default `true`. */
|
|
94
|
+
spa?: boolean;
|
|
95
|
+
/** When both `server` and `static` exist, path prefixes handled by the server. Default `['/api/']`. */
|
|
96
|
+
serverRoutes?: readonly string[];
|
|
97
|
+
/** 3-900. Default 30. */
|
|
98
|
+
timeoutSeconds?: number;
|
|
99
|
+
/** Max concurrent requests per Web Function environment, 1-128. Default 64. */
|
|
100
|
+
concurrency?: number;
|
|
101
|
+
}
|
|
102
|
+
export interface WorkerConfig {
|
|
103
|
+
/** Module whose default export is `defineWorker(...)`. Default `src/worker.ts`. */
|
|
104
|
+
entry?: string;
|
|
105
|
+
/** 1-900. Default 60. */
|
|
106
|
+
timeoutSeconds?: number;
|
|
107
|
+
/** 128-10240. Default 512. */
|
|
108
|
+
memoryMb?: number;
|
|
109
|
+
}
|
|
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. */
|
|
119
|
+
concurrency?: number;
|
|
120
|
+
}
|
|
121
|
+
/** 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 | {
|
|
125
|
+
schedule: string;
|
|
126
|
+
timezone?: string;
|
|
127
|
+
};
|
|
128
|
+
export interface AppConfig {
|
|
129
|
+
/** 3-30 chars of a-z, 0-9 and single hyphens; also the app's host name. */
|
|
130
|
+
name: string;
|
|
131
|
+
description?: string;
|
|
132
|
+
web?: WebConfig;
|
|
133
|
+
/** Present automatically when any queue, event or cron exists. */
|
|
134
|
+
worker?: WorkerConfig;
|
|
135
|
+
/** Sign-in with the shared user pool. `{ required: true }` guards every non-platform route. */
|
|
136
|
+
auth?: boolean | {
|
|
137
|
+
required?: boolean;
|
|
138
|
+
};
|
|
139
|
+
/** One document database per stage; collections are declared in code. */
|
|
140
|
+
db?: boolean;
|
|
141
|
+
/** Keys are 1-20 chars of a-z, 0-9 and hyphens. Each needs a handler in the worker. */
|
|
142
|
+
queues?: {
|
|
143
|
+
readonly [name: string]: QueueConfig;
|
|
144
|
+
};
|
|
145
|
+
/** Event types the worker subscribes to, e.g. `order.created`. Each needs a handler in the worker. */
|
|
146
|
+
events?: readonly string[] | {
|
|
147
|
+
readonly [type: string]: EventConfig;
|
|
148
|
+
};
|
|
149
|
+
/** Scheduled jobs. Each needs a handler in the worker. */
|
|
150
|
+
crons?: {
|
|
151
|
+
readonly [name: string]: CronConfig;
|
|
152
|
+
};
|
|
153
|
+
/** Named file stores. */
|
|
154
|
+
storage?: readonly string[];
|
|
155
|
+
/** Secret names like `STRIPE_KEY`; values are set with `plat secrets set`. */
|
|
156
|
+
secrets?: readonly string[];
|
|
157
|
+
/** Plain, non-secret configuration exposed as environment variables. */
|
|
158
|
+
env?: {
|
|
159
|
+
readonly [name: string]: string;
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Maps every key `T` has but `Shape` doesn't to `never`, recursively, so a
|
|
164
|
+
* misspelled field is a type error. `defineApp` needs this because a generic
|
|
165
|
+
* parameter (which keeps the literal names) skips excess-property checks.
|
|
166
|
+
*/
|
|
167
|
+
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 ? {
|
|
168
|
+
[K in keyof T]: K extends keyof Shape ? Exact<T[K], Shape[K]> : never;
|
|
169
|
+
} : Shape : Shape;
|
|
170
|
+
/**
|
|
171
|
+
* The default export of `plat.config.ts`. Returns the config unchanged with
|
|
172
|
+
* its literal names, which `Register` hands to the SDK so queue, event, cron,
|
|
173
|
+
* store and secret names (and payload types) are checked in app code.
|
|
174
|
+
*/
|
|
175
|
+
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 }) }`. */
|
|
177
|
+
export declare function queue<Body>(options?: QueueConfig): QueueConfig<Body>;
|
|
178
|
+
/** An event subscription whose detail is `Detail`: `events: { 'todo.created': event<TodoCreated>() }`. */
|
|
179
|
+
export declare function event<Detail>(): EventConfig<Detail>;
|
|
69
180
|
/** Manifest with defaults applied and derived fields normalized. */
|
|
70
181
|
export interface ResolvedManifest {
|
|
71
182
|
name: string;
|
|
@@ -96,6 +207,4 @@ export declare class ManifestError extends Error {
|
|
|
96
207
|
}
|
|
97
208
|
export declare function parseManifest(input: unknown): ResolvedManifest;
|
|
98
209
|
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
210
|
export {};
|
package/dist/manifest.js
CHANGED
|
@@ -2,27 +2,30 @@ import { z } from 'zod';
|
|
|
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
|
-
|
|
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.
|
|
7
|
+
*/
|
|
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.
|
|
8
17
|
*/
|
|
9
18
|
const resourceKey = z.string().regex(RESOURCE_KEY_PATTERN, 'must be 1-20 chars of a-z, 0-9, hyphens');
|
|
19
|
+
const eventType = z.string().regex(EVENT_TYPE_PATTERN);
|
|
10
20
|
const WebSchema = z
|
|
11
21
|
.object({
|
|
12
|
-
/** Entry module whose default export is a fetch handler (`{ fetch }` or a Hono app). */
|
|
13
22
|
server: z.string().optional(),
|
|
14
|
-
/** Directory of built static assets (served from the edge). */
|
|
15
23
|
static: z.string().optional(),
|
|
16
|
-
/** Shell command that builds `static` (run by `plat build`). */
|
|
17
24
|
build: z.string().optional(),
|
|
18
|
-
/** Dev server for the frontend, proxied by `plat dev` (e.g. Vite). */
|
|
19
25
|
dev: z.object({ command: z.string(), port: z.number().int().positive() }).optional(),
|
|
20
|
-
/** Serve `index.html` for unknown non-file paths (client-side routing). */
|
|
21
26
|
spa: z.boolean().default(true),
|
|
22
|
-
/** When both `server` and `static` exist, path prefixes handled by the server. */
|
|
23
27
|
serverRoutes: z.array(z.string().startsWith('/')).default(['/api/']),
|
|
24
28
|
timeoutSeconds: z.number().int().min(3).max(900).default(30),
|
|
25
|
-
/** Max concurrent requests per Web Function environment. */
|
|
26
29
|
concurrency: z.number().int().min(1).max(128).default(64),
|
|
27
30
|
})
|
|
28
31
|
.refine((w) => w.server || w.static, { message: 'web needs a server, a static directory, or both' });
|
|
@@ -33,23 +36,14 @@ const WorkerSchema = z.object({
|
|
|
33
36
|
});
|
|
34
37
|
const QueueSchema = z.object({
|
|
35
38
|
batchSize: z.number().int().min(1).max(10).default(10),
|
|
36
|
-
/** Defaults to 6x the worker timeout, as AWS recommends for Lambda consumers. */
|
|
37
39
|
visibilityTimeoutSeconds: z.number().int().min(0).max(43200).optional(),
|
|
38
40
|
maxReceiveCount: z.number().int().min(1).max(1000).default(5),
|
|
39
|
-
/** Max concurrent worker invocations draining this queue. */
|
|
40
41
|
concurrency: z.number().int().min(2).max(1000).optional(),
|
|
41
42
|
});
|
|
42
43
|
const CronSchema = z.union([z.string(), z.object({ schedule: z.string(), timezone: z.string().optional() })]);
|
|
43
|
-
const AuthSchema = z.union([
|
|
44
|
-
z.boolean(),
|
|
45
|
-
z.object({
|
|
46
|
-
/** Require a signed-in user for every non-platform route (`/__platform/*` stays open). */
|
|
47
|
-
required: z.boolean().default(false),
|
|
48
|
-
}),
|
|
49
|
-
]);
|
|
44
|
+
const AuthSchema = z.union([z.boolean(), z.object({ required: z.boolean().default(false) })]);
|
|
50
45
|
export const ManifestSchema = z
|
|
51
46
|
.object({
|
|
52
|
-
$schema: z.string().optional(),
|
|
53
47
|
name: z
|
|
54
48
|
.string()
|
|
55
49
|
// Reserved names are enforced when an app is registered (API), not here:
|
|
@@ -59,17 +53,14 @@ export const ManifestSchema = z
|
|
|
59
53
|
web: WebSchema.optional(),
|
|
60
54
|
worker: WorkerSchema.optional(),
|
|
61
55
|
auth: AuthSchema.default(false),
|
|
62
|
-
/** One document database per stage; collections are declared in code. */
|
|
63
56
|
db: z.boolean().default(false),
|
|
64
57
|
queues: z.record(resourceKey, QueueSchema).default({}),
|
|
65
|
-
|
|
66
|
-
|
|
58
|
+
// The array form predates typed event payloads; deployments recorded
|
|
59
|
+
// before then still store it.
|
|
60
|
+
events: z.union([z.array(eventType), z.record(eventType, z.object({}))]).default([]),
|
|
67
61
|
crons: z.record(resourceKey, CronSchema).default({}),
|
|
68
|
-
/** Named file stores. */
|
|
69
62
|
storage: z.array(resourceKey).default([]),
|
|
70
|
-
/** Secret names; values are set with `plat secrets set`. */
|
|
71
63
|
secrets: z.array(z.string().regex(ENV_NAME_PATTERN)).default([]),
|
|
72
|
-
/** Plain, non-secret configuration exposed as environment variables. */
|
|
73
64
|
env: z.record(z.string().regex(ENV_NAME_PATTERN), z.string()).default({}),
|
|
74
65
|
})
|
|
75
66
|
.superRefine((m, ctx) => {
|
|
@@ -79,10 +70,26 @@ export const ManifestSchema = z
|
|
|
79
70
|
ctx.addIssue({ code: 'custom', path: ['crons', key], message: err });
|
|
80
71
|
}
|
|
81
72
|
});
|
|
73
|
+
/**
|
|
74
|
+
* The default export of `plat.config.ts`. Returns the config unchanged with
|
|
75
|
+
* its literal names, which `Register` hands to the SDK so queue, event, cron,
|
|
76
|
+
* store and secret names (and payload types) are checked in app code.
|
|
77
|
+
*/
|
|
78
|
+
export function defineApp(config) {
|
|
79
|
+
return config;
|
|
80
|
+
}
|
|
81
|
+
/** A queue whose messages are `Body`: `queues: { emails: queue<EmailJob>({ batchSize: 5 }) }`. */
|
|
82
|
+
export function queue(options = {}) {
|
|
83
|
+
return options;
|
|
84
|
+
}
|
|
85
|
+
/** An event subscription whose detail is `Detail`: `events: { 'todo.created': event<TodoCreated>() }`. */
|
|
86
|
+
export function event() {
|
|
87
|
+
return {};
|
|
88
|
+
}
|
|
82
89
|
export class ManifestError extends Error {
|
|
83
90
|
issues;
|
|
84
91
|
constructor(issues) {
|
|
85
|
-
super(`Invalid
|
|
92
|
+
super(`Invalid ${APP_CONFIG_FILE}:\n - ${issues.join('\n - ')}`);
|
|
86
93
|
this.issues = issues;
|
|
87
94
|
}
|
|
88
95
|
}
|
|
@@ -94,7 +101,8 @@ export function parseManifest(input) {
|
|
|
94
101
|
return resolveManifest(parsed.data);
|
|
95
102
|
}
|
|
96
103
|
export function resolveManifest(m) {
|
|
97
|
-
const
|
|
104
|
+
const events = Array.isArray(m.events) ? m.events : Object.keys(m.events);
|
|
105
|
+
const needsWorker = Object.keys(m.queues).length > 0 || events.length > 0 || Object.keys(m.crons).length > 0;
|
|
98
106
|
const worker = m.worker ?? (needsWorker ? WorkerSchema.parse({}) : undefined);
|
|
99
107
|
const auth = typeof m.auth === 'boolean'
|
|
100
108
|
? { enabled: m.auth, required: false }
|
|
@@ -117,13 +125,11 @@ export function resolveManifest(m) {
|
|
|
117
125
|
auth,
|
|
118
126
|
db: m.db,
|
|
119
127
|
queues,
|
|
120
|
-
events: [...new Set(
|
|
128
|
+
events: [...new Set(events)],
|
|
121
129
|
crons,
|
|
122
130
|
storage: [...new Set(m.storage)],
|
|
123
131
|
secrets: [...new Set(m.secrets)],
|
|
124
132
|
env: m.env,
|
|
125
133
|
};
|
|
126
134
|
}
|
|
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
135
|
//# sourceMappingURL=manifest.js.map
|
package/dist/manifest.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manifest.js","sourceRoot":"","sources":["../src/manifest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAE3G
|
|
1
|
+
{"version":3,"file":"manifest.js","sourceRoot":"","sources":["../src/manifest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAE3G;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,gBAAgB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AChC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC7B,IAAI;QACJ,EAAE,EAAE,CAAC,CAAC,EAAE;QACR,MAAM;QACN,MAAM,EAAE,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC;QAC5B,KAAK;QACL,OAAO,EAAE,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QAChC,OAAO,EAAE,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QAChC,GAAG,EAAE,CAAC,CAAC,GAAG;KACX,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ericminassian/platform-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Shared contracts for the platform: naming, manifest schema, bindings, telemetry, routing.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,8 +25,7 @@
|
|
|
25
25
|
},
|
|
26
26
|
"files": [
|
|
27
27
|
"dist",
|
|
28
|
-
"src"
|
|
29
|
-
"platform.schema.json"
|
|
28
|
+
"src"
|
|
30
29
|
],
|
|
31
30
|
"dependencies": {
|
|
32
31
|
"zod": "^4.6.7"
|
|
@@ -34,7 +33,6 @@
|
|
|
34
33
|
"scripts": {
|
|
35
34
|
"build": "tsc -p tsconfig.build.json && mkdir -p dist/router && cp src/router/decide.js src/router/decide.d.ts dist/router/",
|
|
36
35
|
"typecheck": "tsc --noEmit",
|
|
37
|
-
"test": "vitest run"
|
|
38
|
-
"schema": "node scripts/schema.ts"
|
|
36
|
+
"test": "vitest run"
|
|
39
37
|
}
|
|
40
38
|
}
|
package/src/config.ts
CHANGED
|
@@ -20,7 +20,13 @@ export interface PlatformConfig {
|
|
|
20
20
|
edgeHost: string;
|
|
21
21
|
/** Cognito managed login custom domain for app end users. */
|
|
22
22
|
loginHost: string;
|
|
23
|
-
|
|
23
|
+
/**
|
|
24
|
+
* `ownerId`/`repoId` are the numeric GitHub ids (public). Repos created with
|
|
25
|
+
* GitHub's immutable OIDC subject claims sign tokens as
|
|
26
|
+
* `repo:<owner>@<ownerId>/<repo>@<repoId>:...`, so roles that trust GitHub
|
|
27
|
+
* Actions need them (see `gh api repos/<owner>/<repo>/actions/oidc/customization/sub`).
|
|
28
|
+
*/
|
|
29
|
+
github: { owner: string; repo: string; ownerId: number; repoId: number };
|
|
24
30
|
members: Member[];
|
|
25
31
|
/** Names that already exist in the root zone (delegated or static records). */
|
|
26
32
|
reservedAppNames: string[];
|
package/src/manifest.ts
CHANGED
|
@@ -3,28 +3,32 @@ import { validateCron } from './cron.ts';
|
|
|
3
3
|
import { APP_NAME_PATTERN, ENV_NAME_PATTERN, EVENT_TYPE_PATTERN, RESOURCE_KEY_PATTERN } from './naming.ts';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
|
|
6
|
+
* The app's config file, at the app root. `plat` evaluates it and sends the
|
|
7
|
+
* result to the platform as JSON; the control plane never runs app code.
|
|
8
|
+
*/
|
|
9
|
+
export const APP_CONFIG_FILE = 'plat.config.ts';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* What `plat.config.ts` declares: everything an app needs, in cloud-neutral
|
|
13
|
+
* terms. This is the whole contract between an app repo and the platform;
|
|
14
|
+
* apps contain no infrastructure code. Keep this schema small and stable.
|
|
15
|
+
*
|
|
16
|
+
* `ManifestSchema` validates the evaluated config (CLI and API); `AppConfig`
|
|
17
|
+
* below is the same shape written for authors. `test/manifest-types.test.ts`
|
|
18
|
+
* keeps the two in step.
|
|
9
19
|
*/
|
|
10
20
|
const resourceKey = z.string().regex(RESOURCE_KEY_PATTERN, 'must be 1-20 chars of a-z, 0-9, hyphens');
|
|
21
|
+
const eventType = z.string().regex(EVENT_TYPE_PATTERN);
|
|
11
22
|
|
|
12
23
|
const WebSchema = z
|
|
13
24
|
.object({
|
|
14
|
-
/** Entry module whose default export is a fetch handler (`{ fetch }` or a Hono app). */
|
|
15
25
|
server: z.string().optional(),
|
|
16
|
-
/** Directory of built static assets (served from the edge). */
|
|
17
26
|
static: z.string().optional(),
|
|
18
|
-
/** Shell command that builds `static` (run by `plat build`). */
|
|
19
27
|
build: z.string().optional(),
|
|
20
|
-
/** Dev server for the frontend, proxied by `plat dev` (e.g. Vite). */
|
|
21
28
|
dev: z.object({ command: z.string(), port: z.number().int().positive() }).optional(),
|
|
22
|
-
/** Serve `index.html` for unknown non-file paths (client-side routing). */
|
|
23
29
|
spa: z.boolean().default(true),
|
|
24
|
-
/** When both `server` and `static` exist, path prefixes handled by the server. */
|
|
25
30
|
serverRoutes: z.array(z.string().startsWith('/')).default(['/api/']),
|
|
26
31
|
timeoutSeconds: z.number().int().min(3).max(900).default(30),
|
|
27
|
-
/** Max concurrent requests per Web Function environment. */
|
|
28
32
|
concurrency: z.number().int().min(1).max(128).default(64),
|
|
29
33
|
})
|
|
30
34
|
.refine((w) => w.server || w.static, { message: 'web needs a server, a static directory, or both' });
|
|
@@ -37,26 +41,17 @@ const WorkerSchema = z.object({
|
|
|
37
41
|
|
|
38
42
|
const QueueSchema = z.object({
|
|
39
43
|
batchSize: z.number().int().min(1).max(10).default(10),
|
|
40
|
-
/** Defaults to 6x the worker timeout, as AWS recommends for Lambda consumers. */
|
|
41
44
|
visibilityTimeoutSeconds: z.number().int().min(0).max(43200).optional(),
|
|
42
45
|
maxReceiveCount: z.number().int().min(1).max(1000).default(5),
|
|
43
|
-
/** Max concurrent worker invocations draining this queue. */
|
|
44
46
|
concurrency: z.number().int().min(2).max(1000).optional(),
|
|
45
47
|
});
|
|
46
48
|
|
|
47
49
|
const CronSchema = z.union([z.string(), z.object({ schedule: z.string(), timezone: z.string().optional() })]);
|
|
48
50
|
|
|
49
|
-
const AuthSchema = z.union([
|
|
50
|
-
z.boolean(),
|
|
51
|
-
z.object({
|
|
52
|
-
/** Require a signed-in user for every non-platform route (`/__platform/*` stays open). */
|
|
53
|
-
required: z.boolean().default(false),
|
|
54
|
-
}),
|
|
55
|
-
]);
|
|
51
|
+
const AuthSchema = z.union([z.boolean(), z.object({ required: z.boolean().default(false) })]);
|
|
56
52
|
|
|
57
53
|
export const ManifestSchema = z
|
|
58
54
|
.object({
|
|
59
|
-
$schema: z.string().optional(),
|
|
60
55
|
name: z
|
|
61
56
|
.string()
|
|
62
57
|
// Reserved names are enforced when an app is registered (API), not here:
|
|
@@ -66,17 +61,14 @@ export const ManifestSchema = z
|
|
|
66
61
|
web: WebSchema.optional(),
|
|
67
62
|
worker: WorkerSchema.optional(),
|
|
68
63
|
auth: AuthSchema.default(false),
|
|
69
|
-
/** One document database per stage; collections are declared in code. */
|
|
70
64
|
db: z.boolean().default(false),
|
|
71
65
|
queues: z.record(resourceKey, QueueSchema).default({}),
|
|
72
|
-
|
|
73
|
-
|
|
66
|
+
// The array form predates typed event payloads; deployments recorded
|
|
67
|
+
// before then still store it.
|
|
68
|
+
events: z.union([z.array(eventType), z.record(eventType, z.object({}))]).default([]),
|
|
74
69
|
crons: z.record(resourceKey, CronSchema).default({}),
|
|
75
|
-
/** Named file stores. */
|
|
76
70
|
storage: z.array(resourceKey).default([]),
|
|
77
|
-
/** Secret names; values are set with `plat secrets set`. */
|
|
78
71
|
secrets: z.array(z.string().regex(ENV_NAME_PATTERN)).default([]),
|
|
79
|
-
/** Plain, non-secret configuration exposed as environment variables. */
|
|
80
72
|
env: z.record(z.string().regex(ENV_NAME_PATTERN), z.string()).default({}),
|
|
81
73
|
})
|
|
82
74
|
.superRefine((m, ctx) => {
|
|
@@ -86,9 +78,129 @@ export const ManifestSchema = z
|
|
|
86
78
|
}
|
|
87
79
|
});
|
|
88
80
|
|
|
81
|
+
/** The evaluated config as JSON: what the CLI sends and deployments store. */
|
|
89
82
|
export type ManifestInput = z.input<typeof ManifestSchema>;
|
|
90
83
|
export type Manifest = z.output<typeof ManifestSchema>;
|
|
91
84
|
|
|
85
|
+
// ---------------------------------------------------------------------------
|
|
86
|
+
// Authoring types. Arrays are readonly so `defineApp` can keep literal names.
|
|
87
|
+
|
|
88
|
+
/** Type-only marker for a queue's message body or an event's detail. Never set at runtime. */
|
|
89
|
+
declare const payloadType: unique symbol;
|
|
90
|
+
|
|
91
|
+
// A type literal, not an interface, so it fits the schema's `Record<string, never>` event options.
|
|
92
|
+
type Payload<T> = { readonly [payloadType]?: T };
|
|
93
|
+
|
|
94
|
+
/** The message or detail type declared with `queue<T>()` / `event<T>()`; `unknown` if none. */
|
|
95
|
+
export type PayloadOf<D> = D extends Payload<infer T> ? (unknown extends T ? unknown : T) : unknown;
|
|
96
|
+
|
|
97
|
+
export interface WebConfig {
|
|
98
|
+
/** Entry module whose default export is a fetch handler (`{ fetch }`, a function, or a Hono app). */
|
|
99
|
+
server?: string;
|
|
100
|
+
/** Directory of built static assets, served from the edge. */
|
|
101
|
+
static?: string;
|
|
102
|
+
/** Shell command that builds `static` (run by `plat build`). */
|
|
103
|
+
build?: string;
|
|
104
|
+
/** Dev server for the frontend, proxied by `plat dev` (e.g. Vite). */
|
|
105
|
+
dev?: { command: string; port: number };
|
|
106
|
+
/** Serve `index.html` for unknown non-file paths (client-side routing). Default `true`. */
|
|
107
|
+
spa?: boolean;
|
|
108
|
+
/** When both `server` and `static` exist, path prefixes handled by the server. Default `['/api/']`. */
|
|
109
|
+
serverRoutes?: readonly string[];
|
|
110
|
+
/** 3-900. Default 30. */
|
|
111
|
+
timeoutSeconds?: number;
|
|
112
|
+
/** Max concurrent requests per Web Function environment, 1-128. Default 64. */
|
|
113
|
+
concurrency?: number;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export interface WorkerConfig {
|
|
117
|
+
/** Module whose default export is `defineWorker(...)`. Default `src/worker.ts`. */
|
|
118
|
+
entry?: string;
|
|
119
|
+
/** 1-900. Default 60. */
|
|
120
|
+
timeoutSeconds?: number;
|
|
121
|
+
/** 128-10240. Default 512. */
|
|
122
|
+
memoryMb?: number;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** Declare one with `queue<Body>({ ... })` to type what is sent and received. */
|
|
126
|
+
export interface QueueConfig<Body = unknown> extends Payload<Body> {
|
|
127
|
+
/** Messages per worker invocation, 1-10. Default 10. */
|
|
128
|
+
batchSize?: number;
|
|
129
|
+
/** Defaults to 6x the worker timeout, as AWS recommends for Lambda consumers. */
|
|
130
|
+
visibilityTimeoutSeconds?: number;
|
|
131
|
+
/** Deliveries before a message moves to the dead-letter queue, 1-1000. Default 5. */
|
|
132
|
+
maxReceiveCount?: number;
|
|
133
|
+
/** Max concurrent worker invocations draining this queue, 2-1000. */
|
|
134
|
+
concurrency?: number;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** Declare one with `event<Detail>()` to type what is published and handled. */
|
|
138
|
+
export type EventConfig<Detail = unknown> = Payload<Detail>;
|
|
139
|
+
|
|
140
|
+
/** 5-field cron in UTC (`0 3 * * *`) or `rate(5 minutes)`. */
|
|
141
|
+
export type CronConfig = string | { schedule: string; timezone?: string };
|
|
142
|
+
|
|
143
|
+
export interface AppConfig {
|
|
144
|
+
/** 3-30 chars of a-z, 0-9 and single hyphens; also the app's host name. */
|
|
145
|
+
name: string;
|
|
146
|
+
description?: string;
|
|
147
|
+
web?: WebConfig;
|
|
148
|
+
/** Present automatically when any queue, event or cron exists. */
|
|
149
|
+
worker?: WorkerConfig;
|
|
150
|
+
/** Sign-in with the shared user pool. `{ required: true }` guards every non-platform route. */
|
|
151
|
+
auth?: boolean | { required?: boolean };
|
|
152
|
+
/** One document database per stage; collections are declared in code. */
|
|
153
|
+
db?: boolean;
|
|
154
|
+
/** Keys are 1-20 chars of a-z, 0-9 and hyphens. Each needs a handler in the worker. */
|
|
155
|
+
queues?: { readonly [name: string]: QueueConfig };
|
|
156
|
+
/** Event types the worker subscribes to, e.g. `order.created`. Each needs a handler in the worker. */
|
|
157
|
+
events?: readonly string[] | { readonly [type: string]: EventConfig };
|
|
158
|
+
/** Scheduled jobs. Each needs a handler in the worker. */
|
|
159
|
+
crons?: { readonly [name: string]: CronConfig };
|
|
160
|
+
/** Named file stores. */
|
|
161
|
+
storage?: readonly string[];
|
|
162
|
+
/** Secret names like `STRIPE_KEY`; values are set with `plat secrets set`. */
|
|
163
|
+
secrets?: readonly string[];
|
|
164
|
+
/** Plain, non-secret configuration exposed as environment variables. */
|
|
165
|
+
env?: { readonly [name: string]: string };
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Maps every key `T` has but `Shape` doesn't to `never`, recursively, so a
|
|
170
|
+
* misspelled field is a type error. `defineApp` needs this because a generic
|
|
171
|
+
* parameter (which keeps the literal names) skips excess-property checks.
|
|
172
|
+
*/
|
|
173
|
+
type Exact<T, Shape> = Shape extends readonly (infer S)[]
|
|
174
|
+
? T extends readonly (infer E)[]
|
|
175
|
+
? readonly Exact<E, S>[]
|
|
176
|
+
: Shape
|
|
177
|
+
: Shape extends object
|
|
178
|
+
? T extends object
|
|
179
|
+
? { [K in keyof T]: K extends keyof Shape ? Exact<T[K], Shape[K]> : never }
|
|
180
|
+
: Shape
|
|
181
|
+
: Shape;
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* The default export of `plat.config.ts`. Returns the config unchanged with
|
|
185
|
+
* its literal names, which `Register` hands to the SDK so queue, event, cron,
|
|
186
|
+
* store and secret names (and payload types) are checked in app code.
|
|
187
|
+
*/
|
|
188
|
+
export function defineApp<const T extends AppConfig>(config: T & Exact<T, AppConfig>): T {
|
|
189
|
+
return config;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** A queue whose messages are `Body`: `queues: { emails: queue<EmailJob>({ batchSize: 5 }) }`. */
|
|
193
|
+
export function queue<Body>(options: QueueConfig = {}): QueueConfig<Body> {
|
|
194
|
+
return options as QueueConfig<Body>;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** An event subscription whose detail is `Detail`: `events: { 'todo.created': event<TodoCreated>() }`. */
|
|
198
|
+
export function event<Detail>(): EventConfig<Detail> {
|
|
199
|
+
return {};
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// ---------------------------------------------------------------------------
|
|
203
|
+
|
|
92
204
|
/** Manifest with defaults applied and derived fields normalized. */
|
|
93
205
|
export interface ResolvedManifest {
|
|
94
206
|
name: string;
|
|
@@ -109,7 +221,7 @@ export interface ResolvedManifest {
|
|
|
109
221
|
export class ManifestError extends Error {
|
|
110
222
|
readonly issues: string[];
|
|
111
223
|
constructor(issues: string[]) {
|
|
112
|
-
super(`Invalid
|
|
224
|
+
super(`Invalid ${APP_CONFIG_FILE}:\n - ${issues.join('\n - ')}`);
|
|
113
225
|
this.issues = issues;
|
|
114
226
|
}
|
|
115
227
|
}
|
|
@@ -123,8 +235,9 @@ export function parseManifest(input: unknown): ResolvedManifest {
|
|
|
123
235
|
}
|
|
124
236
|
|
|
125
237
|
export function resolveManifest(m: Manifest): ResolvedManifest {
|
|
238
|
+
const events = Array.isArray(m.events) ? m.events : Object.keys(m.events);
|
|
126
239
|
const needsWorker =
|
|
127
|
-
Object.keys(m.queues).length > 0 ||
|
|
240
|
+
Object.keys(m.queues).length > 0 || events.length > 0 || Object.keys(m.crons).length > 0;
|
|
128
241
|
const worker = m.worker ?? (needsWorker ? WorkerSchema.parse({}) : undefined);
|
|
129
242
|
const auth =
|
|
130
243
|
typeof m.auth === 'boolean'
|
|
@@ -147,14 +260,10 @@ export function resolveManifest(m: Manifest): ResolvedManifest {
|
|
|
147
260
|
auth,
|
|
148
261
|
db: m.db,
|
|
149
262
|
queues,
|
|
150
|
-
events: [...new Set(
|
|
263
|
+
events: [...new Set(events)],
|
|
151
264
|
crons,
|
|
152
265
|
storage: [...new Set(m.storage)],
|
|
153
266
|
secrets: [...new Set(m.secrets)],
|
|
154
267
|
env: m.env,
|
|
155
268
|
};
|
|
156
269
|
}
|
|
157
|
-
|
|
158
|
-
/** JSON Schema URL apps reference for editor completion. */
|
|
159
|
-
export const MANIFEST_SCHEMA_URL =
|
|
160
|
-
'https://raw.githubusercontent.com/eric-minassian/platform/main/packages/core/platform.schema.json';
|
package/platform.schema.json
DELETED
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
-
"$id": "https://raw.githubusercontent.com/eric-minassian/platform/main/packages/core/platform.schema.json",
|
|
4
|
-
"title": "platform.json",
|
|
5
|
-
"description": "What an app needs from the platform. See docs/DESIGN.md.",
|
|
6
|
-
"type": "object",
|
|
7
|
-
"properties": {
|
|
8
|
-
"$schema": {
|
|
9
|
-
"type": "string"
|
|
10
|
-
},
|
|
11
|
-
"name": {
|
|
12
|
-
"type": "string",
|
|
13
|
-
"pattern": "^[a-z](?:[a-z0-9]|-(?!-)){1,28}[a-z0-9]$"
|
|
14
|
-
},
|
|
15
|
-
"description": {
|
|
16
|
-
"type": "string",
|
|
17
|
-
"maxLength": 200
|
|
18
|
-
},
|
|
19
|
-
"web": {
|
|
20
|
-
"type": "object",
|
|
21
|
-
"properties": {
|
|
22
|
-
"server": {
|
|
23
|
-
"type": "string"
|
|
24
|
-
},
|
|
25
|
-
"static": {
|
|
26
|
-
"type": "string"
|
|
27
|
-
},
|
|
28
|
-
"build": {
|
|
29
|
-
"type": "string"
|
|
30
|
-
},
|
|
31
|
-
"dev": {
|
|
32
|
-
"type": "object",
|
|
33
|
-
"properties": {
|
|
34
|
-
"command": {
|
|
35
|
-
"type": "string"
|
|
36
|
-
},
|
|
37
|
-
"port": {
|
|
38
|
-
"type": "integer",
|
|
39
|
-
"exclusiveMinimum": 0,
|
|
40
|
-
"maximum": 9007199254740991
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
"required": ["command", "port"]
|
|
44
|
-
},
|
|
45
|
-
"spa": {
|
|
46
|
-
"default": true,
|
|
47
|
-
"type": "boolean"
|
|
48
|
-
},
|
|
49
|
-
"serverRoutes": {
|
|
50
|
-
"default": ["/api/"],
|
|
51
|
-
"type": "array",
|
|
52
|
-
"items": {
|
|
53
|
-
"type": "string",
|
|
54
|
-
"format": "starts_with",
|
|
55
|
-
"pattern": "^\\/.*"
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
"timeoutSeconds": {
|
|
59
|
-
"default": 30,
|
|
60
|
-
"type": "integer",
|
|
61
|
-
"minimum": 3,
|
|
62
|
-
"maximum": 900
|
|
63
|
-
},
|
|
64
|
-
"concurrency": {
|
|
65
|
-
"default": 64,
|
|
66
|
-
"type": "integer",
|
|
67
|
-
"minimum": 1,
|
|
68
|
-
"maximum": 128
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
"worker": {
|
|
73
|
-
"type": "object",
|
|
74
|
-
"properties": {
|
|
75
|
-
"entry": {
|
|
76
|
-
"default": "src/worker.ts",
|
|
77
|
-
"type": "string"
|
|
78
|
-
},
|
|
79
|
-
"timeoutSeconds": {
|
|
80
|
-
"default": 60,
|
|
81
|
-
"type": "integer",
|
|
82
|
-
"minimum": 1,
|
|
83
|
-
"maximum": 900
|
|
84
|
-
},
|
|
85
|
-
"memoryMb": {
|
|
86
|
-
"default": 512,
|
|
87
|
-
"type": "integer",
|
|
88
|
-
"minimum": 128,
|
|
89
|
-
"maximum": 10240
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
},
|
|
93
|
-
"auth": {
|
|
94
|
-
"default": false,
|
|
95
|
-
"anyOf": [
|
|
96
|
-
{
|
|
97
|
-
"type": "boolean"
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
"type": "object",
|
|
101
|
-
"properties": {
|
|
102
|
-
"required": {
|
|
103
|
-
"default": false,
|
|
104
|
-
"type": "boolean"
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
]
|
|
109
|
-
},
|
|
110
|
-
"db": {
|
|
111
|
-
"default": false,
|
|
112
|
-
"type": "boolean"
|
|
113
|
-
},
|
|
114
|
-
"queues": {
|
|
115
|
-
"default": {},
|
|
116
|
-
"type": "object",
|
|
117
|
-
"propertyNames": {
|
|
118
|
-
"type": "string",
|
|
119
|
-
"pattern": "^(?!.*--)[a-z](?:[a-z0-9-]{0,18}[a-z0-9])?$"
|
|
120
|
-
},
|
|
121
|
-
"additionalProperties": {
|
|
122
|
-
"type": "object",
|
|
123
|
-
"properties": {
|
|
124
|
-
"batchSize": {
|
|
125
|
-
"default": 10,
|
|
126
|
-
"type": "integer",
|
|
127
|
-
"minimum": 1,
|
|
128
|
-
"maximum": 10
|
|
129
|
-
},
|
|
130
|
-
"visibilityTimeoutSeconds": {
|
|
131
|
-
"type": "integer",
|
|
132
|
-
"minimum": 0,
|
|
133
|
-
"maximum": 43200
|
|
134
|
-
},
|
|
135
|
-
"maxReceiveCount": {
|
|
136
|
-
"default": 5,
|
|
137
|
-
"type": "integer",
|
|
138
|
-
"minimum": 1,
|
|
139
|
-
"maximum": 1000
|
|
140
|
-
},
|
|
141
|
-
"concurrency": {
|
|
142
|
-
"type": "integer",
|
|
143
|
-
"minimum": 2,
|
|
144
|
-
"maximum": 1000
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
},
|
|
149
|
-
"events": {
|
|
150
|
-
"default": [],
|
|
151
|
-
"type": "array",
|
|
152
|
-
"items": {
|
|
153
|
-
"type": "string",
|
|
154
|
-
"pattern": "^[a-zA-Z][a-zA-Z0-9._:-]{0,63}$"
|
|
155
|
-
}
|
|
156
|
-
},
|
|
157
|
-
"crons": {
|
|
158
|
-
"default": {},
|
|
159
|
-
"type": "object",
|
|
160
|
-
"propertyNames": {
|
|
161
|
-
"type": "string",
|
|
162
|
-
"pattern": "^(?!.*--)[a-z](?:[a-z0-9-]{0,18}[a-z0-9])?$"
|
|
163
|
-
},
|
|
164
|
-
"additionalProperties": {
|
|
165
|
-
"anyOf": [
|
|
166
|
-
{
|
|
167
|
-
"type": "string"
|
|
168
|
-
},
|
|
169
|
-
{
|
|
170
|
-
"type": "object",
|
|
171
|
-
"properties": {
|
|
172
|
-
"schedule": {
|
|
173
|
-
"type": "string"
|
|
174
|
-
},
|
|
175
|
-
"timezone": {
|
|
176
|
-
"type": "string"
|
|
177
|
-
}
|
|
178
|
-
},
|
|
179
|
-
"required": ["schedule"]
|
|
180
|
-
}
|
|
181
|
-
]
|
|
182
|
-
}
|
|
183
|
-
},
|
|
184
|
-
"storage": {
|
|
185
|
-
"default": [],
|
|
186
|
-
"type": "array",
|
|
187
|
-
"items": {
|
|
188
|
-
"type": "string",
|
|
189
|
-
"pattern": "^(?!.*--)[a-z](?:[a-z0-9-]{0,18}[a-z0-9])?$"
|
|
190
|
-
}
|
|
191
|
-
},
|
|
192
|
-
"secrets": {
|
|
193
|
-
"default": [],
|
|
194
|
-
"type": "array",
|
|
195
|
-
"items": {
|
|
196
|
-
"type": "string",
|
|
197
|
-
"pattern": "^[A-Z][A-Z0-9_]{0,63}$"
|
|
198
|
-
}
|
|
199
|
-
},
|
|
200
|
-
"env": {
|
|
201
|
-
"default": {},
|
|
202
|
-
"type": "object",
|
|
203
|
-
"propertyNames": {
|
|
204
|
-
"type": "string",
|
|
205
|
-
"pattern": "^[A-Z][A-Z0-9_]{0,63}$"
|
|
206
|
-
},
|
|
207
|
-
"additionalProperties": {
|
|
208
|
-
"type": "string"
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
},
|
|
212
|
-
"required": ["name"]
|
|
213
|
-
}
|