interaqt 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/agent/.claude/agents/code-generation-handler.md +2 -0
  2. package/agent/.claude/agents/computation-generation-handler.md +1 -0
  3. package/agent/.claude/agents/implement-design-handler.md +4 -13
  4. package/agent/.claude/agents/requirements-analysis-handler.md +46 -14
  5. package/agent/agentspace/knowledge/generator/api-reference.md +3378 -0
  6. package/agent/agentspace/knowledge/generator/basic-interaction-generation.md +377 -0
  7. package/agent/agentspace/knowledge/generator/computation-analysis.md +307 -0
  8. package/agent/agentspace/knowledge/generator/computation-implementation.md +959 -0
  9. package/agent/agentspace/knowledge/generator/data-analysis.md +463 -0
  10. package/agent/agentspace/knowledge/generator/entity-relation-generation.md +395 -0
  11. package/agent/agentspace/knowledge/generator/permission-implementation.md +460 -0
  12. package/agent/agentspace/knowledge/generator/permission-test-implementation.md +870 -0
  13. package/agent/agentspace/knowledge/generator/test-implementation.md +674 -0
  14. package/agent/agentspace/knowledge/usage/00-mindset-shift.md +322 -0
  15. package/agent/agentspace/knowledge/usage/01-core-concepts.md +131 -0
  16. package/agent/agentspace/knowledge/usage/02-define-entities-properties.md +407 -0
  17. package/agent/agentspace/knowledge/usage/03-entity-relations.md +599 -0
  18. package/agent/agentspace/knowledge/usage/04-reactive-computations.md +2186 -0
  19. package/agent/agentspace/knowledge/usage/05-interactions.md +1411 -0
  20. package/agent/agentspace/knowledge/usage/06-attributive-permissions.md +10 -0
  21. package/agent/agentspace/knowledge/usage/07-payload-parameters.md +593 -0
  22. package/agent/agentspace/knowledge/usage/08-activities.md +863 -0
  23. package/agent/agentspace/knowledge/usage/09-filtered-entities.md +784 -0
  24. package/agent/agentspace/knowledge/usage/10-async-computations.md +734 -0
  25. package/agent/agentspace/knowledge/usage/11-global-dictionaries.md +942 -0
  26. package/agent/agentspace/knowledge/usage/12-data-querying.md +1033 -0
  27. package/agent/agentspace/knowledge/usage/13-testing.md +1201 -0
  28. package/agent/agentspace/knowledge/usage/14-api-reference.md +1606 -0
  29. package/agent/agentspace/knowledge/usage/15-entity-crud-patterns.md +1122 -0
  30. package/agent/agentspace/knowledge/usage/16-frontend-page-design-guide.md +485 -0
  31. package/agent/agentspace/knowledge/usage/17-performance-optimization.md +283 -0
  32. package/agent/agentspace/knowledge/usage/18-api-exports-reference.md +176 -0
  33. package/agent/agentspace/knowledge/usage/19-common-anti-patterns.md +563 -0
  34. package/agent/agentspace/knowledge/usage/README.md +148 -0
  35. package/package.json +1 -1
@@ -0,0 +1,377 @@
1
+ # Basic Interaction Generation Guide
2
+
3
+ ## Overview
4
+ This guide covers generating basic interactions without permissions (conditions).
5
+
6
+ ## 🔴 CRITICAL: Common Mistakes to Avoid
7
+
8
+ ### Action Misconception
9
+ ```typescript
10
+ // ❌ WRONG: Action is NOT operational logic
11
+ const CreatePost = Action.create({
12
+ name: 'createPost',
13
+ execute: async () => { /* ... */ }, // No execute method!
14
+ handler: () => { /* ... */ } // No handler either!
15
+ });
16
+
17
+ // ✅ CORRECT: Action is just an identifier
18
+ const CreatePost = Action.create({
19
+ name: 'createPost' // That's it!
20
+ });
21
+ ```
22
+
23
+ ### User Property Mistake
24
+ ```typescript
25
+ // ❌ WRONG: user is not a property of Interaction
26
+ const SomeInteraction = Interaction.create({
27
+ name: 'SomeInteraction',
28
+ user: User, // This doesn't exist!
29
+ action: Action.create({ name: 'someAction' })
30
+ });
31
+
32
+ // ✅ CORRECT: User is passed at execution time
33
+ const SomeInteraction = Interaction.create({
34
+ name: 'SomeInteraction',
35
+ action: Action.create({ name: 'someAction' })
36
+ });
37
+ ```
38
+
39
+ ### Entity Reference Mistake
40
+ ```typescript
41
+ // ❌ WRONG: Using plain 'id' without proper reference
42
+ const UpdateStyle = Interaction.create({
43
+ name: 'UpdateStyle',
44
+ action: Action.create({ name: 'updateStyle' }),
45
+ payload: Payload.create({
46
+ items: [
47
+ PayloadItem.create({
48
+ name: 'id', // Just an id field - NOT a proper entity reference
49
+ required: true
50
+ })
51
+ ]
52
+ })
53
+ });
54
+
55
+ // ✅ CORRECT: Using isRef with base for entity reference
56
+ const UpdateStyle = Interaction.create({
57
+ name: 'UpdateStyle',
58
+ action: Action.create({ name: 'updateStyle' }),
59
+ payload: Payload.create({
60
+ items: [
61
+ PayloadItem.create({
62
+ name: 'style',
63
+ base: Style, // Specify which entity
64
+ isRef: true, // This is a reference to existing entity
65
+ required: true
66
+ })
67
+ ]
68
+ })
69
+ });
70
+ ```
71
+
72
+ ## Key Concepts
73
+
74
+ ### What is an Interaction?
75
+ - User-triggered actions that modify system state
76
+ - The ONLY way to create, update, or delete data
77
+ - Contains: name, action (identifier), payload (parameters)
78
+ - NO operational logic - that's handled by Computations
79
+
80
+ ### User-related Interactions
81
+ - **Skip**: CreateUser, DeleteUser, Login, Register, Logout (handled by external systems)
82
+ - **Generate**: UpdateUserProfile, UpdateUserSettings (only if explicitly required)
83
+ - User entity is for data relationships, not authentication
84
+
85
+ ### Basic Structure
86
+ ```typescript
87
+ import { Interaction, Action, Payload, PayloadItem } from 'interaqt';
88
+
89
+ export const CreateStyle = Interaction.create({
90
+ name: 'CreateStyle',
91
+ action: Action.create({ name: 'createStyle' }), // Just an identifier
92
+ payload: Payload.create({
93
+ items: [
94
+ PayloadItem.create({
95
+ name: 'label',
96
+ required: true
97
+ }),
98
+ PayloadItem.create({
99
+ name: 'slug',
100
+ required: true
101
+ })
102
+ ]
103
+ })
104
+ // NO conditions in basic version
105
+ });
106
+ ```
107
+
108
+ ## Payload Definition
109
+
110
+ ### PayloadItem Properties
111
+ - `name`: Parameter name (required)
112
+ - `required`: Whether parameter is required (default: false)
113
+ - `isCollection`: Whether it's an array (default: false)
114
+
115
+
116
+ ## Common Interaction Patterns
117
+
118
+ ### Create Pattern
119
+ ```typescript
120
+ export const CreateStyle = Interaction.create({
121
+ name: 'CreateStyle',
122
+ action: Action.create({ name: 'createStyle' }),
123
+ payload: Payload.create({
124
+ items: [
125
+ PayloadItem.create({ name: 'label', required: true }),
126
+ PayloadItem.create({ name: 'slug', required: true }),
127
+ PayloadItem.create({ name: 'description' }),
128
+ PayloadItem.create({ name: 'type', required: true }),
129
+ PayloadItem.create({ name: 'thumbKey' }),
130
+ PayloadItem.create({ name: 'priority' })
131
+ ]
132
+ })
133
+ });
134
+ ```
135
+
136
+ ### Update Pattern
137
+ ```typescript
138
+ export const UpdateStyle = Interaction.create({
139
+ name: 'UpdateStyle',
140
+ action: Action.create({ name: 'updateStyle' }),
141
+ payload: Payload.create({
142
+ items: [
143
+ PayloadItem.create({
144
+ name: 'styleId', // Reference to style to update
145
+ required: true
146
+ }),
147
+ // Only include updatable fields
148
+ PayloadItem.create({ name: 'label' }),
149
+ PayloadItem.create({ name: 'description' }),
150
+ PayloadItem.create({ name: 'thumbKey' }),
151
+ PayloadItem.create({ name: 'priority' })
152
+ ]
153
+ })
154
+ });
155
+ ```
156
+
157
+ ### Delete Pattern
158
+ ```typescript
159
+ export const DeleteStyle = Interaction.create({
160
+ name: 'DeleteStyle',
161
+ action: Action.create({ name: 'deleteStyle' }),
162
+ payload: Payload.create({
163
+ items: [
164
+ PayloadItem.create({
165
+ name: 'styleId',
166
+ required: true
167
+ })
168
+ ]
169
+ })
170
+ });
171
+ ```
172
+
173
+ ### State Change Pattern
174
+ ```typescript
175
+ export const PublishStyle = Interaction.create({
176
+ name: 'PublishStyle',
177
+ action: Action.create({ name: 'publishStyle' }),
178
+ payload: Payload.create({
179
+ items: [
180
+ PayloadItem.create({
181
+ name: 'styleId',
182
+ required: true
183
+ })
184
+ ]
185
+ })
186
+ });
187
+ ```
188
+
189
+ ### Query Pattern
190
+ ```typescript
191
+ export const GetStyles = Interaction.create({
192
+ name: 'GetStyles',
193
+ action: Action.create({ name: 'getStyles' }),
194
+ payload: Payload.create({
195
+ items: [
196
+ PayloadItem.create({ name: 'type' }),
197
+ PayloadItem.create({ name: 'status' }),
198
+ PayloadItem.create({ name: 'limit' }),
199
+ PayloadItem.create({ name: 'offset' })
200
+ ]
201
+ })
202
+ });
203
+
204
+ export const GetStyleDetail = Interaction.create({
205
+ name: 'GetStyleDetail',
206
+ action: Action.create({ name: 'getStyleDetail' }),
207
+ payload: Payload.create({
208
+ items: [
209
+ PayloadItem.create({
210
+ name: 'style',
211
+ base: Style,
212
+ isRef: true,
213
+ required: true
214
+ })
215
+ ]
216
+ })
217
+ });
218
+ ```
219
+
220
+ ## Complete Example
221
+
222
+ ```typescript
223
+ import { Interaction, Action, Payload, PayloadItem } from 'interaqt';
224
+ import { Style, Version, User } from '../entities';
225
+
226
+ // Style Management Interactions
227
+ export const CreateStyle = Interaction.create({
228
+ name: 'CreateStyle',
229
+ action: Action.create({ name: 'createStyle' }),
230
+ payload: Payload.create({
231
+ items: [
232
+ PayloadItem.create({ name: 'label', required: true }),
233
+ PayloadItem.create({ name: 'slug', required: true }),
234
+ PayloadItem.create({ name: 'description' }),
235
+ PayloadItem.create({ name: 'type', required: true }),
236
+ PayloadItem.create({ name: 'thumbKey' }),
237
+ PayloadItem.create({ name: 'priority' })
238
+ ]
239
+ })
240
+ });
241
+
242
+ export const UpdateStyle = Interaction.create({
243
+ name: 'UpdateStyle',
244
+ action: Action.create({ name: 'updateStyle' }),
245
+ payload: Payload.create({
246
+ items: [
247
+ PayloadItem.create({
248
+ name: 'styleId',
249
+ required: true
250
+ }),
251
+ PayloadItem.create({ name: 'label' }),
252
+ PayloadItem.create({ name: 'description' }),
253
+ PayloadItem.create({ name: 'thumbKey' }),
254
+ PayloadItem.create({ name: 'priority' })
255
+ ]
256
+ })
257
+ });
258
+
259
+ export const DeleteStyle = Interaction.create({
260
+ name: 'DeleteStyle',
261
+ action: Action.create({ name: 'deleteStyle' }),
262
+ payload: Payload.create({
263
+ items: [
264
+ PayloadItem.create({
265
+ name: 'styleId',
266
+ required: true
267
+ })
268
+ ]
269
+ })
270
+ });
271
+
272
+ export const PublishStyle = Interaction.create({
273
+ name: 'PublishStyle',
274
+ action: Action.create({ name: 'publishStyle' }),
275
+ payload: Payload.create({
276
+ items: [
277
+ PayloadItem.create({
278
+ name: 'styleId',
279
+ required: true
280
+ })
281
+ ]
282
+ })
283
+ });
284
+
285
+ export const UpdateStyleOrder = Interaction.create({
286
+ name: 'UpdateStyleOrder',
287
+ action: Action.create({ name: 'updateStyleOrder' }),
288
+ payload: Payload.create({
289
+ items: [
290
+ PayloadItem.create({
291
+ name: 'updates',
292
+ isCollection: true, // Array of updates
293
+ required: true
294
+ })
295
+ ]
296
+ })
297
+ });
298
+
299
+ // Version Management
300
+ export const RollbackVersion = Interaction.create({
301
+ name: 'RollbackVersion',
302
+ action: Action.create({ name: 'rollbackVersion' }),
303
+ payload: Payload.create({
304
+ items: [
305
+ PayloadItem.create({
306
+ name: 'versionId',
307
+ required: true
308
+ })
309
+ ]
310
+ })
311
+ });
312
+
313
+ // Query Interactions
314
+ export const GetStyles = Interaction.create({
315
+ name: 'GetStyles',
316
+ action: Action.create({ name: 'getStyles' }),
317
+ payload: Payload.create({
318
+ items: [
319
+ PayloadItem.create({ name: 'type' }),
320
+ PayloadItem.create({ name: 'status' })
321
+ ]
322
+ })
323
+ });
324
+
325
+ export const GetStyleDetail = Interaction.create({
326
+ name: 'GetStyleDetail',
327
+ action: Action.create({ name: 'getStyleDetail' }),
328
+ payload: Payload.create({
329
+ items: [
330
+ PayloadItem.create({
331
+ name: 'style',
332
+ base: Style,
333
+ isRef: true,
334
+ required: true
335
+ })
336
+ ]
337
+ })
338
+ });
339
+
340
+ export const GetVersionHistory = Interaction.create({
341
+ name: 'GetVersionHistory',
342
+ action: Action.create({ name: 'getVersionHistory' }),
343
+ payload: Payload.create({
344
+ items: [
345
+ PayloadItem.create({
346
+ name: 'styleId',
347
+ required: true
348
+ })
349
+ ]
350
+ })
351
+ });
352
+ ```
353
+
354
+ ## Important Notes
355
+
356
+ ### DO NOT Include in Basic Interactions
357
+ - conditions (permissions and validation)
358
+ - Complex validation logic
359
+ - Side effects or computations
360
+ - Operational logic in Actions
361
+
362
+ ### Focus On
363
+ - Clear interaction naming
364
+ - Complete payload definitions
365
+ - Correct data types
366
+ - Required field marking
367
+ - Proper entity references with isRef and base
368
+ - One interaction per user action
369
+
370
+
371
+ ## Validation Checklist
372
+ - [ ] All user actions have corresponding interactions
373
+ - [ ] Action only contains name (no logic)
374
+ - [ ] Payload items have appropriate required flags
375
+ - [ ] Collections use isCollection: true
376
+ - [ ] No permissions or constraints included
377
+ - [ ] TypeScript compilation passes
@@ -0,0 +1,307 @@
1
+ # Computation Selection Guide v2 - Streamlined Version
2
+
3
+ ## Overview
4
+
5
+ This guide helps you select the appropriate computation type for each entity, property, relation, and dictionary based on the structured information in `data-design.json` and `interaction-design.md`.
6
+
7
+
8
+ ## Input Files
9
+
10
+ You will receive two input files:
11
+ 1. **data-design.json**: Contains structured data dependencies and lifecycle information
12
+ 2. **interaction-design.md**: Describes all interactions and their effects
13
+
14
+ ## Direct Mapping Rules
15
+
16
+ ### Special Notations
17
+
18
+ #### _parent:[ParentName]
19
+ The `_parent:[ParentName]` notation indicates that this entity or relation is created by its parent's computation, not by its own computation. This occurs when `lifecycle.creation.type` is `"created-with-parent"` (for entities) or `"created-with-entity"` (for relations). The parent entity's computation is responsible for creating this child entity/relation.
20
+
21
+ Example: If an AuditLog has `lifecycle.creation.type: "created-with-parent"` and `lifecycle.creation.parent: "Transaction"`, its computationDecision would be `"_parent:Transaction"`.
22
+
23
+ #### _owner
24
+ The `_owner` notation indicates that this property's value is fully controlled by its owner entity or relation's computation. This applies when:
25
+ - `controlType` is `"creation-only"`: Property is set during entity/relation creation and never modified separately
26
+ - `controlType` is `"derived-with-parent"`: Property belongs to a derived entity/relation and is computed as part of the parent's overall derivation
27
+
28
+ Properties marked with `_owner` don't need separate computation control - their logic is embedded in the owner's creation or derivation process.
29
+
30
+ ### 1. Entity-Level Computations
31
+
32
+ Look at the entity's `lifecycle.creation` and `lifecycle.deletion`:
33
+
34
+ | Creation Type | Deletion | Computation Decision |
35
+ |---------------|----------|---------------------|
36
+ | `"created-with-parent"` | Any | `_parent:[lifecycle.creation.parent]` (created by parent's computation) |
37
+ | `"interaction-created"` | `canBeDeleted: false` | `Transform` with `InteractionEventEntity` |
38
+ | `"interaction-created"` | `canBeDeleted: true` with `hard-delete` | `Transform` + `HardDeletionProperty` with `StateMachine` |
39
+ | `"interaction-created"` | `canBeDeleted: true` with `soft-delete` | `Transform` + status property with `StateMachine` |
40
+ | `"derived"` | Any | `Transform` from source entity |
41
+
42
+ **Critical Rule**: Transform can ONLY create, NEVER delete. For hard deletion:
43
+ - Use `Transform` for entity/relation creation
44
+ - Add `HardDeletionProperty` to the entity/relation
45
+ - Use `StateMachine` on the `HardDeletionProperty` to manage deletion
46
+
47
+ ### 2. Relation-Level Computations
48
+
49
+ Check `lifecycle.creation` and `lifecycle.deletion`:
50
+
51
+ | Creation Type | Deletion | Computation Decision |
52
+ |---------------|----------|---------------------|
53
+ | `"created-with-entity"` | `canBeDeleted: false` | `_parent:[lifecycle.creation.parent]` (created by parent entity's computation) |
54
+ | `"created-with-entity"` | `canBeDeleted: true` | `_parent:[lifecycle.creation.parent]` + `HardDeletionProperty` with `StateMachine` for deletion |
55
+ | `"interaction-created"` | `canBeDeleted: false` | `Transform` with `InteractionEventEntity` |
56
+ | `"interaction-created"` | `canBeDeleted: true` | `Transform` + `HardDeletionProperty` with `StateMachine` |
57
+ | `"derived"` | Any | `Transform` from source conditions |
58
+ | Any | `deletionType: "soft-delete"` | Original computation + status property with `StateMachine` |
59
+
60
+ **Critical Rule**: Transform can ONLY create, NEVER delete. For hard deletion, add `HardDeletionProperty` and use `StateMachine` on it.
61
+
62
+ ### 3. Property-Level Computations
63
+
64
+ First check the property's `controlType`, then analyze dependencies if needed:
65
+
66
+ | Control Type | Computation Decision |
67
+ |--------------|---------------------|
68
+ | `creation-only` | `_owner` - controlled by entity/relation creation |
69
+ | `derived-with-parent` | `_owner` - controlled by parent's derivation |
70
+ | `independent` | Further analysis needed (see below) |
71
+
72
+ #### For `independent` Properties
73
+
74
+ Analyze the property's `dataDependencies`, `interactionDependencies`, and `computationMethod`:
75
+
76
+ | Condition | Computation Decision |
77
+ |-----------|---------------------|
78
+ | Has `interactionDependencies` that can modify it | `StateMachine` for state transitions or value updates |
79
+ | Has `dataDependencies` with relations/entities | Aggregation computation based on `computationMethod` |
80
+ | `dataDependencies` = self properties only | `computed` function |
81
+ | Complex calculation with multiple entities | `Custom` |
82
+ | Only has `initialValue`, no dependencies | No computation (use `defaultValue`) |
83
+
84
+ #### Decision Priority (check in order):
85
+
86
+ 1. **Check `controlType` first**:
87
+ - `creation-only` → **_owner** (property controlled by entity/relation creation)
88
+ - `derived-with-parent` → **_owner** (property controlled by parent derivation)
89
+ - `independent` → Continue to step 2
90
+
91
+ 2. **If has `interactionDependencies` that can modify**:
92
+ - Property changes in response to interactions → `StateMachine`
93
+ - For timestamps: Use StateMachine with `computeValue`
94
+ - For status fields: Use StateMachine with StateNodes
95
+
96
+ 3. **If has `dataDependencies` (no interactions)**:
97
+ - Check `computationMethod` for aggregation type
98
+ - Relations/entities involved → Use appropriate aggregation
99
+
100
+ 4. **If uses only own entity properties**:
101
+ - Simple derivation → `computed` function
102
+ - Better performance than Custom
103
+
104
+ #### Aggregation Type Selection
105
+
106
+ Based on the `computationMethod` description:
107
+ - Contains "count of" → `Count`
108
+ - Contains "sum of" → `Summation`
109
+ - Contains "weighted sum" or "× price" → `WeightedSummation`
110
+ - Contains "all" or "every" → `Every`
111
+ - Contains "any" or "at least one" → `Any`
112
+ - Contains "percentage" or complex logic → `Custom`
113
+ - Time-based comparisons → `RealTime`
114
+
115
+ ### 4. Dictionary-Level Computations
116
+
117
+ Based on `computationMethod` description:
118
+ - "Count of all" → `Count`
119
+ - "Sum of" → `Summation`
120
+ - "Count where condition" → `Count` with filter callback
121
+ - Complex aggregation → `Custom`
122
+
123
+ ## Automated Decision Process
124
+
125
+ ### Step 1: Parse Input Files
126
+ Read `data-design.json` and extract:
127
+ - Entity definitions with their properties and lifecycle (creation and deletion)
128
+ - Relation definitions with their lifecycle
129
+ - Dictionary definitions
130
+
131
+ ### Step 2: Apply Mapping Rules
132
+ For each element:
133
+ 1. Check lifecycle.creation.type and lifecycle.deletion for entities and relations
134
+ 2. For properties, check controlType first:
135
+ - If `creation-only` or `derived-with-parent` → use `_owner`
136
+ - If `independent` → apply standard dependency analysis rules
137
+ 3. Apply the appropriate rules based on creation type and deletion capability
138
+ 4. For entities/relations that can be hard-deleted, use Transform + HardDeletionProperty with StateMachine
139
+
140
+ ### Step 3: Generate Output Document
141
+
142
+ Create `docs/computation-analysis.json` with this structure:
143
+
144
+ ```json
145
+ {
146
+ "entities": [
147
+ {
148
+ "name": "<from data-design.json>",
149
+ "entityAnalysis": {
150
+ "purpose": "<from data-design.json>",
151
+ "lifecycle": "<directly copy from lifecycle field in data-design.json>",
152
+ "computationDecision": "<Transform/StateMachine/_parent:[ParentName]/None based on rules>",
153
+ "reasoning": "<automated based on lifecycle and deletion capability>",
154
+ "calculationMethod": "<from computationMethod>"
155
+ },
156
+ "propertyAnalysis": [
157
+ {
158
+ "propertyName": "<property name>",
159
+ "type": "<from data-design.json>",
160
+ "purpose": "<from data-design.json>",
161
+ "controlType": "<from data-design.json: creation-only/derived-with-parent/independent>",
162
+ "dataSource": "<from computationMethod>",
163
+ "computationDecision": "<_owner/StateMachine/Count/etc. based on controlType and rules>",
164
+ "reasoning": "<automated based on controlType and rules>",
165
+ "dependencies": <convert dataDependencies to proper format>,
166
+ "interactionDependencies": <from data-design.json>,
167
+ "calculationMethod": "<from computationMethod>"
168
+ }
169
+ ]
170
+ }
171
+ ],
172
+ "relations": [
173
+ {
174
+ "name": "<from data-design.json>",
175
+ "relationAnalysis": {
176
+ "purpose": "<from data-design.json>",
177
+ "lifecycle": "<directly copy from lifecycle field in data-design.json>",
178
+ "computationDecision": "<Transform/_parent:[ParentName]/StateMachine based on rules>",
179
+ "reasoning": "<automated based on lifecycle>",
180
+ "calculationMethod": "<from computationMethod>"
181
+ }
182
+ }
183
+ ],
184
+ "dictionaries": [
185
+ {
186
+ "name": "<from data-design.json>",
187
+ "dictionaryAnalysis": {
188
+ "purpose": "<from data-design.json>",
189
+ "type": "<from data-design.json>",
190
+ "collection": "<determine from type>",
191
+ "computationDecision": "<apply dictionary rules>",
192
+ "reasoning": "<automated based on computationMethod>",
193
+ "dependencies": <format properly>,
194
+ "interactionDependencies": <from data-design.json>,
195
+ "calculationMethod": "<from computationMethod>"
196
+ }
197
+ }
198
+ ]
199
+ }
200
+ ```
201
+
202
+ ## Dependency Formatting Rules
203
+
204
+ When converting `dataDependencies` to `dependencies`:
205
+
206
+ 1. **Entity/Relation properties**: Format as `EntityName.propertyName`
207
+ 2. **Self properties**: Convert to `_self.propertyName`
208
+ 3. **Relations without properties**: Use relation name directly
209
+ 4. **Dictionaries**: Use dictionary name without dot notation
210
+ 5. **InteractionEventEntity**: Add when `interactionDependencies` exists
211
+
212
+ Examples:
213
+ - `["User", "Dormitory"]` → `["User.id", "Dormitory.id"]` (specify actual properties used)
214
+ - `["UserDormitoryRelation"]` → `["UserDormitoryRelation"]`
215
+ - Self-reference → `["_self.capacity", "_self.occupancy"]`
216
+
217
+ ## Quick Decision Flowchart
218
+
219
+ ```
220
+ 1. Entity Lifecycle?
221
+ ├─ lifecycle.creation.type: "created-with-parent"? → _parent:[parent]
222
+ ├─ lifecycle.creation.type: "interaction-created" + canBeDeleted: true (hard)? → Transform + HardDeletionProperty with StateMachine
223
+ ├─ lifecycle.creation.type: "interaction-created" + canBeDeleted: true (soft)? → Transform + status StateMachine
224
+ ├─ lifecycle.creation.type: "interaction-created" + canBeDeleted: false? → Transform with InteractionEventEntity
225
+ └─ lifecycle.creation.type: "derived"? → Transform from source entity
226
+
227
+ 2. Relation Lifecycle?
228
+ ├─ lifecycle.creation.type: "created-with-entity"? → _parent:[parent]
229
+ ├─ Can be deleted? → Transform/parent + HardDeletionProperty with StateMachine
230
+ ├─ Needs audit trail? → Original computation + status StateMachine (soft delete)
231
+ └─ Never deleted? → Transform (if interaction-created) or _parent:[parent]
232
+
233
+ 3. Property Value?
234
+ ├─ controlType: "creation-only"? → _owner (controlled by entity/relation)
235
+ ├─ controlType: "derived-with-parent"? → _owner (controlled by parent)
236
+ ├─ controlType: "independent"?
237
+ │ ├─ Has interactionDependencies that can modify? → StateMachine
238
+ │ ├─ Has dataDependencies with relations? → Aggregation computation
239
+ │ ├─ Only uses own properties? → computed
240
+ │ └─ Complex with multiple entities? → Custom
241
+ └─ Only has initialValue? → defaultValue
242
+
243
+ 4. Dictionary Aggregation?
244
+ └─ Check computationMethod → Map to Count/Summation/Custom
245
+ ```
246
+
247
+ ## Implementation Checklist
248
+
249
+ - [ ] Parse `data-design.json` completely
250
+ - [ ] Apply mapping rules for every entity (check deletion capability)
251
+ - [ ] Check `controlType` for every property first
252
+ - [ ] Apply mapping rules for properties based on `controlType`
253
+ - [ ] Apply mapping rules for every relation
254
+ - [ ] Apply mapping rules for every dictionary
255
+ - [ ] Format all dependencies correctly
256
+ - [ ] Separate `dependencies` and `interactionDependencies`
257
+ - [ ] Add `InteractionEventEntity` when needed
258
+ - [ ] Verify properties with `controlType: "creation-only"` or `"derived-with-parent"` use `_owner`
259
+ - [ ] Verify Transform + HardDeletionProperty is used for deletable entities (hard-delete)
260
+ - [ ] Verify Transform + HardDeletionProperty is used for deletable relations (hard-delete)
261
+ - [ ] Generate complete `computation-analysis.json`
262
+
263
+ ## Common Patterns
264
+
265
+ ### Timestamps
266
+ - Creation timestamps (`createdAt`): Use `defaultValue: () => Math.floor(Date.now()/1000)`
267
+ - Update timestamps (`updatedAt`, `processedAt`): Use StateMachine with `computeValue`
268
+
269
+ ### Status Fields
270
+ - With defined transitions: Use StateMachine with StateNodes
271
+ - Example: pending → approved/rejected
272
+
273
+ ### Counts and Aggregations
274
+ - Simple counts: Use `Count`
275
+ - Sums: Use `Summation`
276
+ - Calculated totals (price × quantity): Use `WeightedSummation`
277
+
278
+ ### Deletion Patterns
279
+
280
+ #### For Entities:
281
+ - **Hard delete** (no history): Transform + HardDeletionProperty with StateMachine
282
+ - Creation: Transform creates entity from interaction
283
+ - Deletion: HardDeletionProperty with StateMachine triggers physical deletion
284
+ - **Soft delete** (audit trail): Transform for creation + status property with StateMachine
285
+ - Creation: Transform creates entity
286
+ - Deletion: StateMachine updates status to "deleted"
287
+
288
+ #### For Relations:
289
+ - **Hard delete**: Transform + HardDeletionProperty with StateMachine
290
+ - **Soft delete**: Original creation computation + status property with StateMachine
291
+ - **Created-with-entity + deletable**: `_parent` for creation + HardDeletionProperty with StateMachine for deletion
292
+
293
+ ## Validation
294
+
295
+ Before finalizing, verify:
296
+ 1. Every entity with `interactionDependencies` has appropriate computation:
297
+ - If `canBeDeleted: true` with `hard-delete` → Must use Transform + HardDeletionProperty with StateMachine
298
+ - If `canBeDeleted: false` → Can use Transform (unless `created-with-parent`)
299
+ 2. Entities/relations with `lifecycle.creation.type: "created-with-parent/entity"` use `_parent:[ParentName]`
300
+ 3. Properties with `controlType: "creation-only"` or `"derived-with-parent"` have computation `_owner`
301
+ 4. Properties with `controlType: "independent"` are analyzed for appropriate computation
302
+ 5. Properties with modifying `interactionDependencies` use StateMachine (if `controlType: "independent"`)
303
+ 6. Properties with only `dataDependencies` use data-based computation (if `controlType: "independent"`)
304
+ 7. All entities or relations with `canBeDeleted:true` and `hard-delete` use Transform + HardDeletionProperty
305
+ 8. All dependencies are properly formatted with specific properties
306
+ 9. `InteractionEventEntity` is included when interactions are dependencies
307
+ 10. The parent name in `_parent:[ParentName]` matches `lifecycle.creation.parent`