@strav/machine 0.1.0 → 0.1.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.
- package/README.md +7 -7
- package/package.json +1 -1
- package/src/errors.ts +1 -1
- package/src/machine.ts +1 -1
- package/src/stateful.ts +5 -5
package/README.md
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
# @
|
|
1
|
+
# @strav/machine
|
|
2
2
|
|
|
3
|
-
State machine for the [Strav](https://www.npmjs.com/package/@
|
|
3
|
+
State machine for the [Strav](https://www.npmjs.com/package/@strav/core) framework. Declarative state definitions with transitions, guards, side effects, and event emission.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
bun add @
|
|
8
|
+
bun add @strav/machine
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
Requires `@
|
|
11
|
+
Requires `@strav/core` as a peer dependency.
|
|
12
12
|
|
|
13
13
|
## Usage
|
|
14
14
|
|
|
15
15
|
### Define a Machine
|
|
16
16
|
|
|
17
17
|
```ts
|
|
18
|
-
import { defineMachine } from '@
|
|
18
|
+
import { defineMachine } from '@strav/machine'
|
|
19
19
|
|
|
20
20
|
const orderMachine = defineMachine({
|
|
21
21
|
field: 'status',
|
|
@@ -61,8 +61,8 @@ await orderMachine.apply(order, 'process')
|
|
|
61
61
|
### ORM Mixin
|
|
62
62
|
|
|
63
63
|
```ts
|
|
64
|
-
import { BaseModel } from '@
|
|
65
|
-
import { stateful } from '@
|
|
64
|
+
import { BaseModel } from '@strav/core/orm'
|
|
65
|
+
import { stateful } from '@strav/machine'
|
|
66
66
|
|
|
67
67
|
class Order extends stateful(BaseModel, orderMachine) {
|
|
68
68
|
declare id: number
|
package/package.json
CHANGED
package/src/errors.ts
CHANGED
package/src/machine.ts
CHANGED
package/src/stateful.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import type { BaseModel } from '@
|
|
2
|
-
import type { NormalizeConstructor } from '@
|
|
1
|
+
import type { BaseModel } from '@strav/database'
|
|
2
|
+
import type { NormalizeConstructor } from '@strav/kernel'
|
|
3
3
|
import type { Machine, TransitionMeta } from './types.ts'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Mixin that adds state machine methods to a BaseModel subclass.
|
|
7
7
|
*
|
|
8
8
|
* @example
|
|
9
|
-
* import { BaseModel } from '@
|
|
10
|
-
* import { defineMachine, stateful } from '@
|
|
9
|
+
* import { BaseModel } from '@strav/database'
|
|
10
|
+
* import { defineMachine, stateful } from '@strav/machine'
|
|
11
11
|
*
|
|
12
12
|
* const orderMachine = defineMachine({
|
|
13
13
|
* field: 'status',
|
|
@@ -30,7 +30,7 @@ import type { Machine, TransitionMeta } from './types.ts'
|
|
|
30
30
|
* await order.transition('process') // validates, mutates, saves, emits
|
|
31
31
|
*
|
|
32
32
|
* // Composable with other mixins:
|
|
33
|
-
* import { compose } from '@
|
|
33
|
+
* import { compose } from '@strav/kernel'
|
|
34
34
|
* class Order extends compose(BaseModel, searchable, m => stateful(m, orderMachine)) { }
|
|
35
35
|
*/
|
|
36
36
|
export function stateful<T extends NormalizeConstructor<typeof BaseModel>>(
|