xstate 6.0.0-alpha.43 → 6.0.0-alpha.44
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/dist/declarations/src/schema.types.d.ts +2 -0
- package/dist/declarations/src/setup.d.ts +17 -3
- package/dist/declarations/src/types.d.ts +1 -0
- package/dist/declarations/src/types.v6.d.ts +1 -1
- package/dist/xstate.cjs.js +3 -1
- package/dist/xstate.development.cjs.js +3 -1
- package/dist/xstate.development.esm.js +3 -1
- package/dist/xstate.esm.js +3 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -7,6 +7,8 @@ export interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
|
7
7
|
export type SetupStateSchemas = {
|
|
8
8
|
context?: StandardSchemaV1;
|
|
9
9
|
input?: StandardSchemaV1;
|
|
10
|
+
/** The output emitted when this state node completes. */
|
|
11
|
+
output?: StandardSchemaV1;
|
|
10
12
|
};
|
|
11
13
|
/** A type-only Standard Schema produced by {@link types}. */
|
|
12
14
|
export interface TypeSchema<T> extends StandardSchemaV1<T, T> {
|
|
@@ -140,7 +140,7 @@ export type SetupSchemas = {
|
|
|
140
140
|
tags?: StandardSchemaV1;
|
|
141
141
|
children?: Record<string, StandardSchemaV1>;
|
|
142
142
|
};
|
|
143
|
-
/** State schema with optional
|
|
143
|
+
/** State schema with optional input/output schemas and nested states */
|
|
144
144
|
export interface SetupStateSchema {
|
|
145
145
|
schemas?: SetupStateSchemas;
|
|
146
146
|
states?: Record<string, SetupStateSchema>;
|
|
@@ -236,6 +236,11 @@ type ValidateSetupDelayReferences<TConfig, TSetupDelays extends string> = string
|
|
|
236
236
|
type StateInput<TStateSchema extends SetupStateSchema> = TStateSchema['schemas'] extends {
|
|
237
237
|
input: infer TInputSchema;
|
|
238
238
|
} ? TInputSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TInputSchema> : undefined : undefined;
|
|
239
|
+
/** Extracts the completion output type from a state schema. */
|
|
240
|
+
type StateOutput<TStateSchema extends SetupStateSchema, TFallback> = TStateSchema['schemas'] extends {
|
|
241
|
+
output: infer TOutputSchema;
|
|
242
|
+
} ? TOutputSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TOutputSchema> : TFallback : TFallback;
|
|
243
|
+
type StateCompletionOutput<TStateSchema extends SetupStateSchema> = StateOutput<TStateSchema, unknown>;
|
|
239
244
|
type StateContext<TStateSchema extends SetupStateSchema, TFallbackContext extends MachineContext> = TStateSchema['schemas'] extends {
|
|
240
245
|
context: infer TContextSchema;
|
|
241
246
|
} ? TContextSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TContextSchema> & MachineContext & RootContextMarker<TFallbackContext> : RootContext<TFallbackContext> : RootContext<TFallbackContext>;
|
|
@@ -262,6 +267,9 @@ type SetupStateSchemaToStateSchema<TSetupSchema extends SetupStateSchema> = {
|
|
|
262
267
|
contextSchema: TSetupSchema['schemas'] extends {
|
|
263
268
|
context: infer TContextSchema;
|
|
264
269
|
} ? TContextSchema extends StandardSchemaV1 ? TContextSchema : undefined : undefined;
|
|
270
|
+
outputSchema: TSetupSchema['schemas'] extends {
|
|
271
|
+
output: infer TOutputSchema;
|
|
272
|
+
} ? TOutputSchema extends StandardSchemaV1 ? TOutputSchema : undefined : undefined;
|
|
265
273
|
states: TSetupSchema['states'] extends Record<string, SetupStateSchema> ? {
|
|
266
274
|
[K in keyof TSetupSchema['states'] & string]: SetupStateSchemaToStateSchema<TSetupSchema['states'][K]>;
|
|
267
275
|
} : undefined;
|
|
@@ -286,11 +294,17 @@ type StateSchemaContextSchema<TConfig extends StateSchema, TSetup extends StateS
|
|
|
286
294
|
} ? TContextSchema extends StandardSchemaV1 ? TContextSchema : undefined : TConfig extends {
|
|
287
295
|
contextSchema: infer TContextSchema;
|
|
288
296
|
} ? TContextSchema extends StandardSchemaV1 ? TContextSchema : undefined : undefined;
|
|
297
|
+
type StateSchemaOutputSchema<TConfig extends StateSchema, TSetup extends StateSchema> = TSetup extends {
|
|
298
|
+
outputSchema: infer TOutputSchema;
|
|
299
|
+
} ? TOutputSchema extends StandardSchemaV1 ? TOutputSchema : undefined : TConfig extends {
|
|
300
|
+
outputSchema: infer TOutputSchema;
|
|
301
|
+
} ? TOutputSchema extends StandardSchemaV1 ? TOutputSchema : undefined : undefined;
|
|
289
302
|
type StateSchemaChild<TSetup extends StateSchema, K extends string> = TSetup extends {
|
|
290
303
|
states: infer TStates;
|
|
291
304
|
} ? K extends keyof TStates ? Cast<TStates[K], StateSchema> : EmptyStateSchema : EmptyStateSchema;
|
|
292
305
|
type MergeStateSchema<TConfig extends StateSchema, TSetup extends StateSchema> = Omit<TConfig, 'contextSchema' | 'input' | 'states'> & {
|
|
293
306
|
contextSchema: StateSchemaContextSchema<TConfig, TSetup>;
|
|
307
|
+
outputSchema: StateSchemaOutputSchema<TConfig, TSetup>;
|
|
294
308
|
input: StateSchemaInput<TConfig, TSetup>;
|
|
295
309
|
states: TConfig extends {
|
|
296
310
|
states: infer TStates;
|
|
@@ -321,7 +335,7 @@ type StatesWithInput<TRootStateSchemas extends Record<string, SetupStateSchema>,
|
|
|
321
335
|
[K in TStateKeys]?: StateNodeConfigWithNestedInput<StateSchemasWithKeys<TRootStateSchemas, TStateKeys>, K extends keyof TStateSchemas ? TStateSchemas[K] : {}, TContext, TContextShape, TEvent, TChildren, TDelays, TTag, TOutput, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
|
|
322
336
|
};
|
|
323
337
|
/** State node config that recursively applies typed input for nested states */
|
|
324
|
-
type StateNodeConfigWithNestedInput<TSiblingStateSchemas extends Record<string, SetupStateSchema>, TStateSchema extends SetupStateSchema, TContext extends MachineContext, TContextShape, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TDelays extends string, TTag extends string, TOutput, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Sources['actions'], TActorMap extends Sources['actors'], TGuardMap extends Sources['guards'], TDelayMap extends Sources['delays'], TSystemRegistry extends SystemRegistry> = WithNestedStates<Omit<Next_StateNodeConfig<StateContext<TStateSchema, TContext>, TEvent, TDelays, TTag,
|
|
338
|
+
type StateNodeConfigWithNestedInput<TSiblingStateSchemas extends Record<string, SetupStateSchema>, TStateSchema extends SetupStateSchema, TContext extends MachineContext, TContextShape, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TDelays extends string, TTag extends string, TOutput, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Sources['actions'], TActorMap extends Sources['actors'], TGuardMap extends Sources['guards'], TDelayMap extends Sources['delays'], TSystemRegistry extends SystemRegistry> = WithNestedStates<Omit<Next_StateNodeConfig<StateContext<TStateSchema, TContext>, TEvent, TDelays, TTag, StateOutput<TStateSchema, TOutput>, TEmitted, TMeta, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, StateInput<TStateSchema>, Record<string, unknown>, TSystemRegistry, StateCompletionOutput<TStateSchema>>, 'on' | 'always' | 'initial' | 'invoke' | 'onDone' | 'onError' | 'onTimeout' | 'after'> & {
|
|
325
339
|
initial?: TStateSchema['states'] extends Record<string, SetupStateSchema> ? SetupStateKey<TStateSchema['states']> | (string & {}) | InitialTransitionWithInput<TStateSchema['states'], StateContext<TStateSchema, TContext>, TEvent> : string | {
|
|
326
340
|
target: string;
|
|
327
341
|
input?: Record<string, unknown>;
|
|
@@ -329,7 +343,7 @@ type StateNodeConfigWithNestedInput<TSiblingStateSchemas extends Record<string,
|
|
|
329
343
|
on?: StateTransitions<TSiblingStateSchemas, StateContext<TStateSchema, TContext>, StateContextShape<TStateSchema, TContextShape>, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry, StateInput<TStateSchema>>;
|
|
330
344
|
always?: StateTransitionConfigOrTarget<TSiblingStateSchemas, StateContext<TStateSchema, TContext>, StateContextShape<TStateSchema, TContextShape>, TEvent, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry, StateInput<TStateSchema>>;
|
|
331
345
|
invoke?: SingleOrArray<SetupInvokeConfig<TSiblingStateSchemas, StateContext<TStateSchema, TContext>, StateContextShape<TStateSchema, TContextShape>, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>>;
|
|
332
|
-
onDone?: StateTransitionConfigOrTarget<TSiblingStateSchemas, StateContext<TStateSchema, TContext>, StateContextShape<TStateSchema, TContextShape>, DoneStateEvent
|
|
346
|
+
onDone?: StateTransitionConfigOrTarget<TSiblingStateSchemas, StateContext<TStateSchema, TContext>, StateContextShape<TStateSchema, TContextShape>, DoneStateEvent<StateCompletionOutput<TStateSchema>>, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry, StateInput<TStateSchema>>;
|
|
333
347
|
onError?: StateTransitionConfigOrTarget<TSiblingStateSchemas, StateContext<TStateSchema, TContext>, StateContextShape<TStateSchema, TContextShape>, ErrorEvent, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry, StateInput<TStateSchema>>;
|
|
334
348
|
onTimeout?: StateTransitionConfigOrTarget<TSiblingStateSchemas, StateContext<TStateSchema, TContext>, StateContextShape<TStateSchema, TContextShape>, TimeoutEvent, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry, StateInput<TStateSchema>>;
|
|
335
349
|
after?: {
|
|
@@ -388,7 +388,7 @@ interface Next_RegularStateNodeConfig<TContext extends MachineContext, TEvent ex
|
|
|
388
388
|
* This is equivalent to defining a `[done(id)]` transition on this state
|
|
389
389
|
* node's `on` property.
|
|
390
390
|
*/
|
|
391
|
-
onDone?: Next_TransitionConfigOrTarget<TContext, DoneStateEvent
|
|
391
|
+
onDone?: Next_TransitionConfigOrTarget<TContext, DoneStateEvent<TChildOutput>, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>;
|
|
392
392
|
/**
|
|
393
393
|
* The transition to take when an `xstate.error.*` event is raised while this
|
|
394
394
|
* state node or one of its descendants is active.
|
package/dist/xstate.cjs.js
CHANGED
|
@@ -2248,7 +2248,7 @@ function isTypeSchema(value) {
|
|
|
2248
2248
|
|
|
2249
2249
|
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
2250
2250
|
|
|
2251
|
-
/** State schema with optional
|
|
2251
|
+
/** State schema with optional input/output schemas and nested states */
|
|
2252
2252
|
|
|
2253
2253
|
/**
|
|
2254
2254
|
* The sibling state schemas of a dotted path: the children of the path's
|
|
@@ -2274,6 +2274,8 @@ function isTypeSchema(value) {
|
|
|
2274
2274
|
|
|
2275
2275
|
/** Extracts input type from a state schema */
|
|
2276
2276
|
|
|
2277
|
+
/** Extracts the completion output type from a state schema. */
|
|
2278
|
+
|
|
2277
2279
|
/**
|
|
2278
2280
|
* Converts SetupStateSchema to StateSchema with input types included. This
|
|
2279
2281
|
* allows getInputs() to be strongly typed.
|
|
@@ -2248,7 +2248,7 @@ function isTypeSchema(value) {
|
|
|
2248
2248
|
|
|
2249
2249
|
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
2250
2250
|
|
|
2251
|
-
/** State schema with optional
|
|
2251
|
+
/** State schema with optional input/output schemas and nested states */
|
|
2252
2252
|
|
|
2253
2253
|
/**
|
|
2254
2254
|
* The sibling state schemas of a dotted path: the children of the path's
|
|
@@ -2274,6 +2274,8 @@ function isTypeSchema(value) {
|
|
|
2274
2274
|
|
|
2275
2275
|
/** Extracts input type from a state schema */
|
|
2276
2276
|
|
|
2277
|
+
/** Extracts the completion output type from a state schema. */
|
|
2278
|
+
|
|
2277
2279
|
/**
|
|
2278
2280
|
* Converts SetupStateSchema to StateSchema with input types included. This
|
|
2279
2281
|
* allows getInputs() to be strongly typed.
|
|
@@ -2246,7 +2246,7 @@ function isTypeSchema(value) {
|
|
|
2246
2246
|
|
|
2247
2247
|
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
2248
2248
|
|
|
2249
|
-
/** State schema with optional
|
|
2249
|
+
/** State schema with optional input/output schemas and nested states */
|
|
2250
2250
|
|
|
2251
2251
|
/**
|
|
2252
2252
|
* The sibling state schemas of a dotted path: the children of the path's
|
|
@@ -2272,6 +2272,8 @@ function isTypeSchema(value) {
|
|
|
2272
2272
|
|
|
2273
2273
|
/** Extracts input type from a state schema */
|
|
2274
2274
|
|
|
2275
|
+
/** Extracts the completion output type from a state schema. */
|
|
2276
|
+
|
|
2275
2277
|
/**
|
|
2276
2278
|
* Converts SetupStateSchema to StateSchema with input types included. This
|
|
2277
2279
|
* allows getInputs() to be strongly typed.
|
package/dist/xstate.esm.js
CHANGED
|
@@ -2246,7 +2246,7 @@ function isTypeSchema(value) {
|
|
|
2246
2246
|
|
|
2247
2247
|
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
2248
2248
|
|
|
2249
|
-
/** State schema with optional
|
|
2249
|
+
/** State schema with optional input/output schemas and nested states */
|
|
2250
2250
|
|
|
2251
2251
|
/**
|
|
2252
2252
|
* The sibling state schemas of a dotted path: the children of the path's
|
|
@@ -2272,6 +2272,8 @@ function isTypeSchema(value) {
|
|
|
2272
2272
|
|
|
2273
2273
|
/** Extracts input type from a state schema */
|
|
2274
2274
|
|
|
2275
|
+
/** Extracts the completion output type from a state schema. */
|
|
2276
|
+
|
|
2275
2277
|
/**
|
|
2276
2278
|
* Converts SetupStateSchema to StateSchema with input types included. This
|
|
2277
2279
|
* allows getInputs() to be strongly typed.
|