@punica/form-mcp 0.1.0 → 0.2.1-next.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/README.md +6 -6
- package/bundled/form/controller/index.d.ts +46 -51
- package/bundled/form/decorator/Readers.d.ts +2 -2
- package/bundled/form/decorator/Services.d.ts +2 -2
- package/bundled/form/decorator/Starters.d.ts +2 -2
- package/bundled/form/define/FormItem.d.ts +12 -6
- package/bundled/form/define/FormItemProperty.d.ts +5 -5
- package/bundled/form/define/FormProperty.d.ts +5 -4
- package/bundled/form/define/decorator.d.ts +16 -0
- package/bundled/form/define/index.d.ts +1 -0
- package/bundled/form/index.d.ts +1 -0
- package/bundled/form/metadata/index.d.ts +16 -0
- package/bundled/form/model/command/item.d.ts +11 -5
- package/bundled/form/model/command/service.d.ts +25 -10
- package/bundled/form/model/constants/index.d.ts +13 -2
- package/bundled/form/model/form/index.d.ts +9 -4
- package/bundled/form/model/index.d.ts +0 -1
- package/bundled/form/model/item/index.d.ts +41 -12
- package/bundled/form/model/reader/index.d.ts +5 -1
- package/bundled/form/model/service/index.d.ts +28 -10
- package/bundled/form/package.json +1 -1
- package/bundled/form/reader/index.d.ts +10 -17
- package/bundled/form/register/index.d.ts +26 -39
- package/bundled/form/shared.d.ts +20 -0
- package/bundled/form/utils/deepCopy.d.ts +1 -1
- package/bundled/form/utils/devtools.d.ts +11 -70
- package/bundled/form/utils/index.d.ts +2 -1
- package/bundled/form/utils/path.d.ts +10 -0
- package/bundled/form-service/clearError/index.d.ts +4 -14
- package/bundled/form-service/clearErrors/index.d.ts +4 -16
- package/bundled/form-service/getValues/index.d.ts +5 -13
- package/bundled/form-service/index.d.ts +21 -0
- package/bundled/form-service/package.json +1 -1
- package/bundled/form-service/reset/index.d.ts +4 -13
- package/bundled/form-service/resetItem/index.d.ts +4 -14
- package/bundled/form-service/setValue/index.d.ts +9 -16
- package/bundled/form-service/store/index.d.ts +11 -23
- package/bundled/form-service/trigger/index.d.ts +4 -13
- package/bundled/form-service/validate/index.d.ts +4 -18
- package/bundled/form-service/validateItem.d.ts +13 -0
- package/package.json +5 -4
- package/src/create.mjs +12 -6
- package/src/guide.md +96 -58
- package/src/knowledge.mjs +2 -2
- package/src/validate.mjs +64 -47
- package/bundled/form/model/util/GetItem.d.ts +0 -9
- package/bundled/form/model/util/WriteItems.d.ts +0 -8
- package/bundled/form/model/util/index.d.ts +0 -2
- package/bundled/form/reader/decorators/base/index.d.ts +0 -35
- package/bundled/form/reader/decorators/readers/FormItemsReader.d.ts +0 -17
- package/bundled/form/reader/decorators/readers/ItemDataReader.d.ts +0 -24
- package/bundled/form/reader/decorators/readers/ItemInitializerReader.d.ts +0 -16
- package/bundled/form/reader/decorators/readers/index.d.ts +0 -3
- package/bundled/form/reader/reader/Reader.d.ts +0 -13
- package/bundled/form/reader/reader/index.d.ts +0 -1
package/src/guide.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Punica Form: the rules
|
|
1
|
+
# Punica Form 2: the rules
|
|
2
2
|
|
|
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.
|
|
@@ -7,18 +7,20 @@ Punica Form is a headless form engine. `@punica/form` holds the engine,
|
|
|
7
7
|
|
|
8
8
|
- `@punica/form`: `FormController`, the class decorators `@Services`,
|
|
9
9
|
`@Readers` and `@Starters`, the helpers `defineFormItem`,
|
|
10
|
-
`defineFormItemProperty` and `defineFormProperty`,
|
|
10
|
+
`defineFormItemProperty` and `defineFormProperty`, the metadata readers
|
|
11
|
+
`getFormProperty` and `getFormItemProperties`, the form item register,
|
|
11
12
|
`deepCopy`, the DevTools switches and the types. Use `search_api` for the
|
|
12
13
|
exact list.
|
|
13
14
|
- `@punica/form-service`: `Validate`, `GetValues`, `SetValue`, `Reset`,
|
|
14
15
|
`ResetItem`, `Trigger`, `ClearError`, `ClearErrors`, `Store`.
|
|
15
16
|
- NOT provided: `@Title`, `@Description`, `@Layout`, `@FormItemInputText` or
|
|
16
|
-
any other form item decorator, a `Reader` class, a
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
-
|
|
21
|
-
|
|
17
|
+
any other form item decorator, a `Reader` class, a base form item. These
|
|
18
|
+
belong to the application's own form system. Build them with the `define*`
|
|
19
|
+
helpers and by implementing `IReader`; import them from the application's
|
|
20
|
+
own module, never from `@punica/form`.
|
|
21
|
+
- Decorators work with both the legacy implementation of TypeScript
|
|
22
|
+
(`"experimentalDecorators": true`) and the standard one. There is no
|
|
23
|
+
`reflect-metadata`: never call `Reflect.getMetadata`.
|
|
22
24
|
|
|
23
25
|
## Lifecycle
|
|
24
26
|
|
|
@@ -33,83 +35,122 @@ entity (only properties with an initializer, such as `name = ""`).
|
|
|
33
35
|
order, runs the starters of `@Starters` (each returns the form, possibly a
|
|
34
36
|
new one), initializes the services of `@Services` and returns the form.
|
|
35
37
|
Both calls are asynchronous and reject when a reader, starter or service
|
|
36
|
-
throws.
|
|
38
|
+
throws. `FormController.fromForm(form)` starts from a form written as data.
|
|
39
|
+
|
|
40
|
+
## State
|
|
41
|
+
|
|
42
|
+
The form is immutable. Every change produces a new form object; items that
|
|
43
|
+
did not change keep their identity.
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
controller.getForm(); // the current form
|
|
47
|
+
const unsubscribe = controller.subscribe(() => {}); // after every change
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
In React use `@punica/form-react`:
|
|
51
|
+
|
|
52
|
+
```tsx
|
|
53
|
+
const { controller, error } = useFormController(() => new UserForm());
|
|
54
|
+
// controller is undefined while the form is being started
|
|
55
|
+
const form = useForm(controller); // in a component that has the controller
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Without that package: `useSyncExternalStore(controller.subscribe, controller.getForm)`.
|
|
59
|
+
`start()` publishes the started form the same way (since 2.1).
|
|
60
|
+
Never change a form or an item in place; use the services.
|
|
37
61
|
|
|
38
62
|
## Services
|
|
39
63
|
|
|
40
|
-
Services are
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
| Class |
|
|
44
|
-
|
|
45
|
-
| `Validate` | `
|
|
46
|
-
| `
|
|
47
|
-
| `
|
|
48
|
-
| `
|
|
49
|
-
| `
|
|
50
|
-
| `
|
|
51
|
-
| `
|
|
52
|
-
| `
|
|
53
|
-
| `Store` |
|
|
64
|
+
Services are read by class and executed with `run`. They are bound to the
|
|
65
|
+
entity of the form, so property names and results are type-checked.
|
|
66
|
+
|
|
67
|
+
| Class | Call |
|
|
68
|
+
|---|---|
|
|
69
|
+
| `Validate` | `run(): Promise<boolean>`, validates every visible item |
|
|
70
|
+
| `Trigger` | `run(property): Promise<void>`, validates one item |
|
|
71
|
+
| `GetValues` | `run(): Promise<E>`, a copy of the entity filled with the item values |
|
|
72
|
+
| `SetValue` | `run(property, value): Promise<void>`, then runs the `control` function of the item |
|
|
73
|
+
| `Reset` | `run(): Promise<void>` |
|
|
74
|
+
| `ResetItem` | `run(property): Promise<void>` |
|
|
75
|
+
| `ClearError` | `run(property): Promise<void>` |
|
|
76
|
+
| `ClearErrors` | `run(): Promise<void>` |
|
|
77
|
+
| `Store` | no `run`: it adds `readStoreItem`, `writeStoreItem`, `deleteStoreItem` to the command passed to item functions (`CommandItem<E, F, StoreCommand>`) |
|
|
54
78
|
|
|
55
79
|
```ts
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
await controller.
|
|
59
|
-
await
|
|
80
|
+
import { GetValues, SetValue, Trigger, Validate } from "@punica/form-service";
|
|
81
|
+
|
|
82
|
+
await controller.getService(SetValue).run("name", "Jane");
|
|
83
|
+
await controller.getService(Trigger).run("name");
|
|
84
|
+
|
|
85
|
+
if (await controller.getService(Validate).run()) {
|
|
86
|
+
const values = await controller.getService(GetValues).run();
|
|
87
|
+
}
|
|
60
88
|
```
|
|
61
89
|
|
|
62
90
|
- A service works only when it is listed in `@Services([...])`;
|
|
63
|
-
`
|
|
64
|
-
-
|
|
65
|
-
|
|
91
|
+
`getService` throws for a class that is not, and before `start()`.
|
|
92
|
+
- List service classes (`@Services([GetValues, SetValue])`, since 2.1): every
|
|
93
|
+
form then gets its own services. With 2.0 pass instances
|
|
94
|
+
(`new GetValues()`); instances are shared by all forms of the class.
|
|
95
|
+
- `controller.batch(() => { … })` notifies subscribers once for several
|
|
96
|
+
changes (since 2.1).
|
|
97
|
+
- There is no `getServices('name')`, no `validate(form)`, no
|
|
98
|
+
`item.setValue(…)` and no `validateItem(…)`.
|
|
66
99
|
- `Validate.run()` returns `false` when the form is invalid. Other failures
|
|
67
100
|
(an unknown property, an error thrown by a validation function) reject.
|
|
68
|
-
- Setting a value does not validate it.
|
|
101
|
+
- Setting a value does not validate it. Run `Trigger` for that.
|
|
69
102
|
|
|
70
103
|
## Form items
|
|
71
104
|
|
|
72
105
|
A form item is a plain object: `property`, `label`, `type`, `value`,
|
|
73
|
-
`required`, `disabled`, `hidden`, `error`, `errorMessages
|
|
74
|
-
|
|
75
|
-
|
|
106
|
+
`required`, `disabled`, `hidden`, `error`, `errorMessages`. Add the
|
|
107
|
+
properties of your form system with a type of your own:
|
|
108
|
+
`type AppItem<E> = FormItem<E> & { layout?: Layout }`, then use
|
|
109
|
+
`FormController<UserForm, AppItem<UserForm>>`.
|
|
110
|
+
|
|
111
|
+
The functions of an item receive a command `{ formItem, initialEntity,
|
|
112
|
+
getItem }` holding copies, and return items instead of changing them:
|
|
76
113
|
|
|
77
114
|
- `validation(command): Promise<{ error: boolean, errorMessages?: string[] }>`
|
|
78
115
|
- `control(command): Promise<FormItem[]>`, run after its value is set; the
|
|
79
|
-
returned items are written
|
|
116
|
+
returned items are written to the form
|
|
80
117
|
- `initialize(command): Promise<FormItem[]>`, run once while the form is created
|
|
81
118
|
|
|
82
119
|
## Events
|
|
83
120
|
|
|
84
|
-
`controller.on(event, handler)`
|
|
85
|
-
handler
|
|
121
|
+
`controller.on(event, handler)` returns the function that removes the
|
|
122
|
+
handler. Payloads are typed.
|
|
86
123
|
|
|
87
124
|
| Event | Payload |
|
|
88
125
|
|---|---|
|
|
89
|
-
| `UPDATE_FORM` | the form; fired
|
|
126
|
+
| `UPDATE_FORM` | the form; fired after every change |
|
|
90
127
|
| `UPDATE_ITEM` | an array: the changed item, then the items its `control` returned |
|
|
91
|
-
| `RESET` | the form; fired by `Reset`,
|
|
128
|
+
| `RESET` | the form; fired by `Reset`, after `UPDATE_FORM` |
|
|
92
129
|
| `REGISTER_ITEMS` | `string[]` of registered form item types; fired at the start of `start()` |
|
|
93
130
|
|
|
94
|
-
Services change the form in place. A UI library that compares references,
|
|
95
|
-
such as React, needs a new object: `setForm({ ...form })`.
|
|
96
|
-
|
|
97
131
|
## A complete example
|
|
98
132
|
|
|
99
133
|
The application's form system:
|
|
100
134
|
|
|
101
135
|
```tsx
|
|
102
|
-
import {
|
|
136
|
+
import {
|
|
137
|
+
defineFormItem,
|
|
138
|
+
defineFormProperty,
|
|
139
|
+
getFormProperty,
|
|
140
|
+
type Form,
|
|
141
|
+
type FormItem,
|
|
142
|
+
type IReader,
|
|
143
|
+
} from "@punica/form";
|
|
103
144
|
|
|
104
145
|
export const Title = defineFormProperty<string>("app:title");
|
|
105
146
|
|
|
106
147
|
export class Reader<E extends object, F extends FormItem<E>> implements IReader<E, F> {
|
|
107
|
-
public
|
|
108
|
-
form.title =
|
|
148
|
+
public read(entity: E, form: Form<E, F>): void {
|
|
149
|
+
form.title = getFormProperty<string>(entity, "app:title");
|
|
109
150
|
}
|
|
110
151
|
}
|
|
111
152
|
|
|
112
|
-
// The second argument is the renderer;
|
|
153
|
+
// The second argument is the renderer; defaultFormItemRegister.getItem(item.type) returns it
|
|
113
154
|
export const FormItemInputText = defineFormItem<Omit<FormItem<any>, "property">>(
|
|
114
155
|
"app:input-text",
|
|
115
156
|
InputText
|
|
@@ -119,18 +160,18 @@ export const FormItemInputText = defineFormItem<Omit<FormItem<any>, "property">>
|
|
|
119
160
|
A business form:
|
|
120
161
|
|
|
121
162
|
```ts
|
|
122
|
-
import { Readers, Services
|
|
163
|
+
import { Readers, Services } from "@punica/form";
|
|
123
164
|
import { GetValues, SetValue, Trigger, Validate } from "@punica/form-service";
|
|
124
165
|
import { FormItemInputText, Reader, Title } from "./formSystem";
|
|
125
166
|
|
|
126
167
|
@Title("Create User")
|
|
127
168
|
@Readers([new Reader()])
|
|
128
|
-
@Services([
|
|
169
|
+
@Services([GetValues, SetValue, Validate, Trigger])
|
|
129
170
|
export class UserForm {
|
|
130
171
|
@FormItemInputText({
|
|
131
172
|
label: "Name",
|
|
132
173
|
required: true,
|
|
133
|
-
validation: async ({ formItem })
|
|
174
|
+
validation: async ({ formItem }) => ({
|
|
134
175
|
error: !formItem.value,
|
|
135
176
|
errorMessages: formItem.value ? [] : ["Name is required"],
|
|
136
177
|
}),
|
|
@@ -142,18 +183,15 @@ export class UserForm {
|
|
|
142
183
|
Using it:
|
|
143
184
|
|
|
144
185
|
```ts
|
|
145
|
-
const controller = await FormController.fromEntity
|
|
146
|
-
|
|
147
|
-
controller.on("UPDATE_FORM", (data) => render(data as Form<UserForm, FormItem<UserForm>>));
|
|
186
|
+
const controller = await FormController.fromEntity(new UserForm());
|
|
148
187
|
|
|
149
|
-
|
|
150
|
-
|
|
188
|
+
controller.subscribe(() => render(controller.getForm()));
|
|
189
|
+
await controller.start();
|
|
151
190
|
|
|
152
|
-
await
|
|
153
|
-
await controller.getServices("trigger").run("name");
|
|
191
|
+
await controller.getService(SetValue).run("name", "Jane");
|
|
154
192
|
|
|
155
|
-
if (await controller.
|
|
156
|
-
const values = await controller.
|
|
193
|
+
if (await controller.getService(Validate).run()) {
|
|
194
|
+
const values = await controller.getService(GetValues).run(); // UserForm
|
|
157
195
|
}
|
|
158
196
|
```
|
|
159
197
|
|
package/src/knowledge.mjs
CHANGED
|
@@ -69,8 +69,8 @@ function exportsOf(files, path, seen = new Set()) {
|
|
|
69
69
|
for (const [name, value] of target) found.set(name, value);
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
// export { a, default as b } from './x';
|
|
73
|
-
for (const match of source.matchAll(/^export
|
|
72
|
+
// export { a, default as b } from './x'; export type { a } from './x';
|
|
73
|
+
for (const match of source.matchAll(/^export (?:type )?\{([^}]+)\} from ['"](.+?)['"];/gm)) {
|
|
74
74
|
const targetPath = resolve(files, path, match[2]);
|
|
75
75
|
const target = exportsOf(files, targetPath, new Set(seen));
|
|
76
76
|
const targetSource = files.get(targetPath) || '';
|
package/src/validate.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// Checks code that uses Punica Form for the mistakes models make most often:
|
|
2
|
-
// names the packages do not export and
|
|
3
|
-
|
|
4
|
-
/** The name a service registers under: its class name in camelCase. */
|
|
5
|
-
const serviceName = (className) => className[0].toLowerCase() + className.slice(1);
|
|
2
|
+
// names the packages do not export and calls that do not exist (any more).
|
|
6
3
|
|
|
7
4
|
const lineOf = (code, index) => code.slice(0, index).split('\n').length;
|
|
8
5
|
|
|
6
|
+
/** The name of the service a `run`-less call such as `.validate(form)` means. */
|
|
7
|
+
const className = (method) => method[0].toUpperCase() + method.slice(1);
|
|
8
|
+
|
|
9
9
|
/** @param {ReturnType<typeof import('./knowledge.mjs').createKnowledge>} knowledge */
|
|
10
10
|
export function createValidator(knowledge) {
|
|
11
11
|
const packageNames = knowledge.packages.map((pkg) => pkg.name);
|
|
@@ -13,16 +13,67 @@ export function createValidator(knowledge) {
|
|
|
13
13
|
.map((name) => knowledge.get(name))
|
|
14
14
|
.filter((item) => item.kind === 'class' && item.package.endsWith('-service'))
|
|
15
15
|
.map((item) => item.name);
|
|
16
|
+
const methods = services.map((name) => name[0].toLowerCase() + name.slice(1));
|
|
17
|
+
|
|
18
|
+
/** Calls that do not exist, with what to write instead. */
|
|
19
|
+
const rules = [
|
|
20
|
+
{
|
|
21
|
+
rule: 'service-access',
|
|
22
|
+
pattern: /\.getServices\(/g,
|
|
23
|
+
message: 'There is no getServices: services are read by class, not by name.',
|
|
24
|
+
fix: () => 'controller.getService(Validate) (import the class from "@punica/form-service")'
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
rule: 'service-call',
|
|
28
|
+
pattern: new RegExp(`\\.(${methods.join('|')})\\(\\s*(?:this\\.)?(?:form|mockForm)\\b`, 'g'),
|
|
29
|
+
message: (match) => `There is no ${match[1]}(form, …) method.`,
|
|
30
|
+
fix: (match) => `await controller.getService(${className(match[1])}).run(…)`
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
rule: 'service-call',
|
|
34
|
+
pattern: /\.validateItem\(/g,
|
|
35
|
+
message: 'There is no validateItem method.',
|
|
36
|
+
fix: () => 'await controller.getService(Trigger).run(property)'
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
rule: 'service-call',
|
|
40
|
+
pattern: /\b(?:item|formItem|\w+Item)\.setValue\(/g,
|
|
41
|
+
message: 'Form items have no setValue method.',
|
|
42
|
+
fix: () => 'await controller.getService(SetValue).run(property, value)'
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
rule: 'events',
|
|
46
|
+
pattern: /\bcontroller\.off\(/g,
|
|
47
|
+
message: 'There is no off method.',
|
|
48
|
+
fix: () => 'call the function controller.on(event, handler) returned'
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
rule: 'register',
|
|
52
|
+
pattern: /FormItemRegister\.getInstance\(/g,
|
|
53
|
+
message: 'FormItemRegister is not a singleton.',
|
|
54
|
+
fix: () => 'defaultFormItemRegister.getItem(type), or a register of your own from createFormItemRegister()'
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
rule: 'register',
|
|
58
|
+
pattern: /\.getRenderer\(/g,
|
|
59
|
+
message: 'A register has no getRenderer method.',
|
|
60
|
+
fix: () => 'defaultFormItemRegister.getItem(type)'
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
rule: 'metadata',
|
|
64
|
+
pattern: /Reflect\.(?:get|define)Metadata\(/g,
|
|
65
|
+
message: 'Punica Form does not use reflect-metadata.',
|
|
66
|
+
fix: () => 'getFormProperty(entity, key) or getFormItemProperties(entity, key) from "@punica/form"'
|
|
67
|
+
}
|
|
68
|
+
];
|
|
16
69
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
'g'
|
|
21
|
-
);
|
|
70
|
+
// The rules name what 2.0 removed; for a project that still has 1.x
|
|
71
|
+
// installed that API is correct, so only its imports are checked
|
|
72
|
+
const isLegacy = knowledge.packages.some((pkg) => parseInt(pkg.version) < 2);
|
|
22
73
|
|
|
23
74
|
/**
|
|
24
75
|
* @param {string} code
|
|
25
|
-
* @returns {Array<{ line: number, rule: string, message: string, fix
|
|
76
|
+
* @returns {Array<{ line: number, rule: string, message: string, fix: string }>}
|
|
26
77
|
*/
|
|
27
78
|
function validate(code) {
|
|
28
79
|
const findings = [];
|
|
@@ -51,46 +102,12 @@ export function createValidator(knowledge) {
|
|
|
51
102
|
}
|
|
52
103
|
}
|
|
53
104
|
|
|
54
|
-
for (const
|
|
55
|
-
for (const
|
|
56
|
-
|
|
57
|
-
add(
|
|
58
|
-
match.index,
|
|
59
|
-
'service-name',
|
|
60
|
-
`Services are registered in camelCase; "${name}" is not found.`,
|
|
61
|
-
`getServices('${serviceName(name)}')`
|
|
62
|
-
);
|
|
63
|
-
}
|
|
105
|
+
for (const { rule, pattern, message, fix } of isLegacy ? [] : rules) {
|
|
106
|
+
for (const match of code.matchAll(pattern)) {
|
|
107
|
+
add(match.index, rule, typeof message === 'string' ? message : message(match), fix(match));
|
|
64
108
|
}
|
|
65
109
|
}
|
|
66
110
|
|
|
67
|
-
for (const match of code.matchAll(formCall)) {
|
|
68
|
-
const fix =
|
|
69
|
-
match[1] === 'setValue'
|
|
70
|
-
? 'await item.setValue(item.property, value) (SetValue adds setValue to every form item)'
|
|
71
|
-
: `await controller.getServices('${match[1]}').run(${/^(clearError|resetItem|trigger)$/.test(match[1]) ? 'property' : ''})`;
|
|
72
|
-
|
|
73
|
-
add(match.index, 'service-call', `There is no ${match[1]}(form, …) method.`, fix);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
for (const match of code.matchAll(/\.validateItem\(/g)) {
|
|
77
|
-
add(
|
|
78
|
-
match.index,
|
|
79
|
-
'service-call',
|
|
80
|
-
'There is no validateItem method.',
|
|
81
|
-
"await controller.getServices('trigger').run(property) (needs new Trigger() in @Services)"
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
for (const match of code.matchAll(/FormItemRegister(?:\.getInstance\(\))?\.getRenderer\(/g)) {
|
|
86
|
-
add(
|
|
87
|
-
match.index,
|
|
88
|
-
'register',
|
|
89
|
-
'FormItemRegister has no getRenderer method.',
|
|
90
|
-
'FormItemRegister.getInstance().getItem(type)'
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
111
|
return findings.sort((a, b) => a.line - b.line);
|
|
95
112
|
}
|
|
96
113
|
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { FormItem } from '..';
|
|
2
|
-
/**
|
|
3
|
-
* Type alias for a function that retrieves a specific form item based on a property key.
|
|
4
|
-
* @param E - The type of the entity
|
|
5
|
-
* @param F - The type of the form item
|
|
6
|
-
* @param property - The property key to retrieve the form item
|
|
7
|
-
* @returns The form item corresponding to the property key
|
|
8
|
-
*/
|
|
9
|
-
export type GetItem<E, F extends FormItem<E>> = (property: keyof E) => F;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { FormItem } from '..';
|
|
2
|
-
/**
|
|
3
|
-
* Type alias for a function that writes form items to a storage.
|
|
4
|
-
* @param E - The type of the entity
|
|
5
|
-
* @param items - Array of form items to be written
|
|
6
|
-
* @returns A Promise that resolves once the items are written
|
|
7
|
-
*/
|
|
8
|
-
export type WriteItems<E> = (items: Array<FormItem<E>>) => Promise<void>;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { Form, FormItem, IReader, CommandItem } from '../../../';
|
|
2
|
-
/**
|
|
3
|
-
* Abstract base class for reading form data.
|
|
4
|
-
*/
|
|
5
|
-
declare abstract class BaseReader<E, F extends FormItem<E>> implements IReader<E, F> {
|
|
6
|
-
#private;
|
|
7
|
-
protected reader: IReader<E, F>;
|
|
8
|
-
/**
|
|
9
|
-
* Creates an instance of BaseReader.
|
|
10
|
-
* @param {IReader<E, F>} reader - The reader to be used for reading form data.
|
|
11
|
-
*/
|
|
12
|
-
constructor(reader: IReader<E, F>);
|
|
13
|
-
/**
|
|
14
|
-
* Maps form items to their properties.
|
|
15
|
-
*/
|
|
16
|
-
private mapFormItems;
|
|
17
|
-
/**
|
|
18
|
-
* Gets a command item for a form item.
|
|
19
|
-
* @param {F} item - The form item.
|
|
20
|
-
* @returns {CommandItem<E, F>} - The command item.
|
|
21
|
-
*/
|
|
22
|
-
protected getCommand(item: F): CommandItem<E, F>;
|
|
23
|
-
/**
|
|
24
|
-
* Reads form data from the entity.
|
|
25
|
-
* @param {E} entity - The entity to read form data from.
|
|
26
|
-
* @param form
|
|
27
|
-
*/
|
|
28
|
-
read(entity: E, form: Form<E, F>): Promise<void>;
|
|
29
|
-
/**
|
|
30
|
-
* Writes form items.
|
|
31
|
-
* @param {Array<FormItem<E>>} items - The form items to be written.
|
|
32
|
-
*/
|
|
33
|
-
protected writeItems(items: Array<FormItem<E>>): Promise<void>;
|
|
34
|
-
}
|
|
35
|
-
export default BaseReader;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Form, FormItem } from '../../..';
|
|
2
|
-
import BaseReader from '../base';
|
|
3
|
-
declare class Reader<E, F extends FormItem<E>> extends BaseReader<E, F> {
|
|
4
|
-
/**
|
|
5
|
-
* Creates form items from the entity.
|
|
6
|
-
* @param entity - The entity to be read
|
|
7
|
-
* @returns Promise<Array<F>> - Created form items
|
|
8
|
-
*/
|
|
9
|
-
private createFormItemsFromEntity;
|
|
10
|
-
/**
|
|
11
|
-
* Reads form data from the entity.
|
|
12
|
-
* @param {E} entity - The entity to read form data from.
|
|
13
|
-
* @param form
|
|
14
|
-
*/
|
|
15
|
-
read(entity: E, form: Form<E, F>): Promise<void>;
|
|
16
|
-
}
|
|
17
|
-
export default Reader;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { Form, FormItem } from '../../..';
|
|
2
|
-
import BaseReader from '../base';
|
|
3
|
-
declare class Reader<E, F extends FormItem<E>> extends BaseReader<E, F> {
|
|
4
|
-
/**
|
|
5
|
-
* Retrieves the data for a specific property of the entity.
|
|
6
|
-
* @param entity - The entity from which to retrieve data.
|
|
7
|
-
* @param item - The form item that specifies the property and path.
|
|
8
|
-
* @returns The data for the specified property.
|
|
9
|
-
*/
|
|
10
|
-
private getPropertyData;
|
|
11
|
-
/**
|
|
12
|
-
* Reads data for each form item and updates their values.
|
|
13
|
-
* @param entity - The entity from which to read data.
|
|
14
|
-
* @param items - The array of form items to update.
|
|
15
|
-
*/
|
|
16
|
-
private readItemsData;
|
|
17
|
-
/**
|
|
18
|
-
* Reads form data from the entity.
|
|
19
|
-
* @param {E} entity - The entity to read form data from.
|
|
20
|
-
* @param form
|
|
21
|
-
*/
|
|
22
|
-
read(entity: E, form: Form<E, F>): Promise<void>;
|
|
23
|
-
}
|
|
24
|
-
export default Reader;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Form, FormItem } from '../../..';
|
|
2
|
-
import BaseReader from '../base';
|
|
3
|
-
declare class Reader<E, F extends FormItem<E>> extends BaseReader<E, F> {
|
|
4
|
-
/**
|
|
5
|
-
* Reads and initializes form items if they have an 'initialize' function.
|
|
6
|
-
* @param items - Array of form items.
|
|
7
|
-
*/
|
|
8
|
-
private readItemsData;
|
|
9
|
-
/**
|
|
10
|
-
* Reads form data from the entity.
|
|
11
|
-
* @param {E} entity - The entity to read form data from.
|
|
12
|
-
* @param form
|
|
13
|
-
*/
|
|
14
|
-
read(entity: E, form: Form<E, F>): Promise<void>;
|
|
15
|
-
}
|
|
16
|
-
export default Reader;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { FormItem, Form, IReader } from '../..';
|
|
2
|
-
/**
|
|
3
|
-
* Class for reading form data.
|
|
4
|
-
*/
|
|
5
|
-
declare class Reader<E, F extends FormItem<E>> implements IReader<E, F> {
|
|
6
|
-
/**
|
|
7
|
-
* Reads the form data from the provided entity.
|
|
8
|
-
* @param {E} entity - The entity to read form data from.
|
|
9
|
-
* @param {Form<E, F>} form - The form to write the metadata to.
|
|
10
|
-
*/
|
|
11
|
-
read(entity: E, form: Form<E, F>): Promise<void>;
|
|
12
|
-
}
|
|
13
|
-
export default Reader;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default as Reader } from './Reader';
|