@kubuild/core 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/README.md +122 -0
- package/dist/commands.d.ts +26 -2
- package/dist/commands.d.ts.map +1 -1
- package/dist/conditional-resolver.d.ts +45 -0
- package/dist/conditional-resolver.d.ts.map +1 -0
- package/dist/index.cjs +1314 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1288 -1
- package/dist/index.js.map +1 -1
- package/dist/interpolator.d.ts +50 -0
- package/dist/interpolator.d.ts.map +1 -0
- package/dist/pipeline-executor.d.ts +136 -0
- package/dist/pipeline-executor.d.ts.map +1 -0
- package/dist/state-store.d.ts +128 -0
- package/dist/state-store.d.ts.map +1 -0
- package/dist/validation-engine.d.ts +39 -0
- package/dist/validation-engine.d.ts.map +1 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# @kubuild/core
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@kubuild/core)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
[](https://www.typescriptlang.org/)
|
|
6
|
+
|
|
7
|
+
Framework-agnostic engine for **KUBUILD**: document tree utilities, command engine, history stack (undo/redo), Action Pipeline Executor, Runtime State Store, Validation Engine, template interpolation, migration, and export/import.
|
|
8
|
+
|
|
9
|
+
Core contains **zero UI/DOM dependencies** and runs seamlessly in Node.js, Cloudflare Workers, Electron, and the browser.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## 📦 Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
# Using pnpm (recommended)
|
|
17
|
+
pnpm add @kubuild/core @kubuild/schema
|
|
18
|
+
|
|
19
|
+
# Using npm
|
|
20
|
+
npm install @kubuild/core @kubuild/schema
|
|
21
|
+
|
|
22
|
+
# Using yarn
|
|
23
|
+
yarn add @kubuild/core @kubuild/schema
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## ✨ Features
|
|
29
|
+
|
|
30
|
+
- **Document Tree Manipulation**: Safe operations for finding, inserting, moving, cloning, and removing nodes (`findNodeById`, `insertNode`, `removeNode`, `moveNode`).
|
|
31
|
+
- **Command Engine & History**: Transactional command pattern with an undo/redo stack (`CommandEngine`, `InsertNodeCommand`, `UpdateNodePropsCommand`, `UpdateNodeStylesCommand`).
|
|
32
|
+
- **Action Pipeline Executor**: Comprehensive runner for executing multi-step action flows (`ActionPipelineExecutor`), evaluating success/error branches and conditional expressions.
|
|
33
|
+
- **Runtime State Store**: Lightweight reactive store (`RuntimeStateStore`) for managing form values, execution logs, response data, and runtime variables.
|
|
34
|
+
- **Validation Engine**: Built-in validators for form fields and models (required, email, regex, min/max length, custom rules).
|
|
35
|
+
- **Template Interpolation**: Powerful variable interpolation supporting syntax like `{{form.name}}`, `{{user.id}}`, or `{{response.data}}`.
|
|
36
|
+
- **Portable Export & Import**: Pack page documents and assets into portable `.stora` archives (compressed zip via `fflate`) and unpack them back into memory.
|
|
37
|
+
- **Security Defense**: Strict XSS prevention, safe URL sanitization, and style value validation.
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## 🚀 Quick Usage
|
|
42
|
+
|
|
43
|
+
### Command Engine & Undo/Redo
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
import { CommandEngine, InsertNodeCommand } from '@kubuild/core';
|
|
47
|
+
import type { PageDocument, Node } from '@kubuild/schema';
|
|
48
|
+
|
|
49
|
+
const engine = new CommandEngine(initialPageDocument);
|
|
50
|
+
|
|
51
|
+
// Execute a command to insert a new node
|
|
52
|
+
const buttonNode: Node = {
|
|
53
|
+
id: 'btn-1',
|
|
54
|
+
type: 'button',
|
|
55
|
+
props: { label: 'Click Me' },
|
|
56
|
+
styles: { backgroundColor: '#3b82f6', color: '#ffffff' }
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
engine.execute(new InsertNodeCommand(engine.getDocument(), 'root-1', buttonNode));
|
|
60
|
+
|
|
61
|
+
// Undo the insertion
|
|
62
|
+
engine.undo();
|
|
63
|
+
|
|
64
|
+
// Redo the insertion
|
|
65
|
+
engine.redo();
|
|
66
|
+
|
|
67
|
+
const currentDoc: PageDocument = engine.getDocument();
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Action Pipeline Execution & Interpolation
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
import {
|
|
74
|
+
ActionPipelineExecutor,
|
|
75
|
+
RuntimeStateStore,
|
|
76
|
+
interpolateTemplate
|
|
77
|
+
} from '@kubuild/core';
|
|
78
|
+
import type { ActionPipeline } from '@kubuild/schema';
|
|
79
|
+
|
|
80
|
+
// 1. Initialize State Store
|
|
81
|
+
const stateStore = new RuntimeStateStore({
|
|
82
|
+
form: { email: 'user@example.com', name: 'Alex' },
|
|
83
|
+
user: { role: 'admin' }
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// 2. Interpolate template string
|
|
87
|
+
const greeting = interpolateTemplate('Hello {{form.name}}! Role: {{user.role}}', stateStore.getState());
|
|
88
|
+
console.log(greeting); // "Hello Alex! Role: admin"
|
|
89
|
+
|
|
90
|
+
// 3. Execute Pipeline
|
|
91
|
+
const executor = new ActionPipelineExecutor({
|
|
92
|
+
stateStore,
|
|
93
|
+
runners: {
|
|
94
|
+
async apiRequest(step, context) {
|
|
95
|
+
const response = await fetch(step.config.url, { method: step.config.method });
|
|
96
|
+
return await response.json();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
const result = await executor.execute(pipelineDefinition);
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Exporting & Importing `.stora` Files
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
import { exportStoraArchive, importStoraArchive } from '@kubuild/core';
|
|
108
|
+
|
|
109
|
+
// Export document to binary .stora buffer (zip)
|
|
110
|
+
const storaBuffer: Uint8Array = await exportStoraArchive(pageDocument, {
|
|
111
|
+
includeAssets: true
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
// Import .stora buffer back into validated PageDocument
|
|
115
|
+
const importedDocument = await importStoraArchive(storaBuffer);
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
## 📄 License
|
|
121
|
+
|
|
122
|
+
MIT © [KUBUILD](https://github.com/kustora/kubuild)
|
package/dist/commands.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { PageDocument, Node, ResponsiveStyles, StyleDefinition, AnimationConfig } from '@kubuild/schema';
|
|
2
|
-
export type DocumentChangeType = 'NODE_INSERTED' | 'NODE_MOVED' | 'PROPS_UPDATED' | 'STYLE_UPDATED' | 'ANIMATION_UPDATED' | 'NODE_REMOVED' | 'NODE_DUPLICATED';
|
|
1
|
+
import { PageDocument, Node, ResponsiveStyles, StyleDefinition, AnimationConfig, ActionPipeline, FormConfig } from '@kubuild/schema';
|
|
2
|
+
export type DocumentChangeType = 'NODE_INSERTED' | 'NODE_MOVED' | 'PROPS_UPDATED' | 'STYLE_UPDATED' | 'ANIMATION_UPDATED' | 'ACTIONS_UPDATED' | 'FORM_CONFIG_UPDATED' | 'NODE_REMOVED' | 'NODE_DUPLICATED';
|
|
3
3
|
export interface DocumentChangeEvent {
|
|
4
4
|
type: DocumentChangeType;
|
|
5
5
|
timestamp: string;
|
|
@@ -111,4 +111,28 @@ export interface UpdateAnimationParams {
|
|
|
111
111
|
* Returns a new PageDocument and an ANIMATION_UPDATED event.
|
|
112
112
|
*/
|
|
113
113
|
export declare function updateAnimation(document: PageDocument, params: UpdateAnimationParams): CommandResult;
|
|
114
|
+
export interface UpdateActionsParams {
|
|
115
|
+
nodeId: string;
|
|
116
|
+
actions: ActionPipeline[] | null;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* 8. Update the action pipelines of an existing node.
|
|
120
|
+
* Returns a new PageDocument and an ACTIONS_UPDATED event.
|
|
121
|
+
*/
|
|
122
|
+
export declare function updateActions(document: PageDocument, params: UpdateActionsParams): CommandResult;
|
|
123
|
+
export interface UpdateFormConfigParams {
|
|
124
|
+
nodeId: string;
|
|
125
|
+
formConfig: Partial<FormConfig> | null;
|
|
126
|
+
/**
|
|
127
|
+
* If true (default), shallow merges new formConfig properties with existing config.
|
|
128
|
+
* If false, replaces the formConfig with the provided object.
|
|
129
|
+
* If formConfig is null, removes the form configuration from the node.
|
|
130
|
+
*/
|
|
131
|
+
merge?: boolean;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* 9. Update the form configuration of an existing node.
|
|
135
|
+
* Returns a new PageDocument and a FORM_CONFIG_UPDATED event.
|
|
136
|
+
*/
|
|
137
|
+
export declare function updateFormConfig(document: PageDocument, params: UpdateFormConfigParams): CommandResult;
|
|
114
138
|
//# sourceMappingURL=commands.d.ts.map
|
package/dist/commands.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../src/commands.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,IAAI,EACJ,gBAAgB,EAChB,eAAe,EAGf,eAAe,
|
|
1
|
+
{"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../src/commands.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,IAAI,EACJ,gBAAgB,EAChB,eAAe,EAGf,eAAe,EAEf,cAAc,EAEd,UAAU,EAEX,MAAM,iBAAiB,CAAC;AASzB,MAAM,MAAM,kBAAkB,GAC1B,eAAe,GACf,YAAY,GACZ,eAAe,GACf,eAAe,GACf,mBAAmB,GACnB,iBAAiB,GACjB,qBAAqB,GACrB,cAAc,GACd,iBAAiB,CAAC;AAEtB,MAAM,WAAW,mBAAmB;IAClC,IAAI,E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AAmB,GAC1B,aAAa,CA+Bf;AAED,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,OAAO,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC;IACvC;;;;OAIG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,YAAY,EACtB,MAAM,EAAE,sBAAsB,GAC7B,aAAa,CAsCf"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { ActionStepCondition, ConditionOperator } from '@kubuild/schema';
|
|
2
|
+
/**
|
|
3
|
+
* Extended condition operators supported by the evaluator.
|
|
4
|
+
*/
|
|
5
|
+
export type ExtendedConditionOperator = ConditionOperator | 'starts_with' | 'ends_with' | 'is_empty' | 'is_not_empty' | 'in' | 'not_in';
|
|
6
|
+
/**
|
|
7
|
+
* Options for fine-tuning condition evaluation.
|
|
8
|
+
*/
|
|
9
|
+
export interface ConditionEvaluationOptions {
|
|
10
|
+
caseInsensitive?: boolean;
|
|
11
|
+
trimStrings?: boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Represents a group of conditions evaluated together using AND / OR combinators.
|
|
15
|
+
*/
|
|
16
|
+
export interface ConditionGroup {
|
|
17
|
+
combinator: 'and' | 'or';
|
|
18
|
+
conditions: (ActionStepCondition | ConditionGroup)[];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Type guard to check if a condition item is a ConditionGroup.
|
|
22
|
+
*/
|
|
23
|
+
export declare function isConditionGroup(item: ActionStepCondition | ConditionGroup): item is ConditionGroup;
|
|
24
|
+
/**
|
|
25
|
+
* Checks whether a given value is considered empty.
|
|
26
|
+
* Returns true for undefined, null, empty string, empty array, or empty object.
|
|
27
|
+
*/
|
|
28
|
+
export declare function isValueEmpty(value: unknown): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Evaluates an operator against an actual value and an optional expected value.
|
|
31
|
+
*/
|
|
32
|
+
export declare function evaluateOperator(operator: ExtendedConditionOperator | string, actual: unknown, expected?: unknown, options?: ConditionEvaluationOptions): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Resolves a field value from context and evaluates a single ActionStepCondition.
|
|
35
|
+
*/
|
|
36
|
+
export declare function evaluateCondition(condition: ActionStepCondition | undefined, context: Record<string, unknown>, options?: ConditionEvaluationOptions): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Evaluates a ConditionGroup (AND / OR group with nested conditions).
|
|
39
|
+
*/
|
|
40
|
+
export declare function evaluateConditionGroup(group: ConditionGroup, context: Record<string, unknown>, options?: ConditionEvaluationOptions): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Evaluates a list of conditions and/or condition groups using a given combinator ('and' | 'or').
|
|
43
|
+
*/
|
|
44
|
+
export declare function evaluateConditions(conditions: (ActionStepCondition | ConditionGroup)[], context: Record<string, unknown>, combinator?: 'and' | 'or', options?: ConditionEvaluationOptions): boolean;
|
|
45
|
+
//# sourceMappingURL=conditional-resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conditional-resolver.d.ts","sourceRoot":"","sources":["../src/conditional-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAG9E;;GAEG;AACH,MAAM,MAAM,yBAAyB,GACjC,iBAAiB,GACjB,aAAa,GACb,WAAW,GACX,UAAU,GACV,cAAc,GACd,IAAI,GACJ,QAAQ,CAAC;AAEb;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,KAAK,GAAG,IAAI,CAAC;IACzB,UAAU,EAAE,CAAC,mBAAmB,GAAG,cAAc,CAAC,EAA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