diff --git a/.changeset/tasty-guests-cry.md b/.changeset/tasty-guests-cry.md new file mode 100644 index 00000000..d7388a3b --- /dev/null +++ b/.changeset/tasty-guests-cry.md @@ -0,0 +1,5 @@ +--- +'@xstate/machine-extractor': minor +--- + +Capture any string field from meta instead of just description diff --git a/packages/machine-extractor/examples/meta.ts b/packages/machine-extractor/examples/meta.ts new file mode 100644 index 00000000..81bb72c8 --- /dev/null +++ b/packages/machine-extractor/examples/meta.ts @@ -0,0 +1,8 @@ +import { createMachine } from 'xstate'; + +export const machine = createMachine({ + meta: { + description: 'description', + someOtherField: 'hello there', + }, +}); diff --git a/packages/machine-extractor/src/meta.ts b/packages/machine-extractor/src/meta.ts index 9ae92895..b247d9ae 100644 --- a/packages/machine-extractor/src/meta.ts +++ b/packages/machine-extractor/src/meta.ts @@ -1,9 +1,7 @@ import { StringLiteral, TemplateLiteral } from './scalars'; import { unionType } from './unionType'; -import { objectTypeWithKnownKeys } from './utils'; +import { objectOf } from './utils'; -export const MetaDescription = unionType([StringLiteral, TemplateLiteral]); +export const MetaValues = unionType([StringLiteral, TemplateLiteral]); -export const StateMeta = objectTypeWithKnownKeys({ - description: MetaDescription, -}); +export const StateMeta = objectOf(MetaValues); diff --git a/packages/machine-extractor/src/toMachineConfig.ts b/packages/machine-extractor/src/toMachineConfig.ts index 345d7fb6..4567e986 100644 --- a/packages/machine-extractor/src/toMachineConfig.ts +++ b/packages/machine-extractor/src/toMachineConfig.ts @@ -101,10 +101,14 @@ const parseStateNode = ( config.always = getTransitions(astResult.always, opts); } - if (astResult.meta?.description) { - config.meta = { - description: astResult.meta.description.value, - }; + if (astResult.meta) { + config.meta = astResult.meta.properties.reduce( + (meta, props) => ({ + ...meta, + [props.key]: props.result.value, + }), + {}, + ); } if (astResult.onDone) {