@xmachines/play-xstate 1.0.0-beta.2 → 1.0.0-beta.21
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 +263 -107
- package/dist/define-player.d.ts +6 -56
- package/dist/define-player.d.ts.map +1 -1
- package/dist/define-player.js +8 -60
- package/dist/define-player.js.map +1 -1
- package/dist/define-player.typecheck.d.ts +2 -0
- package/dist/define-player.typecheck.d.ts.map +1 -0
- package/dist/define-player.typecheck.js +48 -0
- package/dist/define-player.typecheck.js.map +1 -0
- package/dist/errors.d.ts +66 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +76 -0
- package/dist/errors.js.map +1 -0
- package/dist/guards/compose.d.ts +14 -3
- package/dist/guards/compose.d.ts.map +1 -1
- package/dist/guards/compose.js +26 -0
- package/dist/guards/compose.js.map +1 -1
- package/dist/guards/helpers.d.ts +13 -17
- package/dist/guards/helpers.d.ts.map +1 -1
- package/dist/guards/helpers.js +20 -25
- package/dist/guards/helpers.js.map +1 -1
- package/dist/guards/index.d.ts +2 -1
- package/dist/guards/index.d.ts.map +1 -1
- package/dist/guards/index.js +1 -1
- package/dist/guards/index.js.map +1 -1
- package/dist/guards/types.d.ts +3 -2
- package/dist/guards/types.d.ts.map +1 -1
- package/dist/index.d.ts +7 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -5
- package/dist/index.js.map +1 -1
- package/dist/player-actor.d.ts +70 -22
- package/dist/player-actor.d.ts.map +1 -1
- package/dist/player-actor.js +290 -88
- package/dist/player-actor.js.map +1 -1
- package/dist/player-actor.typecheck.d.ts +2 -0
- package/dist/player-actor.typecheck.d.ts.map +1 -0
- package/dist/player-actor.typecheck.js +27 -0
- package/dist/player-actor.typecheck.js.map +1 -0
- package/dist/routing/build-url.d.ts +22 -16
- package/dist/routing/build-url.d.ts.map +1 -1
- package/dist/routing/build-url.js +27 -20
- package/dist/routing/build-url.js.map +1 -1
- package/dist/routing/derive-route.d.ts +2 -2
- package/dist/routing/derive-route.d.ts.map +1 -1
- package/dist/routing/derive-route.js +3 -3
- package/dist/routing/derive-route.js.map +1 -1
- package/dist/routing/format-play-route-transitions.d.ts +41 -4
- package/dist/routing/format-play-route-transitions.d.ts.map +1 -1
- package/dist/routing/format-play-route-transitions.js +22 -19
- package/dist/routing/format-play-route-transitions.js.map +1 -1
- package/dist/routing/index.d.ts +2 -1
- package/dist/routing/index.d.ts.map +1 -1
- package/dist/routing/types.d.ts +8 -13
- package/dist/routing/types.d.ts.map +1 -1
- package/dist/signals/index.d.ts +0 -1
- package/dist/signals/index.d.ts.map +1 -1
- package/dist/signals/index.js +0 -1
- package/dist/signals/index.js.map +1 -1
- package/dist/signals/state-signal.d.ts +1 -1
- package/dist/signals/state-signal.d.ts.map +1 -1
- package/dist/types.d.ts +20 -14
- package/dist/types.d.ts.map +1 -1
- package/package.json +26 -19
- package/dist/catalog/index.d.ts +0 -12
- package/dist/catalog/index.d.ts.map +0 -1
- package/dist/catalog/index.js +0 -11
- package/dist/catalog/index.js.map +0 -1
- package/dist/catalog/types.d.ts +0 -36
- package/dist/catalog/types.d.ts.map +0 -1
- package/dist/catalog/types.js +0 -2
- package/dist/catalog/types.js.map +0 -1
- package/dist/catalog/validate-binding.d.ts +0 -21
- package/dist/catalog/validate-binding.d.ts.map +0 -1
- package/dist/catalog/validate-binding.js +0 -30
- package/dist/catalog/validate-binding.js.map +0 -1
- package/dist/catalog/validate-props.d.ts +0 -41
- package/dist/catalog/validate-props.d.ts.map +0 -1
- package/dist/catalog/validate-props.js +0 -95
- package/dist/catalog/validate-props.js.map +0 -1
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { Catalog, ViewMetadata } from "./types.js";
|
|
2
|
-
/**
|
|
3
|
-
* Validate component binding against catalog
|
|
4
|
-
*
|
|
5
|
-
* Per CONTEXT.md:
|
|
6
|
-
* - "Component references: String keys"
|
|
7
|
-
* - "Mismatch detection: Both compile-time (TypeScript) and runtime validation"
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```typescript
|
|
11
|
-
* const view = { component: 'Dashboard', userId: '123' };
|
|
12
|
-
* validateComponentBinding(view, catalog);
|
|
13
|
-
* // Throws if 'Dashboard' not in catalog
|
|
14
|
-
* ```
|
|
15
|
-
*
|
|
16
|
-
* @param view - View metadata from meta.view
|
|
17
|
-
* @param catalog - Component catalog
|
|
18
|
-
* @throws Error if component not found in catalog
|
|
19
|
-
*/
|
|
20
|
-
export declare const validateComponentBinding: (view: ViewMetadata, catalog: Catalog) => void;
|
|
21
|
-
//# sourceMappingURL=validate-binding.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validate-binding.d.ts","sourceRoot":"","sources":["../../src/catalog/validate-binding.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAExD;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,wBAAwB,GAAI,MAAM,YAAY,EAAE,SAAS,OAAO,KAAG,IAc/E,CAAC"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Validate component binding against catalog
|
|
3
|
-
*
|
|
4
|
-
* Per CONTEXT.md:
|
|
5
|
-
* - "Component references: String keys"
|
|
6
|
-
* - "Mismatch detection: Both compile-time (TypeScript) and runtime validation"
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```typescript
|
|
10
|
-
* const view = { component: 'Dashboard', userId: '123' };
|
|
11
|
-
* validateComponentBinding(view, catalog);
|
|
12
|
-
* // Throws if 'Dashboard' not in catalog
|
|
13
|
-
* ```
|
|
14
|
-
*
|
|
15
|
-
* @param view - View metadata from meta.view
|
|
16
|
-
* @param catalog - Component catalog
|
|
17
|
-
* @throws Error if component not found in catalog
|
|
18
|
-
*/
|
|
19
|
-
export const validateComponentBinding = (view, catalog) => {
|
|
20
|
-
if (!view || !view.component) {
|
|
21
|
-
throw new Error("Invalid view metadata: missing 'component' property");
|
|
22
|
-
}
|
|
23
|
-
const { component } = view;
|
|
24
|
-
// Runtime validation
|
|
25
|
-
if (!(component in catalog)) {
|
|
26
|
-
const available = Object.keys(catalog).join(", ");
|
|
27
|
-
throw new Error(`Component "${component}" not found in catalog. Available components: ${available || "(none)"}`);
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
//# sourceMappingURL=validate-binding.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validate-binding.js","sourceRoot":"","sources":["../../src/catalog/validate-binding.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,IAAkB,EAAE,OAAgB,EAAQ,EAAE;IACtF,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;IACxE,CAAC;IAED,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;IAE3B,qBAAqB;IACrB,IAAI,CAAC,CAAC,SAAS,IAAI,OAAO,CAAC,EAAE,CAAC;QAC7B,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAClD,MAAM,IAAI,KAAK,CACd,cAAc,SAAS,iDAAiD,SAAS,IAAI,QAAQ,EAAE,CAC/F,CAAC;IACH,CAAC;AACF,CAAC,CAAC"}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import type { z } from "zod";
|
|
2
|
-
import type { Catalog, ViewMetadata } from "./types.js";
|
|
3
|
-
/**
|
|
4
|
-
* Validate view props against Zod schema
|
|
5
|
-
*
|
|
6
|
-
* Per CONTEXT.md:
|
|
7
|
-
* - "Prop validation: At state entry"
|
|
8
|
-
* - "currentView derivation: Merge meta.view with relevant context data"
|
|
9
|
-
*
|
|
10
|
-
* Per RESEARCH.md Pattern 4: Use safeParse() for validation
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```typescript
|
|
14
|
-
* const props = { userId: '123', stats: { logins: 5 } };
|
|
15
|
-
* const result = validateViewProps('Dashboard', props, catalog);
|
|
16
|
-
* if (!result.success) {
|
|
17
|
-
* console.error(result.error);
|
|
18
|
-
* }
|
|
19
|
-
* ```
|
|
20
|
-
*
|
|
21
|
-
* @param componentName - Component name from catalog
|
|
22
|
-
* @param props - Props to validate
|
|
23
|
-
* @param catalog - Component catalog with schemas
|
|
24
|
-
* @returns Zod parse result
|
|
25
|
-
*/
|
|
26
|
-
export declare const validateViewProps: (componentName: string, props: any, catalog: Catalog) => {
|
|
27
|
-
success: boolean;
|
|
28
|
-
data?: any;
|
|
29
|
-
error?: z.ZodError | Error;
|
|
30
|
-
};
|
|
31
|
-
/**
|
|
32
|
-
* Merge view metadata with context for props
|
|
33
|
-
*
|
|
34
|
-
* Per CONTEXT.md: "Merge meta.view with relevant context data for component props"
|
|
35
|
-
*
|
|
36
|
-
* @param view - View metadata from meta.view
|
|
37
|
-
* @param context - Machine context
|
|
38
|
-
* @returns Merged props object
|
|
39
|
-
*/
|
|
40
|
-
export declare const mergeViewProps: (view: ViewMetadata, context: any) => Record<string, any>;
|
|
41
|
-
//# sourceMappingURL=validate-props.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validate-props.d.ts","sourceRoot":"","sources":["../../src/catalog/validate-props.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAExD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,iBAAiB,GAC7B,eAAe,MAAM,EACrB,OAAO,GAAG,EACV,SAAS,OAAO,KACd;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,IAAI,CAAC,EAAE,GAAG,CAAC;IAAC,KAAK,CAAC,EAAE,CAAC,CAAC,QAAQ,GAAG,KAAK,CAAA;CA2B5D,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc,GAAI,MAAM,YAAY,EAAE,SAAS,GAAG,KAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAwCnF,CAAC"}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Validate view props against Zod schema
|
|
3
|
-
*
|
|
4
|
-
* Per CONTEXT.md:
|
|
5
|
-
* - "Prop validation: At state entry"
|
|
6
|
-
* - "currentView derivation: Merge meta.view with relevant context data"
|
|
7
|
-
*
|
|
8
|
-
* Per RESEARCH.md Pattern 4: Use safeParse() for validation
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```typescript
|
|
12
|
-
* const props = { userId: '123', stats: { logins: 5 } };
|
|
13
|
-
* const result = validateViewProps('Dashboard', props, catalog);
|
|
14
|
-
* if (!result.success) {
|
|
15
|
-
* console.error(result.error);
|
|
16
|
-
* }
|
|
17
|
-
* ```
|
|
18
|
-
*
|
|
19
|
-
* @param componentName - Component name from catalog
|
|
20
|
-
* @param props - Props to validate
|
|
21
|
-
* @param catalog - Component catalog with schemas
|
|
22
|
-
* @returns Zod parse result
|
|
23
|
-
*/
|
|
24
|
-
export const validateViewProps = (componentName, props, catalog) => {
|
|
25
|
-
const entry = catalog[componentName];
|
|
26
|
-
if (!entry) {
|
|
27
|
-
return {
|
|
28
|
-
success: false,
|
|
29
|
-
error: new Error(`Component "${componentName}" not found in catalog`),
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
// Handle both CatalogEntry format and direct Zod schema
|
|
33
|
-
const schema = typeof entry === "object" && "schema" in entry ? entry.schema : entry;
|
|
34
|
-
// Use safeParse to avoid throwing
|
|
35
|
-
const result = schema.safeParse(props);
|
|
36
|
-
if (!result.success) {
|
|
37
|
-
return {
|
|
38
|
-
success: false,
|
|
39
|
-
error: result.error,
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
return {
|
|
43
|
-
success: true,
|
|
44
|
-
data: result.data,
|
|
45
|
-
};
|
|
46
|
-
};
|
|
47
|
-
/**
|
|
48
|
-
* Merge view metadata with context for props
|
|
49
|
-
*
|
|
50
|
-
* Per CONTEXT.md: "Merge meta.view with relevant context data for component props"
|
|
51
|
-
*
|
|
52
|
-
* @param view - View metadata from meta.view
|
|
53
|
-
* @param context - Machine context
|
|
54
|
-
* @returns Merged props object
|
|
55
|
-
*/
|
|
56
|
-
export const mergeViewProps = (view, context) => {
|
|
57
|
-
// Extract component and props from view metadata
|
|
58
|
-
const { component: _component, props, ...rest } = view;
|
|
59
|
-
// Determine view props based on structure
|
|
60
|
-
let viewProps;
|
|
61
|
-
if (typeof props === "function") {
|
|
62
|
-
// Case 0: props is a factory function — call it with { context }
|
|
63
|
-
// e.g. props: ({ context }) => ({ welcome: true, username: context.username })
|
|
64
|
-
viewProps = props({ context });
|
|
65
|
-
}
|
|
66
|
-
else if (props && typeof props === "object" && !Array.isArray(props)) {
|
|
67
|
-
// Case 1: view has explicit props object: { component: 'X', props: { a: 1 } }
|
|
68
|
-
viewProps = props;
|
|
69
|
-
}
|
|
70
|
-
else if (Object.keys(rest).length > 0) {
|
|
71
|
-
// Case 2: props are flat on view: { component: 'X', a: 1, b: 2 }
|
|
72
|
-
viewProps = rest;
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
// Case 3: no props at all
|
|
76
|
-
viewProps = {};
|
|
77
|
-
}
|
|
78
|
-
// Extract infrastructure props that should bypass catalog validation
|
|
79
|
-
// These are reserved keys that components receive but aren't in catalog schemas
|
|
80
|
-
const { routeParams, queryParams, ...catalogContext } = context;
|
|
81
|
-
// Merge catalog-validated context with viewProps
|
|
82
|
-
const mergedProps = {
|
|
83
|
-
...catalogContext,
|
|
84
|
-
...viewProps,
|
|
85
|
-
};
|
|
86
|
-
// Add infrastructure props back (these bypass Zod validation)
|
|
87
|
-
// Spread routeParams so they become top-level props (e.g., section: "profile")
|
|
88
|
-
// Components receive route params as direct props, not nested
|
|
89
|
-
return {
|
|
90
|
-
...mergedProps,
|
|
91
|
-
...routeParams, // Spread route params as top-level props
|
|
92
|
-
...(queryParams && { queryParams }), // Add queryParams as nested object if present
|
|
93
|
-
};
|
|
94
|
-
};
|
|
95
|
-
//# sourceMappingURL=validate-props.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validate-props.js","sourceRoot":"","sources":["../../src/catalog/validate-props.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAChC,aAAqB,EACrB,KAAU,EACV,OAAgB,EAC+C,EAAE;IACjE,MAAM,KAAK,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IAErC,IAAI,CAAC,KAAK,EAAE,CAAC;QACZ,OAAO;YACN,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,IAAI,KAAK,CAAC,cAAc,aAAa,wBAAwB,CAAC;SACrE,CAAC;IACH,CAAC;IAED,wDAAwD;IACxD,MAAM,MAAM,GAAG,OAAO,KAAK,KAAK,QAAQ,IAAI,QAAQ,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC;IAErF,kCAAkC;IAClC,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAEvC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACrB,OAAO;YACN,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,MAAM,CAAC,KAAK;SACnB,CAAC;IACH,CAAC;IAED,OAAO;QACN,OAAO,EAAE,IAAI;QACb,IAAI,EAAE,MAAM,CAAC,IAAI;KACjB,CAAC;AACH,CAAC,CAAC;AAEF;;;;;;;;GAQG;AACH,M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