@xstate/effect 1.0.0-alpha.9 → 1.0.0-beta.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.
@@ -1,8 +1,8 @@
1
1
  import { Cause } from 'effect';
2
2
  import { Atom, AsyncResult } from 'effect/reactivity';
3
- import { c as createEffectActor, N as NotReadyError, t as taggedState } from './state-a2e5cb31.js';
4
- export { N as NotReadyError } from './state-a2e5cb31.js';
5
- import 'xstate';
3
+ import { StateMachine } from 'xstate';
4
+ import { c as createEffectActor, a as causeFromError, N as NotReadyError, t as taggedState } from './state-83513b45.js';
5
+ export { N as NotReadyError } from './state-83513b45.js';
6
6
  import 'xstate/durable';
7
7
 
8
8
  /**
@@ -11,6 +11,8 @@ import 'xstate/durable';
11
11
  * framework, such as `@effect/atom-react`.
12
12
  */
13
13
 
14
+ /** @experimental */
15
+
14
16
  /**
15
17
  * Creates atoms for an actor that runs in an `Atom.runtime`. The runtime's
16
18
  * Layer must provide every service the logic requires; a missing service is
@@ -22,6 +24,8 @@ import 'xstate/durable';
22
24
  * when the atom is released. Wrap the atoms with `Atom.keepAlive` to pin the
23
25
  * actor for the registry's lifetime, or with `Atom.family` to create one
24
26
  * actor per input.
27
+ *
28
+ * @experimental
25
29
  */
26
30
  function createActorAtoms(runtime, logic, ...[options]) {
27
31
  const host = runtime;
@@ -55,7 +59,7 @@ function createActorAtoms(runtime, logic, ...[options]) {
55
59
  }
56
60
  const value = current.value;
57
61
  if (value.status === 'error') {
58
- return AsyncResult.failureWithPrevious(Cause.fail(value.error), {
62
+ return AsyncResult.failureWithPrevious(causeFromError(value.error), {
59
63
  previous: get.self()
60
64
  });
61
65
  }
@@ -75,15 +79,17 @@ function createActorAtoms(runtime, logic, ...[options]) {
75
79
  function select(selector) {
76
80
  return Atom.map(snapshot, result => AsyncResult.map(result, selector));
77
81
  }
78
- const state = select(current => taggedState(current));
79
- return {
82
+ const base = {
80
83
  actor,
81
84
  snapshot,
82
85
  result,
83
86
  send: sendAtom,
84
- select,
85
- state
87
+ select
86
88
  };
89
+ return logic instanceof StateMachine ? {
90
+ ...base,
91
+ state: select(current => taggedState(current))
92
+ } : base;
87
93
  }
88
94
 
89
95
  export { createActorAtoms };
@@ -0,0 +1,3 @@
1
+ export * from "./declarations/src/oxlint.js";
2
+ export { default } from "./declarations/src/oxlint.js";
3
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoieHN0YXRlLWVmZmVjdC1veGxpbnQuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4vZGVjbGFyYXRpb25zL3NyYy9veGxpbnQuZC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSJ9
@@ -0,0 +1,126 @@
1
+ import { defineRule, definePlugin } from '@oxlint/plugins';
2
+
3
+ const ENQUEUE_NAMES = new Set(['enq', 'enqueue']);
4
+ const EFFECT_LOGIC_CONSTRUCTORS = new Set(['createEffectLogic', 'createEffectStreamLogic', 'createEffectEventStreamLogic']);
5
+ const isNode = value => typeof value === 'object' && value !== null && 'type' in value && typeof value.type === 'string';
6
+ const rootIdentifier = node => {
7
+ let current = node;
8
+ for (;;) {
9
+ if (current.type === 'CallExpression') {
10
+ current = current.callee;
11
+ } else if (current.type === 'MemberExpression') {
12
+ current = current.object;
13
+ } else if (current.type === 'Identifier') {
14
+ return current.name;
15
+ } else {
16
+ return undefined;
17
+ }
18
+ }
19
+ };
20
+ const returnedExpressions = fn => {
21
+ if (fn.body === null) {
22
+ return [];
23
+ }
24
+ if (fn.body.type !== 'BlockStatement') {
25
+ return [fn.body];
26
+ }
27
+ const found = [];
28
+ const visit = node => {
29
+ if (node.type === 'ReturnStatement') {
30
+ if (node.argument) {
31
+ found.push(node.argument);
32
+ }
33
+ return;
34
+ }
35
+ if (node.type === 'FunctionExpression' || node.type === 'ArrowFunctionExpression' || node.type === 'FunctionDeclaration') {
36
+ return;
37
+ }
38
+ for (const [key, value] of Object.entries(node)) {
39
+ if (key === 'parent') {
40
+ continue;
41
+ }
42
+ if (Array.isArray(value)) {
43
+ for (const item of value) {
44
+ if (isNode(item)) {
45
+ visit(item);
46
+ }
47
+ }
48
+ } else if (isNode(value)) {
49
+ visit(value);
50
+ }
51
+ }
52
+ };
53
+ visit(fn.body);
54
+ return found;
55
+ };
56
+ const isPromiseResolve = node => node.callee.type === 'MemberExpression' && node.callee.object.type === 'Identifier' && node.callee.object.name === 'Promise' && node.callee.property.type === 'Identifier' && node.callee.property.name === 'resolve';
57
+ const isEffectExpression = node => {
58
+ if (node.type !== 'CallExpression') {
59
+ return false;
60
+ }
61
+ if (isPromiseResolve(node)) {
62
+ const [argument] = node.arguments;
63
+ return argument !== undefined && isEffectExpression(argument);
64
+ }
65
+ return rootIdentifier(node) === 'Effect';
66
+ };
67
+ const isInlineEffectLogic = node => node.type === 'CallExpression' && node.callee.type === 'Identifier' && EFFECT_LOGIC_CONSTRUCTORS.has(node.callee.name);
68
+ const isFunctionNode = node => node.type === 'ArrowFunctionExpression' || node.type === 'FunctionExpression';
69
+ const noInlineEffect = defineRule({
70
+ create(context) {
71
+ return {
72
+ CallExpression(node) {
73
+ const {
74
+ callee
75
+ } = node;
76
+ if (callee.type === 'MemberExpression' && callee.object.type === 'Identifier' && ENQUEUE_NAMES.has(callee.object.name) && callee.property.type === 'Identifier' && callee.property.name === 'spawn') {
77
+ const [logic] = node.arguments;
78
+ if (logic !== undefined && isInlineEffectLogic(logic)) {
79
+ context.report({
80
+ messageId: 'inlineSpawn',
81
+ node: logic
82
+ });
83
+ }
84
+ return;
85
+ }
86
+ if (callee.type !== 'Identifier' || !ENQUEUE_NAMES.has(callee.name)) {
87
+ return;
88
+ }
89
+ const [action] = node.arguments;
90
+ if (action === undefined || !isFunctionNode(action)) {
91
+ return;
92
+ }
93
+ for (const expression of returnedExpressions(action)) {
94
+ if (isEffectExpression(expression)) {
95
+ context.report({
96
+ messageId: 'inlineAction',
97
+ node: expression
98
+ });
99
+ }
100
+ }
101
+ }
102
+ };
103
+ },
104
+ meta: {
105
+ docs: {
106
+ description: 'Disallow Effects in inline enqueue callbacks and inline Effect logic in enq.spawn; declare them in setupEffect({ actions }) or actors.'
107
+ },
108
+ messages: {
109
+ inlineAction: 'An Effect returned from an inline action is discarded. Declare it in setupEffect({ actions }) and run it with enq(args.actions.name, args).',
110
+ inlineSpawn: 'Inline Effect logic passed to enq.spawn is invisible to RequirementsFrom and rejected at runtime. Declare it in actors and spawn args.actors.name.'
111
+ },
112
+ type: 'problem'
113
+ }
114
+ });
115
+
116
+ /** @experimental */
117
+ var oxlint = definePlugin({
118
+ meta: {
119
+ name: 'xstate-effect'
120
+ },
121
+ rules: {
122
+ 'no-inline-effect': noInlineEffect
123
+ }
124
+ });
125
+
126
+ export { oxlint as default };
@@ -0,0 +1,2 @@
1
+ export * from "./declarations/src/test.js";
2
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoieHN0YXRlLWVmZmVjdC10ZXN0LmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuL2RlY2xhcmF0aW9ucy9zcmMvdGVzdC5kLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBIn0=
@@ -0,0 +1 @@
1
+ export { s as sendAndAwait } from './sendAndAwait-bf1d4117.js';