@punica/form-mcp 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +49 -2
- package/bundled/form/controller/index.d.ts +73 -0
- package/bundled/form/decorator/Readers.d.ts +9 -0
- package/bundled/form/decorator/Services.d.ts +9 -0
- package/bundled/form/decorator/Starters.d.ts +9 -0
- package/bundled/form/decorator/index.d.ts +3 -0
- package/bundled/form/define/FormItem.d.ts +9 -0
- package/bundled/form/define/FormItemProperty.d.ts +8 -0
- package/bundled/form/define/FormProperty.d.ts +7 -0
- package/bundled/form/define/index.d.ts +3 -0
- package/bundled/form/index.d.ts +7 -0
- package/bundled/form/model/command/index.d.ts +2 -0
- package/bundled/form/model/command/item.d.ts +7 -0
- package/bundled/form/model/command/service.d.ts +15 -0
- package/bundled/form/model/constants/index.d.ts +4 -0
- package/bundled/form/model/form/index.d.ts +8 -0
- package/bundled/form/model/index.d.ts +8 -0
- package/bundled/form/model/item/index.d.ts +25 -0
- package/bundled/form/model/reader/index.d.ts +4 -0
- package/bundled/form/model/service/index.d.ts +20 -0
- package/bundled/form/model/starter/index.d.ts +13 -0
- package/bundled/form/model/util/GetItem.d.ts +9 -0
- package/bundled/form/model/util/WriteItems.d.ts +8 -0
- package/bundled/form/model/util/index.d.ts +2 -0
- package/bundled/form/package.json +1 -0
- package/bundled/form/reader/decorators/base/index.d.ts +35 -0
- package/bundled/form/reader/decorators/readers/FormItemsReader.d.ts +17 -0
- package/bundled/form/reader/decorators/readers/ItemDataReader.d.ts +24 -0
- package/bundled/form/reader/decorators/readers/ItemInitializerReader.d.ts +16 -0
- package/bundled/form/reader/decorators/readers/index.d.ts +3 -0
- package/bundled/form/reader/index.d.ts +19 -0
- package/bundled/form/reader/reader/Reader.d.ts +13 -0
- package/bundled/form/reader/reader/index.d.ts +1 -0
- package/bundled/form/register/index.d.ts +43 -0
- package/bundled/form/utils/deepCopy.d.ts +8 -0
- package/bundled/form/utils/devtools.d.ts +77 -0
- package/bundled/form/utils/index.d.ts +2 -0
- package/bundled/form-service/clearError/index.d.ts +23 -0
- package/bundled/form-service/clearErrors/index.d.ts +22 -0
- package/bundled/form-service/getValues/index.d.ts +22 -0
- package/bundled/form-service/index.d.ts +9 -0
- package/bundled/form-service/package.json +1 -0
- package/bundled/form-service/reset/index.d.ts +22 -0
- package/bundled/form-service/resetItem/index.d.ts +23 -0
- package/bundled/form-service/setValue/index.d.ts +23 -0
- package/bundled/form-service/store/index.d.ts +30 -0
- package/bundled/form-service/trigger/index.d.ts +22 -0
- package/bundled/form-service/validate/index.d.ts +27 -0
- package/package.json +46 -3
- package/src/create.mjs +128 -0
- package/src/guide.md +160 -0
- package/src/knowledge.mjs +141 -0
- package/src/load.mjs +41 -0
- package/src/main.mjs +12 -0
- package/src/validate.mjs +98 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Uryan Sezgin TEKE
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,50 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @punica/form-mcp
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
An [MCP](https://modelcontextprotocol.io) server that lets an AI assistant use
|
|
4
|
+
[Punica Form](https://form.punicalab.com) correctly: look up the exact API,
|
|
5
|
+
read the rules and check the code it wrote.
|
|
6
|
+
|
|
7
|
+
Punica Form is rarely in a model's training data, so without help a model
|
|
8
|
+
guesses imports, service names and methods. With this server it looks them up
|
|
9
|
+
and validates its answer.
|
|
10
|
+
|
|
11
|
+
## Tools
|
|
12
|
+
|
|
13
|
+
| Tool | What it does |
|
|
14
|
+
| --- | --- |
|
|
15
|
+
| `get_guide` | The rules: what the packages provide and what your application builds, the lifecycle, services, events and a complete example |
|
|
16
|
+
| `search_api` | Finds exports of `@punica/form` and `@punica/form-service` by name or documentation |
|
|
17
|
+
| `get_api` | The exact TypeScript declaration and documentation of one or more exports |
|
|
18
|
+
| `validate_code` | Checks code for imports that do not exist, wrong service names and service calls that do not exist; each problem with a fix |
|
|
19
|
+
|
|
20
|
+
Resources: `punica-form://guide` and `punica-form://api/<name>`.
|
|
21
|
+
|
|
22
|
+
The API is read from the type declarations of the `@punica/form` and
|
|
23
|
+
`@punica/form-service` installed in the project the server is started in, so
|
|
24
|
+
the answers match that version. Without them it uses the versions it was
|
|
25
|
+
built with.
|
|
26
|
+
|
|
27
|
+
## Set up
|
|
28
|
+
|
|
29
|
+
**Claude Code**
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
claude mcp add punica-form -- npx -y @punica/form-mcp
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
**Cursor** (`.cursor/mcp.json`), **VS Code** (`.vscode/mcp.json`, key `servers`), **Claude Desktop** and others:
|
|
36
|
+
|
|
37
|
+
```json
|
|
38
|
+
{
|
|
39
|
+
"mcpServers": {
|
|
40
|
+
"punica-form": { "command": "npx", "args": ["-y", "@punica/form-mcp"] }
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Development
|
|
46
|
+
|
|
47
|
+
```sh
|
|
48
|
+
pnpm build # in the repository root: builds the packages, then bundled/
|
|
49
|
+
pnpm --filter @punica/form-mcp test
|
|
50
|
+
```
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { BaseListener } from '@punica/common';
|
|
2
|
+
import { Form, FormEvents, FormItem, IServiceCommand, IServiceInitialize, IServiceControl } from '..';
|
|
3
|
+
/**
|
|
4
|
+
* Controller for managing a form and its associated services.
|
|
5
|
+
*/
|
|
6
|
+
export declare class FormController<E, F extends FormItem<E>> extends BaseListener<FormEvents> {
|
|
7
|
+
#private;
|
|
8
|
+
/**
|
|
9
|
+
* Private constructor to prevent direct instantiation.
|
|
10
|
+
*/
|
|
11
|
+
private constructor();
|
|
12
|
+
/**
|
|
13
|
+
* Static method to initialize the FormController with form data.
|
|
14
|
+
* @param form The initial form data
|
|
15
|
+
*/
|
|
16
|
+
static fromForm<E, F extends FormItem<E>>(form: Form<E, F>): Promise<FormController<E, F>>;
|
|
17
|
+
/**
|
|
18
|
+
* Static method to initialize the FormController with an entity.
|
|
19
|
+
* @param entity The entity for the form
|
|
20
|
+
*/
|
|
21
|
+
static fromEntity<E, F extends FormItem<E>>(entity: E): Promise<FormController<E, F>>;
|
|
22
|
+
/**
|
|
23
|
+
* Trigger a form event.
|
|
24
|
+
* @param eventType The type of the event
|
|
25
|
+
* @param data Data associated with the event
|
|
26
|
+
*/
|
|
27
|
+
private fireEvent;
|
|
28
|
+
/**
|
|
29
|
+
* Send entity data to DevTools
|
|
30
|
+
*/
|
|
31
|
+
private sendEntityToDevTools;
|
|
32
|
+
/**
|
|
33
|
+
* Create a command service for the form.
|
|
34
|
+
* @returns A CommandService for the form
|
|
35
|
+
*/
|
|
36
|
+
private createCommandService;
|
|
37
|
+
/**
|
|
38
|
+
* Registers form items by triggering the REGISTER_ITEMS event.
|
|
39
|
+
*/
|
|
40
|
+
private registerFormItems;
|
|
41
|
+
/**
|
|
42
|
+
* Maps form items to their properties.
|
|
43
|
+
*/
|
|
44
|
+
private mapFormItems;
|
|
45
|
+
/**
|
|
46
|
+
* Initializes the services defined in the form data.
|
|
47
|
+
*/
|
|
48
|
+
private initializeServices;
|
|
49
|
+
/**
|
|
50
|
+
* Executes the readers defined in the form data.
|
|
51
|
+
*/
|
|
52
|
+
private runReaders;
|
|
53
|
+
/**
|
|
54
|
+
* Executes the starters defined in the form data.
|
|
55
|
+
*/
|
|
56
|
+
private runStarters;
|
|
57
|
+
/**
|
|
58
|
+
* Keeps a deep copy of the form items for the initial state.
|
|
59
|
+
* Services, readers and starters are shared, not copied.
|
|
60
|
+
*/
|
|
61
|
+
private deepCopyForm;
|
|
62
|
+
/**
|
|
63
|
+
* Get services by their names.
|
|
64
|
+
* Overloads to return a single item or an array based on provided names.
|
|
65
|
+
*/
|
|
66
|
+
getServices<T = IServiceInitialize<E, F> & IServiceControl & IServiceCommand>(serviceName: string): T;
|
|
67
|
+
getServices<T = IServiceInitialize<E, F> & IServiceControl & IServiceCommand>(serviceName: string, ...additionalServiceNames: string[]): T[];
|
|
68
|
+
/**
|
|
69
|
+
* Starts the form controller by executing all necessary steps to initialize the form.
|
|
70
|
+
* @returns A promise that resolves when the form is fully initialized.
|
|
71
|
+
*/
|
|
72
|
+
start(): Promise<Form<E, F>>;
|
|
73
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FormItem, IReader } from '..';
|
|
2
|
+
/**
|
|
3
|
+
* Constant for identifying form readers decorator.
|
|
4
|
+
*/
|
|
5
|
+
export declare const DECORATOR_READERS = "form-readers";
|
|
6
|
+
/**
|
|
7
|
+
* Decorator for adding readers to a form class.
|
|
8
|
+
*/
|
|
9
|
+
export declare const Readers: <E, F extends FormItem<E>>(data: IReader<E, F>[]) => ClassDecorator;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IService } from '..';
|
|
2
|
+
/**
|
|
3
|
+
* Constant for identifying form services decorator.
|
|
4
|
+
*/
|
|
5
|
+
export declare const DECORATOR_SERVICES = "form-services";
|
|
6
|
+
/**
|
|
7
|
+
* Decorator for adding services to a form class.
|
|
8
|
+
*/
|
|
9
|
+
export declare const Services: (data: Array<IService>) => ClassDecorator;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FormItem, IStarter } from '..';
|
|
2
|
+
/**
|
|
3
|
+
* Constant for identifying form starters decorator.
|
|
4
|
+
*/
|
|
5
|
+
export declare const DECORATOR_STARTERS = "form-starters";
|
|
6
|
+
/**
|
|
7
|
+
* Decorator for adding starters to a form class.
|
|
8
|
+
*/
|
|
9
|
+
export declare const Starters: <E, F extends FormItem<E>>(data: IStarter<E, F>[]) => ClassDecorator;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IPropertyDecorator } from '@punica/common';
|
|
2
|
+
/**
|
|
3
|
+
* Defines a form item with the specified type and renderer.
|
|
4
|
+
* @param {string} type - Type of the form item.
|
|
5
|
+
* @param {Function} renderer - Renderer function for the form item.
|
|
6
|
+
* @returns {IPropertyDecorator<T>} - Decorator function.
|
|
7
|
+
*/
|
|
8
|
+
declare const defineFormItem: <T>(type: string, renderer: (props: T) => any) => IPropertyDecorator<T>;
|
|
9
|
+
export default defineFormItem;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IPropertyDecorator } from '@punica/common';
|
|
2
|
+
/**
|
|
3
|
+
* Defines a form item with the specified type and renderer.
|
|
4
|
+
* @param {string} type - Type of the form item.
|
|
5
|
+
* @returns {IPropertyDecorator<T>} - Decorator function.
|
|
6
|
+
*/
|
|
7
|
+
declare const defineFormItemProperty: <T>(type: string) => IPropertyDecorator<T>;
|
|
8
|
+
export default defineFormItemProperty;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defines a form property with the specified type.
|
|
3
|
+
* @param {string} type - Type of the form property.
|
|
4
|
+
* @returns {ClassDecorator<T>} - Decorator function.
|
|
5
|
+
*/
|
|
6
|
+
declare const defineFormProperty: <T>(type: string) => (data: T) => ClassDecorator;
|
|
7
|
+
export default defineFormProperty;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Form, FormEvents, FormItem } from '..';
|
|
2
|
+
import { CommandItem } from '.';
|
|
3
|
+
/**
|
|
4
|
+
* Defines the structure of the CommandService.
|
|
5
|
+
*/
|
|
6
|
+
export type CommandService<E, F extends FormItem<E>> = {
|
|
7
|
+
initialForm: Form<E, F>;
|
|
8
|
+
initialEntity: E;
|
|
9
|
+
form: Form<E, F>;
|
|
10
|
+
itemsMap: Record<keyof E, number>;
|
|
11
|
+
createCommandItem: (item: F) => Promise<CommandItem<E, F>>;
|
|
12
|
+
fireEvent: (eventType: FormEvents, data: any) => void;
|
|
13
|
+
getItem: (property: keyof E) => F;
|
|
14
|
+
writeItems: (items: Array<FormItem<E>>) => Promise<void>;
|
|
15
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { FormItem, IReader, IService, IStarter } from '../..';
|
|
2
|
+
export type Form<E = any, F extends FormItem<E> = any> = {
|
|
3
|
+
items: Array<F>;
|
|
4
|
+
services?: Array<IService>;
|
|
5
|
+
readers?: Array<IReader<E, F>>;
|
|
6
|
+
starters?: Array<IStarter<E, F>>;
|
|
7
|
+
[key: string]: any;
|
|
8
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { CommandItem } from '../command';
|
|
2
|
+
export type FormItem<E> = {
|
|
3
|
+
property: keyof E;
|
|
4
|
+
path?: string;
|
|
5
|
+
label: string;
|
|
6
|
+
required?: boolean;
|
|
7
|
+
type?: string;
|
|
8
|
+
value?: any;
|
|
9
|
+
error?: boolean;
|
|
10
|
+
errorMessages?: Array<string>;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
hidden?: boolean;
|
|
13
|
+
getData?: (params?: any) => Promise<any>;
|
|
14
|
+
setValue?: (property: keyof E, value: any) => Promise<void>;
|
|
15
|
+
control?: (command: CommandItem<E, any>) => Promise<Array<FormItem<E>>>;
|
|
16
|
+
submitted?: (command: CommandItem<E, any>) => Promise<void>;
|
|
17
|
+
initialize?: (command: CommandItem<E, any>) => Promise<Array<FormItem<E>>>;
|
|
18
|
+
validation?: (command: CommandItem<E, any>) => Promise<ErrorDetail>;
|
|
19
|
+
[key: string]: any;
|
|
20
|
+
};
|
|
21
|
+
export type ErrorDetail = {
|
|
22
|
+
error: boolean;
|
|
23
|
+
errorMessages?: Array<string>;
|
|
24
|
+
[key: string]: any;
|
|
25
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { CommandService, Form, FormItem } from '..';
|
|
2
|
+
export interface IService {
|
|
3
|
+
get name(): string;
|
|
4
|
+
}
|
|
5
|
+
export interface IServiceInitialize<E, F extends FormItem<E>> extends IService {
|
|
6
|
+
initialize: (command: CommandService<E, F>) => Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
export interface IServiceControl<T = any> extends IService {
|
|
9
|
+
run: (...args: any[]) => Promise<T>;
|
|
10
|
+
}
|
|
11
|
+
export interface IServiceCommand extends IService {
|
|
12
|
+
addCustomFeaturesForCommandItem: () => {
|
|
13
|
+
[key: string]: any;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export interface IServiceStartup<E, F extends FormItem<E>> extends IService {
|
|
17
|
+
start: (entity: E, form: Form<E, F>) => {
|
|
18
|
+
[key: string]: any;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Form, FormItem } from '..';
|
|
2
|
+
/**
|
|
3
|
+
* Interface representing a Starter for initializing form data.
|
|
4
|
+
*/
|
|
5
|
+
export interface IStarter<E, F extends FormItem<E>> {
|
|
6
|
+
/**
|
|
7
|
+
* Function to run the starter logic.
|
|
8
|
+
* @param form - The current form data.
|
|
9
|
+
* @param entity - The entity associated with the form.
|
|
10
|
+
* @returns A Promise that resolves to the updated form data after initialization.
|
|
11
|
+
*/
|
|
12
|
+
run: (form: Form<E, F>, entity: E) => Promise<Form<E, F>>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
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;
|
|
@@ -0,0 +1,8 @@
|
|
|
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>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":"1.2.0"}
|
|
@@ -0,0 +1,35 @@
|
|
|
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;
|
|
@@ -0,0 +1,17 @@
|
|
|
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;
|
|
@@ -0,0 +1,24 @@
|
|
|
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;
|
|
@@ -0,0 +1,16 @@
|
|
|
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;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { IReader } from '..';
|
|
2
|
+
/**
|
|
3
|
+
* Decorator Design Pattern for a Reader System
|
|
4
|
+
*
|
|
5
|
+
* - The `IReader` interface defines the contract for all types of readers.
|
|
6
|
+
* - The `Reader` class serves as the base reader.
|
|
7
|
+
* - Decorators are implemented as classes (e.g., `FormItemsReader`, `ItemDataReader`, `ItemInitializerReader`) that wrap existing readers and enhance their behavior.
|
|
8
|
+
* - The `createInitialReader` function creates an initial reader object with a chain of decorators applied.
|
|
9
|
+
*
|
|
10
|
+
* - `FormItemsReader` adds functionality related to reading form items.
|
|
11
|
+
* - `ItemDataReader` adds functionality related to reading item data.
|
|
12
|
+
* - `ItemInitializerReader` adds functionality related to initializing items.
|
|
13
|
+
*
|
|
14
|
+
* - The final `itemInitializerReader` returned by `createInitialReader` has all the decorators chained together,
|
|
15
|
+
* creating a powerful reader object that can perform a series of operations in a coordinated way.
|
|
16
|
+
*
|
|
17
|
+
* @returns {IReader<any, any>} - Initial reader object with a chain of decorators.
|
|
18
|
+
*/
|
|
19
|
+
export declare const createInitialReader: () => IReader<any, any>;
|
|
@@ -0,0 +1,13 @@
|
|
|
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;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as Reader } from './Reader';
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { FormItem } from '..';
|
|
2
|
+
type Render<F> = (props: F) => any;
|
|
3
|
+
export declare class FormItemRegister<E, F extends FormItem<E>> {
|
|
4
|
+
#private;
|
|
5
|
+
private static _instance;
|
|
6
|
+
/**
|
|
7
|
+
* Private constructor to prevent external instantiation.
|
|
8
|
+
*/
|
|
9
|
+
private constructor();
|
|
10
|
+
/**
|
|
11
|
+
* Singleton pattern: Get the instance of FormItemRegister.
|
|
12
|
+
* @returns The instance of FormItemRegister.
|
|
13
|
+
*/
|
|
14
|
+
static getInstance(): FormItemRegister<any, any>;
|
|
15
|
+
/**
|
|
16
|
+
* Register a form item property with its corresponding renderer.
|
|
17
|
+
* @param property - The form item property.
|
|
18
|
+
* @param renderer - The rendering function for the form item.
|
|
19
|
+
*/
|
|
20
|
+
register(property: string, renderer: (props: F) => any): void;
|
|
21
|
+
/**
|
|
22
|
+
* Unregister a form item property.
|
|
23
|
+
* @param property - The form item property to unregister.
|
|
24
|
+
*/
|
|
25
|
+
unRegister(property: string): void;
|
|
26
|
+
/**
|
|
27
|
+
* Get the rendering function for a specific form item property.
|
|
28
|
+
* @param property - The form item property.
|
|
29
|
+
* @returns The rendering function for the specified property.
|
|
30
|
+
*/
|
|
31
|
+
getItem(property: string): Render<F>;
|
|
32
|
+
/**
|
|
33
|
+
* Get all registered form item properties and their corresponding renderers.
|
|
34
|
+
* @returns A map containing form item properties and their renderers.
|
|
35
|
+
*/
|
|
36
|
+
getItems(): Map<string, Render<F>>;
|
|
37
|
+
/**
|
|
38
|
+
* Get an iterable of all registered form item properties.
|
|
39
|
+
* @returns An iterable of form item properties.
|
|
40
|
+
*/
|
|
41
|
+
getItemKeys(): IterableIterator<string>;
|
|
42
|
+
}
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a deep copy of the given value.
|
|
3
|
+
* Functions are kept by reference, prototypes are preserved and
|
|
4
|
+
* circular references are supported.
|
|
5
|
+
* @param value - The value to copy
|
|
6
|
+
* @returns The copied value
|
|
7
|
+
*/
|
|
8
|
+
export declare const deepCopy: <T>(value: T, seen?: WeakMap<object, any>) => T;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Form, FormItem } from '../model';
|
|
2
|
+
/**
|
|
3
|
+
* Marker used by the DevTools extension to recognize bridge messages
|
|
4
|
+
*/
|
|
5
|
+
export declare const DEVTOOLS_MESSAGE_SOURCE = "punica-form-devtools";
|
|
6
|
+
/**
|
|
7
|
+
* DevTools bridge for sending form events to Chrome DevTools extension
|
|
8
|
+
*/
|
|
9
|
+
declare class DevToolsBridge {
|
|
10
|
+
private static instance;
|
|
11
|
+
private enabled;
|
|
12
|
+
/**
|
|
13
|
+
* Get singleton instance
|
|
14
|
+
*/
|
|
15
|
+
static getInstance(): DevToolsBridge;
|
|
16
|
+
/**
|
|
17
|
+
* Enable DevTools bridge
|
|
18
|
+
*/
|
|
19
|
+
enable(): void;
|
|
20
|
+
/**
|
|
21
|
+
* Disable DevTools bridge
|
|
22
|
+
*/
|
|
23
|
+
disable(): void;
|
|
24
|
+
/**
|
|
25
|
+
* Check if DevTools bridge is enabled
|
|
26
|
+
*/
|
|
27
|
+
isEnabled(): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Send message to DevTools extension
|
|
30
|
+
*/
|
|
31
|
+
private sendMessage;
|
|
32
|
+
/**
|
|
33
|
+
* Send initialization event
|
|
34
|
+
*/
|
|
35
|
+
sendInit<E, F extends FormItem<E>>(form: Form<E, F>): void;
|
|
36
|
+
/**
|
|
37
|
+
* Send entity data
|
|
38
|
+
*/
|
|
39
|
+
sendEntity<E>(entity: E): void;
|
|
40
|
+
/**
|
|
41
|
+
* Send form update event
|
|
42
|
+
*/
|
|
43
|
+
sendUpdate<E, F extends FormItem<E>>(form: Form<E, F>): void;
|
|
44
|
+
/**
|
|
45
|
+
* Send form reset event
|
|
46
|
+
*/
|
|
47
|
+
sendReset<E, F extends FormItem<E>>(form: Form<E, F>): void;
|
|
48
|
+
/**
|
|
49
|
+
* Send item update event
|
|
50
|
+
*/
|
|
51
|
+
sendUpdateItem<E, F extends FormItem<E>>(item: F | F[]): void;
|
|
52
|
+
/**
|
|
53
|
+
* Send register items event
|
|
54
|
+
*/
|
|
55
|
+
sendRegisterItems(itemKeys: string[]): void;
|
|
56
|
+
/**
|
|
57
|
+
* Send property value update event
|
|
58
|
+
*/
|
|
59
|
+
sendUpdatePropertyValue<E, F extends FormItem<E>>(property: keyof E, value: any, item: F): void;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Get DevTools bridge instance
|
|
63
|
+
*/
|
|
64
|
+
export declare const getDevToolsBridge: () => DevToolsBridge;
|
|
65
|
+
/**
|
|
66
|
+
* Enable DevTools bridge
|
|
67
|
+
*/
|
|
68
|
+
export declare const enableDevTools: () => void;
|
|
69
|
+
/**
|
|
70
|
+
* Disable DevTools bridge
|
|
71
|
+
*/
|
|
72
|
+
export declare const disableDevTools: () => void;
|
|
73
|
+
/**
|
|
74
|
+
* Check if DevTools bridge is enabled
|
|
75
|
+
*/
|
|
76
|
+
export declare const isDevToolsEnabled: () => boolean;
|
|
77
|
+
export {};
|