@xmachines/play-actor 1.0.0-beta.53 → 1.0.0-beta.54
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/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/provider-guards.d.ts +54 -0
- package/dist/provider-guards.d.ts.map +1 -0
- package/dist/provider-guards.js +69 -0
- package/dist/provider-guards.js.map +1 -0
- package/package.json +6 -5
package/dist/index.d.ts
CHANGED
|
@@ -16,4 +16,5 @@
|
|
|
16
16
|
* @see [Play RFC](../../docs/rfc/play.md)
|
|
17
17
|
*/
|
|
18
18
|
export { AbstractActor, typedSpec, type Routable, type Viewable, type PlaySpec, type BaseActorProviderProps, type BaseViewContextValue, } from "./abstract-actor.js";
|
|
19
|
+
export { toAtomState, attachRenderErrorHandler } from "./provider-guards.js";
|
|
19
20
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EACN,aAAa,EACb,SAAS,EACT,KAAK,QAAQ,EACb,KAAK,QAAQ,EACb,KAAK,QAAQ,EACb,KAAK,sBAAsB,EAC3B,KAAK,oBAAoB,GACzB,MAAM,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EACN,aAAa,EACb,SAAS,EACT,KAAK,QAAQ,EACb,KAAK,QAAQ,EACb,KAAK,QAAQ,EACb,KAAK,sBAAsB,EAC3B,KAAK,oBAAoB,GACzB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,WAAW,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EACN,aAAa,EACb,SAAS,GAMT,MAAM,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EACN,aAAa,EACb,SAAS,GAMT,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,WAAW,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared provider guards for framework ActorProvider implementations.
|
|
3
|
+
*
|
|
4
|
+
* Every framework integration (React, Vue, Solid, Svelte, DOM) performs the same
|
|
5
|
+
* two rituals when bridging an actor's view to a json-render tree:
|
|
6
|
+
*
|
|
7
|
+
* 1. Sanitize `spec.state` before seeding a fresh `@xstate/store` atom
|
|
8
|
+
* ({@link toAtomState}).
|
|
9
|
+
* 2. Inject a component-level `onRenderError` handler into the component
|
|
10
|
+
* registry without mutating the caller's registry
|
|
11
|
+
* ({@link attachRenderErrorHandler}).
|
|
12
|
+
*
|
|
13
|
+
* Centralising them here keeps the guard semantics identical across frameworks.
|
|
14
|
+
*
|
|
15
|
+
* @packageDocumentation
|
|
16
|
+
*/
|
|
17
|
+
import type { RenderErrorHandler } from "@json-render/core";
|
|
18
|
+
/**
|
|
19
|
+
* Safely coerce a spec's `state` field to a plain object for `createAtom`.
|
|
20
|
+
*
|
|
21
|
+
* `spec.state` is typed as `unknown` in `PlaySpec`. At runtime it can be
|
|
22
|
+
* `null`, `undefined`, a primitive, or a plain object depending on what the
|
|
23
|
+
* machine author put in the view spec. `createAtom` requires a plain object as
|
|
24
|
+
* its initial value — anything else produces a broken store at runtime.
|
|
25
|
+
*
|
|
26
|
+
* Only plain objects (prototype is `Object.prototype` or `null`) are accepted
|
|
27
|
+
* and returned as-is. Everything else — `null`, `undefined`, primitives,
|
|
28
|
+
* arrays, class instances, and built-in objects (Date, Map, Set, etc.) — falls
|
|
29
|
+
* back to a fresh `{}`, preventing silent broken-store bugs at runtime.
|
|
30
|
+
*
|
|
31
|
+
* @param state - The raw `spec.state` value from a `PlaySpec`.
|
|
32
|
+
* @returns `state` itself when it is a plain object, otherwise a new empty object.
|
|
33
|
+
*/
|
|
34
|
+
export declare function toAtomState(state: unknown): Record<string, unknown>;
|
|
35
|
+
/**
|
|
36
|
+
* Clone a component registry and inject an `onRenderError` handler.
|
|
37
|
+
*
|
|
38
|
+
* The handler is defined as a non-enumerable, configurable own property on the
|
|
39
|
+
* clone (per D-19 — one injection convention for all framework renderers), so
|
|
40
|
+
* it overrides any handler set at `defineRegistry` level without showing up
|
|
41
|
+
* when the registry's component entries are enumerated.
|
|
42
|
+
*
|
|
43
|
+
* The caller's registry is never mutated — a shallow clone is returned. Callers
|
|
44
|
+
* that need per-instance handlers (e.g. an `onRenderError` prop on
|
|
45
|
+
* `ActorProvider`) can therefore share one `defineRegistry` result across
|
|
46
|
+
* providers safely.
|
|
47
|
+
*
|
|
48
|
+
* @typeParam TRegistry - The framework-specific component registry type.
|
|
49
|
+
* @param registry - The component registry from `defineRegistry().registry`.
|
|
50
|
+
* @param handler - Called with `(error, componentName)` when a catalog component throws during render.
|
|
51
|
+
* @returns A shallow clone of `registry` with `onRenderError` attached.
|
|
52
|
+
*/
|
|
53
|
+
export declare function attachRenderErrorHandler<TRegistry extends object>(registry: TRegistry, handler: RenderErrorHandler): TRegistry;
|
|
54
|
+
//# sourceMappingURL=provider-guards.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-guards.d.ts","sourceRoot":"","sources":["../src/provider-guards.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAE5D;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAQnE;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,wBAAwB,CAAC,SAAS,SAAS,MAAM,EAChE,QAAQ,EAAE,SAAS,EACnB,OAAO,EAAE,kBAAkB,GACzB,SAAS,CAQX"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared provider guards for framework ActorProvider implementations.
|
|
3
|
+
*
|
|
4
|
+
* Every framework integration (React, Vue, Solid, Svelte, DOM) performs the same
|
|
5
|
+
* two rituals when bridging an actor's view to a json-render tree:
|
|
6
|
+
*
|
|
7
|
+
* 1. Sanitize `spec.state` before seeding a fresh `@xstate/store` atom
|
|
8
|
+
* ({@link toAtomState}).
|
|
9
|
+
* 2. Inject a component-level `onRenderError` handler into the component
|
|
10
|
+
* registry without mutating the caller's registry
|
|
11
|
+
* ({@link attachRenderErrorHandler}).
|
|
12
|
+
*
|
|
13
|
+
* Centralising them here keeps the guard semantics identical across frameworks.
|
|
14
|
+
*
|
|
15
|
+
* @packageDocumentation
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Safely coerce a spec's `state` field to a plain object for `createAtom`.
|
|
19
|
+
*
|
|
20
|
+
* `spec.state` is typed as `unknown` in `PlaySpec`. At runtime it can be
|
|
21
|
+
* `null`, `undefined`, a primitive, or a plain object depending on what the
|
|
22
|
+
* machine author put in the view spec. `createAtom` requires a plain object as
|
|
23
|
+
* its initial value — anything else produces a broken store at runtime.
|
|
24
|
+
*
|
|
25
|
+
* Only plain objects (prototype is `Object.prototype` or `null`) are accepted
|
|
26
|
+
* and returned as-is. Everything else — `null`, `undefined`, primitives,
|
|
27
|
+
* arrays, class instances, and built-in objects (Date, Map, Set, etc.) — falls
|
|
28
|
+
* back to a fresh `{}`, preventing silent broken-store bugs at runtime.
|
|
29
|
+
*
|
|
30
|
+
* @param state - The raw `spec.state` value from a `PlaySpec`.
|
|
31
|
+
* @returns `state` itself when it is a plain object, otherwise a new empty object.
|
|
32
|
+
*/
|
|
33
|
+
export function toAtomState(state) {
|
|
34
|
+
if (state !== null && typeof state === "object" && !Array.isArray(state)) {
|
|
35
|
+
const proto = Object.getPrototypeOf(state);
|
|
36
|
+
if (proto === Object.prototype || proto === null) {
|
|
37
|
+
return state;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return {};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Clone a component registry and inject an `onRenderError` handler.
|
|
44
|
+
*
|
|
45
|
+
* The handler is defined as a non-enumerable, configurable own property on the
|
|
46
|
+
* clone (per D-19 — one injection convention for all framework renderers), so
|
|
47
|
+
* it overrides any handler set at `defineRegistry` level without showing up
|
|
48
|
+
* when the registry's component entries are enumerated.
|
|
49
|
+
*
|
|
50
|
+
* The caller's registry is never mutated — a shallow clone is returned. Callers
|
|
51
|
+
* that need per-instance handlers (e.g. an `onRenderError` prop on
|
|
52
|
+
* `ActorProvider`) can therefore share one `defineRegistry` result across
|
|
53
|
+
* providers safely.
|
|
54
|
+
*
|
|
55
|
+
* @typeParam TRegistry - The framework-specific component registry type.
|
|
56
|
+
* @param registry - The component registry from `defineRegistry().registry`.
|
|
57
|
+
* @param handler - Called with `(error, componentName)` when a catalog component throws during render.
|
|
58
|
+
* @returns A shallow clone of `registry` with `onRenderError` attached.
|
|
59
|
+
*/
|
|
60
|
+
export function attachRenderErrorHandler(registry, handler) {
|
|
61
|
+
const clone = { ...registry };
|
|
62
|
+
Object.defineProperty(clone, "onRenderError", {
|
|
63
|
+
value: handler,
|
|
64
|
+
enumerable: false,
|
|
65
|
+
configurable: true,
|
|
66
|
+
});
|
|
67
|
+
return clone;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=provider-guards.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-guards.js","sourceRoot":"","sources":["../src/provider-guards.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,WAAW,CAAC,KAAc;IACzC,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1E,MAAM,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAY,CAAC;QACtD,IAAI,KAAK,KAAK,MAAM,CAAC,SAAS,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YAClD,OAAO,KAAgC,CAAC;QACzC,CAAC;IACF,CAAC;IACD,OAAO,EAAE,CAAC;AACX,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,wBAAwB,CACvC,QAAmB,EACnB,OAA2B;IAE3B,MAAM,KAAK,GAAG,EAAE,GAAG,QAAQ,EAAE,CAAC;IAC9B,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,eAAe,EAAE;QAC7C,KAAK,EAAE,OAAO;QACd,UAAU,EAAE,KAAK;QACjB,YAAY,EAAE,IAAI;KAClB,CAAC,CAAC;IACH,OAAO,KAAK,CAAC;AACd,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xmachines/play-actor",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.54",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Abstract Actor base class for XMachines Play Architecture",
|
|
6
6
|
"keywords": [
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"scripts": {
|
|
32
32
|
"build": "tsc --build",
|
|
33
|
-
"clean": "rm -rf dist *.tsbuildinfo coverage node_modules/.svelte2tsx-*",
|
|
33
|
+
"clean": "rm -rf dist *.tsbuildinfo coverage node_modules/.svelte2tsx-* node_modules/.vite*",
|
|
34
34
|
"test": "vitest",
|
|
35
35
|
"lint": "oxlint .",
|
|
36
36
|
"lint:fix": "oxlint --fix .",
|
|
@@ -42,16 +42,17 @@
|
|
|
42
42
|
"@json-render/core": "^0.18.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
+
"@testing-library/jest-dom": "^6.9.1",
|
|
45
46
|
"@types/node": "^25.6.0",
|
|
46
|
-
"@xmachines/shared": "1.0.0-beta.
|
|
47
|
+
"@xmachines/shared": "1.0.0-beta.54",
|
|
47
48
|
"oxfmt": "^0.47.0",
|
|
48
49
|
"oxlint": "^1.62.0",
|
|
49
50
|
"vitest": "^4.1.5",
|
|
50
51
|
"xstate": "^5.31.0"
|
|
51
52
|
},
|
|
52
53
|
"peerDependencies": {
|
|
53
|
-
"@xmachines/play": "1.0.0-beta.
|
|
54
|
-
"@xmachines/play-signals": "1.0.0-beta.
|
|
54
|
+
"@xmachines/play": "1.0.0-beta.54",
|
|
55
|
+
"@xmachines/play-signals": "1.0.0-beta.54",
|
|
55
56
|
"xstate": "^5.31.0"
|
|
56
57
|
},
|
|
57
58
|
"engines": {
|