@punica/form-mcp 0.7.0 → 0.9.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/decorators.d.ts +7 -0
- package/bundled/form-kit/package.json +1 -1
- package/bundled/form-kit/react/index.d.ts +13 -0
- package/bundled/form-service/fieldArray/index.d.ts +4 -0
- 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/knowledge.mjs +137 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"2.3.
|
|
1
|
+
{"version":"2.3.2"}
|
|
@@ -73,6 +73,13 @@ export declare const FileField: (props: FieldProps) => FormPropertyDecorator;
|
|
|
73
73
|
* @ArrayField({ label: 'Lines', row: () => new LineForm(), minItems: 1 })
|
|
74
74
|
* lines: LineForm[] = [];
|
|
75
75
|
*
|
|
76
|
+
* The rows start from the value of the property: a row for every element,
|
|
77
|
+
* whose values replace those of a new `row()`. `lines: LineForm[] =
|
|
78
|
+
* [new LineForm()]` starts with one row as the class has it; an element may
|
|
79
|
+
* name only what differs (`{ quantity: 1 } as LineForm`), the other fields
|
|
80
|
+
* then come from the class. `[]` starts with none: `minItems` only checks
|
|
81
|
+
* how many there are, it adds no rows.
|
|
82
|
+
*
|
|
76
83
|
* The row class needs no `@FormKit`; with it, `columns` lays out its fields.
|
|
77
84
|
*/
|
|
78
85
|
export declare const ArrayField: (props: FieldProps & {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"0.7.
|
|
1
|
+
{"version":"0.7.2"}
|
|
@@ -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> & {
|
|
@@ -15,6 +15,10 @@ export type RowOf<E, K extends keyof E> = NonNullable<E[K]> extends ReadonlyArra
|
|
|
15
15
|
* await lines.append('lines', { name: 'Paper' });
|
|
16
16
|
* lines.rows('lines')[0].controller.getService(SetValue).run('price', 5);
|
|
17
17
|
*
|
|
18
|
+
* The rows start from the value of the item: a row for every element, whose
|
|
19
|
+
* values replace those of a new `row()`, so an element names only what
|
|
20
|
+
* differs (`[{ quantity: 1 }]`); an empty or missing value starts with none.
|
|
21
|
+
*
|
|
18
22
|
* The value of the item is the array of the values of its rows. The item is
|
|
19
23
|
* dirty, touched and in error when a row is, and validating the form
|
|
20
24
|
* validates the rows. A row class without `@Services` gets the services of
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"2.3.
|
|
1
|
+
{"version":"2.3.2"}
|
|
@@ -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.9.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.2",
|
|
44
|
+
"@punica/form-service": "^2.3.2",
|
|
45
45
|
"@punica/form-react": "^0.2.0",
|
|
46
|
-
"@punica/form-kit": "^0.7.
|
|
46
|
+
"@punica/form-kit": "^0.7.2",
|
|
47
47
|
"@punica/form-schema": "^0.1.0"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
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,11 +209,74 @@ 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
|
+
|
|
240
|
+
/** The words of a name, with the ones that mean the same made one. */
|
|
241
|
+
const wordsOf = (name) =>
|
|
242
|
+
name
|
|
243
|
+
.split(/(?=[A-Z][a-z])|_/)
|
|
244
|
+
.map((word) => word.toLowerCase())
|
|
245
|
+
.map((word) => (/^(options|config|params)$/.test(word) ? 'props' : word))
|
|
246
|
+
.filter(Boolean);
|
|
247
|
+
|
|
248
|
+
/** The exports that share most words with a name that is not one. */
|
|
249
|
+
function closest(name) {
|
|
250
|
+
const wanted = new Set(wordsOf(name));
|
|
251
|
+
|
|
252
|
+
return names
|
|
253
|
+
.map((other) => ({
|
|
254
|
+
other,
|
|
255
|
+
shared: wordsOf(other).filter((word) => wanted.has(word)).length
|
|
256
|
+
}))
|
|
257
|
+
.filter(({ shared }) => shared > 0)
|
|
258
|
+
.sort((a, b) => b.shared - a.shared || a.other.length - b.other.length)
|
|
259
|
+
.slice(0, 6)
|
|
260
|
+
.map(({ other }) => other);
|
|
261
|
+
}
|
|
262
|
+
|
|
146
263
|
function formatMarkdown(name) {
|
|
147
264
|
const item = get(name);
|
|
148
265
|
|
|
266
|
+
if (!item && /^\w+$/.test(name) && local(name)) return local(name);
|
|
267
|
+
|
|
149
268
|
if (!item) {
|
|
150
|
-
|
|
269
|
+
const missing = `${name} is not exported by ${packages.map((p) => p.name).join(' or ')}.`;
|
|
270
|
+
// TextFieldOptions: what TextField takes is in its own declaration
|
|
271
|
+
const owner = /^(\w+?)(?:Options|Props|Config|Params)$/.exec(name)?.[1];
|
|
272
|
+
|
|
273
|
+
if (owner && get(owner)) {
|
|
274
|
+
return `${missing} What ${owner} takes is in its declaration:\n\n${formatMarkdown(owner)}`;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const near = /^\w+$/.test(name) ? closest(name) : [];
|
|
278
|
+
|
|
279
|
+
return `${missing}${near.length ? ` Closest: ${near.join(', ')}.` : ''} Exports: ${names.join(', ')}`;
|
|
151
280
|
}
|
|
152
281
|
|
|
153
282
|
return `## ${item.name} (${item.kind}, ${item.package})\n\n\`\`\`ts\n${item.declaration}\n\`\`\``;
|