@punica/form-mcp 0.9.0 → 0.10.1

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.
@@ -17,6 +17,10 @@ export type FormItem<E> = {
17
17
  * property and on the form item type.
18
18
  */
19
19
  value?: any;
20
+ /**
21
+ * The item needs a value. What counts as empty is up to its validation;
22
+ * `@punica/form-kit` takes `undefined`, `null`, `''`, `false` and `[]`.
23
+ */
20
24
  required?: boolean;
21
25
  disabled?: boolean;
22
26
  hidden?: boolean;
@@ -1 +1 @@
1
- {"version":"2.3.2"}
1
+ {"version":"2.3.3"}
@@ -80,6 +80,16 @@ export declare const FileField: (props: FieldProps) => FormPropertyDecorator;
80
80
  * then come from the class. `[]` starts with none: `minItems` only checks
81
81
  * how many there are, it adds no rows.
82
82
  *
83
+ * Each row has a remove button and the list an add button below the rows,
84
+ * with the texts `removeLabel` and `addLabel` (`Remove` and `Add` by
85
+ * default). The add button is disabled once the list has `maxItems` rows.
86
+ *
87
+ * @ArrayField({ label: 'Tickets', row: () => new TicketForm(), addLabel: 'Add ticket', removeLabel: 'Remove ticket' })
88
+ * tickets: TicketForm[] = [{ quantity: 1 } as TicketForm];
89
+ *
90
+ * A row's messages are its fields' own: an error for `tickets.0.quantity`
91
+ * that `SetErrors` returns shows under that row's Quantity.
92
+ *
83
93
  * The row class needs no `@FormKit`; with it, `columns` lays out its fields.
84
94
  */
85
95
  export declare const ArrayField: (props: FieldProps & {
@@ -1 +1 @@
1
- {"version":"0.7.2"}
1
+ {"version":"0.7.3"}
@@ -40,7 +40,16 @@ export type FormViewProps<E extends object> = ViewProps<E> & {
40
40
  * state while the submit runs, and a reset button when `resetLabel` is set.
41
41
  *
42
42
  * A submit validates every item first: an invalid form shows its messages
43
- * and `onSubmit` is not called.
43
+ * and `onSubmit` is not called. A valid one calls `onSubmit(values,
44
+ * controller)`: `values` is a copy of the form's class instance holding the
45
+ * current values (what `GetValues` returns), a list as an array of its rows'
46
+ * values. Outside a submit, read them with
47
+ * `controller.getService(GetValues).run()`.
48
+ *
49
+ * ```tsx
50
+ * <FormView controller={controller} submitLabel="Create"
51
+ * onSubmit={(values) => api.create(values)} />
52
+ * ```
44
53
  */
45
54
  export declare function FormView<E extends object>({ controller, onSubmit, onError, submitLabel, resetLabel, components }: FormViewProps<E>): ReactNode;
46
55
  export type KitFormProps<E extends object> = ViewProps<E> & {
@@ -12,7 +12,25 @@ export type Option = string | {
12
12
  export type Options = Option[] | (() => Promise<Option[]>);
13
13
  /** How many columns of the form a field takes. */
14
14
  export type Span = 1 | 2 | 3 | 4 | 'full';
15
- /** The rules the kit validates by itself. */
15
+ /**
16
+ * The rules the kit validates by itself, on submit, on `Trigger` and when a
17
+ * field that shows an error changes.
18
+ *
19
+ * - An empty value (`undefined`, `null`, `''`, `false`, `[]`) is checked only
20
+ * by `required` (and a list by `minItems`): an empty optional field passes,
21
+ * whatever its other rules say. A `NumberField` is `undefined` while empty.
22
+ * - `minLength`, `maxLength` and `pattern` check strings; `min` and `max`
23
+ * check numbers; `minDate` and `maxDate` check `yyyy-mm-dd` strings;
24
+ * `minItems` and `maxItems` check arrays (choices, files, rows).
25
+ * - The first rule a value breaks is its only message; the field's own
26
+ * `validation` runs after the rules, for a value that passed them.
27
+ * - Messages come from `setMessages` (every form) or `messages` (one field).
28
+ *
29
+ * ```ts
30
+ * @NumberField({ label: 'Quantity', required: true, min: 1 })
31
+ * quantity?: number;
32
+ * ```
33
+ */
16
34
  export type Rules = {
17
35
  /** Fewest characters allowed. */
18
36
  minLength?: number;
@@ -66,9 +84,15 @@ export type KitItem<E> = FormItem<E> & Rules & {
66
84
  accept?: string;
67
85
  /** The language a date field is typed and shown in, the one of the page by default. */
68
86
  locale?: string;
69
- /** The text of the button that adds a row to a list, `Add` by default. */
87
+ /**
88
+ * The text of the button that adds a row to a list (`ArrayField`), `Add`
89
+ * by default. It is the button's accessible name as well.
90
+ */
70
91
  addLabel?: string;
71
- /** The text of the button that removes a row from a list, `Remove` by default. */
92
+ /**
93
+ * The text of the button that removes a row from a list (`ArrayField`),
94
+ * `Remove` by default; every row has one.
95
+ */
72
96
  removeLabel?: string;
73
97
  /** Visible lines of a text area. */
74
98
  rows?: number;
@@ -77,7 +101,16 @@ export type KitItem<E> = FormItem<E> & Rules & {
77
101
  /** Messages of this field, in place of the kit's. */
78
102
  messages?: Partial<Messages>;
79
103
  };
80
- /** What a field decorator takes: everything of an item but its property and type. */
104
+ /**
105
+ * What a field decorator takes: everything of a `KitItem` but its property
106
+ * and type. That is `label`, `required`, `disabled`, `hidden` and
107
+ * `validation` of a form item, the `Rules` the kit checks, and what the
108
+ * components show (`help`, `placeholder`, `options`, `addLabel`, …).
109
+ *
110
+ * `required: true` means the value must not be empty: a text that is not
111
+ * `''`, a number that is not `undefined`, a ticked checkbox, a list with an
112
+ * element.
113
+ */
81
114
  export type FieldProps = Omit<KitItem<any>, 'property' | 'type'>;
82
115
  /** The messages of the built-in rules. Each receives the label of the field. */
83
116
  export type Messages = {
@@ -1 +1 @@
1
- {"version":"2.3.2"}
1
+ {"version":"2.3.3"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@punica/form-mcp",
3
- "version": "0.9.0",
3
+ "version": "0.10.1",
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.2",
44
- "@punica/form-service": "^2.3.2",
43
+ "@punica/form": "^2.3.3",
44
+ "@punica/form-service": "^2.3.3",
45
45
  "@punica/form-react": "^0.2.0",
46
- "@punica/form-kit": "^0.7.2",
46
+ "@punica/form-kit": "^0.7.3",
47
47
  "@punica/form-schema": "^0.1.0"
48
48
  },
49
49
  "scripts": {
package/src/guide.md CHANGED
@@ -3,6 +3,11 @@
3
3
  Punica Form is a headless form engine. `@punica/form` holds the engine,
4
4
  `@punica/form-service` the built-in services. There are no UI components.
5
5
 
6
+ Exact declarations are one call away: `get_api` with the names
7
+ (`KitFormProps`, `FieldProps`, `SetErrors`) returns each one with the types
8
+ it refers to, and `search_api` lists the exports. Ask them instead of reading
9
+ the `.d.ts` files in `node_modules`; `validate_code` checks the result.
10
+
6
11
  ## What the packages provide, and what they do not
7
12
 
8
13
  - `@punica/form`: `FormController`, the class decorators `@Services`,
package/src/knowledge.mjs CHANGED
@@ -64,12 +64,13 @@ function declarationAt(source, index) {
64
64
  * such as the interface a configuration type is made of: without them the
65
65
  * options of a middleware could not be looked up.
66
66
  */
67
- function localsOf(source, text, seen = new Set()) {
67
+ function localsOf(source, text, seen = new Set(), exported = false) {
68
68
  const found = [];
69
+ const pattern = exported
70
+ ? /^(?:export )?(?:declare )?(?:interface|type) (\w+)/gm
71
+ : /^(?:declare )?(?:interface|type) (\w+)/gm;
69
72
 
70
- for (const match of source.matchAll(
71
- /^(?:declare )?(?:interface|type) (\w+)/gm
72
- )) {
73
+ for (const match of source.matchAll(pattern)) {
73
74
  const name = match[1];
74
75
 
75
76
  if (seen.has(name) || !new RegExp(`\\b${name}\\b`).test(text)) continue;
@@ -82,7 +83,7 @@ function localsOf(source, text, seen = new Set()) {
82
83
  .filter(Boolean)
83
84
  .join('\n');
84
85
 
85
- found.push(declaration, ...localsOf(source, declaration, seen));
86
+ found.push(declaration, ...localsOf(source, declaration, seen, exported));
86
87
  }
87
88
 
88
89
  return found;
@@ -113,17 +114,33 @@ function entry(source, index, kind, name) {
113
114
  '.'
114
115
  );
115
116
 
117
+ // A type made of other types (`Omit<KitItem, …>`, `A & B`) says nothing by
118
+ // itself: the types of its module it names come along, exported or not
119
+ const derived = kind === 'type' && !/=\s*\{/.test(declaration);
120
+
121
+ const own = [
122
+ comment,
123
+ declaration,
124
+ ...localsOf(source, declaration, new Set([name]))
125
+ ]
126
+ .filter(Boolean)
127
+ .join('\n');
128
+
116
129
  return {
117
130
  name,
118
131
  kind,
119
132
  summary: summary.trim(),
120
- declaration: [
121
- comment,
122
- declaration,
123
- ...localsOf(source, declaration, new Set([name]))
124
- ]
125
- .filter(Boolean)
126
- .join('\n')
133
+ // What a search reads: the types that only come along are not its words
134
+ text: own,
135
+ declaration: derived
136
+ ? [
137
+ comment,
138
+ declaration,
139
+ ...localsOf(source, declaration, new Set([name]), true)
140
+ ]
141
+ .filter(Boolean)
142
+ .join('\n')
143
+ : own
127
144
  };
128
145
  }
129
146
 
@@ -203,7 +220,7 @@ export function createKnowledge(packages) {
203
220
  return names
204
221
  .map((name) => api.get(name))
205
222
  .filter((item) => {
206
- const text = `${item.name} ${item.declaration}`.toLowerCase();
223
+ const text = `${item.name} ${item.text}`.toLowerCase();
207
224
 
208
225
  return words.every((word) => text.includes(word));
209
226
  });