@punica/form-mcp 0.6.2 → 0.8.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/bundled/form/package.json +1 -1
- package/bundled/form-kit/package.json +1 -1
- package/bundled/form-kit/react/index.d.ts +13 -0
- package/bundled/form-kit/types.d.ts +8 -1
- package/bundled/form-service/package.json +1 -1
- package/bundled/form-service/submit/index.d.ts +3 -0
- package/package.json +4 -4
- package/src/guide.md +3 -1
- package/src/knowledge.mjs +103 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"2.3.
|
|
1
|
+
{"version":"2.3.1"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"0.
|
|
1
|
+
{"version":"0.7.1"}
|
|
@@ -28,6 +28,19 @@ export type FormViewProps<E extends object> = ViewProps<E> & {
|
|
|
28
28
|
};
|
|
29
29
|
/**
|
|
30
30
|
* Renders the form of a started controller with `@punica/components`.
|
|
31
|
+
*
|
|
32
|
+
* What it draws, in order, in a `<form noValidate>`:
|
|
33
|
+
* - the `title` and `description` of the form, when it has them;
|
|
34
|
+
* - the errors of the form (`state.errors`: what `onSubmit` threw, such as
|
|
35
|
+
* the messages about no item that `SetErrors` returned) in one
|
|
36
|
+
* `<p role="alert">`; a new submit clears them;
|
|
37
|
+
* - a field per item, each showing its own messages under it (`punica-field`),
|
|
38
|
+
* rows of a list with their add and remove buttons;
|
|
39
|
+
* - a `type="submit"` `punica-button` with `submitLabel`, in its `loading`
|
|
40
|
+
* state while the submit runs, and a reset button when `resetLabel` is set.
|
|
41
|
+
*
|
|
42
|
+
* A submit validates every item first: an invalid form shows its messages
|
|
43
|
+
* and `onSubmit` is not called.
|
|
31
44
|
*/
|
|
32
45
|
export declare function FormView<E extends object>({ controller, onSubmit, onError, submitLabel, resetLabel, components }: FormViewProps<E>): ReactNode;
|
|
33
46
|
export type KitFormProps<E extends object> = ViewProps<E> & {
|
|
@@ -44,7 +44,10 @@ export type KitItem<E> = FormItem<E> & Rules & {
|
|
|
44
44
|
help?: string;
|
|
45
45
|
/** Shown while the field is empty. */
|
|
46
46
|
placeholder?: string;
|
|
47
|
-
/**
|
|
47
|
+
/**
|
|
48
|
+
* The type of a text field, `text` by default. `email` and `url` are
|
|
49
|
+
* checked as the browser checks them, unless the field has a `pattern`.
|
|
50
|
+
*/
|
|
48
51
|
inputType?: 'text' | 'email' | 'password' | 'tel' | 'url' | 'date';
|
|
49
52
|
/**
|
|
50
53
|
* What the browser may fill a text or password field in with, as the
|
|
@@ -91,6 +94,10 @@ export type Messages = {
|
|
|
91
94
|
maxFileSize: (label: string, bytes: number) => string;
|
|
92
95
|
date: (label: string) => string;
|
|
93
96
|
accept: (label: string) => string;
|
|
97
|
+
/** A text field with `inputType: 'email'` and no `pattern` (since 0.7). */
|
|
98
|
+
email: (label: string) => string;
|
|
99
|
+
/** A text field with `inputType: 'url'` and no `pattern` (since 0.7). */
|
|
100
|
+
url: (label: string) => string;
|
|
94
101
|
};
|
|
95
102
|
/** A validation of an item. */
|
|
96
103
|
export type Validation = NonNullable<FieldProps['validation']>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"2.3.
|
|
1
|
+
{"version":"2.3.1"}
|
|
@@ -11,6 +11,9 @@ export declare class Submit<E, F extends FormItem<E> = FormItem<E>> implements I
|
|
|
11
11
|
* its values and fires SUBMIT. While it runs the state of the form is
|
|
12
12
|
* `submitting`; a submit that is started meanwhile is ignored.
|
|
13
13
|
*
|
|
14
|
+
* It starts by clearing the errors of the form (`state.errors`), so the
|
|
15
|
+
* message of an earlier submit goes away by itself.
|
|
16
|
+
*
|
|
14
17
|
* What the handler or a validation throws does not reject: the message of
|
|
15
18
|
* the error, or a general one when it has none, becomes an error of the
|
|
16
19
|
* form (`state.errors`) and SUBMIT_ERROR is fired.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@punica/form-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "MCP server for Punica Form: look up the exact API of its packages, read the rules and check code that uses them.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mcp",
|
|
@@ -40,10 +40,10 @@
|
|
|
40
40
|
"zod": "^4.6.7"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@punica/form": "^2.3.
|
|
44
|
-
"@punica/form-service": "^2.3.
|
|
43
|
+
"@punica/form": "^2.3.1",
|
|
44
|
+
"@punica/form-service": "^2.3.1",
|
|
45
45
|
"@punica/form-react": "^0.2.0",
|
|
46
|
-
"@punica/form-kit": "^0.
|
|
46
|
+
"@punica/form-kit": "^0.7.1",
|
|
47
47
|
"@punica/form-schema": "^0.1.0"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
package/src/guide.md
CHANGED
|
@@ -62,7 +62,9 @@ is `yyyy-mm-dd`), `PasswordField`, `FileField` and `ArrayField` (a list of
|
|
|
62
62
|
rows: `@ArrayField({ label, row: () => new LineForm() })`, the kit renders a
|
|
63
63
|
form for every row) with the rules `required`, `minLength`, `maxLength`,
|
|
64
64
|
`pattern`, `min`, `max`, `minDate`, `maxDate`, `minItems`, `maxItems` and
|
|
65
|
-
`maxFileSize`; `
|
|
65
|
+
`maxFileSize`; `inputType: 'email'` or `'url'` on a `TextField` checks the
|
|
66
|
+
address too (since form-kit 0.7; a `pattern` of the field decides instead);
|
|
67
|
+
`options` may be a function that loads the choices. And from `@punica/form-kit/react` the component
|
|
66
68
|
`<KitForm entity={() => new UserForm()} onSubmit={…} />`, which renders the
|
|
67
69
|
form with `@punica/components`, shows what `onSubmit` throws above the
|
|
68
70
|
fields and reports it to `onError`. Use it when the project has it installed;
|
package/src/knowledge.mjs
CHANGED
|
@@ -16,7 +16,9 @@ function resolve(files, from, specifier) {
|
|
|
16
16
|
|
|
17
17
|
/** The JSDoc comment that ends right before `index`, if there is one. */
|
|
18
18
|
function commentBefore(source, index) {
|
|
19
|
-
const match = /\/\*\*(?:(?!\*\/)[\s\S])*\*\/\s*$/.exec(
|
|
19
|
+
const match = /\/\*\*(?:(?!\*\/)[\s\S])*\*\/\s*$/.exec(
|
|
20
|
+
source.slice(0, index)
|
|
21
|
+
);
|
|
20
22
|
|
|
21
23
|
return match ? match[0].trimEnd() : '';
|
|
22
24
|
}
|
|
@@ -28,6 +30,25 @@ function declarationAt(source, index) {
|
|
|
28
30
|
for (let i = index; i < source.length; i++) {
|
|
29
31
|
const char = source[i];
|
|
30
32
|
|
|
33
|
+
// Comments and texts hold brackets and semicolons of their own
|
|
34
|
+
if (source.startsWith('/*', i)) {
|
|
35
|
+
i = source.indexOf('*/', i + 2) + 1 || source.length;
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (source.startsWith('//', i)) {
|
|
40
|
+
i = source.indexOf('\n', i);
|
|
41
|
+
if (i === -1) break;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (char === "'" || char === '"' || char === '`') {
|
|
46
|
+
for (i++; i < source.length && source[i] !== char; i++) {
|
|
47
|
+
if (source[i] === '\\') i++;
|
|
48
|
+
}
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
|
|
31
52
|
if ('({['.includes(char)) depth++;
|
|
32
53
|
if (')}]'.includes(char)) depth--;
|
|
33
54
|
if (depth === 0 && (char === ';' || char === '}')) {
|
|
@@ -38,8 +59,38 @@ function declarationAt(source, index) {
|
|
|
38
59
|
return source.slice(index);
|
|
39
60
|
}
|
|
40
61
|
|
|
62
|
+
/**
|
|
63
|
+
* The declarations of a module that are not exported but that `text` names,
|
|
64
|
+
* such as the interface a configuration type is made of: without them the
|
|
65
|
+
* options of a middleware could not be looked up.
|
|
66
|
+
*/
|
|
67
|
+
function localsOf(source, text, seen = new Set()) {
|
|
68
|
+
const found = [];
|
|
69
|
+
|
|
70
|
+
for (const match of source.matchAll(
|
|
71
|
+
/^(?:declare )?(?:interface|type) (\w+)/gm
|
|
72
|
+
)) {
|
|
73
|
+
const name = match[1];
|
|
74
|
+
|
|
75
|
+
if (seen.has(name) || !new RegExp(`\\b${name}\\b`).test(text)) continue;
|
|
76
|
+
seen.add(name);
|
|
77
|
+
|
|
78
|
+
const declaration = [
|
|
79
|
+
commentBefore(source, match.index),
|
|
80
|
+
declarationAt(source, match.index)
|
|
81
|
+
]
|
|
82
|
+
.filter(Boolean)
|
|
83
|
+
.join('\n');
|
|
84
|
+
|
|
85
|
+
found.push(declaration, ...localsOf(source, declaration, seen));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return found;
|
|
89
|
+
}
|
|
90
|
+
|
|
41
91
|
function entry(source, index, kind, name) {
|
|
42
92
|
const comment = commentBefore(source, index);
|
|
93
|
+
const declaration = declarationAt(source, index);
|
|
43
94
|
// The first paragraph of the comment, without its stars, up to the end of
|
|
44
95
|
// its first sentence
|
|
45
96
|
const lines = comment
|
|
@@ -51,18 +102,28 @@ function entry(source, index, kind, name) {
|
|
|
51
102
|
const paragraph = [];
|
|
52
103
|
|
|
53
104
|
for (let i = start; i >= 0 && i < lines.length; i++) {
|
|
54
|
-
if (!lines[i] || lines[i].startsWith('@') || lines[i].startsWith('```'))
|
|
105
|
+
if (!lines[i] || lines[i].startsWith('@') || lines[i].startsWith('```'))
|
|
106
|
+
break;
|
|
55
107
|
paragraph.push(lines[i]);
|
|
56
108
|
}
|
|
57
109
|
|
|
58
110
|
const text = paragraph.join(' ');
|
|
59
|
-
const summary = (/^.*?[.:](?=\s|$)/.exec(text)?.[0] ?? text).replace(
|
|
111
|
+
const summary = (/^.*?[.:](?=\s|$)/.exec(text)?.[0] ?? text).replace(
|
|
112
|
+
/:$/,
|
|
113
|
+
'.'
|
|
114
|
+
);
|
|
60
115
|
|
|
61
116
|
return {
|
|
62
117
|
name,
|
|
63
118
|
kind,
|
|
64
119
|
summary: summary.trim(),
|
|
65
|
-
declaration: [
|
|
120
|
+
declaration: [
|
|
121
|
+
comment,
|
|
122
|
+
declaration,
|
|
123
|
+
...localsOf(source, declaration, new Set([name]))
|
|
124
|
+
]
|
|
125
|
+
.filter(Boolean)
|
|
126
|
+
.join('\n')
|
|
66
127
|
};
|
|
67
128
|
}
|
|
68
129
|
|
|
@@ -79,14 +140,18 @@ function exportsOf(files, path, seen = new Set()) {
|
|
|
79
140
|
}
|
|
80
141
|
|
|
81
142
|
// export * from './x'; export type * from './x';
|
|
82
|
-
for (const match of source.matchAll(
|
|
143
|
+
for (const match of source.matchAll(
|
|
144
|
+
/^export (?:type )?\* from ['"](.+?)['"];/gm
|
|
145
|
+
)) {
|
|
83
146
|
const target = exportsOf(files, resolve(files, path, match[1]), seen);
|
|
84
147
|
|
|
85
148
|
for (const [name, value] of target) found.set(name, value);
|
|
86
149
|
}
|
|
87
150
|
|
|
88
151
|
// export { a, default as b } from './x'; export type { a } from './x';
|
|
89
|
-
for (const match of source.matchAll(
|
|
152
|
+
for (const match of source.matchAll(
|
|
153
|
+
/^export (?:type )?\{([^}]+)\} from ['"](.+?)['"];/gm
|
|
154
|
+
)) {
|
|
90
155
|
const targetPath = resolve(files, path, match[2]);
|
|
91
156
|
const target = exportsOf(files, targetPath, new Set(seen));
|
|
92
157
|
const targetSource = files.get(targetPath) || '';
|
|
@@ -103,7 +168,8 @@ function exportsOf(files, path, seen = new Set()) {
|
|
|
103
168
|
'm'
|
|
104
169
|
).exec(targetSource);
|
|
105
170
|
|
|
106
|
-
value =
|
|
171
|
+
value =
|
|
172
|
+
declared && entry(targetSource, declared.index, declared[1], alias);
|
|
107
173
|
}
|
|
108
174
|
|
|
109
175
|
if (value) found.set(alias, { ...value, name: alias });
|
|
@@ -143,9 +209,39 @@ export function createKnowledge(packages) {
|
|
|
143
209
|
});
|
|
144
210
|
}
|
|
145
211
|
|
|
212
|
+
/**
|
|
213
|
+
* A type the packages declare without exporting it, as the exports that
|
|
214
|
+
* are made of it bring it along: an import of it would fail, but what it
|
|
215
|
+
* holds is part of the API.
|
|
216
|
+
*/
|
|
217
|
+
function local(name) {
|
|
218
|
+
const pattern = new RegExp(
|
|
219
|
+
`^(?:declare )?(?:interface|type) ${name}\\b`,
|
|
220
|
+
'm'
|
|
221
|
+
);
|
|
222
|
+
const users = names.filter((other) =>
|
|
223
|
+
pattern.test(api.get(other).declaration)
|
|
224
|
+
);
|
|
225
|
+
|
|
226
|
+
if (!users.length) return undefined;
|
|
227
|
+
|
|
228
|
+
const source = api.get(users[0]).declaration;
|
|
229
|
+
const index = pattern.exec(source).index;
|
|
230
|
+
const declaration = [
|
|
231
|
+
commentBefore(source, index),
|
|
232
|
+
declarationAt(source, index)
|
|
233
|
+
]
|
|
234
|
+
.filter(Boolean)
|
|
235
|
+
.join('\n');
|
|
236
|
+
|
|
237
|
+
return `## ${name} (not exported, ${api.get(users[0]).package})\n\nIt cannot be imported; it is part of ${users.join(', ')}, which can.\n\n\`\`\`ts\n${declaration}\n\`\`\``;
|
|
238
|
+
}
|
|
239
|
+
|
|
146
240
|
function formatMarkdown(name) {
|
|
147
241
|
const item = get(name);
|
|
148
242
|
|
|
243
|
+
if (!item && /^\w+$/.test(name) && local(name)) return local(name);
|
|
244
|
+
|
|
149
245
|
if (!item) {
|
|
150
246
|
return `${name} is not exported by ${packages.map((p) => p.name).join(' or ')}. Exports: ${names.join(', ')}`;
|
|
151
247
|
}
|