@typeonce/ritmo 0.6.0 → 0.8.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 +2 -0
- package/dist/Brand.d.ts +9 -4
- package/dist/Brand.d.ts.map +1 -1
- package/dist/Brand.js +9 -4
- package/dist/Brand.js.map +1 -1
- package/dist/Clock.d.ts +186 -0
- package/dist/Clock.d.ts.map +1 -0
- package/dist/Clock.js +111 -0
- package/dist/Clock.js.map +1 -0
- package/dist/Command.d.ts +250 -41
- package/dist/Command.d.ts.map +1 -1
- package/dist/Command.js +59 -23
- package/dist/Command.js.map +1 -1
- package/dist/Condition.d.ts +12 -1
- package/dist/Condition.d.ts.map +1 -1
- package/dist/Condition.js.map +1 -1
- package/dist/Debug.d.ts +163 -15
- package/dist/Debug.d.ts.map +1 -1
- package/dist/Debug.js.map +1 -1
- package/dist/Decode.d.ts +1 -1
- package/dist/Decode.js +1 -1
- package/dist/Descriptor.d.ts +67 -24
- package/dist/Descriptor.d.ts.map +1 -1
- package/dist/Descriptor.js +32 -15
- package/dist/Descriptor.js.map +1 -1
- package/dist/Entity.d.ts +22 -5
- package/dist/Entity.d.ts.map +1 -1
- package/dist/Entity.js +2 -2
- package/dist/Entity.js.map +1 -1
- package/dist/EntityScope.d.ts +26 -1
- package/dist/EntityScope.d.ts.map +1 -1
- package/dist/EntityScope.js +14 -2
- package/dist/EntityScope.js.map +1 -1
- package/dist/HostClock.d.ts +49 -0
- package/dist/HostClock.d.ts.map +1 -0
- package/dist/HostClock.js +46 -0
- package/dist/HostClock.js.map +1 -0
- package/dist/Inspector.d.ts +7 -1
- package/dist/Inspector.d.ts.map +1 -1
- package/dist/Inspector.js.map +1 -1
- package/dist/Machine.d.ts +67 -36
- package/dist/Machine.d.ts.map +1 -1
- package/dist/Machine.js +10 -3
- package/dist/Machine.js.map +1 -1
- package/dist/Query.d.ts +74 -26
- package/dist/Query.d.ts.map +1 -1
- package/dist/Query.js +32 -28
- package/dist/Query.js.map +1 -1
- package/dist/Runtime.d.ts +39 -16
- package/dist/Runtime.d.ts.map +1 -1
- package/dist/Runtime.js +556 -87
- package/dist/Runtime.js.map +1 -1
- package/dist/Schedule.d.ts +217 -10
- package/dist/Schedule.d.ts.map +1 -1
- package/dist/Schedule.js +5 -0
- package/dist/Schedule.js.map +1 -1
- package/dist/Schema.d.ts +196 -44
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +29 -11
- package/dist/Schema.js.map +1 -1
- package/dist/Snapshot.d.ts +14 -0
- package/dist/Snapshot.d.ts.map +1 -1
- package/dist/Snapshot.js.map +1 -1
- package/dist/System.d.ts +212 -58
- package/dist/System.d.ts.map +1 -1
- package/dist/System.js +84 -6
- package/dist/System.js.map +1 -1
- package/dist/index.d.ts +8 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -7
- package/dist/index.js.map +1 -1
- package/dist/internal/cells.d.ts +3 -3
- package/dist/internal/cells.d.ts.map +1 -1
- package/dist/internal/cells.js +9 -11
- package/dist/internal/cells.js.map +1 -1
- package/dist/internal/debug.d.ts +13 -0
- package/dist/internal/debug.d.ts.map +1 -1
- package/dist/internal/debug.js +192 -7
- package/dist/internal/debug.js.map +1 -1
- package/dist/internal/equal.d.ts +8 -0
- package/dist/internal/equal.d.ts.map +1 -0
- package/dist/internal/equal.js +38 -0
- package/dist/internal/equal.js.map +1 -0
- package/dist/internal/fragments.d.ts.map +1 -1
- package/dist/internal/fragments.js +11 -1
- package/dist/internal/fragments.js.map +1 -1
- package/dist/internal/game.d.ts.map +1 -1
- package/dist/internal/game.js +41 -6
- package/dist/internal/game.js.map +1 -1
- package/dist/internal/order.d.ts +10 -0
- package/dist/internal/order.d.ts.map +1 -0
- package/dist/internal/order.js +122 -0
- package/dist/internal/order.js.map +1 -0
- package/dist/internal/queries.d.ts.map +1 -1
- package/dist/internal/queries.js +32 -10
- package/dist/internal/queries.js.map +1 -1
- package/dist/internal/requirements.d.ts +26 -0
- package/dist/internal/requirements.d.ts.map +1 -0
- package/dist/internal/requirements.js +46 -0
- package/dist/internal/requirements.js.map +1 -0
- package/package.json +1 -1
- package/src/Brand.ts +9 -4
- package/src/Clock.ts +311 -0
- package/src/Command.ts +407 -89
- package/src/Condition.ts +17 -1
- package/src/Debug.ts +172 -14
- package/src/Decode.ts +1 -1
- package/src/Descriptor.ts +92 -37
- package/src/Entity.ts +24 -5
- package/src/EntityScope.ts +27 -2
- package/src/HostClock.ts +64 -0
- package/src/Inspector.ts +7 -2
- package/src/Machine.ts +81 -37
- package/src/Query.ts +110 -38
- package/src/Runtime.ts +607 -111
- package/src/Schedule.ts +380 -13
- package/src/Schema.ts +249 -63
- package/src/Snapshot.ts +4 -0
- package/src/System.ts +248 -93
- package/src/index.ts +8 -7
- package/src/internal/cells.ts +10 -12
- package/src/internal/debug.ts +208 -12
- package/src/internal/equal.ts +31 -0
- package/src/internal/fragments.ts +12 -2
- package/src/internal/game.ts +61 -7
- package/src/internal/order.ts +144 -0
- package/src/internal/queries.ts +37 -13
- package/src/internal/requirements.ts +71 -0
- package/dist/Definition.d.ts +0 -99
- package/dist/Definition.d.ts.map +0 -1
- package/dist/Definition.js +0 -68
- package/dist/Definition.js.map +0 -1
- package/dist/Feature.d.ts +0 -106
- package/dist/Feature.d.ts.map +0 -1
- package/dist/Feature.js +0 -87
- package/dist/Feature.js.map +0 -1
- package/dist/Fx.d.ts +0 -128
- package/dist/Fx.d.ts.map +0 -1
- package/dist/Fx.js +0 -112
- package/dist/Fx.js.map +0 -1
- package/dist/internal/definition.d.ts +0 -17
- package/dist/internal/definition.d.ts.map +0 -1
- package/dist/internal/definition.js +0 -25
- package/dist/internal/definition.js.map +0 -1
- package/src/Definition.ts +0 -106
- package/src/Feature.ts +0 -241
- package/src/Fx.ts +0 -176
- package/src/internal/definition.ts +0 -56
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The host's wall clock, as an injected contract.
|
|
3
|
+
*
|
|
4
|
+
* Core and the generic devtools modules never read a platform clock
|
|
5
|
+
* (`performance`, `Date`) themselves: whatever measures host time (debug
|
|
6
|
+
* trace durations, session timings, replay windows) takes a `HostClock`.
|
|
7
|
+
* Platform packages provide implementations (`BrowserHostClock.make(window)`
|
|
8
|
+
* in the browser package); `standard` works in every JavaScript engine, and
|
|
9
|
+
* `test()` is a manual clock for deterministic tests.
|
|
10
|
+
*
|
|
11
|
+
* Host time is for measuring the host (how long a tick took), never for game
|
|
12
|
+
* logic: simulation time is a resource the schedule advances.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* const runtime = Game.Runtime.make({ services, debug: { hostClock: HostClock.standard } })
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @module HostClock
|
|
20
|
+
* @docGroup runtime
|
|
21
|
+
*/
|
|
22
|
+
import * as Result from "./Result.js";
|
|
23
|
+
/**
|
|
24
|
+
* `Date.now`, which every JavaScript engine provides. Its readings can jump
|
|
25
|
+
* (the system clock is adjusted, or the device sleeps), so a duration
|
|
26
|
+
* computed from two readings can be negative: consumers clamp durations to
|
|
27
|
+
* 0. Prefer a monotonic platform clock when there is one
|
|
28
|
+
* (`BrowserHostClock.make(window)`).
|
|
29
|
+
*/
|
|
30
|
+
export const standard = { now: () => Date.now() };
|
|
31
|
+
/** A test clock at 0. Every reading is the same until `adjust` moves it. */
|
|
32
|
+
export const test = () => {
|
|
33
|
+
let current = 0;
|
|
34
|
+
return {
|
|
35
|
+
now: () => current,
|
|
36
|
+
adjust: (ms) => {
|
|
37
|
+
if (!Number.isFinite(ms) || ms < 0 || !Number.isFinite(current + ms))
|
|
38
|
+
return Result.failure({ _tag: "InvalidAdjustment", ms });
|
|
39
|
+
current += ms;
|
|
40
|
+
return Result.success(undefined);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
/** A duration between two readings, clamped to 0 when the clock went backwards. */
|
|
45
|
+
export const elapsed = (from, to) => Math.max(0, to - from);
|
|
46
|
+
//# sourceMappingURL=HostClock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HostClock.js","sourceRoot":"","sources":["../src/HostClock.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAOrC;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAc,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,CAAA;AAc5D,4EAA4E;AAC5E,MAAM,CAAC,MAAM,IAAI,GAAG,GAAkB,EAAE;IACtC,IAAI,OAAO,GAAG,CAAC,CAAA;IACf,OAAO;QACL,GAAG,EAAE,GAAG,EAAE,CAAC,OAAO;QAClB,MAAM,EAAE,CAAC,EAAE,EAAE,EAAE;YACb,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,GAAG,EAAE,CAAC;gBAAE,OAAO,MAAM,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,mBAAmB,EAAE,EAAE,EAAE,CAAC,CAAA;YAC9H,OAAO,IAAI,EAAE,CAAA;YACb,OAAO,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;QAClC,CAAC;KACF,CAAA;AACH,CAAC,CAAA;AAED,mFAAmF;AACnF,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,IAAY,EAAE,EAAU,EAAU,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,GAAG,IAAI,CAAC,CAAA"}
|
package/dist/Inspector.d.ts
CHANGED
|
@@ -6,6 +6,12 @@
|
|
|
6
6
|
* They run on demand through `runtime.inspect(...)` and return a value without
|
|
7
7
|
* advancing schedule visibility.
|
|
8
8
|
*
|
|
9
|
+
* An inspector is the one typed read-only view of the world: tests, saves, UI,
|
|
10
|
+
* `Game.Condition.check(...)` projections, and devtools invariants
|
|
11
|
+
* (`Invariant.fromInspector(...)`) are all built from it. `runtime.inspect`
|
|
12
|
+
* rejects at compile time an inspector that reads a resource, service, or
|
|
13
|
+
* machine the runtime was not given.
|
|
14
|
+
*
|
|
9
15
|
* @module Inspector
|
|
10
16
|
* @docGroup runtime
|
|
11
17
|
*/
|
|
@@ -48,7 +54,7 @@ export type InspectorContext<Spec extends System.AnySystemSpec> = Pick<System.Sy
|
|
|
48
54
|
export interface InspectorDefinition<Spec extends System.AnySystemSpec = System.AnySystemSpec, out Value = unknown, out Root = unknown, out Name extends string = string, out Needs extends Requirement.Requirement = Requirement.Requirement> {
|
|
49
55
|
readonly kind: "inspector";
|
|
50
56
|
readonly name: Name;
|
|
51
|
-
readonly system: System.SystemDefinition<Spec,
|
|
57
|
+
readonly system: System.SystemDefinition<Spec, never, Root, Name, Needs>;
|
|
52
58
|
readonly requirements: ReadonlyArray<Needs>;
|
|
53
59
|
readonly read: (context: InspectorContext<Spec>) => Value;
|
|
54
60
|
readonly __schemaRoot?: Root | undefined;
|
package/dist/Inspector.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Inspector.d.ts","sourceRoot":"","sources":["../src/Inspector.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"Inspector.d.ts","sourceRoot":"","sources":["../src/Inspector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,KAAK,KAAK,OAAO,MAAM,cAAc,CAAA;AAC5C,OAAO,KAAK,KAAK,KAAK,MAAM,YAAY,CAAA;AACxC,OAAO,KAAK,KAAK,QAAQ,MAAM,eAAe,CAAA;AAC9C,OAAO,KAAK,KAAK,WAAW,MAAM,kBAAkB,CAAA;AACpD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,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ED,iFAAiF;AACjF,eAAO,MAAM,IAAI,GACf,CAAC,SAAS,MAAM,CAAC,GAAG,EACpB,KAAK,CAAC,IAAI,SAAS,MAAM,EACzB,KAAK,CAAC,MAAM,SAAS,oBAAoB,EACzC,KAAK,EACL,IAAI,GAAG,OAAO,QAER,IAAI,QACJ;IAAE,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAA;CAAE,GAAG,oBAAoB,CAAC,MAAM,CAAC,QACrD,CAAC,OAAO,EAAE,gBAAgB,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC,KAAK,KAAK,KAC7E,mBAAmB,CACpB,MAAM,CAAC,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAClC,KAAK,EACL,IAAI,EACJ,IAAI,EACJ,MAAM,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAqBjC,CAAA"}
|
package/dist/Inspector.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Inspector.js","sourceRoot":"","sources":["../src/Inspector.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Inspector.js","sourceRoot":"","sources":["../src/Inspector.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAyErC,iFAAiF;AACjF,MAAM,CAAC,MAAM,IAAI,GAAG,CAOlB,IAAU,EACV,IAA2D,EAC3D,IAA8E,EAO9E,EAAE;IACF,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAC1B,IAAI,EACJ,IAAa,EACb,GAAG,EAAE,CAAC,SAAS,CAOhB,CAAA;IAED,OAAO;QACL,IAAI,EAAE,WAAW;QACjB,IAAI;QACJ,MAAM;QACN,YAAY,EAAE,MAAM,CAAC,YAAY;QACjC,IAAI;KACL,CAAA;AACH,CAAC,CAAA"}
|
package/dist/Machine.d.ts
CHANGED
|
@@ -9,6 +9,10 @@
|
|
|
9
9
|
* run around that boundary. Menus, rounds, encounter phases, pause flows, and
|
|
10
10
|
* restart/reset pipelines are the canonical cases.
|
|
11
11
|
*
|
|
12
|
+
* A machine holds one value for the whole game. A state that each entity has
|
|
13
|
+
* on its own (an enemy's attack windup, a door's open/closed) is not a
|
|
14
|
+
* machine: use a `Descriptor.EntityState(...)` component instead.
|
|
15
|
+
*
|
|
12
16
|
* @example
|
|
13
17
|
* ```ts
|
|
14
18
|
* // Model a gameplay phase whose transition timing matters.
|
|
@@ -33,8 +37,9 @@
|
|
|
33
37
|
* @groupDescription Functions
|
|
34
38
|
* Public constructors for machines, conditions, and explicit transition bundles.
|
|
35
39
|
*/
|
|
36
|
-
import type { Schedule } from "./Schedule.ts";
|
|
40
|
+
import type { AnyScheduleOrder, Schedule } from "./Schedule.ts";
|
|
37
41
|
import * as Requirement from "./Requirement.ts";
|
|
42
|
+
import type * as Result from "./Result.ts";
|
|
38
43
|
import type { Schema } from "./Schema.ts";
|
|
39
44
|
import type { SystemFailure } from "./System.ts";
|
|
40
45
|
/**
|
|
@@ -47,54 +52,62 @@ export type StateValue = string | number;
|
|
|
47
52
|
/**
|
|
48
53
|
* One schema-bound finite state machine definition.
|
|
49
54
|
*/
|
|
50
|
-
export interface StateMachineDefinition<out Name extends string = string, out Values extends readonly [StateValue, ...StateValue[]] = readonly [StateValue, ...StateValue[]], out Root = unknown> {
|
|
55
|
+
export interface StateMachineDefinition<out Name extends string = string, out Values extends readonly [StateValue, ...StateValue[]] = readonly [StateValue, ...StateValue[]], out Root = unknown, out Parent = unknown> {
|
|
51
56
|
readonly kind: "stateMachine";
|
|
52
57
|
readonly name: Name;
|
|
53
58
|
readonly key: symbol;
|
|
54
59
|
readonly values: Values;
|
|
60
|
+
/** For a sub-state: the machine and the state it exists in. */
|
|
61
|
+
readonly within?: SubStateParent | undefined;
|
|
55
62
|
readonly __schemaRoot?: Root | undefined;
|
|
63
|
+
/** The machine a sub-state exists within; `unknown` for a top-level machine. */
|
|
64
|
+
readonly __parent?: (_: never) => Parent;
|
|
65
|
+
}
|
|
66
|
+
/** Where a sub-state exists: while `machine` is in `state`. */
|
|
67
|
+
export interface SubStateParent {
|
|
68
|
+
readonly machine: StateMachine.Any;
|
|
69
|
+
readonly state: StateValue;
|
|
56
70
|
}
|
|
57
71
|
/**
|
|
58
|
-
*
|
|
72
|
+
* Whether `M` is a sub-state (declared with `within`): it has no value while
|
|
73
|
+
* its parent machine is in another state.
|
|
59
74
|
*/
|
|
60
|
-
export
|
|
61
|
-
readonly
|
|
62
|
-
|
|
63
|
-
}
|
|
75
|
+
export type IsSubState<M> = M extends {
|
|
76
|
+
readonly __parent?: (_: never) => infer Parent;
|
|
77
|
+
} ? unknown extends Parent ? false : true : false;
|
|
64
78
|
/**
|
|
65
|
-
* A
|
|
79
|
+
* The committed value of `M`. A sub-state has none (`undefined`) while its
|
|
80
|
+
* parent machine is not in the state it exists in; a top-level machine
|
|
81
|
+
* always has one.
|
|
66
82
|
*/
|
|
67
|
-
export
|
|
68
|
-
get(): StateMachine.Value<M>;
|
|
69
|
-
is(value: StateMachine.Value<M>): boolean;
|
|
70
|
-
}
|
|
83
|
+
export type CurrentValue<M extends StateMachine.Any> = IsSubState<M> extends true ? StateMachine.Value<M> | undefined : StateMachine.Value<M>;
|
|
71
84
|
/**
|
|
72
|
-
*
|
|
85
|
+
* Why queuing a sub-state's next value failed: its parent machine is not in
|
|
86
|
+
* the state the sub-state exists in, so there is nothing to change.
|
|
73
87
|
*/
|
|
74
|
-
export interface
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
88
|
+
export interface SubStateInactive {
|
|
89
|
+
readonly _tag: "SubStateInactive";
|
|
90
|
+
/** The sub-state's name. */
|
|
91
|
+
readonly machine: string;
|
|
92
|
+
/** The parent machine's name. */
|
|
93
|
+
readonly parent: string;
|
|
94
|
+
/** The parent state the sub-state exists in. */
|
|
95
|
+
readonly requires: StateValue;
|
|
79
96
|
}
|
|
80
97
|
/**
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
* only exposed to systems that explicitly declare transition access.
|
|
98
|
+
* What `nextMachines.x.set(...)` returns: nothing for a top-level machine,
|
|
99
|
+
* and for a sub-state a `Result` that fails with `SubStateInactive` when its
|
|
100
|
+
* parent is in another state.
|
|
85
101
|
*/
|
|
86
|
-
export
|
|
87
|
-
get(): TransitionSnapshot<M>;
|
|
88
|
-
}
|
|
102
|
+
export type SetResult<M extends StateMachine.Any> = IsSubState<M> extends true ? Result.Result<void, SubStateInactive> : void;
|
|
89
103
|
/**
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
* transition commits. Like events, each reader sees the transitions published
|
|
94
|
-
* since its own previous run.
|
|
104
|
+
* The runtime-visible transition payload for one machine. For a sub-state,
|
|
105
|
+
* `from` is `undefined` when it starts existing (its parent entered its
|
|
106
|
+
* state) and `to` is `undefined` when it stops.
|
|
95
107
|
*/
|
|
96
|
-
export interface
|
|
97
|
-
|
|
108
|
+
export interface TransitionSnapshot<M extends StateMachineDefinition = StateMachineDefinition> {
|
|
109
|
+
readonly from: CurrentValue<M>;
|
|
110
|
+
readonly to: CurrentValue<M>;
|
|
98
111
|
}
|
|
99
112
|
/**
|
|
100
113
|
* Read access to the current committed state in a system spec.
|
|
@@ -188,12 +201,14 @@ export interface CheckProjection {
|
|
|
188
201
|
/**
|
|
189
202
|
* A machine-bound transition schedule created through the schema-bound API.
|
|
190
203
|
*/
|
|
191
|
-
export interface TransitionScheduleDefinition<S extends Schema.Any = Schema.Any, M extends StateMachineDefinition = StateMachineDefinition, Needs extends Requirement.Requirement = Requirement.Requirement, Root = unknown, Failure extends SystemFailure = never> {
|
|
204
|
+
export interface TransitionScheduleDefinition<S extends Schema.Any = Schema.Any, M extends StateMachineDefinition = StateMachineDefinition, Needs extends Requirement.Requirement = Requirement.Requirement, Root = unknown, Failure extends SystemFailure = never, Order extends AnyScheduleOrder = AnyScheduleOrder> {
|
|
192
205
|
readonly steps: ReadonlyArray<Schedule.Step>;
|
|
193
206
|
readonly systems: ReadonlyArray<unknown>;
|
|
194
207
|
readonly schema: S;
|
|
195
208
|
readonly requirements: ReadonlyArray<Needs>;
|
|
196
209
|
readonly __failure?: (_: never) => Failure;
|
|
210
|
+
/** The plan's order, for `Game.System.thisTick` checks of the tick that applies it. */
|
|
211
|
+
readonly __order?: (_: never) => Order;
|
|
197
212
|
readonly __schemaRoot?: Root | undefined;
|
|
198
213
|
readonly transition: {
|
|
199
214
|
readonly machine: M;
|
|
@@ -207,12 +222,22 @@ export interface TransitionScheduleDefinition<S extends Schema.Any = Schema.Any,
|
|
|
207
222
|
* Type-level and value-level helpers for finite-state machines.
|
|
208
223
|
*/
|
|
209
224
|
export declare namespace StateMachine {
|
|
210
|
-
type Any = StateMachineDefinition<string, readonly [StateValue, ...StateValue[]], unknown>;
|
|
225
|
+
type Any = StateMachineDefinition<string, readonly [StateValue, ...StateValue[]], unknown, unknown>;
|
|
211
226
|
type Value<M extends Any> = M["values"][number];
|
|
212
227
|
type Root<M extends Any> = M extends StateMachineDefinition<string, readonly [StateValue, ...StateValue[]], infer R> ? R : never;
|
|
213
228
|
type AnyCondition<Root = unknown> = Condition<Root>;
|
|
214
229
|
type AnyTransitionSchedule<S extends Schema.Any = Schema.Any, Root = unknown> = TransitionScheduleDefinition<S, Any, Requirement.Requirement, Root, SystemFailure>;
|
|
215
230
|
}
|
|
231
|
+
/**
|
|
232
|
+
* `unknown` when `M` was defined by the game rooted at `Root`; otherwise a
|
|
233
|
+
* type naming the fix, so passing another game's machine fails with that
|
|
234
|
+
* message.
|
|
235
|
+
*/
|
|
236
|
+
export type SameGame<M, Root> = M extends StateMachineDefinition<infer Name, readonly [StateValue, ...StateValue[]], infer MachineRoot> ? [Root] extends [MachineRoot] ? [MachineRoot] extends [Root] ? unknown : ForeignMachine<`${Name} is a state machine of another game: use a machine defined with this game's Game.StateMachine(...)`> : ForeignMachine<`${Name} is a state machine of another game: use a machine defined with this game's Game.StateMachine(...)`> : unknown;
|
|
237
|
+
/** The message type `SameGame` resolves to: a type error prints `Message`. */
|
|
238
|
+
type ForeignMachine<Message extends string> = {
|
|
239
|
+
readonly __foreignMachine__: Message;
|
|
240
|
+
};
|
|
216
241
|
/** Extracts the machine token from one declared machine access slot. */
|
|
217
242
|
type MachineFromAccess<Access> = Access extends {
|
|
218
243
|
readonly machine: infer M extends StateMachine.Any;
|
|
@@ -233,7 +258,7 @@ export type MachineNeedsFromRecord<R extends Record<string, unknown>> = MachineF
|
|
|
233
258
|
/** Extracts the machine-token union carried by a condition list. */
|
|
234
259
|
export type MachineNeedsFromConditions<C extends ReadonlyArray<Condition>> = MachineNeedsFromCondition<C[number]>;
|
|
235
260
|
/**
|
|
236
|
-
* Creates a schema-bound finite-state machine definition.
|
|
261
|
+
* Creates a schema-bound finite-state machine definition: one game-wide mode.
|
|
237
262
|
*
|
|
238
263
|
* This is the intended default for gameplay phases and other discrete modes
|
|
239
264
|
* where the transition boundary itself matters.
|
|
@@ -244,8 +269,14 @@ export type MachineNeedsFromConditions<C extends ReadonlyArray<Condition>> = Mac
|
|
|
244
269
|
* - explicit `applyStateTransitions(...)`
|
|
245
270
|
* - `inState(...)` gating
|
|
246
271
|
* - transition events or enter/exit schedules
|
|
272
|
+
*
|
|
273
|
+
* Use `Descriptor.EntityState(...)` instead when every entity carries its own
|
|
274
|
+
* state (per-entity, written immediately, no enter/exit schedules).
|
|
275
|
+
*
|
|
276
|
+
* Pass `within` for a sub-state: a machine that exists only while another
|
|
277
|
+
* machine is in one state (`Game.StateMachine(name, values, { within })`).
|
|
247
278
|
*/
|
|
248
|
-
export declare const StateMachine: <const Name extends string, const Values extends readonly [StateValue, ...StateValue[]], Root = unknown>(name: Name, values: Values) => StateMachineDefinition<Name, Values, Root>;
|
|
279
|
+
export declare const StateMachine: <const Name extends string, const Values extends readonly [StateValue, ...StateValue[]], Root = unknown>(name: Name, values: Values, within?: SubStateParent) => StateMachineDefinition<Name, Values, Root>;
|
|
249
280
|
/**
|
|
250
281
|
* Declares that a system wants to read the current committed state.
|
|
251
282
|
*
|
package/dist/Machine.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Machine.d.ts","sourceRoot":"","sources":["../src/Machine.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"Machine.d.ts","sourceRoot":"","sources":["../src/Machine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,OAAO,KAAK,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC/D,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAA;AAC/C,OAAO,KAAK,KAAK,MAAM,MAAM,aAAa,CAAA;AAC1C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAEhD;;;;;GAKG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,MAAM,CAAA;AAExC;;GAEG;AACH,MAAM,WAAW,sBAAsB,CACrC,GAAG,CAAC,IAAI,SAAS,MAAM,GAAG,MAAM,EAChC,GAAG,CAAC,MAAM,SAAS,SAAS,CAAC,UAAU,EAAE,GAAG,UAAU,EAAE,CAAC,GAAG,SAAS,CAAC,UAAU,EAAE,GAAG,UAAU,EAAE,CAAC,EAClG,GAAG,CAAC,IAAI,GAAG,OAAO,EAClB,GAAG,CAAC,MAAM,GAAG,OAAO;IAEpB,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAA;IAC7B,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAA;IACnB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,+DAA+D;IAC/D,QAAQ,CAAC,MAAM,CAAC,EAAE,cAAc,GAAG,SAAS,CAAA;IAC5C,QAAQ,C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AS,aAAa,CAAC,SAAS,CAAC,iBAAiB,CAAC,KAAG,WAAW,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAItH,CAAA"}
|
package/dist/Machine.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as Requirement from "./Requirement.js";
|
|
2
2
|
/**
|
|
3
|
-
* Creates a schema-bound finite-state machine definition.
|
|
3
|
+
* Creates a schema-bound finite-state machine definition: one game-wide mode.
|
|
4
4
|
*
|
|
5
5
|
* This is the intended default for gameplay phases and other discrete modes
|
|
6
6
|
* where the transition boundary itself matters.
|
|
@@ -11,12 +11,19 @@ import * as Requirement from "./Requirement.js";
|
|
|
11
11
|
* - explicit `applyStateTransitions(...)`
|
|
12
12
|
* - `inState(...)` gating
|
|
13
13
|
* - transition events or enter/exit schedules
|
|
14
|
+
*
|
|
15
|
+
* Use `Descriptor.EntityState(...)` instead when every entity carries its own
|
|
16
|
+
* state (per-entity, written immediately, no enter/exit schedules).
|
|
17
|
+
*
|
|
18
|
+
* Pass `within` for a sub-state: a machine that exists only while another
|
|
19
|
+
* machine is in one state (`Game.StateMachine(name, values, { within })`).
|
|
14
20
|
*/
|
|
15
|
-
export const StateMachine = (name, values) => ({
|
|
21
|
+
export const StateMachine = (name, values, within) => ({
|
|
16
22
|
kind: "stateMachine",
|
|
17
23
|
name,
|
|
18
24
|
key: Symbol.for(`ritmo/stateMachine/${name}`),
|
|
19
|
-
values
|
|
25
|
+
values,
|
|
26
|
+
...(within === undefined ? {} : { within })
|
|
20
27
|
});
|
|
21
28
|
/**
|
|
22
29
|
* Declares that a system wants to read the current committed state.
|
package/dist/Machine.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Machine.js","sourceRoot":"","sources":["../src/Machine.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Machine.js","sourceRoot":"","sources":["../src/Machine.ts"],"names":[],"mappings":"AAwCA,OAAO,K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AC;CACxB,CAAC,CAAA;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,GAAG,GAAG,CAAsB,SAAY,EAAsC,EAAE,CAAC,CAAC;IAC7F,IAAI,EAAE,KAAK;IACX,SAAS;IACT,YAAY,EAAE,SAAS,CAAC,YAAY;CACrC,CAAC,CAAA;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,GAAG,GAAG,CAA2C,GAAG,UAAa,EAA8C,EAAE,CAAC,CAAC;IAC9H,IAAI,EAAE,KAAK;IACX,UAAU;IACV,YAAY,EAAE,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;CAC7F,CAAC,CAAA;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,EAAE,GAAG,CAA2C,GAAG,UAAa,EAA6C,EAAE,CAAC,CAAC;IAC5H,IAAI,EAAE,IAAI;IACV,UAAU;IACV,YAAY,EAAE,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;CAC7F,CAAC,CAAA"}
|
package/dist/Query.d.ts
CHANGED
|
@@ -69,7 +69,8 @@
|
|
|
69
69
|
* Query authoring helpers for selecting components and declaring explicit filters.
|
|
70
70
|
*/
|
|
71
71
|
import type { DecodeError } from "./Decode.ts";
|
|
72
|
-
import
|
|
72
|
+
import * as DescriptorModule from "./Descriptor.ts";
|
|
73
|
+
import type { Descriptor, EntityStateValue } from "./Descriptor.ts";
|
|
73
74
|
import type { EntityId, EntityMut, EntityRef } from "./Entity.ts";
|
|
74
75
|
import type * as Result from "./Result.ts";
|
|
75
76
|
import type * as Relation from "./Relation.ts";
|
|
@@ -163,7 +164,17 @@ export interface ChangedFilter<D extends ComponentDescriptor> {
|
|
|
163
164
|
readonly kind: "changed";
|
|
164
165
|
readonly descriptor: D;
|
|
165
166
|
}
|
|
166
|
-
|
|
167
|
+
/** An `added` or `changed` filter: the filters `anyOf` combines. */
|
|
168
|
+
export type LifecycleFilter<D extends ComponentDescriptor> = AddedFilter<D> | ChangedFilter<D>;
|
|
169
|
+
/**
|
|
170
|
+
* A filter that matches entities passing at least one of its `added` /
|
|
171
|
+
* `changed` filters since the reading system's previous run.
|
|
172
|
+
*/
|
|
173
|
+
export interface AnyOfFilter<D extends ComponentDescriptor> {
|
|
174
|
+
readonly kind: "anyOf";
|
|
175
|
+
readonly filters: ReadonlyArray<LifecycleFilter<D>>;
|
|
176
|
+
}
|
|
177
|
+
export type Filter<D extends ComponentDescriptor> = LifecycleFilter<D> | AnyOfFilter<D>;
|
|
167
178
|
/**
|
|
168
179
|
* Declares read-only access to a component in a query selection.
|
|
169
180
|
*
|
|
@@ -180,8 +191,21 @@ export declare const read: <D extends ComponentDescriptor>(descriptor: D) => Rea
|
|
|
180
191
|
* place. A write slot both requires component presence and exposes the slot as
|
|
181
192
|
* a `WriteCell`, so mutation capability stays visible in the query spec rather
|
|
182
193
|
* than appearing ad hoc in the loop body.
|
|
194
|
+
*
|
|
195
|
+
* Components declared `immutable: true` cannot be written: replace them with
|
|
196
|
+
* `commands.insert(...)` instead.
|
|
197
|
+
*/
|
|
198
|
+
export declare const write: <D extends ComponentDescriptor>(descriptor: D & Writable<D>) => WriteAccess<D>;
|
|
199
|
+
type NameOf<D> = D extends {
|
|
200
|
+
readonly name: infer Name extends string;
|
|
201
|
+
} ? Name : never;
|
|
202
|
+
/**
|
|
203
|
+
* `unknown` for a component a query may write; for one declared
|
|
204
|
+
* `immutable: true`, an argument error naming the fix.
|
|
183
205
|
*/
|
|
184
|
-
export
|
|
206
|
+
export type Writable<D> = D extends DescriptorModule.Immutable ? {
|
|
207
|
+
readonly __immutable__: `${NameOf<D>} is immutable: replace it with commands.insert(entity, Game.Command.entry(${NameOf<D>}, ...))`;
|
|
208
|
+
} : unknown;
|
|
185
209
|
/**
|
|
186
210
|
* Declares maybe-present read-only access to a component in a query
|
|
187
211
|
* specification.
|
|
@@ -243,6 +267,24 @@ export declare const added: <D extends ComponentDescriptor>(descriptor: D) => Ad
|
|
|
243
267
|
* ```
|
|
244
268
|
*/
|
|
245
269
|
export declare const changed: <D extends ComponentDescriptor>(descriptor: D) => ChangedFilter<D>;
|
|
270
|
+
/**
|
|
271
|
+
* Declares a filter that matches entities passing at least one of `filters`
|
|
272
|
+
* (`added` / `changed`) since the reading system's previous run. Each entity
|
|
273
|
+
* is matched once, however many of its filters pass.
|
|
274
|
+
*
|
|
275
|
+
* Filters listed side by side in `filters: [...]` must all pass; use `anyOf`
|
|
276
|
+
* when any one of them is enough, for example to redraw when either the
|
|
277
|
+
* position or the sprite changed.
|
|
278
|
+
*
|
|
279
|
+
* @example
|
|
280
|
+
* ```ts
|
|
281
|
+
* const RedrawQuery = Game.Query({
|
|
282
|
+
* selection: { position: Game.Query.read(Position), sprite: Game.Query.read(Sprite) },
|
|
283
|
+
* filters: [Game.Query.anyOf(Game.Query.changed(Position), Game.Query.changed(Sprite))]
|
|
284
|
+
* })
|
|
285
|
+
* ```
|
|
286
|
+
*/
|
|
287
|
+
export declare const anyOf: <const Filters extends readonly [LifecycleFilter<ComponentDescriptor>, LifecycleFilter<ComponentDescriptor>, ...ReadonlyArray<LifecycleFilter<ComponentDescriptor>>]>(...filters: Filters) => AnyOfFilter<Filters[number]["descriptor"]>;
|
|
246
288
|
/**
|
|
247
289
|
* A fully explicit query specification.
|
|
248
290
|
*
|
|
@@ -313,6 +355,10 @@ export declare namespace Query {
|
|
|
313
355
|
* only be resolved with queries that actually prove the intended role.
|
|
314
356
|
*/
|
|
315
357
|
export type ProvesComponent<T extends Any, D extends ComponentDescriptor> = [Extract<RequiredSelectionDescriptors<T> | T["with"][number], D>] extends [never] ? false : true;
|
|
358
|
+
/** The component descriptors a query proves its matches have: required selection slots and `with`. */
|
|
359
|
+
export type Proven<T extends Any> = RequiredSelectionDescriptors<T> | T["with"][number];
|
|
360
|
+
/** The component descriptors a query proves its matches lack: its `without`. */
|
|
361
|
+
export type Excluded<T extends Any> = T["without"][number];
|
|
316
362
|
/**
|
|
317
363
|
* The readable proof produced by a query.
|
|
318
364
|
*/
|
|
@@ -390,24 +436,20 @@ export interface ReadCell<T> {
|
|
|
390
436
|
* A mutable cell returned from query or resource access.
|
|
391
437
|
*
|
|
392
438
|
* This gives a narrow mutation surface instead of exposing raw storage objects.
|
|
439
|
+
* Values written here are already valid. Data that still needs validation
|
|
440
|
+
* goes through its descriptor's own validator: declare the descriptor with
|
|
441
|
+
* `Descriptor.ConstructedComponent` / `ConstructedResource` and write with
|
|
442
|
+
* `setRaw` / `updateRaw` on its {@link ConstructedWriteCell}.
|
|
393
443
|
*/
|
|
394
444
|
export interface WriteCell<T> extends ReadCell<T> {
|
|
395
445
|
/**
|
|
396
446
|
* Replaces the current value.
|
|
397
447
|
*/
|
|
398
448
|
set(value: T): void;
|
|
399
|
-
/**
|
|
400
|
-
* Replaces the current value from an explicit result.
|
|
401
|
-
*/
|
|
402
|
-
setResult<E>(result: Result.Result<T, E>): Result.Result<void, E>;
|
|
403
449
|
/**
|
|
404
450
|
* Updates the current value based on the previous one.
|
|
405
451
|
*/
|
|
406
452
|
update(f: (current: ReadonlyValue<T>) => T): void;
|
|
407
|
-
/**
|
|
408
|
-
* Updates the current value from an explicit result-producing callback.
|
|
409
|
-
*/
|
|
410
|
-
updateResult<E>(f: (current: ReadonlyValue<T>) => Result.Result<T, E>): Result.Result<void, E>;
|
|
411
453
|
}
|
|
412
454
|
/**
|
|
413
455
|
* Writable cell for data backed by a constructed descriptor.
|
|
@@ -440,45 +482,45 @@ export interface ConstructedWriteCell<T, Raw, Error> extends WriteCell<T> {
|
|
|
440
482
|
updateRaw(f: (current: ReadonlyValue<T>) => Raw): Result.Result<void, Error>;
|
|
441
483
|
}
|
|
442
484
|
/**
|
|
443
|
-
* A `transition(from, to)` found the state
|
|
485
|
+
* A `transition(from, to)` found the entity state in another state, so
|
|
444
486
|
* nothing was written.
|
|
445
487
|
*/
|
|
446
|
-
export interface
|
|
447
|
-
readonly _tag: "
|
|
448
|
-
/** Name of the
|
|
449
|
-
readonly
|
|
488
|
+
export interface EntityStateMismatchError<T> {
|
|
489
|
+
readonly _tag: "EntityStateMismatch";
|
|
490
|
+
/** Name of the `Descriptor.EntityState` component. */
|
|
491
|
+
readonly component: string;
|
|
450
492
|
/** The `from` state the transition expected. */
|
|
451
493
|
readonly expected: T;
|
|
452
494
|
/** The state the component was actually in. */
|
|
453
495
|
readonly actual: T;
|
|
454
496
|
}
|
|
455
497
|
/**
|
|
456
|
-
* Writable cell for
|
|
498
|
+
* Writable cell for an entity state component (`Descriptor.EntityState`).
|
|
457
499
|
*
|
|
458
500
|
* `transition(from, to)` is a compare-and-set: it writes `to` only while the
|
|
459
|
-
* current state is `from`, and otherwise returns `
|
|
501
|
+
* current state is `from`, and otherwise returns `EntityStateMismatch` without
|
|
460
502
|
* writing. With a transition graph, `to` must be one of the moves the graph
|
|
461
503
|
* allows from `from`; without one, any pair of states is accepted.
|
|
462
504
|
*/
|
|
463
|
-
export interface
|
|
505
|
+
export interface EntityStateWriteCell<T, Transitions> extends ConstructedWriteCell<T, T, DecodeError> {
|
|
464
506
|
/**
|
|
465
507
|
* Moves from `from` to `to` if the component is still in `from`.
|
|
466
508
|
*
|
|
467
509
|
* @example
|
|
468
510
|
* ```ts
|
|
469
|
-
* const moved = data.
|
|
511
|
+
* const moved = data.attack.transition("windup", "active")
|
|
470
512
|
* if (!moved.ok) {
|
|
471
513
|
* // moved.error.actual is the state some earlier write left
|
|
472
514
|
* }
|
|
473
515
|
* ```
|
|
474
516
|
*/
|
|
475
|
-
transition<const From extends T & keyof Transitions>(from: From, to:
|
|
517
|
+
transition<const From extends T & keyof Transitions>(from: From, to: EntityStateTarget<T, Transitions, From>): Result.Result<void, EntityStateMismatchError<T>>;
|
|
476
518
|
}
|
|
477
|
-
type
|
|
519
|
+
type EntityStateTarget<T, Transitions, From extends keyof Transitions> = Transitions[From] extends ReadonlyArray<infer To> ? To & T : never;
|
|
478
520
|
/**
|
|
479
521
|
* Write-cell surface produced for one queried component descriptor.
|
|
480
522
|
*/
|
|
481
|
-
export type WriteCellForDescriptor<D extends ComponentDescriptor> = D extends import("./Descriptor.ts").
|
|
523
|
+
export type WriteCellForDescriptor<D extends ComponentDescriptor> = D extends import("./Descriptor.ts").EntityStateDescriptor<string, infer States extends readonly [EntityStateValue, ...Array<EntityStateValue>], any> ? EntityStateWriteCell<States[number], D["transitions"] extends undefined ? {
|
|
482
524
|
readonly [K in States[number]]: States;
|
|
483
525
|
} : D["transitions"]> : D extends import("./Descriptor.ts").ConstructedDescriptor<"component", string, infer Value, infer Raw, infer Error> ? ConstructedWriteCell<Value, Raw, Error> : WriteCell<Descriptor.Value<D>>;
|
|
484
526
|
/**
|
|
@@ -506,10 +548,10 @@ export type OptionalReadCell<T> = PresentOptionalReadCell<T> | AbsentOptionalRea
|
|
|
506
548
|
* Otherwise it remains read-only.
|
|
507
549
|
*/
|
|
508
550
|
export type QueryMatch<S extends Schema.Any, Q extends Query.Any> = keyof Query.WriteProof<Q> extends never ? {
|
|
509
|
-
readonly entity: EntityRef<S, Query.ReadProof<Q>, Query.Root<Q>>;
|
|
551
|
+
readonly entity: EntityRef<S, Query.ReadProof<Q>, Query.Root<Q>, Query.Proven<Q>, Query.Excluded<Q>>;
|
|
510
552
|
readonly data: Query.Cells<Q>;
|
|
511
553
|
} : {
|
|
512
|
-
readonly entity: EntityMut<S, Query.ReadProof<Q>, Query.WriteProof<Q>, Query.Root<Q>>;
|
|
554
|
+
readonly entity: EntityMut<S, Query.ReadProof<Q>, Query.WriteProof<Q>, Query.Root<Q>, Query.Proven<Q>, Query.Excluded<Q>>;
|
|
513
555
|
readonly data: Query.Cells<Q>;
|
|
514
556
|
};
|
|
515
557
|
/**
|
|
@@ -552,6 +594,12 @@ export declare const multipleEntitiesError: (count: number) => Query.MultipleEnt
|
|
|
552
594
|
* })
|
|
553
595
|
* ```
|
|
554
596
|
*/
|
|
597
|
+
/**
|
|
598
|
+
* `T` itself, but not a place inference reads from: a list a query omits
|
|
599
|
+
* stays `[]` even when the call sits where a wider query type is expected
|
|
600
|
+
* (`queries: { ... }` in a spec). Unlike `NoInfer`, it prints as `T`.
|
|
601
|
+
*/
|
|
602
|
+
export type Uninferred<T, Bound> = [T] extends [infer U extends Bound] ? U : never;
|
|
555
603
|
export declare const Query: <const Selection extends Record<string, SelectionAccess<any, Root>>, const With extends ReadonlyArray<ComponentDescriptor> = [], const Without extends ReadonlyArray<ComponentDescriptor> = [], const Filters extends ReadonlyArray<Filter<ComponentDescriptor>> = [], const WithRelations extends ReadonlyArray<Relation.Relation.Any> = [], const WithoutRelations extends ReadonlyArray<Relation.Relation.Any> = [], const WithRelated extends ReadonlyArray<Relation.Relation.Any> = [], const WithoutRelated extends ReadonlyArray<Relation.Relation.Any> = [], Root = unknown>(spec: {
|
|
556
604
|
readonly selection: Selection;
|
|
557
605
|
readonly with?: With;
|
|
@@ -561,6 +609,6 @@ export declare const Query: <const Selection extends Record<string, SelectionAcc
|
|
|
561
609
|
readonly withoutRelations?: WithoutRelations;
|
|
562
610
|
readonly withRelated?: WithRelated;
|
|
563
611
|
readonly withoutRelated?: WithoutRelated;
|
|
564
|
-
}) => QuerySpec<Selection, With, Without, Filters, WithRelations, WithoutRelations, WithRelated, WithoutRelated, Root>;
|
|
612
|
+
}) => QuerySpec<Selection, Uninferred<With, ReadonlyArray<ComponentDescriptor>>, Uninferred<Without, ReadonlyArray<ComponentDescriptor>>, Uninferred<Filters, ReadonlyArray<Filter<ComponentDescriptor>>>, Uninferred<WithRelations, ReadonlyArray<Relation.Relation.Any>>, Uninferred<WithoutRelations, ReadonlyArray<Relation.Relation.Any>>, Uninferred<WithRelated, ReadonlyArray<Relation.Relation.Any>>, Uninferred<WithoutRelated, ReadonlyArray<Relation.Relation.Any>>, Root>;
|
|
565
613
|
export {};
|
|
566
614
|
//# sourceMappingURL=Query.d.ts.map
|