@prb/effect-xstate 1.0.0-beta.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 +85 -0
- package/dist/errors/extract.d.ts +15 -0
- package/dist/errors/extract.d.ts.map +1 -0
- package/dist/errors/extract.js +29 -0
- package/dist/errors/extract.js.map +1 -0
- package/dist/errors/index.d.ts +3 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +3 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/errors/types.d.ts +13 -0
- package/dist/errors/types.d.ts.map +1 -0
- package/dist/errors/types.js +2 -0
- package/dist/errors/types.js.map +1 -0
- package/dist/hooks/index.d.ts +3 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +3 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/useFacilitatorWorkflow.d.ts +38 -0
- package/dist/hooks/useFacilitatorWorkflow.d.ts.map +1 -0
- package/dist/hooks/useFacilitatorWorkflow.js +36 -0
- package/dist/hooks/useFacilitatorWorkflow.js.map +1 -0
- package/dist/hooks/useFormWorkflow.d.ts +33 -0
- package/dist/hooks/useFormWorkflow.d.ts.map +1 -0
- package/dist/hooks/useFormWorkflow.js +32 -0
- package/dist/hooks/useFormWorkflow.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/machines/facilitator-machine.d.ts +81 -0
- package/dist/machines/facilitator-machine.d.ts.map +1 -0
- package/dist/machines/facilitator-machine.js +155 -0
- package/dist/machines/facilitator-machine.js.map +1 -0
- package/dist/machines/form-machine.d.ts +79 -0
- package/dist/machines/form-machine.d.ts.map +1 -0
- package/dist/machines/form-machine.js +171 -0
- package/dist/machines/form-machine.js.map +1 -0
- package/dist/machines/index.d.ts +3 -0
- package/dist/machines/index.d.ts.map +1 -0
- package/dist/machines/index.js +3 -0
- package/dist/machines/index.js.map +1 -0
- package/package.json +61 -0
package/README.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# @prb/xstate
|
|
2
|
+
|
|
3
|
+
Effect-TS and xState v5 workflow utilities for React applications.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This package provides reusable state machines and React hooks that combine Effect-TS's functional effect system with
|
|
8
|
+
xState v5's state management capabilities.
|
|
9
|
+
|
|
10
|
+
## Features
|
|
11
|
+
|
|
12
|
+
- **Form Machine**: Generic form workflow with validation, processing, and error handling
|
|
13
|
+
- **Facilitator Machine**: Check-then-create workflow for eligibility and resource creation
|
|
14
|
+
- **React Hooks**: Type-safe hooks for managing machine state in React components
|
|
15
|
+
- **Error Utilities**: Helpers for extracting and displaying structured error data
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
bun add @prb/xstate effect xstate @xstate/react
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
### Form Machine
|
|
26
|
+
|
|
27
|
+
Create a form workflow that validates inputs before processing:
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
import { createFormMachine } from "@prb/xstate";
|
|
31
|
+
import { Effect } from "effect";
|
|
32
|
+
|
|
33
|
+
const machine = createFormMachine({
|
|
34
|
+
id: "create-stream",
|
|
35
|
+
services: {
|
|
36
|
+
onCheck: (payload) => Effect.succeed(undefined),
|
|
37
|
+
onValidate: (payload) => Effect.succeed({ validated: true }),
|
|
38
|
+
onProcess: ({ payload, preprocess }) => Effect.succeed(undefined),
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Facilitator Machine
|
|
44
|
+
|
|
45
|
+
Create a check-then-create workflow:
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import { createFacilitatorMachine } from "@prb/xstate";
|
|
49
|
+
import { Effect } from "effect";
|
|
50
|
+
|
|
51
|
+
const machine = createFacilitatorMachine({
|
|
52
|
+
id: "claim-airdrop",
|
|
53
|
+
services: {
|
|
54
|
+
onCheck: (payload) => Effect.succeed({ status: "true", transitive: { proof: "0x..." } }),
|
|
55
|
+
onCreate: ({ create, transitive }) => Effect.succeed(undefined),
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### React Hook
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
import { useFacilitatorWorkflow } from "@prb/xstate";
|
|
64
|
+
|
|
65
|
+
function MyComponent() {
|
|
66
|
+
const workflow = useFacilitatorWorkflow(machine);
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<div>
|
|
70
|
+
<button onClick={() => workflow.check({ id: 123 })}>
|
|
71
|
+
Check Eligibility
|
|
72
|
+
</button>
|
|
73
|
+
{workflow.status.isEligible && (
|
|
74
|
+
<button onClick={() => workflow.create({ id: 123 })}>
|
|
75
|
+
Create Resource
|
|
76
|
+
</button>
|
|
77
|
+
)}
|
|
78
|
+
</div>
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## License
|
|
84
|
+
|
|
85
|
+
MIT
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { TransactionError } from "./types.js";
|
|
2
|
+
type TaggedErrorShape = {
|
|
3
|
+
_tag: string;
|
|
4
|
+
message: string;
|
|
5
|
+
address?: string;
|
|
6
|
+
calldata?: string;
|
|
7
|
+
functionName?: string;
|
|
8
|
+
sender?: string;
|
|
9
|
+
cause?: unknown;
|
|
10
|
+
};
|
|
11
|
+
declare function hasTaggedErrorShape(error: unknown): error is TaggedErrorShape;
|
|
12
|
+
export declare function extractErrorData(error: unknown, fallbackMessage?: string): TransactionError;
|
|
13
|
+
export { hasTaggedErrorShape };
|
|
14
|
+
export type { TaggedErrorShape };
|
|
15
|
+
//# sourceMappingURL=extract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract.d.ts","sourceRoot":"","sources":["../../src/errors/extract.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAKnD,KAAK,gBAAgB,GAAG;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AAKF,iBAAS,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,gBAAgB,CAStE;AAOD,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,OAAO,EACd,eAAe,SAAqB,GACnC,gBAAgB,CAoBlB;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAC;AAC/B,YAAY,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
function hasTaggedErrorShape(error) {
|
|
2
|
+
return (typeof error === "object" &&
|
|
3
|
+
error !== null &&
|
|
4
|
+
"_tag" in error &&
|
|
5
|
+
typeof error._tag === "string" &&
|
|
6
|
+
"message" in error &&
|
|
7
|
+
typeof error.message === "string");
|
|
8
|
+
}
|
|
9
|
+
export function extractErrorData(error, fallbackMessage = "Operation failed") {
|
|
10
|
+
if (hasTaggedErrorShape(error)) {
|
|
11
|
+
return {
|
|
12
|
+
details: {
|
|
13
|
+
address: error.address,
|
|
14
|
+
calldata: error.calldata,
|
|
15
|
+
cause: error.cause,
|
|
16
|
+
functionName: error.functionName,
|
|
17
|
+
sender: error.sender,
|
|
18
|
+
tag: error._tag,
|
|
19
|
+
},
|
|
20
|
+
message: error.message,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
if (error instanceof Error) {
|
|
24
|
+
return error.message;
|
|
25
|
+
}
|
|
26
|
+
return fallbackMessage;
|
|
27
|
+
}
|
|
28
|
+
export { hasTaggedErrorShape };
|
|
29
|
+
//# sourceMappingURL=extract.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract.js","sourceRoot":"","sources":["../../src/errors/extract.ts"],"names":[],"mappings":"AAkBA,SAAS,mBAAmB,CAAC,KAAc;IACzC,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,MAAM,IAAI,KAAK;QACf,OAAQ,KAA0B,CAAC,IAAI,KAAK,QAAQ;QACpD,SAAS,IAAI,KAAK;QAClB,OAAQ,KAA0B,CAAC,OAAO,KAAK,QAAQ,CACxD,CAAC;AACJ,CAAC;AAOD,MAAM,UAAU,gBAAgB,CAC9B,KAAc,EACd,eAAe,GAAG,kBAAkB;IAEpC,IAAI,mBAAmB,CAAC,KAAK,CAAC,EAAE,CAAC;QAC/B,OAAO;YACL,OAAO,EAAE;gBACP,OAAO,EAAE,KAAK,CAAC,OAAO;gBACtB,QAAQ,EAAE,KAAK,CAAC,QAAQ;gBACxB,KAAK,EAAE,KAAK,CAAC,KAAK;gBAClB,YAAY,EAAE,KAAK,CAAC,YAAY;gBAChC,MAAM,EAAE,KAAK,CAAC,MAAM;gBACpB,GAAG,EAAE,KAAK,CAAC,IAAI;aAChB;YACD,OAAO,EAAE,KAAK,CAAC,OAAO;SACvB,CAAC;IACJ,CAAC;IAED,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC3B,OAAO,KAAK,CAAC,OAAO,CAAC;IACvB,CAAC;IAED,OAAO,eAAe,CAAC;AACzB,CAAC;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type ErrorDetails = {
|
|
2
|
+
address?: string;
|
|
3
|
+
calldata?: string;
|
|
4
|
+
cause?: unknown;
|
|
5
|
+
functionName?: string;
|
|
6
|
+
sender?: string;
|
|
7
|
+
tag?: string;
|
|
8
|
+
};
|
|
9
|
+
export type TransactionError = string | {
|
|
10
|
+
details?: ErrorDetails;
|
|
11
|
+
message: string;
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/errors/types.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,YAAY,GAAG;IAEzB,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAGF,MAAM,MAAM,gBAAgB,GACxB,MAAM,GACN;IACE,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/errors/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,sBAAsB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { AnyActorLogic, InspectionEvent, Observer } from "xstate";
|
|
2
|
+
import type { EligibilityStatus, FacilitatorMachineContext } from "../machines/index.js";
|
|
3
|
+
type FacilitatorMachineSnapshot<TTransitive> = {
|
|
4
|
+
value: string;
|
|
5
|
+
context: FacilitatorMachineContext<TTransitive>;
|
|
6
|
+
};
|
|
7
|
+
type UseFacilitatorWorkflowReturn<TCheck, TCreate, TTransitive> = {
|
|
8
|
+
state: string;
|
|
9
|
+
context: FacilitatorMachineContext<TTransitive>;
|
|
10
|
+
error: string | null;
|
|
11
|
+
eligibility: EligibilityStatus;
|
|
12
|
+
transitive: TTransitive | null;
|
|
13
|
+
status: {
|
|
14
|
+
isIdle: boolean;
|
|
15
|
+
isChecking: boolean;
|
|
16
|
+
isChecked: boolean;
|
|
17
|
+
isCreating: boolean;
|
|
18
|
+
isCreated: boolean;
|
|
19
|
+
isFailed: boolean;
|
|
20
|
+
isEligible: boolean;
|
|
21
|
+
isNotEligible: boolean;
|
|
22
|
+
isExpired: boolean;
|
|
23
|
+
isLoading: boolean;
|
|
24
|
+
};
|
|
25
|
+
check: (payload: TCheck & {
|
|
26
|
+
soft?: boolean;
|
|
27
|
+
}) => void;
|
|
28
|
+
create: (payload: TCreate) => void;
|
|
29
|
+
reset: () => void;
|
|
30
|
+
send: (event: unknown) => void;
|
|
31
|
+
snapshot: FacilitatorMachineSnapshot<TTransitive>;
|
|
32
|
+
};
|
|
33
|
+
type UseFacilitatorWorkflowOptions = {
|
|
34
|
+
inspect?: Observer<InspectionEvent> | ((event: InspectionEvent) => void);
|
|
35
|
+
};
|
|
36
|
+
export declare function useFacilitatorWorkflow<TCheck = unknown, TCreate = unknown, TTransitive = unknown>(machine: AnyActorLogic, options?: UseFacilitatorWorkflowOptions): UseFacilitatorWorkflowReturn<TCheck, TCreate, TTransitive>;
|
|
37
|
+
export {};
|
|
38
|
+
//# sourceMappingURL=useFacilitatorWorkflow.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFacilitatorWorkflow.d.ts","sourceRoot":"","sources":["../../src/hooks/useFacilitatorWorkflow.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AACvE,OAAO,KAAK,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AAM5F,KAAK,0BAA0B,CAAC,WAAW,IAAI;IAC7C,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,yBAAyB,CAAC,WAAW,CAAC,CAAC;CACjD,CAAC;AAEF,KAAK,4BAA4B,CAAC,MAAM,EAAE,OAAO,EAAE,WAAW,IAAI;IAEhE,KAAK,EAAE,MAAM,CAAC;IAGd,OAAO,EAAE,yBAAyB,CAAC,WAAW,CAAC,CAAC;IAGhD,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAGrB,WAAW,EAAE,iBAAiB,CAAC;IAG/B,UAAU,EAAE,WAAW,GAAG,IAAI,CAAC;IAG/B,MAAM,EAAE;QACN,MAAM,EAAE,OAAO,CAAC;QAChB,UAAU,EAAE,OAAO,CAAC;QACpB,SAAS,EAAE,OAAO,CAAC;QACnB,UAAU,EAAE,OAAO,CAAC;QACpB,SAAS,EAAE,OAAO,CAAC;QACnB,QAAQ,EAAE,OAAO,CAAC;QAClB,UAAU,EAAE,OAAO,CAAC;QACpB,aAAa,EAAE,OAAO,CAAC;QACvB,SAAS,EAAE,OAAO,CAAC;QACnB,SAAS,EAAE,OAAO,CAAC;KACpB,CAAC;IAGF,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,GAAG;QAAE,IAAI,CAAC,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,CAAC;IAGtD,MAAM,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;IAGnC,KAAK,EAAE,MAAM,IAAI,CAAC;IAGlB,IAAI,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IAG/B,QAAQ,EAAE,0BAA0B,CAAC,WAAW,CAAC,CAAC;CACnD,CAAC;AAEF,KAAK,6BAA6B,GAAG;IAEnC,OAAO,CAAC,EAAE,QAAQ,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,CAAC,CAAC;CAC1E,CAAC;AASF,wBAAgB,sBAAsB,CAAC,MAAM,GAAG,OAAO,EAAE,OAAO,GAAG,OAAO,EAAE,WAAW,GAAG,OAAO,EAC/F,OAAO,EAAE,aAAa,EACtB,OAAO,CAAC,EAAE,6BAA6B,GACtC,4BAA4B,CAAC,MAAM,EAAE,OAAO,EAAE,WAAW,CAAC,CAsC5D"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useActor } from "@xstate/react";
|
|
3
|
+
export function useFacilitatorWorkflow(machine, options) {
|
|
4
|
+
const [snapshot, send] = useActor(machine, { inspect: options?.inspect });
|
|
5
|
+
const check = (payload) => send({ payload, type: "CHECK" });
|
|
6
|
+
const create = (payload) => send({ payload, type: "CREATE" });
|
|
7
|
+
const reset = () => send({ type: "RESET" });
|
|
8
|
+
const typedSnapshot = snapshot;
|
|
9
|
+
const eligibility = typedSnapshot.context.status;
|
|
10
|
+
const status = {
|
|
11
|
+
isChecked: typedSnapshot.value === "checked",
|
|
12
|
+
isChecking: typedSnapshot.value === "checking",
|
|
13
|
+
isCreated: typedSnapshot.value === "created",
|
|
14
|
+
isCreating: typedSnapshot.value === "creating",
|
|
15
|
+
isEligible: eligibility === "true",
|
|
16
|
+
isExpired: eligibility === "expired",
|
|
17
|
+
isFailed: typedSnapshot.value === "failed",
|
|
18
|
+
isIdle: typedSnapshot.value === "idle",
|
|
19
|
+
isLoading: ["checking", "creating"].includes(typedSnapshot.value),
|
|
20
|
+
isNotEligible: eligibility === "false",
|
|
21
|
+
};
|
|
22
|
+
return {
|
|
23
|
+
check,
|
|
24
|
+
context: typedSnapshot.context,
|
|
25
|
+
create,
|
|
26
|
+
eligibility,
|
|
27
|
+
error: typedSnapshot.context.error,
|
|
28
|
+
reset,
|
|
29
|
+
send,
|
|
30
|
+
snapshot: typedSnapshot,
|
|
31
|
+
state: typedSnapshot.value,
|
|
32
|
+
status,
|
|
33
|
+
transitive: typedSnapshot.context.transitive,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=useFacilitatorWorkflow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFacilitatorWorkflow.js","sourceRoot":"","sources":["../../src/hooks/useFacilitatorWorkflow.ts"],"names":[],"mappings":"AAMA,YAAY,CAAC;AAEb,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAuEzC,MAAM,UAAU,sBAAsB,CACpC,OAAsB,EACtB,OAAuC;IAEvC,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,GAAG,QAAQ,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;IAE1E,MAAM,KAAK,GAAG,CAAC,OAAoC,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;IAEzF,MAAM,MAAM,GAAG,CAAC,OAAgB,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;IAEvE,MAAM,KAAK,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;IAE5C,MAAM,aAAa,GAAG,QAAmD,CAAC;IAC1E,MAAM,WAAW,GAAG,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC;IAEjD,MAAM,MAAM,GAAG;QACb,SAAS,EAAE,aAAa,CAAC,KAAK,KAAK,SAAS;QAC5C,UAAU,EAAE,aAAa,CAAC,KAAK,KAAK,UAAU;QAC9C,SAAS,EAAE,aAAa,CAAC,KAAK,KAAK,SAAS;QAC5C,UAAU,EAAE,aAAa,CAAC,KAAK,KAAK,UAAU;QAC9C,UAAU,EAAE,WAAW,KAAK,MAAM;QAClC,SAAS,EAAE,WAAW,KAAK,SAAS;QACpC,QAAQ,EAAE,aAAa,CAAC,KAAK,KAAK,QAAQ;QAC1C,MAAM,EAAE,aAAa,CAAC,KAAK,KAAK,MAAM;QACtC,SAAS,EAAE,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC;QACjE,aAAa,EAAE,WAAW,KAAK,OAAO;KACvC,CAAC;IAEF,OAAO;QACL,KAAK;QACL,OAAO,EAAE,aAAa,CAAC,OAAO;QAC9B,MAAM;QACN,WAAW;QACX,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC,KAAK;QAClC,KAAK;QACL,IAAI;QACJ,QAAQ,EAAE,aAAa;QACvB,KAAK,EAAE,aAAa,CAAC,KAAK;QAC1B,MAAM;QACN,UAAU,EAAE,aAAa,CAAC,OAAO,CAAC,UAAU;KAC7C,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { AnyActorLogic, InspectionEvent, Observer } from "xstate";
|
|
2
|
+
import type { FormMachineContext } from "../machines/index.js";
|
|
3
|
+
type FormMachineSnapshot<TPayload, TResult, TPreprocess> = {
|
|
4
|
+
value: string;
|
|
5
|
+
context: FormMachineContext<TPayload, TResult, TPreprocess>;
|
|
6
|
+
};
|
|
7
|
+
type UseFormWorkflowReturn<TCheck, TPayload, TResult, TPreprocess> = {
|
|
8
|
+
state: string;
|
|
9
|
+
context: FormMachineContext<TPayload, TResult, TPreprocess>;
|
|
10
|
+
error: string | null;
|
|
11
|
+
preprocess: TPreprocess;
|
|
12
|
+
result: TResult | null;
|
|
13
|
+
status: {
|
|
14
|
+
isIdle: boolean;
|
|
15
|
+
isChecking: boolean;
|
|
16
|
+
isValidating: boolean;
|
|
17
|
+
isProcessing: boolean;
|
|
18
|
+
isSuccess: boolean;
|
|
19
|
+
isFailure: boolean;
|
|
20
|
+
isLoading: boolean;
|
|
21
|
+
};
|
|
22
|
+
check: (payload: TCheck) => void;
|
|
23
|
+
save: (payload: TPayload) => void;
|
|
24
|
+
reset: () => void;
|
|
25
|
+
send: (event: unknown) => void;
|
|
26
|
+
snapshot: FormMachineSnapshot<TPayload, TResult, TPreprocess>;
|
|
27
|
+
};
|
|
28
|
+
type UseFormWorkflowOptions = {
|
|
29
|
+
inspect?: Observer<InspectionEvent> | ((event: InspectionEvent) => void);
|
|
30
|
+
};
|
|
31
|
+
export declare function useFormWorkflow<TCheck = unknown, TPayload = unknown, TResult = unknown, TPreprocess = unknown>(machine: AnyActorLogic, options?: UseFormWorkflowOptions): UseFormWorkflowReturn<TCheck, TPayload, TResult, TPreprocess>;
|
|
32
|
+
export {};
|
|
33
|
+
//# sourceMappingURL=useFormWorkflow.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFormWorkflow.d.ts","sourceRoot":"","sources":["../../src/hooks/useFormWorkflow.ts"],"names":[],"mappings":"AAsCA,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AACvE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAMlE,KAAK,mBAAmB,CAAC,QAAQ,EAAE,OAAO,EAAE,WAAW,IAAI;IACzD,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,kBAAkB,CAAC,QAAQ,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC;CAC7D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AE,OAAO,EAAE,WAAW,CAAC,CAkC/D"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useActor } from "@xstate/react";
|
|
3
|
+
export function useFormWorkflow(machine, options) {
|
|
4
|
+
const [snapshot, send] = useActor(machine, { inspect: options?.inspect });
|
|
5
|
+
const check = (payload) => send({ payload, type: "CHECK" });
|
|
6
|
+
const save = (payload) => send({ payload, type: "SAVE" });
|
|
7
|
+
const reset = () => send({ type: "RESET" });
|
|
8
|
+
const typedSnapshot = snapshot;
|
|
9
|
+
const status = {
|
|
10
|
+
isChecking: typedSnapshot.value === "check",
|
|
11
|
+
isFailure: typedSnapshot.value === "failure",
|
|
12
|
+
isIdle: typedSnapshot.value === "initial",
|
|
13
|
+
isLoading: ["check", "validate", "process"].includes(typedSnapshot.value),
|
|
14
|
+
isProcessing: typedSnapshot.value === "process",
|
|
15
|
+
isSuccess: typedSnapshot.value === "success",
|
|
16
|
+
isValidating: typedSnapshot.value === "validate",
|
|
17
|
+
};
|
|
18
|
+
return {
|
|
19
|
+
check,
|
|
20
|
+
context: typedSnapshot.context,
|
|
21
|
+
error: typedSnapshot.context.error,
|
|
22
|
+
preprocess: typedSnapshot.context.preprocess,
|
|
23
|
+
reset,
|
|
24
|
+
result: typedSnapshot.context.result,
|
|
25
|
+
save,
|
|
26
|
+
send,
|
|
27
|
+
snapshot: typedSnapshot,
|
|
28
|
+
state: typedSnapshot.value,
|
|
29
|
+
status,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=useFormWorkflow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFormWorkflow.js","sourceRoot":"","sources":["../../src/hooks/useFormWorkflow.ts"],"names":[],"mappings":"AAmCA,YAAY,CAAC;AAEb,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAiFzC,MAAM,UAAU,eAAe,CAM7B,OAAsB,EACtB,OAAgC;IAEhC,M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AK;QAC1B,MAAM;KACP,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
type EligibilityStatus = "idle" | "true" | "false" | "expired";
|
|
3
|
+
type FacilitatedResult<TTransitive> = {
|
|
4
|
+
status: EligibilityStatus;
|
|
5
|
+
transitive: TTransitive | null;
|
|
6
|
+
};
|
|
7
|
+
type FacilitatorMachineContext<TTransitive> = {
|
|
8
|
+
error: string | null;
|
|
9
|
+
status: EligibilityStatus;
|
|
10
|
+
transitive: TTransitive | null;
|
|
11
|
+
};
|
|
12
|
+
type FacilitatorMachineEvents<TCheck, TCreate> = {
|
|
13
|
+
type: "CHECK";
|
|
14
|
+
payload: TCheck & {
|
|
15
|
+
soft?: boolean;
|
|
16
|
+
};
|
|
17
|
+
} | {
|
|
18
|
+
type: "CREATE";
|
|
19
|
+
payload: TCreate;
|
|
20
|
+
} | {
|
|
21
|
+
type: "RESET";
|
|
22
|
+
};
|
|
23
|
+
type FacilitatorMachineServices<TCheck, TCreate, TTransitive> = {
|
|
24
|
+
onCheck: (payload: TCheck & {
|
|
25
|
+
soft?: boolean;
|
|
26
|
+
}) => Effect.Effect<FacilitatedResult<TTransitive>, Error>;
|
|
27
|
+
onCreate: (input: {
|
|
28
|
+
create: TCreate;
|
|
29
|
+
transitive: TTransitive | null;
|
|
30
|
+
}) => Effect.Effect<void, Error>;
|
|
31
|
+
};
|
|
32
|
+
type FacilitatorMachineConfig<TCheck, TCreate, TTransitive> = {
|
|
33
|
+
id: string;
|
|
34
|
+
services: FacilitatorMachineServices<TCheck, TCreate, TTransitive>;
|
|
35
|
+
};
|
|
36
|
+
declare function createFacilitatorMachine<TCheck, TCreate, TTransitive>({ id, services, }: FacilitatorMachineConfig<TCheck, TCreate, TTransitive>): import("xstate").StateMachine<FacilitatorMachineContext<TTransitive>, {
|
|
37
|
+
type: "RESET";
|
|
38
|
+
} | {
|
|
39
|
+
type: "CHECK";
|
|
40
|
+
payload: TCheck & {
|
|
41
|
+
soft?: boolean;
|
|
42
|
+
};
|
|
43
|
+
} | {
|
|
44
|
+
type: "CREATE";
|
|
45
|
+
payload: TCreate;
|
|
46
|
+
}, {
|
|
47
|
+
[x: string]: import("xstate").ActorRefFromLogic<import("xstate").PromiseActorLogic<FacilitatedResult<TTransitive>, TCheck & {
|
|
48
|
+
soft?: boolean;
|
|
49
|
+
}, import("xstate").EventObject>> | import("xstate").ActorRefFromLogic<import("xstate").PromiseActorLogic<void, {
|
|
50
|
+
create: TCreate;
|
|
51
|
+
transitive: TTransitive | null;
|
|
52
|
+
}, import("xstate").EventObject>> | undefined;
|
|
53
|
+
}, {
|
|
54
|
+
src: "doCheck";
|
|
55
|
+
logic: import("xstate").PromiseActorLogic<FacilitatedResult<TTransitive>, TCheck & {
|
|
56
|
+
soft?: boolean;
|
|
57
|
+
}, import("xstate").EventObject>;
|
|
58
|
+
id: string | undefined;
|
|
59
|
+
} | {
|
|
60
|
+
src: "doCreate";
|
|
61
|
+
logic: import("xstate").PromiseActorLogic<void, {
|
|
62
|
+
create: TCreate;
|
|
63
|
+
transitive: TTransitive | null;
|
|
64
|
+
}, import("xstate").EventObject>;
|
|
65
|
+
id: string | undefined;
|
|
66
|
+
}, {
|
|
67
|
+
type: "doCache";
|
|
68
|
+
params: import("xstate").NonReducibleUnknown;
|
|
69
|
+
} | {
|
|
70
|
+
type: "doClean";
|
|
71
|
+
params: import("xstate").NonReducibleUnknown;
|
|
72
|
+
} | {
|
|
73
|
+
type: "doError";
|
|
74
|
+
params: import("xstate").NonReducibleUnknown;
|
|
75
|
+
}, never, never, {}, string, import("xstate").NonReducibleUnknown, import("xstate").NonReducibleUnknown, import("xstate").EventObject, import("xstate").MetaObject, {
|
|
76
|
+
id?: string | undefined | undefined;
|
|
77
|
+
states?: {} | undefined;
|
|
78
|
+
}>;
|
|
79
|
+
export { createFacilitatorMachine };
|
|
80
|
+
export type { EligibilityStatus, FacilitatedResult, FacilitatorMachineConfig, FacilitatorMachineContext, FacilitatorMachineEvents, FacilitatorMachineServices, };
|
|
81
|
+
//# sourceMappingURL=facilitator-machine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"facilitator-machine.d.ts","sourceRoot":"","sources":["../../src/machines/facilitator-machine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAMhC,KAAK,iBAAiB,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC;AAK/D,KAAK,iBAAiB,CAAC,WAAW,IAAI;IACpC,MAAM,EAAE,iBAAiB,CAAC;IAC1B,UAAU,EAAE,WAAW,GAAG,IAAI,CAAC;CAChC,CAAC;AAKF,KAAK,yBAAyB,CAAC,WAAW,IAAI;IAE5C,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAErB,MAAM,EAAE,iBAAiB,CAAC;IAE1B,UAAU,EAAE,WAAW,GAAG,IAAI,CAAC;CAChC,CAAC;AAKF,KAAK,wBAAwB,CAAC,MAAM,EAAE,OAAO,IACzC;IACE,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,MAAM,GAAG;QAAE,IAAI,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;CACtC,GACD;IACE,IAAI,EAAE,QAAQ,CAAC;IACf,OAAO,EAAE,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
2
|
+
import { assign, fromPromise, setup } from "xstate";
|
|
3
|
+
function createFacilitatorMachine({ id, services, }) {
|
|
4
|
+
return setup({
|
|
5
|
+
actions: {
|
|
6
|
+
doCache: assign({
|
|
7
|
+
error: () => null,
|
|
8
|
+
status: ({ event }) => {
|
|
9
|
+
if ("output" in event) {
|
|
10
|
+
const result = event.output;
|
|
11
|
+
return result.status;
|
|
12
|
+
}
|
|
13
|
+
return "idle";
|
|
14
|
+
},
|
|
15
|
+
transitive: ({ event }) => {
|
|
16
|
+
if ("output" in event) {
|
|
17
|
+
const result = event.output;
|
|
18
|
+
return result.transitive;
|
|
19
|
+
}
|
|
20
|
+
return null;
|
|
21
|
+
},
|
|
22
|
+
}),
|
|
23
|
+
doClean: assign({
|
|
24
|
+
error: () => null,
|
|
25
|
+
status: () => "idle",
|
|
26
|
+
transitive: () => null,
|
|
27
|
+
}),
|
|
28
|
+
doError: assign({
|
|
29
|
+
error: ({ event }) => {
|
|
30
|
+
if ("error" in event && event.error instanceof Error) {
|
|
31
|
+
return event.error.message;
|
|
32
|
+
}
|
|
33
|
+
return "An unknown error occurred";
|
|
34
|
+
},
|
|
35
|
+
}),
|
|
36
|
+
},
|
|
37
|
+
actors: {
|
|
38
|
+
doCheck: fromPromise(async ({ input }) => Effect.runPromise(services.onCheck(input))),
|
|
39
|
+
doCreate: fromPromise(async ({ input }) => Effect.runPromise(services.onCreate(input))),
|
|
40
|
+
},
|
|
41
|
+
types: {
|
|
42
|
+
context: {},
|
|
43
|
+
events: {},
|
|
44
|
+
},
|
|
45
|
+
}).createMachine({
|
|
46
|
+
context: {
|
|
47
|
+
error: null,
|
|
48
|
+
status: "idle",
|
|
49
|
+
transitive: null,
|
|
50
|
+
},
|
|
51
|
+
id: `facilitator-${id}`,
|
|
52
|
+
initial: "idle",
|
|
53
|
+
states: {
|
|
54
|
+
checked: {
|
|
55
|
+
on: {
|
|
56
|
+
CHECK: {
|
|
57
|
+
target: "checking",
|
|
58
|
+
},
|
|
59
|
+
CREATE: {
|
|
60
|
+
target: "creating",
|
|
61
|
+
},
|
|
62
|
+
RESET: {
|
|
63
|
+
target: "idle",
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
checking: {
|
|
68
|
+
entry: "doClean",
|
|
69
|
+
invoke: {
|
|
70
|
+
id: "check",
|
|
71
|
+
input: ({ event }) => {
|
|
72
|
+
if (event.type === "CHECK") {
|
|
73
|
+
return event.payload;
|
|
74
|
+
}
|
|
75
|
+
throw new Error("Invalid event type for check");
|
|
76
|
+
},
|
|
77
|
+
onDone: {
|
|
78
|
+
actions: "doCache",
|
|
79
|
+
target: "checked",
|
|
80
|
+
},
|
|
81
|
+
onError: {
|
|
82
|
+
actions: "doError",
|
|
83
|
+
target: "failed",
|
|
84
|
+
},
|
|
85
|
+
src: "doCheck",
|
|
86
|
+
},
|
|
87
|
+
on: {
|
|
88
|
+
CHECK: {
|
|
89
|
+
target: "checking",
|
|
90
|
+
},
|
|
91
|
+
RESET: {
|
|
92
|
+
target: "idle",
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
created: {
|
|
97
|
+
on: {
|
|
98
|
+
RESET: {
|
|
99
|
+
target: "idle",
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
creating: {
|
|
104
|
+
invoke: {
|
|
105
|
+
id: "create",
|
|
106
|
+
input: ({ event, context }) => {
|
|
107
|
+
if (event.type === "CREATE") {
|
|
108
|
+
return {
|
|
109
|
+
create: event.payload,
|
|
110
|
+
transitive: context.transitive,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
throw new Error("Invalid event type for create");
|
|
114
|
+
},
|
|
115
|
+
onDone: {
|
|
116
|
+
target: "created",
|
|
117
|
+
},
|
|
118
|
+
onError: {
|
|
119
|
+
actions: "doError",
|
|
120
|
+
target: "failed",
|
|
121
|
+
},
|
|
122
|
+
src: "doCreate",
|
|
123
|
+
},
|
|
124
|
+
on: {
|
|
125
|
+
RESET: {
|
|
126
|
+
target: "idle",
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
failed: {
|
|
131
|
+
on: {
|
|
132
|
+
CHECK: {
|
|
133
|
+
target: "checking",
|
|
134
|
+
},
|
|
135
|
+
CREATE: {
|
|
136
|
+
target: "creating",
|
|
137
|
+
},
|
|
138
|
+
RESET: {
|
|
139
|
+
target: "idle",
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
idle: {
|
|
144
|
+
entry: "doClean",
|
|
145
|
+
on: {
|
|
146
|
+
CHECK: {
|
|
147
|
+
target: "checking",
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
export { createFacilitatorMachine };
|
|
155
|
+
//# sourceMappingURL=facilitator-machine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"facilitator-machine.js","sourceRoot":"","sources":["../../src/machines/facilitator-machine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AA0FpD,SAAS,wBAAwB,CAA+B,EAC9D,EAAE,EACF,QAAQ,GAC+C;IACvD,OAAO,KAAK,CAAC;QACX,OAAO,EAAE;YACP,OAAO,EAAE,MAAM,CAAC;gBACd,KAAK,EAAE,GAAG,EAAE,CAAC,IAAI;gBACjB,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;oBACpB,IAAI,QAAQ,IAAI,KAAK,EAAE,CAAC;wBACtB,MAAM,MAAM,GAAG,KAAK,CAAC,MAAwC,CAAC;wBAC9D,OAAO,MAAM,CAAC,MAAM,CAAC;oBACvB,CAAC;oBACD,OAAO,MAAe,CAAC;gBACzB,CAAC;gBACD,UAAU,E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U;6BAC/B,CAAC;wBACJ,CAAC;wBACD,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;oBACnD,CAAC;oBACD,MAAM,EAAE;wBACN,MAAM,EAAE,SAAS;qBAClB;oBACD,OAAO,EAAE;wBACP,OAAO,EAAE,SAAS;wBAClB,MAAM,EAAE,QAAQ;qBACjB;oBACD,GAAG,EAAE,UAAU;iBAChB;gBACD,EAAE,EAAE;oBACF,KAAK,EAAE;wBACL,MAAM,EAAE,MAAM;qBACf;iBACF;aACF;YACD,MAAM,EAAE;gBACN,EAAE,EAAE;oBACF,KAAK,EAAE;wBACL,MAAM,EAAE,UAAU;qBACnB;oBACD,MAAM,EAAE;wBACN,MAAM,EAAE,UAAU;qBACnB;oBACD,KAAK,EAAE;wBACL,MAAM,EAAE,MAAM;qBACf;iBACF;aACF;YACD,IAAI,EAAE;gBACJ,KAAK,EAAE,SAAS;gBAChB,EAAE,EAAE;oBACF,KAAK,EAAE;wBACL,MAAM,EAAE,UAAU;qBACnB;iBACF;aACF;SACF;KACF,CAAC,CAAC;AACL,CAAC;AAED,OAAO,EAAE,wBAAwB,EAAE,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
type FormMachineContext<TPayload, TResult, TPreprocess> = {
|
|
3
|
+
error: string | null;
|
|
4
|
+
payload: TPayload;
|
|
5
|
+
preprocess: TPreprocess;
|
|
6
|
+
result: TResult | null;
|
|
7
|
+
};
|
|
8
|
+
type FormMachineEvents<TCheck, TPayload> = {
|
|
9
|
+
type: "SAVE";
|
|
10
|
+
payload: TPayload;
|
|
11
|
+
} | {
|
|
12
|
+
type: "CHECK";
|
|
13
|
+
payload: TCheck;
|
|
14
|
+
} | {
|
|
15
|
+
type: "RESET";
|
|
16
|
+
};
|
|
17
|
+
type FormMachineServices<TCheck, TPayload, TResult, TPreprocess> = {
|
|
18
|
+
onCheck: (payload: TCheck) => Effect.Effect<void, Error>;
|
|
19
|
+
onValidate: (payload: TPayload) => Effect.Effect<TPreprocess, Error>;
|
|
20
|
+
onProcess: (input: {
|
|
21
|
+
payload: TPayload;
|
|
22
|
+
preprocess: TPreprocess;
|
|
23
|
+
}) => Effect.Effect<TResult, Error>;
|
|
24
|
+
};
|
|
25
|
+
type FormMachineConfig<TCheck, TPayload, TResult, TPreprocess> = {
|
|
26
|
+
id: string;
|
|
27
|
+
services: FormMachineServices<TCheck, TPayload, TResult, TPreprocess>;
|
|
28
|
+
isUserRejectedError?: (error: unknown) => boolean;
|
|
29
|
+
};
|
|
30
|
+
declare function createFormMachine<TCheck, TPayload, TResult, TPreprocess = undefined>({ id, services, isUserRejectedError, }: FormMachineConfig<TCheck, TPayload, TResult, TPreprocess>): import("xstate").StateMachine<FormMachineContext<TPayload, TResult, TPreprocess>, {
|
|
31
|
+
type: "RESET";
|
|
32
|
+
} | {
|
|
33
|
+
type: "SAVE";
|
|
34
|
+
payload: TPayload;
|
|
35
|
+
} | {
|
|
36
|
+
type: "CHECK";
|
|
37
|
+
payload: TCheck;
|
|
38
|
+
}, {
|
|
39
|
+
[x: string]: import("xstate").ActorRefFromLogic<import("xstate").PromiseActorLogic<void, TCheck, import("xstate").EventObject>> | import("xstate").ActorRefFromLogic<import("xstate").PromiseActorLogic<TResult, {
|
|
40
|
+
payload: TPayload;
|
|
41
|
+
preprocess: TPreprocess;
|
|
42
|
+
}, import("xstate").EventObject>> | import("xstate").ActorRefFromLogic<import("xstate").PromiseActorLogic<TPreprocess, TPayload, import("xstate").EventObject>> | undefined;
|
|
43
|
+
}, {
|
|
44
|
+
src: "doCheck";
|
|
45
|
+
logic: import("xstate").PromiseActorLogic<void, TCheck, import("xstate").EventObject>;
|
|
46
|
+
id: string | undefined;
|
|
47
|
+
} | {
|
|
48
|
+
src: "doProcess";
|
|
49
|
+
logic: import("xstate").PromiseActorLogic<TResult, {
|
|
50
|
+
payload: TPayload;
|
|
51
|
+
preprocess: TPreprocess;
|
|
52
|
+
}, import("xstate").EventObject>;
|
|
53
|
+
id: string | undefined;
|
|
54
|
+
} | {
|
|
55
|
+
src: "doValidate";
|
|
56
|
+
logic: import("xstate").PromiseActorLogic<TPreprocess, TPayload, import("xstate").EventObject>;
|
|
57
|
+
id: string | undefined;
|
|
58
|
+
}, {
|
|
59
|
+
type: "doCache";
|
|
60
|
+
params: import("xstate").NonReducibleUnknown;
|
|
61
|
+
} | {
|
|
62
|
+
type: "doError";
|
|
63
|
+
params: import("xstate").NonReducibleUnknown;
|
|
64
|
+
} | {
|
|
65
|
+
type: "doPreprocess";
|
|
66
|
+
params: import("xstate").NonReducibleUnknown;
|
|
67
|
+
} | {
|
|
68
|
+
type: "doReset";
|
|
69
|
+
params: import("xstate").NonReducibleUnknown;
|
|
70
|
+
} | {
|
|
71
|
+
type: "doResult";
|
|
72
|
+
params: import("xstate").NonReducibleUnknown;
|
|
73
|
+
}, never, never, {}, string, import("xstate").NonReducibleUnknown, import("xstate").NonReducibleUnknown, import("xstate").EventObject, import("xstate").MetaObject, {
|
|
74
|
+
id?: string | undefined | undefined;
|
|
75
|
+
states?: {} | undefined;
|
|
76
|
+
}>;
|
|
77
|
+
export { createFormMachine };
|
|
78
|
+
export type { FormMachineConfig, FormMachineContext, FormMachineEvents, FormMachineServices };
|
|
79
|
+
//# sourceMappingURL=form-machine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"form-machine.d.ts","sourceRoot":"","sources":["../../src/machines/form-machine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAMhC,KAAK,kBAAkB,CAAC,QAAQ,EAAE,OAAO,EAAE,WAAW,IAAI;IAExD,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAErB,OAAO,EAAE,QAAQ,CAAC;IAElB,UAAU,EAAE,WAAW,CAAC;IAExB,MAAM,EAAE,OAAO,GAAG,IAAI,CAAC;CACxB,CAAC;AAKF,KAAK,iBAAiB,CAAC,MAAM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;iBAAjC,QAAQ;oBAAc,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;GAgI9E;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAC;AAC7B,YAAY,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,CAAC"}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { assign, fromPromise, setup } from "xstate";
|
|
3
|
+
function createFormMachine({ id, services, isUserRejectedError, }) {
|
|
4
|
+
return setup({
|
|
5
|
+
actions: {
|
|
6
|
+
doCache: assign({
|
|
7
|
+
payload: ({ event }) => {
|
|
8
|
+
if (event.type === "SAVE") {
|
|
9
|
+
return event.payload;
|
|
10
|
+
}
|
|
11
|
+
return {};
|
|
12
|
+
},
|
|
13
|
+
}),
|
|
14
|
+
doError: assign({
|
|
15
|
+
error: ({ event }) => {
|
|
16
|
+
if ("error" in event && event.error instanceof Error) {
|
|
17
|
+
return event.error.message;
|
|
18
|
+
}
|
|
19
|
+
return "An unknown error occurred";
|
|
20
|
+
},
|
|
21
|
+
}),
|
|
22
|
+
doPreprocess: assign({
|
|
23
|
+
preprocess: ({ event }) => {
|
|
24
|
+
if ("output" in event) {
|
|
25
|
+
return event.output;
|
|
26
|
+
}
|
|
27
|
+
return {};
|
|
28
|
+
},
|
|
29
|
+
}),
|
|
30
|
+
doReset: assign({
|
|
31
|
+
error: () => null,
|
|
32
|
+
payload: () => ({}),
|
|
33
|
+
preprocess: () => ({}),
|
|
34
|
+
result: () => null,
|
|
35
|
+
}),
|
|
36
|
+
doResult: assign({
|
|
37
|
+
result: ({ event }) => {
|
|
38
|
+
if ("output" in event) {
|
|
39
|
+
return event.output;
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
},
|
|
43
|
+
}),
|
|
44
|
+
},
|
|
45
|
+
actors: {
|
|
46
|
+
doCheck: fromPromise(async ({ input }) => Effect.runPromise(services.onCheck(input))),
|
|
47
|
+
doProcess: fromPromise(async ({ input }) => Effect.runPromise(services.onProcess(input))),
|
|
48
|
+
doValidate: fromPromise(async ({ input }) => Effect.runPromise(services.onValidate(input))),
|
|
49
|
+
},
|
|
50
|
+
types: {
|
|
51
|
+
context: {},
|
|
52
|
+
events: {},
|
|
53
|
+
},
|
|
54
|
+
}).createMachine({
|
|
55
|
+
context: {
|
|
56
|
+
error: null,
|
|
57
|
+
payload: {},
|
|
58
|
+
preprocess: {},
|
|
59
|
+
result: null,
|
|
60
|
+
},
|
|
61
|
+
id: `formMachine-${id}`,
|
|
62
|
+
initial: "initial",
|
|
63
|
+
states: {
|
|
64
|
+
check: {
|
|
65
|
+
invoke: {
|
|
66
|
+
id: "check",
|
|
67
|
+
input: ({ event }) => {
|
|
68
|
+
if (event.type === "CHECK") {
|
|
69
|
+
return event.payload;
|
|
70
|
+
}
|
|
71
|
+
throw new Error("Invalid event type for check");
|
|
72
|
+
},
|
|
73
|
+
onDone: {
|
|
74
|
+
actions: "doReset",
|
|
75
|
+
target: "initial",
|
|
76
|
+
},
|
|
77
|
+
onError: {
|
|
78
|
+
actions: "doError",
|
|
79
|
+
target: "initial",
|
|
80
|
+
},
|
|
81
|
+
src: "doCheck",
|
|
82
|
+
},
|
|
83
|
+
on: {
|
|
84
|
+
CHECK: {
|
|
85
|
+
actions: "doReset",
|
|
86
|
+
target: "check",
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
failure: {
|
|
91
|
+
on: {
|
|
92
|
+
RESET: {
|
|
93
|
+
target: "initial",
|
|
94
|
+
},
|
|
95
|
+
SAVE: {
|
|
96
|
+
target: "validate",
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
initial: {
|
|
101
|
+
exit: "doReset",
|
|
102
|
+
on: {
|
|
103
|
+
CHECK: {
|
|
104
|
+
target: "check",
|
|
105
|
+
},
|
|
106
|
+
SAVE: {
|
|
107
|
+
target: "validate",
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
process: {
|
|
112
|
+
invoke: {
|
|
113
|
+
id: "process",
|
|
114
|
+
input: ({ context }) => ({
|
|
115
|
+
payload: context.payload,
|
|
116
|
+
preprocess: context.preprocess,
|
|
117
|
+
}),
|
|
118
|
+
onDone: {
|
|
119
|
+
actions: "doResult",
|
|
120
|
+
target: "success",
|
|
121
|
+
},
|
|
122
|
+
onError: isUserRejectedError
|
|
123
|
+
? [
|
|
124
|
+
{
|
|
125
|
+
actions: "doReset",
|
|
126
|
+
guard: ({ event }) => isUserRejectedError(event.error),
|
|
127
|
+
target: "initial",
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
actions: "doError",
|
|
131
|
+
target: "failure",
|
|
132
|
+
},
|
|
133
|
+
]
|
|
134
|
+
: {
|
|
135
|
+
actions: "doError",
|
|
136
|
+
target: "failure",
|
|
137
|
+
},
|
|
138
|
+
src: "doProcess",
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
success: {
|
|
142
|
+
on: {
|
|
143
|
+
RESET: {
|
|
144
|
+
target: "initial",
|
|
145
|
+
},
|
|
146
|
+
SAVE: {
|
|
147
|
+
target: "validate",
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
validate: {
|
|
152
|
+
entry: "doCache",
|
|
153
|
+
invoke: {
|
|
154
|
+
id: "validate",
|
|
155
|
+
input: ({ context }) => context.payload,
|
|
156
|
+
onDone: {
|
|
157
|
+
actions: "doPreprocess",
|
|
158
|
+
target: "process",
|
|
159
|
+
},
|
|
160
|
+
onError: {
|
|
161
|
+
actions: "doError",
|
|
162
|
+
target: "failure",
|
|
163
|
+
},
|
|
164
|
+
src: "doValidate",
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
export { createFormMachine };
|
|
171
|
+
//# sourceMappingURL=form-machine.js.map
|
|
@@ -0,0 +1 @@
|
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B;4BACD;gCACE,OAAO,EAAE,SAAS;gCAClB,MAAM,EAAE,SAAS;6BAClB;yBACF;wBACH,CAAC,CAAC;4BACE,OAAO,EAAE,SAAS;4BAClB,MAAM,EAAE,SAAS;yBAClB;oBACL,GAAG,EAAE,WAAW;iBACjB;aACF;YACD,OAAO,EAAE;gBACP,EAAE,EAAE;oBACF,KAAK,EAAE;wBACL,MAAM,EAAE,SAAS;qBAClB;oBACD,IAAI,EAAE;wBACJ,MAAM,EAAE,UAAU;qBACnB;iBACF;aACF;YACD,QAAQ,EAAE;gBACR,KAAK,EAAE,SAAS;gBAEhB,MAAM,EAAE;oBACN,EAAE,EAAE,UAAU;oBACd,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO;oBACvC,MAAM,EAAE;wBACN,OAAO,EAAE,cAAc;wBACvB,MAAM,EAAE,SAAS;qBAClB;oBACD,OAAO,EAAE;wBACP,OAAO,EAAE,SAAS;wBAClB,MAAM,EAAE,SAAS;qBAClB;oBACD,GAAG,EAAE,YAAY;iBAClB;aACF;SACF;KACF,CAAC,CAAC;AACL,CAAC;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/machines/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/machines/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,mBAAmB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@prb/effect-xstate",
|
|
3
|
+
"description": "Effect-TS and xState v5 workflow utilities",
|
|
4
|
+
"version": "1.0.0-beta.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"author": {
|
|
9
|
+
"name": "Paul Razvan Berg",
|
|
10
|
+
"url": "https://github.com/PaulRBerg"
|
|
11
|
+
},
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"@biomejs/biome": "catalog:dev",
|
|
15
|
+
"@effect/vitest": "catalog:dev",
|
|
16
|
+
"@sablier/devkit": "catalog:dev",
|
|
17
|
+
"@types/node": "catalog:dev",
|
|
18
|
+
"@types/react": "catalog:dev",
|
|
19
|
+
"@typescript/native-preview": "catalog:dev",
|
|
20
|
+
"@vitest/ui": "catalog:dev",
|
|
21
|
+
"@xstate/react": "^6.0.0",
|
|
22
|
+
"effect": "catalog:effect",
|
|
23
|
+
"react": "catalog:",
|
|
24
|
+
"tsc-alias": "catalog:dev",
|
|
25
|
+
"typescript": "catalog:dev",
|
|
26
|
+
"vitest": "catalog:dev",
|
|
27
|
+
"xstate": "^5.25.0"
|
|
28
|
+
},
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"import": "./dist/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./internal/*": null,
|
|
35
|
+
"./*": {
|
|
36
|
+
"types": "./dist/*/index.d.ts",
|
|
37
|
+
"import": "./dist/*/index.js"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"files": [
|
|
41
|
+
"dist/**",
|
|
42
|
+
"README.md"
|
|
43
|
+
],
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"@xstate/react": "catalog:peers",
|
|
46
|
+
"effect": "catalog:peers",
|
|
47
|
+
"react": "catalog:peers",
|
|
48
|
+
"xstate": "catalog:peers"
|
|
49
|
+
},
|
|
50
|
+
"peerDependenciesMeta": {
|
|
51
|
+
"react": {
|
|
52
|
+
"optional": true
|
|
53
|
+
},
|
|
54
|
+
"@xstate/react": {
|
|
55
|
+
"optional": true
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"publishConfig": {
|
|
59
|
+
"access": "public"
|
|
60
|
+
}
|
|
61
|
+
}
|