@pexis/core 0.1.1 → 0.1.3
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/AGENTS.md +65 -15
- package/API.md +11 -8
- package/README.md +1 -1
- package/api.json +5951 -0
- package/dist/app.d.ts +77 -3
- package/dist/app.js +284 -38
- package/dist/app.js.map +1 -1
- package/dist/components.d.ts +100 -6
- package/dist/components.js +87 -19
- package/dist/components.js.map +1 -1
- package/dist/context.d.ts +27 -2
- package/dist/context.js +18 -2
- package/dist/context.js.map +1 -1
- package/dist/cors.d.ts +14 -0
- package/dist/cors.js +8 -0
- package/dist/cors.js.map +1 -1
- package/dist/csrf.d.ts +9 -0
- package/dist/csrf.js +9 -0
- package/dist/csrf.js.map +1 -1
- package/dist/form.d.ts +21 -3
- package/dist/form.js +38 -4
- package/dist/form.js.map +1 -1
- package/dist/host.d.ts +6 -1
- package/dist/host.js +6 -1
- package/dist/host.js.map +1 -1
- package/dist/html.d.ts +46 -5
- package/dist/html.js +112 -5
- package/dist/html.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/jsx-runtime.d.ts +32 -0
- package/dist/jsx-runtime.js +16 -0
- package/dist/jsx-runtime.js.map +1 -1
- package/dist/page.d.ts +74 -1
- package/dist/page.js +48 -5
- package/dist/page.js.map +1 -1
- package/dist/rate-limit.d.ts +46 -0
- package/dist/rate-limit.js +19 -0
- package/dist/rate-limit.js.map +1 -1
- package/dist/registry.d.ts +126 -3
- package/dist/registry.js +53 -1
- package/dist/registry.js.map +1 -1
- package/dist/schema.d.ts +129 -3
- package/dist/schema.js +80 -7
- package/dist/schema.js.map +1 -1
- package/dist/security.d.ts +38 -2
- package/dist/security.js +44 -9
- package/dist/security.js.map +1 -1
- package/dist/styles.d.ts +37 -2
- package/dist/styles.js +32 -2
- package/dist/styles.js.map +1 -1
- package/dist/types.d.ts +163 -19
- package/dist/urls.d.ts +8 -1
- package/dist/urls.js +8 -1
- package/dist/urls.js.map +1 -1
- package/package.json +2 -1
package/dist/registry.d.ts
CHANGED
|
@@ -1,16 +1,39 @@
|
|
|
1
1
|
import { type Fields, type Infer, type ObjectSchema } from './schema.js';
|
|
2
2
|
import type { Context } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* How much an action changes. `read` changes nothing and is sent as a GET
|
|
5
|
+
* form; `write` changes data; `irreversible` cannot be undone, so people
|
|
6
|
+
* confirm it on the page and agents must get the person's approval.
|
|
7
|
+
*/
|
|
3
8
|
export type Risk = 'read' | 'write' | 'irreversible';
|
|
4
9
|
/** Actions receive the full request context, including fields plugins add. */
|
|
5
10
|
export type ActionContext = Context;
|
|
11
|
+
/** What an action's `run` returns when it succeeds. */
|
|
6
12
|
export interface ActionResult {
|
|
7
13
|
/** Shown to a person and returned to an agent. */
|
|
8
14
|
message: string;
|
|
15
|
+
/** Structured data for agents and scripts, returned as `data` in the JSON reply. People see only the message. */
|
|
9
16
|
data?: unknown;
|
|
17
|
+
/**
|
|
18
|
+
* One link to show with the message, such as the page for what was just
|
|
19
|
+
* made: a path on this site, or a URL on its own origin. Anything else is
|
|
20
|
+
* dropped and logged, never rendered. People see it with the message;
|
|
21
|
+
* agents get it as an absolute URL.
|
|
22
|
+
*/
|
|
23
|
+
link?: ResultLink;
|
|
24
|
+
}
|
|
25
|
+
/** A link in an action's result. */
|
|
26
|
+
export interface ResultLink {
|
|
27
|
+
/** A path on this site, or a URL on its own origin. */
|
|
28
|
+
href: string;
|
|
29
|
+
/** The link's text. */
|
|
30
|
+
text: string;
|
|
10
31
|
}
|
|
11
32
|
/** Values run() refused, from invalid(). */
|
|
12
33
|
export interface Invalid {
|
|
34
|
+
/** Marks the object as a refusal from invalid(). */
|
|
13
35
|
readonly pexisInvalid: true;
|
|
36
|
+
/** One message per field name. */
|
|
14
37
|
readonly errors: Readonly<Record<string, string>>;
|
|
15
38
|
}
|
|
16
39
|
/**
|
|
@@ -19,10 +42,15 @@ export interface Invalid {
|
|
|
19
42
|
* these errors, and a person sees the form again with each message under its
|
|
20
43
|
* field. Keys are field names.
|
|
21
44
|
*
|
|
22
|
-
*
|
|
45
|
+
* @param errors One message per field name; at least one.
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* if (input.pickup < today()) return invalid({ pickup: 'Choose a date from tomorrow on.' });
|
|
49
|
+
* ```
|
|
23
50
|
*/
|
|
24
51
|
export declare function invalid(errors: Record<string, string>): Invalid;
|
|
25
52
|
export declare function isInvalid(value: unknown): value is Invalid;
|
|
53
|
+
/** What defineAction() takes: everything an action is, declared once. */
|
|
26
54
|
export interface ActionDefinition<F extends Fields> {
|
|
27
55
|
/** Tool name: lowercase letters, digits and underscores, starting with a letter. */
|
|
28
56
|
name: string;
|
|
@@ -30,7 +58,14 @@ export interface ActionDefinition<F extends Fields> {
|
|
|
30
58
|
title: string;
|
|
31
59
|
/** What the action does and what it returns, written for a model to read. */
|
|
32
60
|
description: string;
|
|
61
|
+
/**
|
|
62
|
+
* The fields the action takes, by name, made with `field.*` or a custom field
|
|
63
|
+
* kind. They become the form's controls, the tool's input schema and the
|
|
64
|
+
* typed input `run` receives. Use `{}` for an action that takes no input,
|
|
65
|
+
* shown as a single button.
|
|
66
|
+
*/
|
|
33
67
|
input: F;
|
|
68
|
+
/** How much the action changes: `read`, `write` or `irreversible`. Sets the form's method and whether people and agents must confirm. */
|
|
34
69
|
risk: Risk;
|
|
35
70
|
/** Require the user's approval before an agent submits. Always true for irreversible actions. */
|
|
36
71
|
confirm?: boolean;
|
|
@@ -53,13 +88,29 @@ export interface ActionDefinition<F extends Fields> {
|
|
|
53
88
|
* (see @pexis/approvals). The undo is another registered action, run as the
|
|
54
89
|
* person. It must be idempotent, and should check the thing is still as this
|
|
55
90
|
* write left it. A write with outside effects (mail, payments) is
|
|
56
|
-
* irreversible, or its undo must compensate.
|
|
91
|
+
* irreversible, or its undo must compensate.
|
|
92
|
+
*
|
|
93
|
+
* @experimental
|
|
57
94
|
*/
|
|
58
95
|
undo?: UndoDefinition<F>;
|
|
96
|
+
/**
|
|
97
|
+
* Who may run the action, checked on the server before every call from a
|
|
98
|
+
* form, an agent or `ctx.call`. Return false to refuse with 403. An action
|
|
99
|
+
* needs this or `public: true`.
|
|
100
|
+
*/
|
|
59
101
|
permission?(ctx: ActionContext): boolean | Promise<boolean>;
|
|
102
|
+
/**
|
|
103
|
+
* Does the work, with input already validated against the fields. Returns a
|
|
104
|
+
* result with a message, or invalid() to refuse values with a message per
|
|
105
|
+
* field. Throwing answers 500 without showing the error.
|
|
106
|
+
*/
|
|
60
107
|
run(input: Infer<F>, ctx: ActionContext): ActionResult | Invalid | Promise<ActionResult | Invalid>;
|
|
61
108
|
}
|
|
62
|
-
/**
|
|
109
|
+
/**
|
|
110
|
+
* How a write is undone.
|
|
111
|
+
*
|
|
112
|
+
* @experimental
|
|
113
|
+
*/
|
|
63
114
|
export interface UndoDefinition<F extends Fields> {
|
|
64
115
|
/** The registered action that reverses this one, such as cancel_booking. */
|
|
65
116
|
action: Action<any>;
|
|
@@ -72,28 +123,100 @@ export interface UndoDefinition<F extends Fields> {
|
|
|
72
123
|
/** How long the person can undo it, in hours. Default 24, at most 168. */
|
|
73
124
|
hours?: number;
|
|
74
125
|
}
|
|
126
|
+
/** An action, as defineAction() returns it: the definition with its defaults filled in. */
|
|
75
127
|
export interface Action<F extends Fields = Fields> extends ActionDefinition<F> {
|
|
128
|
+
/** Whether an agent needs the person's approval first: as declared, and always true for irreversible actions. */
|
|
76
129
|
confirm: boolean;
|
|
130
|
+
/** The form's method: GET for `read` actions, POST otherwise. */
|
|
77
131
|
method: 'GET' | 'POST';
|
|
78
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* An action as the tool description agents read, in `/pexis/actions.json`,
|
|
135
|
+
* MCP and the page's own forms.
|
|
136
|
+
*
|
|
137
|
+
* @category plugins
|
|
138
|
+
*/
|
|
79
139
|
export interface ToolDescriptor {
|
|
140
|
+
/** The action's name. */
|
|
80
141
|
name: string;
|
|
142
|
+
/** The action's title. */
|
|
81
143
|
title: string;
|
|
144
|
+
/** What the action does, for a model to read. */
|
|
82
145
|
description: string;
|
|
146
|
+
/** How much the action changes. */
|
|
83
147
|
risk: Risk;
|
|
148
|
+
/** Whether the agent must get the person's approval first. */
|
|
84
149
|
confirm: boolean;
|
|
150
|
+
/** The input as JSON Schema (draft 2020-12). */
|
|
85
151
|
inputSchema: ObjectSchema;
|
|
86
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* Declares an action once: its name, input fields, risk, who may run it, and
|
|
155
|
+
* what it does. The same definition becomes the form people fill in, the tool
|
|
156
|
+
* agents call (in `/pexis/actions.json`, MCP and the page), the JSON endpoint
|
|
157
|
+
* `POST /actions/<name>` and an OpenAPI operation. The server validates every
|
|
158
|
+
* call against the fields and checks the permission before `run`.
|
|
159
|
+
*
|
|
160
|
+
* Throws when the definition is invalid: a bad name, an empty title or
|
|
161
|
+
* description, `public` together with `permission`, a field that asks for a
|
|
162
|
+
* password or a file, or a broken undo.
|
|
163
|
+
*
|
|
164
|
+
* @param def The action: name, title, description, input, risk, and run.
|
|
165
|
+
* @returns The action, with `confirm` and `method` filled in.
|
|
166
|
+
* @example
|
|
167
|
+
* A booking form
|
|
168
|
+
* ```ts
|
|
169
|
+
* export default defineAction({
|
|
170
|
+
* name: 'book_table',
|
|
171
|
+
* title: 'Book a table',
|
|
172
|
+
* description: 'Reserves a table. Returns a booking reference.',
|
|
173
|
+
* risk: 'write',
|
|
174
|
+
* public: true,
|
|
175
|
+
* input: {
|
|
176
|
+
* name: field.text({ label: 'Name', max: 80 }),
|
|
177
|
+
* guests: field.integer({ label: 'Guests', min: 1, max: 12 }),
|
|
178
|
+
* },
|
|
179
|
+
* run: async (input, ctx) => ({ message: `Booked for ${input.guests}, ${input.name}.` }),
|
|
180
|
+
* });
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
87
183
|
export declare function defineAction<F extends Fields>(def: ActionDefinition<F>): Action<F>;
|
|
88
184
|
/**
|
|
89
185
|
* Checks an action file found in actions/: it must default-export one action,
|
|
90
186
|
* named like the file. Used by the generated pexis.gen.ts.
|
|
187
|
+
*
|
|
188
|
+
* @category plugins
|
|
189
|
+
* @param file The file's path, for error messages.
|
|
190
|
+
* @param name The action name the file's name implies.
|
|
191
|
+
* @param value The file's default export.
|
|
192
|
+
* @returns The action, when it is one and its name matches.
|
|
91
193
|
*/
|
|
92
194
|
export declare function actionFile(file: string, name: string, value: unknown): Action;
|
|
195
|
+
/**
|
|
196
|
+
* An action as the tool description agents read, with its input as JSON Schema.
|
|
197
|
+
*
|
|
198
|
+
* @category plugins
|
|
199
|
+
* @param action A defined action.
|
|
200
|
+
*/
|
|
93
201
|
export declare function describeAction(action: Action): ToolDescriptor;
|
|
202
|
+
/**
|
|
203
|
+
* The registry of actions behind createApp: one place every action is
|
|
204
|
+
* declared, looked up and described.
|
|
205
|
+
*
|
|
206
|
+
* @category plugins
|
|
207
|
+
*/
|
|
94
208
|
export interface Registry {
|
|
209
|
+
/** The action with this name, or undefined. */
|
|
95
210
|
get(name: string): Action | undefined;
|
|
211
|
+
/** Every action, in the order given. */
|
|
96
212
|
list(): readonly Action[];
|
|
213
|
+
/** The tool descriptions of the actions offered to agents (not `agents: false` ones). */
|
|
97
214
|
describe(): ToolDescriptor[];
|
|
98
215
|
}
|
|
216
|
+
/**
|
|
217
|
+
* Builds a registry from actions. Throws when two share a name.
|
|
218
|
+
*
|
|
219
|
+
* @category plugins
|
|
220
|
+
* @param actions The app's actions.
|
|
221
|
+
*/
|
|
99
222
|
export declare function createRegistry(actions: readonly Action[]): Registry;
|
package/dist/registry.js
CHANGED
|
@@ -6,7 +6,11 @@ import { toJsonSchema } from './schema.js';
|
|
|
6
6
|
* these errors, and a person sees the form again with each message under its
|
|
7
7
|
* field. Keys are field names.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
9
|
+
* @param errors One message per field name; at least one.
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* if (input.pickup < today()) return invalid({ pickup: 'Choose a date from tomorrow on.' });
|
|
13
|
+
* ```
|
|
10
14
|
*/
|
|
11
15
|
export function invalid(errors) {
|
|
12
16
|
if (Object.keys(errors).length === 0)
|
|
@@ -41,6 +45,36 @@ function forbiddenInput(f, name) {
|
|
|
41
45
|
return null;
|
|
42
46
|
}
|
|
43
47
|
const RISKS = ['read', 'write', 'irreversible'];
|
|
48
|
+
/**
|
|
49
|
+
* Declares an action once: its name, input fields, risk, who may run it, and
|
|
50
|
+
* what it does. The same definition becomes the form people fill in, the tool
|
|
51
|
+
* agents call (in `/pexis/actions.json`, MCP and the page), the JSON endpoint
|
|
52
|
+
* `POST /actions/<name>` and an OpenAPI operation. The server validates every
|
|
53
|
+
* call against the fields and checks the permission before `run`.
|
|
54
|
+
*
|
|
55
|
+
* Throws when the definition is invalid: a bad name, an empty title or
|
|
56
|
+
* description, `public` together with `permission`, a field that asks for a
|
|
57
|
+
* password or a file, or a broken undo.
|
|
58
|
+
*
|
|
59
|
+
* @param def The action: name, title, description, input, risk, and run.
|
|
60
|
+
* @returns The action, with `confirm` and `method` filled in.
|
|
61
|
+
* @example
|
|
62
|
+
* A booking form
|
|
63
|
+
* ```ts
|
|
64
|
+
* export default defineAction({
|
|
65
|
+
* name: 'book_table',
|
|
66
|
+
* title: 'Book a table',
|
|
67
|
+
* description: 'Reserves a table. Returns a booking reference.',
|
|
68
|
+
* risk: 'write',
|
|
69
|
+
* public: true,
|
|
70
|
+
* input: {
|
|
71
|
+
* name: field.text({ label: 'Name', max: 80 }),
|
|
72
|
+
* guests: field.integer({ label: 'Guests', min: 1, max: 12 }),
|
|
73
|
+
* },
|
|
74
|
+
* run: async (input, ctx) => ({ message: `Booked for ${input.guests}, ${input.name}.` }),
|
|
75
|
+
* });
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
44
78
|
export function defineAction(def) {
|
|
45
79
|
if (!NAME.test(def.name)) {
|
|
46
80
|
throw new Error(`Action name "${def.name}" must start with a lowercase letter and use only lowercase letters, digits and underscores (64 characters at most).`);
|
|
@@ -106,6 +140,12 @@ export function defineAction(def) {
|
|
|
106
140
|
/**
|
|
107
141
|
* Checks an action file found in actions/: it must default-export one action,
|
|
108
142
|
* named like the file. Used by the generated pexis.gen.ts.
|
|
143
|
+
*
|
|
144
|
+
* @category plugins
|
|
145
|
+
* @param file The file's path, for error messages.
|
|
146
|
+
* @param name The action name the file's name implies.
|
|
147
|
+
* @param value The file's default export.
|
|
148
|
+
* @returns The action, when it is one and its name matches.
|
|
109
149
|
*/
|
|
110
150
|
export function actionFile(file, name, value) {
|
|
111
151
|
const action = value;
|
|
@@ -117,6 +157,12 @@ export function actionFile(file, name, value) {
|
|
|
117
157
|
}
|
|
118
158
|
return action;
|
|
119
159
|
}
|
|
160
|
+
/**
|
|
161
|
+
* An action as the tool description agents read, with its input as JSON Schema.
|
|
162
|
+
*
|
|
163
|
+
* @category plugins
|
|
164
|
+
* @param action A defined action.
|
|
165
|
+
*/
|
|
120
166
|
export function describeAction(action) {
|
|
121
167
|
return {
|
|
122
168
|
name: action.name,
|
|
@@ -127,6 +173,12 @@ export function describeAction(action) {
|
|
|
127
173
|
inputSchema: toJsonSchema(action.input),
|
|
128
174
|
};
|
|
129
175
|
}
|
|
176
|
+
/**
|
|
177
|
+
* Builds a registry from actions. Throws when two share a name.
|
|
178
|
+
*
|
|
179
|
+
* @category plugins
|
|
180
|
+
* @param actions The app's actions.
|
|
181
|
+
*/
|
|
130
182
|
export function createRegistry(actions) {
|
|
131
183
|
const byName = new Map();
|
|
132
184
|
for (const action of actions) {
|
package/dist/registry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAChC,OAAO,EAAE,YAAY,EAA0D,MAAM,aAAa,CAAC;
|
|
1
|
+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|
+
/** The control's label, shown to people and used as the input's title for agents. */
|
|
3
5
|
label: string;
|
|
6
|
+
/** Hint text shown under the label, and the input's description for agents. */
|
|
4
7
|
description?: string;
|
|
8
|
+
/** The field may be left empty. Fields are required unless this is true. */
|
|
5
9
|
optional?: boolean;
|
|
6
10
|
}
|
|
11
|
+
/** A text input, or a textarea with `multiline`. The value is a string. */
|
|
7
12
|
export interface TextField extends FieldBase {
|
|
13
|
+
/** Set by field.text(). */
|
|
8
14
|
kind: 'text';
|
|
15
|
+
/** The fewest characters (minlength). Counted as people count them, so an emoji is one. */
|
|
9
16
|
min?: number;
|
|
17
|
+
/** The most characters (maxlength). */
|
|
10
18
|
max?: number;
|
|
19
|
+
/** An email address, a full http(s) web address, or a telephone number. Sets the input's type. A URL must start with http:// or https://. */
|
|
11
20
|
format?: 'email' | 'url' | 'tel';
|
|
12
21
|
/** HTML pattern semantics: must match the whole value. */
|
|
13
22
|
pattern?: string;
|
|
23
|
+
/** A textarea instead of a one-line input. */
|
|
14
24
|
multiline?: boolean;
|
|
15
25
|
/** Passed to the HTML autocomplete attribute. Not part of the schema. */
|
|
16
26
|
autocomplete?: string;
|
|
17
27
|
}
|
|
28
|
+
/** A whole number, as a number input. The value is a number. */
|
|
18
29
|
export interface IntegerField extends FieldBase {
|
|
30
|
+
/** Set by field.integer(). */
|
|
19
31
|
kind: 'integer';
|
|
32
|
+
/** The smallest value allowed. */
|
|
20
33
|
min?: number;
|
|
34
|
+
/** The largest value allowed. */
|
|
21
35
|
max?: number;
|
|
22
36
|
}
|
|
37
|
+
/** Any number, decimals included, as a number input. The value is a number. */
|
|
23
38
|
export interface NumberField extends FieldBase {
|
|
39
|
+
/** Set by field.number(). */
|
|
24
40
|
kind: 'number';
|
|
41
|
+
/** The smallest value allowed. */
|
|
25
42
|
min?: number;
|
|
43
|
+
/** The largest value allowed. */
|
|
26
44
|
max?: number;
|
|
27
45
|
}
|
|
46
|
+
/** A date input. The value is an ISO date string, YYYY-MM-DD. */
|
|
28
47
|
export interface DateField extends FieldBase {
|
|
48
|
+
/** Set by field.date(). */
|
|
29
49
|
kind: 'date';
|
|
30
50
|
/** ISO date, YYYY-MM-DD. */
|
|
31
51
|
min?: string;
|
|
52
|
+
/** The latest date allowed, YYYY-MM-DD. */
|
|
32
53
|
max?: string;
|
|
33
54
|
}
|
|
55
|
+
/** One option of a choice or choices field. */
|
|
34
56
|
export interface ChoiceOption<V extends string = string> {
|
|
57
|
+
/** What is sent and what agents choose: the value `run` receives. */
|
|
35
58
|
value: V;
|
|
59
|
+
/** What people see. */
|
|
36
60
|
label: string;
|
|
37
61
|
}
|
|
62
|
+
/** One of a list of options, as a select. The value is the chosen option's value. */
|
|
38
63
|
export interface ChoiceField<V extends string = string> extends FieldBase {
|
|
64
|
+
/** Set by field.choice(). */
|
|
39
65
|
kind: 'choice';
|
|
66
|
+
/** The options, in order. */
|
|
40
67
|
options: readonly ChoiceOption<V>[];
|
|
41
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Any number of options, as a group of checkboxes sharing one name. Like a
|
|
71
|
+
* single checkbox, none checked is a valid answer (an empty list), because
|
|
72
|
+
* HTML cannot require "at least one" of a group without a script.
|
|
73
|
+
*/
|
|
74
|
+
export interface ChoicesField<V extends string = string> extends Omit<FieldBase, 'optional'> {
|
|
75
|
+
/** Set by field.choices(). */
|
|
76
|
+
kind: 'choices';
|
|
77
|
+
/** The options, in order; at least two. */
|
|
78
|
+
options: readonly ChoiceOption<V>[];
|
|
79
|
+
}
|
|
80
|
+
/** A checkbox. The value is true when checked and false otherwise, so it is never required. */
|
|
42
81
|
export interface BooleanField extends Omit<FieldBase, 'optional'> {
|
|
82
|
+
/** Set by field.boolean(). */
|
|
43
83
|
kind: 'boolean';
|
|
44
84
|
}
|
|
45
85
|
/** What a custom field kind gets to render its control. */
|
|
46
86
|
export interface ControlProps {
|
|
87
|
+
/** The control's id, which the label points at. */
|
|
47
88
|
id: string;
|
|
89
|
+
/** The control's name: the field's name, sent with the form. */
|
|
48
90
|
name: string;
|
|
49
91
|
/** The value to show (after a failed submission, for example). */
|
|
50
92
|
value: unknown;
|
|
93
|
+
/** Whether the field is required. */
|
|
51
94
|
required: boolean;
|
|
95
|
+
/** Whether the last submission had an error for this field. */
|
|
52
96
|
invalid: boolean;
|
|
53
97
|
/**
|
|
54
98
|
* id, name, px-description, aria-describedby, aria-invalid and required,
|
|
@@ -70,6 +114,7 @@ export interface FieldKind<O extends FieldBase = FieldBase, V = unknown> {
|
|
|
70
114
|
name: string;
|
|
71
115
|
/** JSON Schema for the value, without title and description (added for you). */
|
|
72
116
|
schema(field: O): JsonSchemaProperty;
|
|
117
|
+
/** Renders the control: a standard input, select or textarea carrying `props.attributes`. */
|
|
73
118
|
control(field: O, props: ControlProps): SafeHtml;
|
|
74
119
|
/** Turns raw input into a value. Only called with a non-empty value. */
|
|
75
120
|
parse(raw: unknown, field: O): {
|
|
@@ -86,15 +131,34 @@ export interface FieldKind<O extends FieldBase = FieldBase, V = unknown> {
|
|
|
86
131
|
*/
|
|
87
132
|
group?: boolean;
|
|
88
133
|
}
|
|
134
|
+
/** A field of a kind made with defineFieldKind(). */
|
|
89
135
|
export interface CustomField<O extends FieldBase = FieldBase, V = unknown> extends FieldBase {
|
|
136
|
+
/** Set by the function defineFieldKind() returns. */
|
|
90
137
|
kind: 'custom';
|
|
138
|
+
/** The kind: how it renders, its schema and how it parses. */
|
|
91
139
|
fieldKind: FieldKind<O, V>;
|
|
92
140
|
}
|
|
93
|
-
|
|
94
|
-
|
|
141
|
+
/** Any field: one of the built-in kinds, or a custom one. */
|
|
142
|
+
export type Field = TextField | IntegerField | NumberField | DateField | ChoiceField | ChoicesField | BooleanField | CustomField<any, any>;
|
|
143
|
+
/**
|
|
144
|
+
* Defines a new field kind. Returns a function to use it in action inputs,
|
|
145
|
+
* like the built-in `field.*` ones.
|
|
146
|
+
*
|
|
147
|
+
* @param kind Its name, schema, control and parser.
|
|
148
|
+
* @example
|
|
149
|
+
* ```ts
|
|
150
|
+
* const postcode = defineFieldKind<FieldBase, string>({
|
|
151
|
+
* name: 'postcode',
|
|
152
|
+
* schema: () => ({ type: 'string', pattern: '^(?:[0-9]{5})$' }),
|
|
153
|
+
* control: (f, p) => html`<input type="text" inputmode="numeric" pattern="[0-9]{5}"${p.attributes} value="${String(p.value ?? '')}">`,
|
|
154
|
+
* parse: (raw) => (typeof raw === 'string' && /^[0-9]{5}$/.test(raw) ? { value: raw } : { error: 'Enter five digits.' }),
|
|
155
|
+
* });
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
95
158
|
export declare function defineFieldKind<O extends FieldBase, V>(kind: FieldKind<O, V>): <const P extends O>(options: P) => P & CustomField<O, V>;
|
|
159
|
+
/** An action's input: fields by name. */
|
|
96
160
|
export type Fields = Record<string, Field>;
|
|
97
|
-
type ValueOf<F> = F extends CustomField<any, infer V> ? V : F extends TextField | DateField ? string : F extends IntegerField | NumberField ? number : F extends BooleanField ? boolean : F extends ChoiceField<infer V> ? V : never;
|
|
161
|
+
type ValueOf<F> = F extends CustomField<any, infer V> ? V : F extends TextField | DateField ? string : F extends IntegerField | NumberField ? number : F extends BooleanField ? boolean : F extends ChoiceField<infer V> ? V : F extends ChoicesField<infer V> ? V[] : never;
|
|
98
162
|
type OptionalKeys<F extends Fields> = {
|
|
99
163
|
[K in keyof F]: F[K] extends {
|
|
100
164
|
optional: true;
|
|
@@ -110,39 +174,92 @@ export type Infer<F extends Fields> = Simplify<{
|
|
|
110
174
|
[K in OptionalKeys<F>]?: ValueOf<F[K]>;
|
|
111
175
|
}>;
|
|
112
176
|
type Without<T, K extends PropertyKey> = Omit<T, K>;
|
|
177
|
+
/**
|
|
178
|
+
* The built-in field kinds, for an action's `input`. Each maps to one standard
|
|
179
|
+
* HTML control and one JSON Schema type, so people and agents see the same
|
|
180
|
+
* input with the same constraints.
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* ```ts
|
|
184
|
+
* input: {
|
|
185
|
+
* name: field.text({ label: 'Name', max: 80 }),
|
|
186
|
+
* email: field.text({ label: 'Email', format: 'email' }),
|
|
187
|
+
* guests: field.integer({ label: 'Guests', min: 1, max: 12 }),
|
|
188
|
+
* date: field.date({ label: 'Date', min: '2026-12-01' }),
|
|
189
|
+
* seating: field.choice({ label: 'Seating', options: [{ value: 'inside', label: 'Inside' }, { value: 'terrace', label: 'Terrace' }] }),
|
|
190
|
+
* notes: field.text({ label: 'Notes', multiline: true, optional: true }),
|
|
191
|
+
* newsletter: field.boolean({ label: 'Send me news' }),
|
|
192
|
+
* }
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
113
195
|
export declare const field: {
|
|
196
|
+
/** Text: a one-line input, or a textarea with `multiline`. Formats: email, url, tel. */
|
|
114
197
|
text<const O extends Without<TextField, 'kind'>>(options: O): O & {
|
|
115
198
|
kind: 'text';
|
|
116
199
|
};
|
|
200
|
+
/** A whole number. */
|
|
117
201
|
integer<const O extends Without<IntegerField, 'kind'>>(options: O): O & {
|
|
118
202
|
kind: 'integer';
|
|
119
203
|
};
|
|
204
|
+
/** Any number, decimals included. */
|
|
120
205
|
number<const O extends Without<NumberField, 'kind'>>(options: O): O & {
|
|
121
206
|
kind: 'number';
|
|
122
207
|
};
|
|
208
|
+
/** A date, YYYY-MM-DD. */
|
|
123
209
|
date<const O extends Without<DateField, 'kind'>>(options: O): O & {
|
|
124
210
|
kind: 'date';
|
|
125
211
|
};
|
|
212
|
+
/** One of the options, as a select. Agents send the option's value. */
|
|
126
213
|
choice<const V extends string, const O extends Without<ChoiceField<V>, 'kind'>>(options: O & {
|
|
127
214
|
options: readonly ChoiceOption<V>[];
|
|
128
215
|
}): O & {
|
|
129
216
|
kind: 'choice';
|
|
130
217
|
options: readonly ChoiceOption<V>[];
|
|
131
218
|
};
|
|
219
|
+
/** Any number of the options, as checkboxes. The value is a list, empty when none is checked. */
|
|
220
|
+
choices<const V extends string, const O extends Without<ChoicesField<V>, 'kind'>>(options: O & {
|
|
221
|
+
options: readonly ChoiceOption<V>[];
|
|
222
|
+
}): O & {
|
|
223
|
+
kind: 'choices';
|
|
224
|
+
options: readonly ChoiceOption<V>[];
|
|
225
|
+
};
|
|
226
|
+
/** A checkbox: true or false. */
|
|
132
227
|
boolean<const O extends Without<BooleanField, 'kind'>>(options: O): O & {
|
|
133
228
|
kind: 'boolean';
|
|
134
229
|
};
|
|
135
230
|
};
|
|
136
231
|
export declare function isRequired(f: Field): boolean;
|
|
137
232
|
export type JsonSchemaProperty = Record<string, unknown>;
|
|
233
|
+
/**
|
|
234
|
+
* An action's input as a JSON Schema object, as agents and OpenAPI see it.
|
|
235
|
+
*
|
|
236
|
+
* @category plugins
|
|
237
|
+
*/
|
|
138
238
|
export interface ObjectSchema {
|
|
239
|
+
/** Always "object". */
|
|
139
240
|
type: 'object';
|
|
241
|
+
/** One JSON Schema per field, by name, in order. */
|
|
140
242
|
properties: Record<string, JsonSchemaProperty>;
|
|
243
|
+
/** The names of required fields. */
|
|
141
244
|
required: string[];
|
|
245
|
+
/** Always false: no other properties are accepted. */
|
|
142
246
|
additionalProperties: false;
|
|
143
247
|
}
|
|
248
|
+
/**
|
|
249
|
+
* One field as JSON Schema, with its label as `title` and its hint as `description`.
|
|
250
|
+
*
|
|
251
|
+
* @category plugins
|
|
252
|
+
* @param f The field.
|
|
253
|
+
*/
|
|
144
254
|
export declare function fieldSchema(f: Field): JsonSchemaProperty;
|
|
255
|
+
/**
|
|
256
|
+
* An action's fields as a JSON Schema object: what agents and OpenAPI see as its input.
|
|
257
|
+
*
|
|
258
|
+
* @category plugins
|
|
259
|
+
* @param fields The action's input fields.
|
|
260
|
+
*/
|
|
145
261
|
export declare function toJsonSchema(fields: Fields): ObjectSchema;
|
|
262
|
+
/** What validate() returns: the typed value, or an error message per field name. */
|
|
146
263
|
export type ValidationResult<T> = {
|
|
147
264
|
ok: true;
|
|
148
265
|
value: T;
|
|
@@ -150,5 +267,14 @@ export type ValidationResult<T> = {
|
|
|
150
267
|
ok: false;
|
|
151
268
|
errors: Record<string, string>;
|
|
152
269
|
};
|
|
270
|
+
/**
|
|
271
|
+
* Validates and coerces raw input (from a form submission or JSON) against the
|
|
272
|
+
* fields, as the server does on every call. Unknown keys are dropped, so
|
|
273
|
+
* hidden inputs such as CSRF tokens do not leak into the action's input.
|
|
274
|
+
*
|
|
275
|
+
* @param fields The fields to check against.
|
|
276
|
+
* @param input Raw values: strings from a form, or JSON values.
|
|
277
|
+
* @returns The typed values, or an error message per field.
|
|
278
|
+
*/
|
|
153
279
|
export declare function validate<F extends Fields>(fields: F, input: Record<string, unknown>): ValidationResult<Infer<F>>;
|
|
154
280
|
export {};
|