@punica/form-mcp 0.1.0 → 0.2.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/controller/index.d.ts +43 -53
- 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 +20 -0
- package/bundled/form/model/command/item.d.ts +11 -5
- package/bundled/form/model/command/service.d.ts +19 -10
- package/bundled/form/model/constants/index.d.ts +13 -2
- package/bundled/form/model/form/index.d.ts +8 -4
- package/bundled/form/model/index.d.ts +0 -1
- package/bundled/form/model/item/index.d.ts +27 -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 +8 -16
- package/bundled/form/register/index.d.ts +26 -39
- 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 +1 -1
- 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 +7 -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 +7 -0
- package/package.json +3 -3
- package/src/create.mjs +4 -4
- package/src/guide.md +81 -57
- package/src/knowledge.mjs +2 -2
- package/src/validate.mjs +61 -48
- 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,108 @@ 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: `useSyncExternalStore(controller.subscribe, controller.getForm)`.
|
|
51
|
+
Never change a form or an item in place; use the services.
|
|
37
52
|
|
|
38
53
|
## Services
|
|
39
54
|
|
|
40
|
-
Services are
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
| Class |
|
|
44
|
-
|
|
45
|
-
| `Validate` | `
|
|
46
|
-
| `
|
|
47
|
-
| `
|
|
48
|
-
| `
|
|
49
|
-
| `
|
|
50
|
-
| `
|
|
51
|
-
| `
|
|
52
|
-
| `
|
|
53
|
-
| `Store` |
|
|
55
|
+
Services are read by class and executed with `run`. They are bound to the
|
|
56
|
+
entity of the form, so property names and results are type-checked.
|
|
57
|
+
|
|
58
|
+
| Class | Call |
|
|
59
|
+
|---|---|
|
|
60
|
+
| `Validate` | `run(): Promise<boolean>`, validates every visible item |
|
|
61
|
+
| `Trigger` | `run(property): Promise<void>`, validates one item |
|
|
62
|
+
| `GetValues` | `run(): Promise<E>`, a copy of the entity filled with the item values |
|
|
63
|
+
| `SetValue` | `run(property, value): Promise<void>`, then runs the `control` function of the item |
|
|
64
|
+
| `Reset` | `run(): Promise<void>` |
|
|
65
|
+
| `ResetItem` | `run(property): Promise<void>` |
|
|
66
|
+
| `ClearError` | `run(property): Promise<void>` |
|
|
67
|
+
| `ClearErrors` | `run(): Promise<void>` |
|
|
68
|
+
| `Store` | no `run`: it adds `readStoreItem`, `writeStoreItem`, `deleteStoreItem` to the command passed to item functions (`CommandItem<E, F, StoreCommand>`) |
|
|
54
69
|
|
|
55
70
|
```ts
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
await controller.
|
|
59
|
-
await
|
|
71
|
+
import { GetValues, SetValue, Trigger, Validate } from "@punica/form-service";
|
|
72
|
+
|
|
73
|
+
await controller.getService(SetValue).run("name", "Jane");
|
|
74
|
+
await controller.getService(Trigger).run("name");
|
|
75
|
+
|
|
76
|
+
if (await controller.getService(Validate).run()) {
|
|
77
|
+
const values = await controller.getService(GetValues).run();
|
|
78
|
+
}
|
|
60
79
|
```
|
|
61
80
|
|
|
62
81
|
- A service works only when it is listed in `@Services([...])`;
|
|
63
|
-
`
|
|
64
|
-
- There is no `
|
|
65
|
-
`
|
|
82
|
+
`getService` throws for a class that is not.
|
|
83
|
+
- There is no `getServices('name')`, no `validate(form)`, no
|
|
84
|
+
`item.setValue(…)` and no `validateItem(…)`.
|
|
66
85
|
- `Validate.run()` returns `false` when the form is invalid. Other failures
|
|
67
86
|
(an unknown property, an error thrown by a validation function) reject.
|
|
68
|
-
- Setting a value does not validate it.
|
|
87
|
+
- Setting a value does not validate it. Run `Trigger` for that.
|
|
69
88
|
|
|
70
89
|
## Form items
|
|
71
90
|
|
|
72
91
|
A form item is a plain object: `property`, `label`, `type`, `value`,
|
|
73
|
-
`required`, `disabled`, `hidden`, `error`, `errorMessages
|
|
74
|
-
|
|
75
|
-
|
|
92
|
+
`required`, `disabled`, `hidden`, `error`, `errorMessages`. Add the
|
|
93
|
+
properties of your form system with a type of your own:
|
|
94
|
+
`type AppItem<E> = FormItem<E> & { layout?: Layout }`, then use
|
|
95
|
+
`FormController<UserForm, AppItem<UserForm>>`.
|
|
96
|
+
|
|
97
|
+
The functions of an item receive a command `{ formItem, initialEntity,
|
|
98
|
+
getItem }` holding copies, and return items instead of changing them:
|
|
76
99
|
|
|
77
100
|
- `validation(command): Promise<{ error: boolean, errorMessages?: string[] }>`
|
|
78
101
|
- `control(command): Promise<FormItem[]>`, run after its value is set; the
|
|
79
|
-
returned items are written
|
|
102
|
+
returned items are written to the form
|
|
80
103
|
- `initialize(command): Promise<FormItem[]>`, run once while the form is created
|
|
81
104
|
|
|
82
105
|
## Events
|
|
83
106
|
|
|
84
|
-
`controller.on(event, handler)`
|
|
85
|
-
handler
|
|
107
|
+
`controller.on(event, handler)` returns the function that removes the
|
|
108
|
+
handler. Payloads are typed.
|
|
86
109
|
|
|
87
110
|
| Event | Payload |
|
|
88
111
|
|---|---|
|
|
89
|
-
| `UPDATE_FORM` | the form; fired
|
|
112
|
+
| `UPDATE_FORM` | the form; fired after every change |
|
|
90
113
|
| `UPDATE_ITEM` | an array: the changed item, then the items its `control` returned |
|
|
91
|
-
| `RESET` | the form; fired by `Reset`,
|
|
114
|
+
| `RESET` | the form; fired by `Reset`, after `UPDATE_FORM` |
|
|
92
115
|
| `REGISTER_ITEMS` | `string[]` of registered form item types; fired at the start of `start()` |
|
|
93
116
|
|
|
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
117
|
## A complete example
|
|
98
118
|
|
|
99
119
|
The application's form system:
|
|
100
120
|
|
|
101
121
|
```tsx
|
|
102
|
-
import {
|
|
122
|
+
import {
|
|
123
|
+
defineFormItem,
|
|
124
|
+
defineFormProperty,
|
|
125
|
+
getFormProperty,
|
|
126
|
+
type Form,
|
|
127
|
+
type FormItem,
|
|
128
|
+
type IReader,
|
|
129
|
+
} from "@punica/form";
|
|
103
130
|
|
|
104
131
|
export const Title = defineFormProperty<string>("app:title");
|
|
105
132
|
|
|
106
133
|
export class Reader<E extends object, F extends FormItem<E>> implements IReader<E, F> {
|
|
107
|
-
public
|
|
108
|
-
form.title =
|
|
134
|
+
public read(entity: E, form: Form<E, F>): void {
|
|
135
|
+
form.title = getFormProperty<string>(entity, "app:title");
|
|
109
136
|
}
|
|
110
137
|
}
|
|
111
138
|
|
|
112
|
-
// The second argument is the renderer;
|
|
139
|
+
// The second argument is the renderer; defaultFormItemRegister.getItem(item.type) returns it
|
|
113
140
|
export const FormItemInputText = defineFormItem<Omit<FormItem<any>, "property">>(
|
|
114
141
|
"app:input-text",
|
|
115
142
|
InputText
|
|
@@ -119,7 +146,7 @@ export const FormItemInputText = defineFormItem<Omit<FormItem<any>, "property">>
|
|
|
119
146
|
A business form:
|
|
120
147
|
|
|
121
148
|
```ts
|
|
122
|
-
import { Readers, Services
|
|
149
|
+
import { Readers, Services } from "@punica/form";
|
|
123
150
|
import { GetValues, SetValue, Trigger, Validate } from "@punica/form-service";
|
|
124
151
|
import { FormItemInputText, Reader, Title } from "./formSystem";
|
|
125
152
|
|
|
@@ -130,7 +157,7 @@ export class UserForm {
|
|
|
130
157
|
@FormItemInputText({
|
|
131
158
|
label: "Name",
|
|
132
159
|
required: true,
|
|
133
|
-
validation: async ({ formItem })
|
|
160
|
+
validation: async ({ formItem }) => ({
|
|
134
161
|
error: !formItem.value,
|
|
135
162
|
errorMessages: formItem.value ? [] : ["Name is required"],
|
|
136
163
|
}),
|
|
@@ -142,18 +169,15 @@ export class UserForm {
|
|
|
142
169
|
Using it:
|
|
143
170
|
|
|
144
171
|
```ts
|
|
145
|
-
const controller = await FormController.fromEntity
|
|
146
|
-
|
|
147
|
-
controller.on("UPDATE_FORM", (data) => render(data as Form<UserForm, FormItem<UserForm>>));
|
|
172
|
+
const controller = await FormController.fromEntity(new UserForm());
|
|
148
173
|
|
|
149
|
-
|
|
150
|
-
|
|
174
|
+
controller.subscribe(() => render(controller.getForm()));
|
|
175
|
+
await controller.start();
|
|
151
176
|
|
|
152
|
-
await
|
|
153
|
-
await controller.getServices("trigger").run("name");
|
|
177
|
+
await controller.getService(SetValue).run("name", "Jane");
|
|
154
178
|
|
|
155
|
-
if (await controller.
|
|
156
|
-
const values = await controller.
|
|
179
|
+
if (await controller.getService(Validate).run()) {
|
|
180
|
+
const values = await controller.getService(GetValues).run(); // UserForm
|
|
157
181
|
}
|
|
158
182
|
```
|
|
159
183
|
|
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,63 @@ 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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
+
];
|
|
22
69
|
|
|
23
70
|
/**
|
|
24
71
|
* @param {string} code
|
|
25
|
-
* @returns {Array<{ line: number, rule: string, message: string, fix
|
|
72
|
+
* @returns {Array<{ line: number, rule: string, message: string, fix: string }>}
|
|
26
73
|
*/
|
|
27
74
|
function validate(code) {
|
|
28
75
|
const findings = [];
|
|
@@ -51,46 +98,12 @@ export function createValidator(knowledge) {
|
|
|
51
98
|
}
|
|
52
99
|
}
|
|
53
100
|
|
|
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
|
-
}
|
|
101
|
+
for (const { rule, pattern, message, fix } of rules) {
|
|
102
|
+
for (const match of code.matchAll(pattern)) {
|
|
103
|
+
add(match.index, rule, typeof message === 'string' ? message : message(match), fix(match));
|
|
64
104
|
}
|
|
65
105
|
}
|
|
66
106
|
|
|
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
107
|
return findings.sort((a, b) => a.line - b.line);
|
|
95
108
|
}
|
|
96
109
|
|
|
@@ -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';
|