interaqt 0.6.4 → 0.7.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.
Files changed (31) hide show
  1. package/agent/agentspace/knowledge/generator/api-reference.md +14 -14
  2. package/agent/agentspace/knowledge/generator/computation-implementation.md +10 -10
  3. package/agent/agentspace/knowledge/usage/04-reactive-computations.md +3 -3
  4. package/agent/agentspace/knowledge/usage/05-interactions.md +5 -5
  5. package/agent/agentspace/knowledge/usage/13-testing.md +1 -1
  6. package/agent/agentspace/knowledge/usage/14-api-reference.md +2 -2
  7. package/agent/agentspace/knowledge/usage/15-entity-crud-patterns.md +11 -11
  8. package/agent/agentspace/knowledge/usage/19-common-anti-patterns.md +2 -2
  9. package/dist/index.js +553 -532
  10. package/dist/index.js.map +1 -1
  11. package/dist/runtime/Controller.d.ts +2 -2
  12. package/dist/runtime/Controller.d.ts.map +1 -1
  13. package/dist/runtime/computations/Any.d.ts +2 -2
  14. package/dist/runtime/computations/Average.d.ts +2 -2
  15. package/dist/runtime/computations/Computation.d.ts +2 -2
  16. package/dist/runtime/computations/Count.d.ts +2 -2
  17. package/dist/runtime/computations/Custom.d.ts +2 -2
  18. package/dist/runtime/computations/Every.d.ts +2 -2
  19. package/dist/runtime/computations/RealTime.d.ts +2 -2
  20. package/dist/runtime/computations/StateMachine.d.ts +4 -4
  21. package/dist/runtime/computations/StateMachine.d.ts.map +1 -1
  22. package/dist/runtime/computations/Summation.d.ts +2 -2
  23. package/dist/runtime/computations/Transform.d.ts +1 -1
  24. package/dist/runtime/computations/WeightedSummation.d.ts +2 -2
  25. package/dist/runtime/errors/SideEffectError.d.ts +19 -0
  26. package/dist/runtime/errors/SideEffectError.d.ts.map +1 -0
  27. package/dist/runtime/errors/index.d.ts +1 -0
  28. package/dist/runtime/errors/index.d.ts.map +1 -1
  29. package/dist/shared/Custom.d.ts +4 -4
  30. package/dist/shared/StateMachine.d.ts +4 -4
  31. package/package.json +1 -1
@@ -175,7 +175,7 @@ import { DELETED_STATE, NON_DELETED_STATE, HARD_DELETION_PROPERTY_NAME } from 'i
175
175
  // Define deletion StateMachine for the HardDeletionProperty
176
176
  const deletionStateMachine = StateMachine.create({
177
177
  states: [NON_DELETED_STATE, DELETED_STATE],
178
- defaultState: NON_DELETED_STATE,
178
+ initialState: NON_DELETED_STATE,
179
179
  transfers: [
180
180
  StateTransfer.create({
181
181
  trigger: {
@@ -263,7 +263,7 @@ const Article = Entity.create({
263
263
  const deletionProperty = HardDeletionProperty.create()
264
264
  deletionProperty.computation = StateMachine.create({
265
265
  states: [NON_DELETED_STATE, DELETED_STATE],
266
- defaultState: NON_DELETED_STATE,
266
+ initialState: NON_DELETED_STATE,
267
267
  transfers: [
268
268
  StateTransfer.create({
269
269
  trigger: {
@@ -1028,20 +1028,20 @@ StateMachine.create(config: StateMachineConfig): StateMachineInstance
1028
1028
  **Parameters**
1029
1029
  - `config.states` (StateNode[], required): List of state nodes
1030
1030
  - `config.transfers` (StateTransfer[], required): List of state transfers
1031
- - `config.defaultState` (StateNode, required): Default state
1031
+ - `config.initialState` (StateNode, required): Default state
1032
1032
 
1033
1033
  **Important: Initial Value Handling**
1034
1034
 
1035
1035
  When using StateMachine for entity/relation properties:
1036
1036
  - If the property's initial value is set when the entity/relation is created, handle it in the entity/relation's computation
1037
- - If the StateMachine needs to save or modify this initial value, explicitly define `computeValue` on the `defaultState` to handle it
1037
+ - If the StateMachine needs to save or modify this initial value, explicitly define `computeValue` on the `initialState` to handle it
1038
1038
 
1039
1039
  ```typescript
1040
1040
  // Example: StateMachine handling initial value
1041
1041
  const MyStateMachine = StateMachine.create({
1042
1042
  states: [pendingState, activeState],
1043
1043
  transfers: [...],
1044
- defaultState: StateNode.create({
1044
+ initialState: StateNode.create({
1045
1045
  name: 'pending',
1046
1046
  computeValue: (lastValue, mutationEvent) => {
1047
1047
  // Explicitly handle initial value
@@ -1074,7 +1074,7 @@ const OrderStateMachine = StateMachine.create({
1074
1074
  computeTarget: (mutationEvent) => ({ id: mutationEvent.record.payload.orderId })
1075
1075
  })
1076
1076
  ],
1077
- defaultState: pendingState
1077
+ initialState: pendingState
1078
1078
  });
1079
1079
 
1080
1080
  // Relation with HardDeletionProperty for deletion management
@@ -1128,7 +1128,7 @@ const relationDeletionProperty = HardDeletionProperty.create()
1128
1128
  // Configure deletion for relation's HardDeletionProperty
1129
1129
  relationDeletionProperty.computation = StateMachine.create({
1130
1130
  states: [NON_DELETED_STATE, DELETED_STATE],
1131
- defaultState: NON_DELETED_STATE,
1131
+ initialState: NON_DELETED_STATE,
1132
1132
  transfers: [
1133
1133
  StateTransfer.create({
1134
1134
  trigger: {
@@ -1384,7 +1384,7 @@ Custom.create(config: CustomConfig): CustomInstance
1384
1384
  ```typescript
1385
1385
  function(): any
1386
1386
  ```
1387
- - `config.getDefaultValue` (function, optional): Provide default value when computation hasn't run:
1387
+ - `config.getInitialValue` (function, optional): Provide default value when computation hasn't run:
1388
1388
  ```typescript
1389
1389
  function(): any
1390
1390
  ```
@@ -1438,7 +1438,7 @@ const userStats = Dictionary.create({
1438
1438
  avgPostsPerUser: dataDeps.posts.length / dataDeps.users.length || 0
1439
1439
  };
1440
1440
  },
1441
- getDefaultValue: function() {
1441
+ getInitialValue: function() {
1442
1442
  return {
1443
1443
  totalUsers: 0,
1444
1444
  activeUsers: 0,
@@ -1481,7 +1481,7 @@ const counterDict = Dictionary.create({
1481
1481
  timestamp: Math.floor(Date.now()/1000) // In seconds
1482
1482
  };
1483
1483
  },
1484
- getDefaultValue: function() {
1484
+ getInitialValue: function() {
1485
1485
  return { total: 0, count: 0, lastChange: 0 };
1486
1486
  }
1487
1487
  })
@@ -1549,7 +1549,7 @@ const apiDataProcessor = Dictionary.create({
1549
1549
  processAt: Date.now()
1550
1550
  };
1551
1551
  },
1552
- getDefaultValue: function() {
1552
+ getInitialValue: function() {
1553
1553
  return { status: 'pending', data: null };
1554
1554
  }
1555
1555
  })
@@ -1721,7 +1721,7 @@ const Order = Entity.create({
1721
1721
 
1722
1722
  **Best Practices**
1723
1723
 
1724
- 1. **Always provide `getDefaultValue`**: This ensures the computation has a valid initial value
1724
+ 1. **Always provide `getInitialValue`**: This ensures the computation has a valid initial value
1725
1725
  2. **Use appropriate context type**: Global computations for system-wide values, property computations for entity-specific values
1726
1726
  3. **Use correct dataDeps type**:
1727
1727
  - `type: 'property'` for accessing current record data in Property computations (use nested attributeQuery for relations)
@@ -2016,7 +2016,7 @@ const CounterStateMachine = StateMachine.create({
2016
2016
  computeTarget: (mutationEvent) => ({ id: mutationEvent.record.payload.counterId })
2017
2017
  })
2018
2018
  ],
2019
- defaultState: idleState
2019
+ initialState: idleState
2020
2020
  });
2021
2021
 
2022
2022
  // Timestamp tracking
@@ -2041,7 +2041,7 @@ const ProcessingStateMachine = StateMachine.create({
2041
2041
  computeTarget: (mutationEvent) => ({ id: mutationEvent.record.payload.itemId })
2042
2042
  })
2043
2043
  ],
2044
- defaultState: pendingState
2044
+ initialState: pendingState
2045
2045
  });
2046
2046
 
2047
2047
  // Apply to property
@@ -133,7 +133,7 @@ When using `InteractionEventEntity` as the Transform input source, understand th
133
133
  });
134
134
  statusProperty.computation = StateMachine.create({
135
135
  states: [activeState, deletedState],
136
- defaultState: activeState, // StateMachine controls initial value
136
+ initialState: activeState, // StateMachine controls initial value
137
137
  transfers: [
138
138
  StateTransfer.create({
139
139
  trigger: DeleteStyleInteraction,
@@ -386,7 +386,7 @@ const statusProperty = Property.create({
386
386
  statusProperty.computation = StateMachine.create({
387
387
  name: 'StyleStatus',
388
388
  states: [draftState, activeState, offlineState],
389
- defaultState: draftState, // defaultState determines initial value
389
+ initialState: draftState, // initialState determines initial value
390
390
  transfers: [
391
391
  StateTransfer.create({
392
392
  current: draftState,
@@ -432,7 +432,7 @@ const updatedAtProperty = Property.create({
432
432
  updatedAtProperty.computation = StateMachine.create({
433
433
  name: 'UpdatedAt',
434
434
  states: [updatedState],
435
- defaultState: updatedState, // computeValue in updatedState provides initial value
435
+ initialState: updatedState, // computeValue in updatedState provides initial value
436
436
  transfers: [
437
437
  StateTransfer.create({
438
438
  current: updatedState,
@@ -495,7 +495,7 @@ const modificationInfoProperty = Property.create({
495
495
  modificationInfoProperty.computation = StateMachine.create({
496
496
  name: 'ModificationTracker',
497
497
  states: [modifiedState],
498
- defaultState: modifiedState, // computeValue in modifiedState handles initial value
498
+ initialState: modifiedState, // computeValue in modifiedState handles initial value
499
499
  transfers: [
500
500
  StateTransfer.create({
501
501
  current: modifiedState,
@@ -597,7 +597,7 @@ totalProductValue.computation = Custom.create({
597
597
  }, 0);
598
598
  return total;
599
599
  },
600
- getDefaultValue: function() {
600
+ getInitialValue: function() {
601
601
  return 0;
602
602
  }
603
603
  });
@@ -637,7 +637,7 @@ finalPriceProperty.computation = Custom.create({
637
637
 
638
638
  return Math.round(finalPrice * 100) / 100; // Round to 2 decimals
639
639
  },
640
- getDefaultValue: function() {
640
+ getInitialValue: function() {
641
641
  return 0;
642
642
  }
643
643
  });
@@ -702,7 +702,7 @@ EmployeeDepartmentInfoProperty.computation = Custom.create({
702
702
  }
703
703
  return `${employeeName} ($${salary}) - No department assigned`;
704
704
  },
705
- getDefaultValue: function() {
705
+ getInitialValue: function() {
706
706
  return 'No info available';
707
707
  }
708
708
  });
@@ -813,7 +813,7 @@ const updatedAtProperty = Property.create({
813
813
  });
814
814
  updatedAtProperty.computation = StateMachine.create({
815
815
  states: [updatedState],
816
- defaultState: updatedState,
816
+ initialState: updatedState,
817
817
  transfers: [
818
818
  StateTransfer.create({
819
819
  current: updatedState,
@@ -849,7 +849,7 @@ const statusProperty = Property.create({
849
849
  });
850
850
  statusProperty.computation = StateMachine.create({
851
851
  states: [activeState, offlineState],
852
- defaultState: activeState,
852
+ initialState: activeState,
853
853
  transfers: [
854
854
  StateTransfer.create({
855
855
  current: activeState,
@@ -921,7 +921,7 @@ const updatedAtProperty = Property.create({
921
921
  });
922
922
  updatedAtProperty.computation = StateMachine.create({
923
923
  states: [updatedState],
924
- defaultState: updatedState,
924
+ initialState: updatedState,
925
925
  transfers: [
926
926
  StateTransfer.create({
927
927
  current: updatedState,
@@ -1223,7 +1223,7 @@ const EventEntity = Entity.create({
1223
1223
  computeTarget: (event) => ({ id: event.payload.eventId })
1224
1224
  })
1225
1225
  ],
1226
- defaultState: triggeredState
1226
+ initialState: triggeredState
1227
1227
  })
1228
1228
  })
1229
1229
  ]
@@ -1274,7 +1274,7 @@ const CounterEntity = Entity.create({
1274
1274
  computeTarget: (event) => ({ id: event.payload.counterId })
1275
1275
  })
1276
1276
  ],
1277
- defaultState: idleState
1277
+ initialState: idleState
1278
1278
  })
1279
1279
  })
1280
1280
  ]
@@ -1341,7 +1341,7 @@ const TaskEntity = Entity.create({
1341
1341
  computeTarget: (event) => ({ id: event.payload.taskId })
1342
1342
  })
1343
1343
  ],
1344
- defaultState: newState
1344
+ initialState: newState
1345
1345
  })
1346
1346
  })
1347
1347
  ]
@@ -609,7 +609,7 @@ const User = Entity.create({
609
609
  computeTarget: (event) => ({ id: event.payload.userId })
610
610
  })
611
611
  ],
612
- defaultState: NameUpdatedState
612
+ initialState: NameUpdatedState
613
613
  })
614
614
  }),
615
615
  Property.create({
@@ -625,7 +625,7 @@ const User = Entity.create({
625
625
  computeTarget: (event) => ({ id: event.payload.userId })
626
626
  })
627
627
  ],
628
- defaultState: BioUpdatedState
628
+ initialState: BioUpdatedState
629
629
  })
630
630
  })
631
631
  ]
@@ -675,7 +675,7 @@ const Post = Entity.create({
675
675
  computation: StateMachine.create({
676
676
  name: 'PostStatus',
677
677
  states: [draftState, publishedState, deletedState],
678
- defaultState: draftState,
678
+ initialState: draftState,
679
679
  transfers: [
680
680
  StateTransfer.create({
681
681
  current: draftState,
@@ -792,7 +792,7 @@ const Order = Entity.create({
792
792
  computation: StateMachine.create({
793
793
  name: 'OrderStatus',
794
794
  states: [pendingState, confirmedState, shippedState, deliveredState, cancelledState],
795
- defaultState: pendingState,
795
+ initialState: pendingState,
796
796
  transfers: [
797
797
  StateTransfer.create({
798
798
  current: pendingState,
@@ -1101,7 +1101,7 @@ const DeliveredState = StateNode.create({ name: 'delivered' });
1101
1101
  const OrderStateMachine = StateMachine.create({
1102
1102
  name: 'OrderStatus',
1103
1103
  states: [PendingState, PaidState, ShippedState, DeliveredState],
1104
- defaultState: PendingState,
1104
+ initialState: PendingState,
1105
1105
  transfers: [
1106
1106
  StateTransfer.create({
1107
1107
  current: PendingState,
@@ -618,7 +618,7 @@ describe('Approval Process Activity', () => {
618
618
  name: 'ApprovalProcess',
619
619
  states: [submittedState, reviewingState, approvedState, rejectedState],
620
620
  transfers: [submitTransfer, approveTransfer, rejectTransfer],
621
- defaultState: submittedState
621
+ initialState: submittedState
622
622
  });
623
623
 
624
624
  const controller = new Controller({
@@ -527,7 +527,7 @@ StateMachine.create(config: StateMachineConfig): KlassInstance<typeof StateMachi
527
527
  **Parameters**
528
528
  - `config.states` (StateNode[], required): List of state nodes
529
529
  - `config.transfers` (StateTransfer[], required): List of state transfers
530
- - `config.defaultState` (StateNode, required): Default state
530
+ - `config.initialState` (StateNode, required): Default state
531
531
 
532
532
  **Examples**
533
533
  ```typescript
@@ -547,7 +547,7 @@ const OrderStateMachine = StateMachine.create({
547
547
  trigger: ConfirmOrderInteraction
548
548
  })
549
549
  ],
550
- defaultState: pendingState
550
+ initialState: pendingState
551
551
  })
552
552
  ```
553
553
 
@@ -358,7 +358,7 @@ const DeletedState = StateNode.create({ name: 'deleted' });
358
358
  const ArticleStatusStateMachine = StateMachine.create({
359
359
  name: 'ArticleStatus',
360
360
  states: [ActiveState, DeletedState],
361
- defaultState: ActiveState,
361
+ initialState: ActiveState,
362
362
  transfers: [
363
363
  StateTransfer.create({
364
364
  current: ActiveState,
@@ -393,7 +393,7 @@ const Article = Entity.create({
393
393
  name: 'status',
394
394
  type: 'string',
395
395
  computation: ArticleStatusStateMachine,
396
- defaultValue: () => ArticleStatusStateMachine.defaultState.name
396
+ defaultValue: () => ArticleStatusStateMachine.initialState.name
397
397
  }),
398
398
  Property.create({
399
399
  name: 'deletedAt',
@@ -428,7 +428,7 @@ const Article = Entity.create({
428
428
  computeTarget: (event) => ({ id: event.payload.articleId })
429
429
  })
430
430
  ],
431
- defaultState: activeState
431
+ initialState: activeState
432
432
  });
433
433
  })()
434
434
  })
@@ -473,7 +473,7 @@ const Article = Entity.create({
473
473
  const deletionProperty = Article.properties.find(p => p.name === '_isDeleted_');
474
474
  deletionProperty.computation = StateMachine.create({
475
475
  states: [NON_DELETED_STATE, DELETED_STATE],
476
- defaultState: NON_DELETED_STATE,
476
+ initialState: NON_DELETED_STATE,
477
477
  transfers: [
478
478
  StateTransfer.create({
479
479
  trigger: DeleteArticle,
@@ -606,7 +606,7 @@ const PublishedState = StateNode.create({ name: 'published' });
606
606
  const ArticlePublishStateMachine = StateMachine.create({
607
607
  name: 'ArticlePublishStatus',
608
608
  states: [DraftState, PublishedState],
609
- defaultState: DraftState,
609
+ initialState: DraftState,
610
610
  transfers: [
611
611
  StateTransfer.create({
612
612
  current: DraftState,
@@ -716,7 +716,7 @@ const TimestampState = StateNode.create({
716
716
  const TimestampStateMachine = StateMachine.create({
717
717
  name: 'TimestampRecorder',
718
718
  states: [TimestampState],
719
- defaultState: TimestampState,
719
+ initialState: TimestampState,
720
720
  transfers: [
721
721
  // Self-transition: stays in same state but triggers computeValue
722
722
  StateTransfer.create({
@@ -771,7 +771,7 @@ const User = Entity.create({
771
771
  computeTarget: (event) => ({ id: event.user.id })
772
772
  })
773
773
  ],
774
- defaultState: activeState
774
+ initialState: activeState
775
775
  })
776
776
  })
777
777
  ]
@@ -805,7 +805,7 @@ const Article = Entity.create({
805
805
  computeTarget: (event) => ({ id: event.payload.articleId })
806
806
  })
807
807
  ],
808
- defaultState: modifiedState
808
+ initialState: modifiedState
809
809
  })
810
810
  })
811
811
  ]
@@ -838,7 +838,7 @@ const Sensor = Entity.create({
838
838
  computeTarget: (event) => ({ id: event.payload.sensorId })
839
839
  })
840
840
  ],
841
- defaultState: triggeredState
841
+ initialState: triggeredState
842
842
  })
843
843
  })
844
844
  ]
@@ -891,7 +891,7 @@ Property.create({
891
891
  name: 'lastActivityAt',
892
892
  computation: StateMachine.create({
893
893
  states: [activeState],
894
- defaultState: activeState,
894
+ initialState: activeState,
895
895
  transfers: [
896
896
  StateTransfer.create({
897
897
  current: activeState,
@@ -1028,7 +1028,7 @@ const DeletedState = StateNode.create({ name: 'deleted' });
1028
1028
  const ArticleLifecycleStateMachine = StateMachine.create({
1029
1029
  name: 'ArticleLifecycle',
1030
1030
  states: [DraftState, PublishedState, DeletedState],
1031
- defaultState: DraftState,
1031
+ initialState: DraftState,
1032
1032
  transfers: [
1033
1033
  StateTransfer.create({
1034
1034
  current: DraftState,
@@ -235,7 +235,7 @@ StateMachine.create({
235
235
  trigger: SomeInteraction
236
236
  })
237
237
  ],
238
- defaultState: 'active' // Should be object reference!
238
+ initialState: 'active' // Should be object reference!
239
239
  });
240
240
 
241
241
  // ✅ CORRECT: Use object references
@@ -251,7 +251,7 @@ StateMachine.create({
251
251
  trigger: SomeInteraction
252
252
  })
253
253
  ],
254
- defaultState: activeState // Object reference
254
+ initialState: activeState // Object reference
255
255
  });
256
256
  ```
257
257