@xmachines/play-xstate 1.0.0 → 1.1.0
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 +32 -14
- package/dist/errors.d.ts +46 -32
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +69 -32
- package/dist/errors.js.map +1 -1
- package/dist/guards/compose.d.ts +8 -0
- package/dist/guards/compose.d.ts.map +1 -1
- package/dist/guards/compose.js +7 -2
- package/dist/guards/compose.js.map +1 -1
- package/dist/guards/helpers.d.ts +6 -2
- package/dist/guards/helpers.d.ts.map +1 -1
- package/dist/guards/helpers.js +6 -2
- package/dist/guards/helpers.js.map +1 -1
- package/dist/guards/index.d.ts +7 -0
- package/dist/guards/index.d.ts.map +1 -1
- package/dist/guards/index.js +7 -0
- package/dist/guards/index.js.map +1 -1
- package/dist/guards/types.d.ts +4 -5
- package/dist/guards/types.d.ts.map +1 -1
- package/dist/player-actor.d.ts +105 -39
- package/dist/player-actor.d.ts.map +1 -1
- package/dist/player-actor.js +312 -318
- package/dist/player-actor.js.map +1 -1
- package/dist/routing/build-url.d.ts +2 -7
- package/dist/routing/build-url.d.ts.map +1 -1
- package/dist/routing/build-url.js +21 -25
- package/dist/routing/build-url.js.map +1 -1
- package/dist/routing/derive-current-route.d.ts +32 -0
- package/dist/routing/derive-current-route.d.ts.map +1 -1
- package/dist/routing/derive-current-route.js +20 -19
- package/dist/routing/derive-current-route.js.map +1 -1
- package/dist/routing/derive-initial-route.d.ts +0 -3
- package/dist/routing/derive-initial-route.d.ts.map +1 -1
- package/dist/routing/derive-initial-route.js +0 -3
- package/dist/routing/derive-initial-route.js.map +1 -1
- package/dist/routing/index.d.ts +1 -1
- package/dist/routing/index.d.ts.map +1 -1
- package/dist/routing/index.js +1 -1
- package/dist/routing/index.js.map +1 -1
- package/dist/types.d.ts +86 -13
- package/dist/types.d.ts.map +1 -1
- package/dist/view/derive-current-view.d.ts +54 -0
- package/dist/view/derive-current-view.d.ts.map +1 -0
- package/dist/view/derive-current-view.js +167 -0
- package/dist/view/derive-current-view.js.map +1 -0
- package/package.json +11 -14
- package/dist/define-player.typecheck.d.ts +0 -2
- package/dist/define-player.typecheck.d.ts.map +0 -1
- package/dist/define-player.typecheck.js +0 -48
- package/dist/define-player.typecheck.js.map +0 -1
- package/dist/player-actor.typecheck.d.ts +0 -2
- package/dist/player-actor.typecheck.d.ts.map +0 -1
- package/dist/player-actor.typecheck.js +0 -27
- package/dist/player-actor.typecheck.js.map +0 -1
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { activeStateMeta } from "../routing/index.js";
|
|
2
|
+
const resolveViewMeta = (meta) => {
|
|
3
|
+
// Iterate last-to-first: snapshot.getMeta() orders keys ancestors-first, so
|
|
4
|
+
// scanning from the end makes the deepest active state's meta.view win over
|
|
5
|
+
// an ancestor's instead of being shadowed by it.
|
|
6
|
+
const values = Object.values(meta);
|
|
7
|
+
for (let i = values.length - 1; i >= 0; i--) {
|
|
8
|
+
const stateMeta = values[i]; // nosemgrep: gitlab.eslint.detect-object-injection
|
|
9
|
+
const maybeView = stateMeta && typeof stateMeta === "object"
|
|
10
|
+
? stateMeta.view
|
|
11
|
+
: undefined;
|
|
12
|
+
if (maybeView &&
|
|
13
|
+
typeof maybeView === "object" &&
|
|
14
|
+
"root" in maybeView &&
|
|
15
|
+
"elements" in maybeView) {
|
|
16
|
+
return maybeView;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return null;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Merge route parameters and an explicit allowlist of context fields into a single
|
|
23
|
+
* element's props.
|
|
24
|
+
*
|
|
25
|
+
* Priority rule (highest → lowest):
|
|
26
|
+
* 1. Explicit non-`undefined` spec prop — always wins (static values are authoritative).
|
|
27
|
+
* 2. URL route params (`context.params`) — fills `undefined` slots from the URL path.
|
|
28
|
+
* 3. Allowlisted context fields (`contextProps`) — fills remaining `undefined` slots from
|
|
29
|
+
* the machine context (e.g. `context.username` on a state with no URL username param).
|
|
30
|
+
*
|
|
31
|
+
* The `contextProps` allowlist is the key safety mechanism: only fields the machine
|
|
32
|
+
* explicitly opts in to are ever exposed to components.
|
|
33
|
+
*
|
|
34
|
+
* @param urlParams - Extracted URL path parameters from `context.params`.
|
|
35
|
+
* @param contextValues - Object containing only the allowlisted context fields.
|
|
36
|
+
* @param existingProps - The element's props as declared in the machine spec.
|
|
37
|
+
* @returns Merged props object with URL params and allowlisted context values filling
|
|
38
|
+
* undefined slots.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* // spec: { section: undefined, username: undefined, title: "Dashboard" }
|
|
43
|
+
* // urlParams: { section: "profile" } ← from URL /:section
|
|
44
|
+
* // contextValues: { username: "alice" } ← from contextProps: ["username"]
|
|
45
|
+
* // result: { section: "profile", username: "alice", title: "Dashboard" }
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
function mergeRouteParamsIntoProps(urlParams, contextValues, existingProps) {
|
|
49
|
+
// Layer 3 (lowest priority): allowlisted context values
|
|
50
|
+
const merged = { ...contextValues };
|
|
51
|
+
// Layer 2: URL params override context values for the same key
|
|
52
|
+
for (const [k, v] of Object.entries(urlParams)) {
|
|
53
|
+
merged[k] = v; // nosemgrep: gitlab.eslint.detect-object-injection
|
|
54
|
+
}
|
|
55
|
+
// Layer 1 (highest priority): explicit non-undefined spec props always win
|
|
56
|
+
for (const [k, v] of Object.entries(existingProps)) {
|
|
57
|
+
if (v !== undefined)
|
|
58
|
+
merged[k] = v; // nosemgrep: gitlab.eslint.detect-object-injection
|
|
59
|
+
}
|
|
60
|
+
return merged;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Derive the actor's current view from state metadata.
|
|
64
|
+
*
|
|
65
|
+
* Always returns a **fresh** `PlaySpec` object so a genuine view change is never
|
|
66
|
+
* suppressed by `Signal.State`'s `Object.is` equality check. Whether that fresh
|
|
67
|
+
* object is actually emitted is decided by `PlayerActor.validateAndCacheView`,
|
|
68
|
+
* which compares against the last emitted spec and skips emission when the
|
|
69
|
+
* rendered view is unchanged — preventing downstream providers from remounting
|
|
70
|
+
* the UI on every event.
|
|
71
|
+
*
|
|
72
|
+
* ### Prop enrichment
|
|
73
|
+
*
|
|
74
|
+
* Each spec element's `props` are enriched before the view is emitted using two sources:
|
|
75
|
+
*
|
|
76
|
+
* **1. URL route params** (`context.params`, populated by `formatPlayRouteTransitions`):
|
|
77
|
+
* Makes `:section?` / `:username` URL path parameters automatically available as component
|
|
78
|
+
* props without manual wiring.
|
|
79
|
+
*
|
|
80
|
+
* **2. Context fields** (`spec.contextProps` allowlist):
|
|
81
|
+
* Exposes selected context fields as component props for states where no URL param covers
|
|
82
|
+
* the data (e.g. `context.username` on a `/dashboard` route). Only fields explicitly named
|
|
83
|
+
* in `spec.contextProps: string[]` are ever exposed — nothing leaks from context implicitly.
|
|
84
|
+
*
|
|
85
|
+
* Merge priority (see `mergeRouteParamsIntoProps`):
|
|
86
|
+
* 1. Explicit non-`undefined` spec prop — always wins (authoritative static value).
|
|
87
|
+
* 2. URL route param (`context.params`) — fills `undefined` slots from the URL path.
|
|
88
|
+
* 3. Allowlisted context field (`contextProps`) — fills remaining `undefined` slots.
|
|
89
|
+
*
|
|
90
|
+
* @param snapshot - Current XState machine snapshot.
|
|
91
|
+
* @returns Enriched `PlaySpec`, or `null` if the current state has no view metadata.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* // spec: { contextProps: ["username"], elements: { root: { props: { username: undefined } } } }
|
|
96
|
+
* // context.username = "alice", context.params = {}
|
|
97
|
+
* // Derived props: { username: "alice" }
|
|
98
|
+
*
|
|
99
|
+
* // spec: { contextProps: ["username"], elements: { root: { props: { username: undefined } } } }
|
|
100
|
+
* // context.username = "alice", context.params = { username: "demo" }
|
|
101
|
+
* // Derived props: { username: "demo" } ← URL param wins
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
export const deriveCurrentView = (snapshot) => {
|
|
105
|
+
// Follow the SAME single active branch the route derivation walks, so that
|
|
106
|
+
// for a parallel machine the rendered view belongs to the region the URL
|
|
107
|
+
// points at whenever that region declares one.
|
|
108
|
+
const meta = activeStateMeta(snapshot);
|
|
109
|
+
if (!meta) {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
// A parallel machine may keep routes and views in DIFFERENT regions (one
|
|
113
|
+
// region owns navigation, another owns the shell). When the walked branch
|
|
114
|
+
// declares no view, scan the flat record of every active region — deepest
|
|
115
|
+
// entry wins — before concluding there is no view at all.
|
|
116
|
+
let viewMeta = resolveViewMeta(meta);
|
|
117
|
+
if (!viewMeta) {
|
|
118
|
+
const flatMeta = snapshot.getMeta();
|
|
119
|
+
if (flatMeta && typeof flatMeta === "object") {
|
|
120
|
+
viewMeta = resolveViewMeta(flatMeta);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (!viewMeta) {
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
// Extract params from context (set by formatPlayRouteTransitions on play.route events)
|
|
127
|
+
const context = snapshot.context !== null &&
|
|
128
|
+
snapshot.context !== undefined &&
|
|
129
|
+
typeof snapshot.context === "object"
|
|
130
|
+
? snapshot.context
|
|
131
|
+
: null;
|
|
132
|
+
// Values flow into props verbatim — only the URL layer stringifies. The
|
|
133
|
+
// type matches RouteContext.params; a `Record<string, string>` cast here
|
|
134
|
+
// would lie about e.g. numeric params assigned by hand-rolled handlers.
|
|
135
|
+
const urlParams = context !== null && typeof context.params === "object" && context.params !== null
|
|
136
|
+
? context.params
|
|
137
|
+
: {};
|
|
138
|
+
// Extract the allowlisted context fields declared in contextProps.
|
|
139
|
+
// Only fields explicitly named in the allowlist are ever exposed to components.
|
|
140
|
+
const contextPropsAllowlist = viewMeta?.contextProps ?? [];
|
|
141
|
+
const contextValues = {};
|
|
142
|
+
if (context !== null && contextPropsAllowlist.length > 0) {
|
|
143
|
+
for (const key of contextPropsAllowlist) {
|
|
144
|
+
// nosemgrep: gitlab.eslint.detect-object-injection
|
|
145
|
+
if (key in context && context[key] !== null && context[key] !== undefined) {
|
|
146
|
+
contextValues[key] = context[key]; // nosemgrep: gitlab.eslint.detect-object-injection
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
// Enrich element props when there is anything to merge.
|
|
151
|
+
if (viewMeta?.elements) {
|
|
152
|
+
const enrichedElements = Object.fromEntries(Object.entries(viewMeta.elements).map(([key, el]) => {
|
|
153
|
+
const element = el;
|
|
154
|
+
const existingProps = element.props ?? {};
|
|
155
|
+
return [
|
|
156
|
+
key,
|
|
157
|
+
{
|
|
158
|
+
...element,
|
|
159
|
+
props: mergeRouteParamsIntoProps(urlParams, contextValues, existingProps),
|
|
160
|
+
},
|
|
161
|
+
];
|
|
162
|
+
}));
|
|
163
|
+
return { ...viewMeta, elements: enrichedElements };
|
|
164
|
+
}
|
|
165
|
+
return viewMeta;
|
|
166
|
+
};
|
|
167
|
+
//# sourceMappingURL=derive-current-view.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"derive-current-view.js","sourceRoot":"","sources":["../../src/view/derive-current-view.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,MAAM,eAAe,GAAG,CAAC,IAA6B,EAAmB,EAAE;IAC1E,4EAA4E;IAC5E,4EAA4E;IAC5E,iDAAiD;IACjD,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACnC,KAAK,IAAI,CAAC,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC7C,MAAM,SAAS,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,mDAAmD;QAChF,MAAM,SAAS,GACd,SAAS,IAAI,OAAO,SAAS,KA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AC;gBAC3E,aAAa,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,mDAAmD;YACvF,CAAC;QACF,CAAC;IACF,CAAC;IAED,wDAAwD;IACxD,IAAI,QAAQ,EAAE,QAAQ,EAAE,CAAC;QACxB,MAAM,gBAAgB,GAAG,MAAM,CAAC,WAAW,CAC1C,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAmC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,EAAE;YAC9E,MAAM,OAAO,GAAG,EAA6B,CAAC;YAC9C,MAAM,aAAa,GAAI,OAAO,CAAC,KAAiC,IAAI,EAAE,CAAC;YACvE,OAAO;gBACN,GAAG;gBACH;oBACC,GAAG,OAAO;oBACV,KAAK,EAAE,yBAAyB,CAAC,SAAS,EAAE,aAAa,EAAE,aAAa,CAAC;iBACzE;aACD,CAAC;QACH,CAAC,CAAC,CAC0B,CAAC;QAE9B,OAAO,EAAE,GAAG,QAAQ,EAAE,QAAQ,EAAE,gBAAgB,EAAc,CAAC;IAChE,CAAC;IAED,OAAO,QAAQ,CAAC;AACjB,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xmachines/play-xstate",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "XState v5 adapter for Play Architecture",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"actor-model",
|
|
@@ -22,16 +22,15 @@
|
|
|
22
22
|
"LICENSE"
|
|
23
23
|
],
|
|
24
24
|
"type": "module",
|
|
25
|
+
"sideEffects": false,
|
|
25
26
|
"main": "./dist/index.js",
|
|
26
27
|
"types": "./dist/index.d.ts",
|
|
27
28
|
"exports": {
|
|
28
29
|
".": {
|
|
29
|
-
"source": "./src/index.ts",
|
|
30
30
|
"types": "./dist/index.d.ts",
|
|
31
31
|
"import": "./dist/index.js"
|
|
32
32
|
},
|
|
33
33
|
"./errors": {
|
|
34
|
-
"source": "./src/errors.ts",
|
|
35
34
|
"types": "./dist/errors.d.ts",
|
|
36
35
|
"import": "./dist/errors.js"
|
|
37
36
|
}
|
|
@@ -44,24 +43,22 @@
|
|
|
44
43
|
"clean": "rm -rf dist *.tsbuildinfo coverage node_modules/.svelte2tsx-* node_modules/.vite*",
|
|
45
44
|
"lint": "oxlint .",
|
|
46
45
|
"format": "oxfmt .",
|
|
47
|
-
"test": "vitest"
|
|
48
|
-
"prepublishOnly": "npm run build"
|
|
46
|
+
"test": "vitest"
|
|
49
47
|
},
|
|
50
48
|
"dependencies": {
|
|
51
|
-
"@xmachines/play": "1.
|
|
52
|
-
"@xmachines/play-actor": "1.
|
|
53
|
-
"@xmachines/play-signals": "1.
|
|
49
|
+
"@xmachines/play": "1.1.0",
|
|
50
|
+
"@xmachines/play-actor": "1.1.0",
|
|
51
|
+
"@xmachines/play-signals": "1.1.0",
|
|
54
52
|
"dequal": "^2.0.3"
|
|
55
53
|
},
|
|
56
54
|
"devDependencies": {
|
|
57
55
|
"@testing-library/jest-dom": "^6.9.1",
|
|
58
|
-
"@types/node": "^26.
|
|
59
|
-
"@xmachines/play-router": "1.
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"oxlint": "^1.73.0",
|
|
56
|
+
"@types/node": "^26.2.0",
|
|
57
|
+
"@xmachines/play-router": "1.1.0",
|
|
58
|
+
"oxfmt": "^0.64.0",
|
|
59
|
+
"oxlint": "^1.79.0",
|
|
63
60
|
"typescript": "^5.9.3 || ^6.0.3",
|
|
64
|
-
"vitest": "^4.1.
|
|
61
|
+
"vitest": "^4.1.11",
|
|
65
62
|
"xstate": "^5.31.0"
|
|
66
63
|
},
|
|
67
64
|
"peerDependencies": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"define-player.typecheck.d.ts","sourceRoot":"","sources":["../src/define-player.typecheck.ts"],"names":[],"mappings":""}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { setup } from "xstate";
|
|
2
|
-
import { definePlayer } from "./define-player.js";
|
|
3
|
-
const machine = setup({
|
|
4
|
-
types: {
|
|
5
|
-
context: {},
|
|
6
|
-
input: {},
|
|
7
|
-
events: {},
|
|
8
|
-
},
|
|
9
|
-
}).createMachine({
|
|
10
|
-
context: ({ input }) => ({ count: input.count }),
|
|
11
|
-
initial: "active",
|
|
12
|
-
states: {
|
|
13
|
-
active: {
|
|
14
|
-
on: {
|
|
15
|
-
inc: {
|
|
16
|
-
actions: ({ context }) => {
|
|
17
|
-
context.count += 1;
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
});
|
|
24
|
-
const createPlayer = definePlayer({
|
|
25
|
-
machine,
|
|
26
|
-
options: {
|
|
27
|
-
onTransition: (actor, prevState, nextState) => {
|
|
28
|
-
const actorNotAny = false;
|
|
29
|
-
const prevNotAny = false;
|
|
30
|
-
const nextNotAny = false;
|
|
31
|
-
void actorNotAny;
|
|
32
|
-
void prevNotAny;
|
|
33
|
-
void nextNotAny;
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
const actor = createPlayer({ count: 1 });
|
|
38
|
-
const snapshot = actor.getSnapshot();
|
|
39
|
-
const restoredActor = createPlayer({ count: 1 }, { snapshot });
|
|
40
|
-
const returnNotAny = false;
|
|
41
|
-
const restoredReturnNotAny = false;
|
|
42
|
-
void returnNotAny;
|
|
43
|
-
void restoredReturnNotAny;
|
|
44
|
-
// @ts-expect-error factory input must match machine input shape
|
|
45
|
-
createPlayer("invalid");
|
|
46
|
-
// @ts-expect-error snapshot must be nested under the `snapshot` key
|
|
47
|
-
createPlayer({ count: 1 }, { persisted: snapshot });
|
|
48
|
-
//# sourceMappingURL=define-player.typecheck.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"define-player.typecheck.js","s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AE,QAAQ,EAAE,CAAC,CAAC;AAI/D,MAAM,YAAY,GAA6B,KAAK,CAAC;AACrD,MAAM,oBAAoB,GAAqC,KAAK,CAAC;AACrE,KAAK,YAAY,CAAC;AAClB,KAAK,oBAAoB,CAAC;AAE1B,gEAAgE;AAChE,YAAY,CAAC,SAAS,CAAC,CAAC;AAExB,oEAAoE;AACpE,YAAY,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"player-actor.typecheck.d.ts","sourceRoot":"","sources":["../src/player-actor.typecheck.ts"],"names":[],"mappings":""}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { setup } from "xstate";
|
|
2
|
-
import { definePlayer } from "./define-player.js";
|
|
3
|
-
const machine = setup({
|
|
4
|
-
types: {
|
|
5
|
-
context: {},
|
|
6
|
-
input: {},
|
|
7
|
-
events: {},
|
|
8
|
-
},
|
|
9
|
-
}).createMachine({
|
|
10
|
-
context: ({ input }) => ({ value: input.value }),
|
|
11
|
-
initial: "idle",
|
|
12
|
-
states: {
|
|
13
|
-
idle: {},
|
|
14
|
-
},
|
|
15
|
-
});
|
|
16
|
-
const createPlayer = definePlayer({ machine });
|
|
17
|
-
const actor = createPlayer({ value: 1 });
|
|
18
|
-
const restoredActor = createPlayer({ value: 1 }, { snapshot: actor.getSnapshot() });
|
|
19
|
-
// Verify actor instances are created successfully
|
|
20
|
-
void actor;
|
|
21
|
-
void restoredActor;
|
|
22
|
-
// CONS-16: [key: string]: unknown index signature removed.
|
|
23
|
-
// Accessing unknown properties on PlayerActor is now a type error (correct behavior).
|
|
24
|
-
// @ts-expect-error — unknown fields no longer accessible via index signature
|
|
25
|
-
const unknownField = actor["custom-extension-field"];
|
|
26
|
-
void unknownField;
|
|
27
|
-
//# sourceMappingURL=player-actor.typecheck.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"player-actor.typecheck.js","sourceRoot":"","sources":["../src/player-actor.typecheck.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAC/B,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,MAAM,OAAO,GAAG,KAAK,CAAC;IACrB,KAAK,EAAE;QACN,OAAO,EAAE,EAAuB;QAChC,KAAK,EAAE,EAAuB;QAC9B,MAAM,EAAE,EAAsB;KAC9B;CACD,CAAC,CAAC,aAAa,CAAC;IAChB,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC;IAChD,OAAO,EAAE,MAAM;IACf,MAAM,EAAE;QACP,IAAI,EAAE,EAAE;KACR;CACD,CAAC,CAAC;AAEH,MAAM,YAAY,GAAG,YAAY,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;AAC/C,MAAM,KAAK,GAAG,YAAY,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;AACzC,MAAM,aAAa,GAAG,YAAY,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;AAEpF,kDAAkD;AAClD,KAAK,KAAK,CAAC;AACX,KAAK,aAAa,CAAC;AAEnB,2DAA2D;AAC3D,sFAAsF;AACtF,6EAA6E;AAC7E,MAAM,YAAY,GAAG,KAAK,CAAC,wBAAwB,CAAC,CAAC;AACrD,KAAK,YAAY,CAAC"}
|