@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
package/dist/Feature.js
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Pre-bind features: reusable slices that contribute a schema fragment and the
|
|
3
|
-
* schedules that operate on it.
|
|
4
|
-
*
|
|
5
|
-
* A feature builds its schedules only after the final merged schema is bound,
|
|
6
|
-
* and its builder can only reach descriptors from its own fragment and from
|
|
7
|
-
* the features it `requires`.
|
|
8
|
-
*
|
|
9
|
-
* @module Feature
|
|
10
|
-
* @docGroup core
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```ts
|
|
14
|
-
* const Combat = Schema.Feature.define("Combat", {
|
|
15
|
-
* schema: CombatSchema,
|
|
16
|
-
* requires: [Core],
|
|
17
|
-
* build: (Game) => ({ update: [Game.Schedule(Attack, Game.Schedule.applyDeferred())] })
|
|
18
|
-
* })
|
|
19
|
-
*
|
|
20
|
-
* const project = Schema.Feature.compose({ root: Root, features: [Core, Combat] })
|
|
21
|
-
* const runtime = project.Game.Runtime.make({ services: project.Game.Runtime.services() })
|
|
22
|
-
* runtime.tick(...project.schedules.update)
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
import { buildSchema } from "./internal/fragments.js";
|
|
26
|
-
import { makeGame } from "./internal/game.js";
|
|
27
|
-
/**
|
|
28
|
-
* Defines one pre-bind feature.
|
|
29
|
-
*/
|
|
30
|
-
export const define = (name, options) => ({
|
|
31
|
-
kind: "feature",
|
|
32
|
-
name,
|
|
33
|
-
schema: options.schema,
|
|
34
|
-
requires: (options.requires ?? []),
|
|
35
|
-
build: options.build,
|
|
36
|
-
output: undefined
|
|
37
|
-
});
|
|
38
|
-
/**
|
|
39
|
-
* Composes features into one merged schema and one bound `Game`, then builds
|
|
40
|
-
* every feature against it.
|
|
41
|
-
*
|
|
42
|
-
* Aggregated schedule order is the selected feature order, not dependency
|
|
43
|
-
* order. Run them with `runtime.tick(...project.schedules.update)`.
|
|
44
|
-
*/
|
|
45
|
-
export const compose = (options) => {
|
|
46
|
-
const featureNames = new Set();
|
|
47
|
-
for (const feature of options.features) {
|
|
48
|
-
if (featureNames.has(feature.name)) {
|
|
49
|
-
throw new Error(`Duplicate feature name: ${feature.name}`);
|
|
50
|
-
}
|
|
51
|
-
featureNames.add(feature.name);
|
|
52
|
-
}
|
|
53
|
-
for (const feature of options.features) {
|
|
54
|
-
for (const requirement of feature.requires) {
|
|
55
|
-
if (!featureNames.has(requirement.name)) {
|
|
56
|
-
throw new Error(`Missing required feature: ${requirement.name}`);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
const schema = buildSchema(options.features.map((feature) => feature.schema));
|
|
61
|
-
const Game = makeGame(schema, options.root);
|
|
62
|
-
const features = Object.create(null);
|
|
63
|
-
const bootstrap = [];
|
|
64
|
-
const update = [];
|
|
65
|
-
for (const feature of options.features) {
|
|
66
|
-
const built = feature.build(Game);
|
|
67
|
-
const normalized = {
|
|
68
|
-
...built,
|
|
69
|
-
bootstrap: [...(built.bootstrap ?? [])],
|
|
70
|
-
update: [...(built.update ?? [])]
|
|
71
|
-
};
|
|
72
|
-
bootstrap.push(...normalized.bootstrap);
|
|
73
|
-
update.push(...normalized.update);
|
|
74
|
-
features[feature.name] = normalized;
|
|
75
|
-
}
|
|
76
|
-
return {
|
|
77
|
-
schema,
|
|
78
|
-
Game,
|
|
79
|
-
features,
|
|
80
|
-
schedules: { bootstrap, update }
|
|
81
|
-
};
|
|
82
|
-
};
|
|
83
|
-
export const Feature = {
|
|
84
|
-
define,
|
|
85
|
-
compose
|
|
86
|
-
};
|
|
87
|
-
//# sourceMappingURL=Feature.js.map
|
package/dist/Feature.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Feature.js","sourceRoot":"","sources":["../src/Feature.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAqI7C;;GAEG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,CAMpB,I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,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IAC5D,MAAM,SAAS,GAAuB,EAAE,CAAA;IACxC,MAAM,MAAM,GAAuB,EAAE,CAAA;IAErC,KAAK,MAAM,OAAO,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;QACvC,MAAM,KAAK,GAAI,OAAO,CAAC,KAAyE,CAAC,IAAI,CAAC,CAAA;QACtG,MAAM,UAAU,GAAG;YACjB,GAAG,KAAK;YACR,SAAS,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC;YACvC,MAAM,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC;SAClC,CAAA;QACD,SAAS,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,SAAS,CAAC,CAAA;QACvC,MAAM,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,MAAM,CAAC,CAAA;QACjC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,UAAU,CAAA;IACrC,CAAC;IAED,OAAO;QACL,MAAM;QACN,IAAI;QACJ,QAAQ;QACR,SAAS,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE;KACoB,CAAA;AACxD,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,MAAM;IACN,OAAO;CACR,CAAA"}
|
package/dist/Fx.d.ts
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Small explicit effect type used for systems and runtime orchestration.
|
|
3
|
-
*
|
|
4
|
-
* `Fx` models delayed computation with typed success, failure, and environment
|
|
5
|
-
* channels. Expected failures are returned as `Result` values; exceptions are
|
|
6
|
-
* reserved for unexpected defects in user code.
|
|
7
|
-
*
|
|
8
|
-
* Systems that cannot fail return nothing. A system returns an `Fx` when it
|
|
9
|
-
* has an expected failure: `Fx.fail(...)` rolls back the system's ECS writes
|
|
10
|
-
* and surfaces a typed `SystemFailure` from `runtime.tick(...)`. `map` and
|
|
11
|
-
* `flatMap` compose such effects.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```ts
|
|
15
|
-
* // Build one small delayed computation.
|
|
16
|
-
* const program = Fx.map(Fx.succeed(1), (value) => value + 1)
|
|
17
|
-
*
|
|
18
|
-
* // Execute it explicitly at the runtime boundary.
|
|
19
|
-
* const result = Fx.runSync(program)
|
|
20
|
-
* ```
|
|
21
|
-
*
|
|
22
|
-
* @module Fx
|
|
23
|
-
* @docGroup runtime
|
|
24
|
-
*
|
|
25
|
-
* @groupDescription Namespaces
|
|
26
|
-
* Grouped helper types that extract success, error, and environment information from effects.
|
|
27
|
-
*
|
|
28
|
-
* @groupDescription Interfaces
|
|
29
|
-
* Public effect contracts used by systems and runtime orchestration.
|
|
30
|
-
*
|
|
31
|
-
* @groupDescription Type Aliases
|
|
32
|
-
* Shared helper types derived from one `Fx` value.
|
|
33
|
-
*
|
|
34
|
-
* @groupDescription Functions
|
|
35
|
-
* Minimal constructors and combinators for explicit delayed computations.
|
|
36
|
-
*/
|
|
37
|
-
import * as Result from "./Result.ts";
|
|
38
|
-
/**
|
|
39
|
-
* String-literal type id used to mirror Effect's current `~effect/...` style.
|
|
40
|
-
*/
|
|
41
|
-
export type FxTypeId = "~ritmo/Fx";
|
|
42
|
-
/**
|
|
43
|
-
* Runtime value for the `Fx` type id.
|
|
44
|
-
*/
|
|
45
|
-
declare const fxTypeId: FxTypeId;
|
|
46
|
-
/**
|
|
47
|
-
* A minimal Effect-style computation used by the runtime.
|
|
48
|
-
*
|
|
49
|
-
* `Fx<A, E, R>` models a computation that succeeds with `A`, may fail with `E`,
|
|
50
|
-
* and requires an environment `R`.
|
|
51
|
-
*/
|
|
52
|
-
export interface Fx<A, E = never, R = unknown> {
|
|
53
|
-
readonly [fxTypeId]: {
|
|
54
|
-
readonly _A: (_: never) => A;
|
|
55
|
-
readonly _E: (_: never) => E;
|
|
56
|
-
readonly _R: (_: R) => void;
|
|
57
|
-
};
|
|
58
|
-
readonly run: (environment: R) => Result.Result<A, E>;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Type-level helpers for `Fx`.
|
|
62
|
-
*/
|
|
63
|
-
export declare namespace Fx {
|
|
64
|
-
/**
|
|
65
|
-
* Extracts the success type from an effect.
|
|
66
|
-
*/
|
|
67
|
-
type Success<T extends Fx<any, any, any>> = T extends Fx<infer A, infer _E, infer _R> ? A : never;
|
|
68
|
-
/**
|
|
69
|
-
* Extracts the error type from an effect.
|
|
70
|
-
*/
|
|
71
|
-
type Error<T extends Fx<any, any, any>> = T extends Fx<infer _A, infer E, infer _R> ? E : never;
|
|
72
|
-
/**
|
|
73
|
-
* Extracts the required environment from an effect.
|
|
74
|
-
*/
|
|
75
|
-
type Context<T extends Fx<any, any, any>> = T extends Fx<infer _A, infer _E, infer R> ? R : never;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Creates an effect that immediately succeeds with a value.
|
|
79
|
-
*
|
|
80
|
-
* Use this for pure values that should still participate in the typed effect
|
|
81
|
-
* composition model.
|
|
82
|
-
*/
|
|
83
|
-
export declare const succeed: <A, R = unknown>(value: A) => Fx<A, never, R>;
|
|
84
|
-
/**
|
|
85
|
-
* Wraps a synchronous computation in an `Fx`.
|
|
86
|
-
*
|
|
87
|
-
* This is the most common constructor for system implementations in the current
|
|
88
|
-
* runtime because systems are executed synchronously.
|
|
89
|
-
*/
|
|
90
|
-
export declare const sync: <A, R = unknown>(evaluate: () => A) => Fx<A, never, R>;
|
|
91
|
-
/**
|
|
92
|
-
* Creates an effect that returns one expected failure when run.
|
|
93
|
-
*/
|
|
94
|
-
export declare const fail: <E, R = unknown>(error: E) => Fx<never, E, R>;
|
|
95
|
-
/**
|
|
96
|
-
* Transforms the success value of an effect.
|
|
97
|
-
*/
|
|
98
|
-
export declare const map: <A, B, E, R>(self: Fx<A, E, R>, f: (value: A) => B) => Fx<B, E, R>;
|
|
99
|
-
/**
|
|
100
|
-
* Sequences two effects, allowing the second one to depend on the first result.
|
|
101
|
-
*/
|
|
102
|
-
export declare const flatMap: <A, B, E1, E2, R1, R2>(self: Fx<A, E1, R1>, f: (value: A) => Fx<B, E2, R2>) => Fx<B, E1 | E2, R1 & R2>;
|
|
103
|
-
/**
|
|
104
|
-
* Reads the whole effect environment.
|
|
105
|
-
*
|
|
106
|
-
* Use this when a system helper wants access to all declared services at once.
|
|
107
|
-
*/
|
|
108
|
-
export declare const access: <R>() => Fx<R, never, R>;
|
|
109
|
-
/**
|
|
110
|
-
* Reads a single service from the environment by key.
|
|
111
|
-
*
|
|
112
|
-
* This is useful for small helpers that need one dependency without threading
|
|
113
|
-
* the entire environment type manually.
|
|
114
|
-
*/
|
|
115
|
-
export declare const accessService: <R, K extends keyof R>(key: K) => Fx<R[K], never, R>;
|
|
116
|
-
/**
|
|
117
|
-
* Supplies the environment needed by an effect.
|
|
118
|
-
*/
|
|
119
|
-
export declare const provide: <A, E, R>(self: Fx<A, E, R>, environment: R) => Fx<A, E, unknown>;
|
|
120
|
-
/**
|
|
121
|
-
* Runs an effect that no longer requires any environment.
|
|
122
|
-
*
|
|
123
|
-
* The runtime uses this at the edge after it has provided the services declared
|
|
124
|
-
* by a system spec.
|
|
125
|
-
*/
|
|
126
|
-
export declare const runSync: <A, E>(self: Fx<A, E, unknown>) => Result.Result<A, E>;
|
|
127
|
-
export {};
|
|
128
|
-
//# sourceMappingURL=Fx.d.ts.map
|
package/dist/Fx.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Fx.d.ts","sourceRoot":"","sources":["../src/Fx.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAErC;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,WAAW,CAAA;AAElC;;GAEG;AACH,QAAA,MAAM,QAAQ,EAAE,QAAsB,CA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K,EAAE,CAAC,CACrB,CAAA;AAEzD;;GAEG;AACH,eAAO,MAAM,OAAO,GAAI,CAAC,EAAE,CAAC,EAAE,CAAC,QACvB,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,eACJ,CAAC,KACb,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,CAAsC,CAAA;AAEzD;;;;;GAKG;AACH,eAAO,MAAM,OAAO,GAAI,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,KAAG,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CACrD,CAAA"}
|
package/dist/Fx.js
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Small explicit effect type used for systems and runtime orchestration.
|
|
3
|
-
*
|
|
4
|
-
* `Fx` models delayed computation with typed success, failure, and environment
|
|
5
|
-
* channels. Expected failures are returned as `Result` values; exceptions are
|
|
6
|
-
* reserved for unexpected defects in user code.
|
|
7
|
-
*
|
|
8
|
-
* Systems that cannot fail return nothing. A system returns an `Fx` when it
|
|
9
|
-
* has an expected failure: `Fx.fail(...)` rolls back the system's ECS writes
|
|
10
|
-
* and surfaces a typed `SystemFailure` from `runtime.tick(...)`. `map` and
|
|
11
|
-
* `flatMap` compose such effects.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```ts
|
|
15
|
-
* // Build one small delayed computation.
|
|
16
|
-
* const program = Fx.map(Fx.succeed(1), (value) => value + 1)
|
|
17
|
-
*
|
|
18
|
-
* // Execute it explicitly at the runtime boundary.
|
|
19
|
-
* const result = Fx.runSync(program)
|
|
20
|
-
* ```
|
|
21
|
-
*
|
|
22
|
-
* @module Fx
|
|
23
|
-
* @docGroup runtime
|
|
24
|
-
*
|
|
25
|
-
* @groupDescription Namespaces
|
|
26
|
-
* Grouped helper types that extract success, error, and environment information from effects.
|
|
27
|
-
*
|
|
28
|
-
* @groupDescription Interfaces
|
|
29
|
-
* Public effect contracts used by systems and runtime orchestration.
|
|
30
|
-
*
|
|
31
|
-
* @groupDescription Type Aliases
|
|
32
|
-
* Shared helper types derived from one `Fx` value.
|
|
33
|
-
*
|
|
34
|
-
* @groupDescription Functions
|
|
35
|
-
* Minimal constructors and combinators for explicit delayed computations.
|
|
36
|
-
*/
|
|
37
|
-
import * as Result from "./Result.js";
|
|
38
|
-
/**
|
|
39
|
-
* Runtime value for the `Fx` type id.
|
|
40
|
-
*/
|
|
41
|
-
const fxTypeId = "~ritmo/Fx";
|
|
42
|
-
/**
|
|
43
|
-
* Low-level constructor for `Fx`.
|
|
44
|
-
*
|
|
45
|
-
* All public constructors eventually delegate here so the runtime shape stays
|
|
46
|
-
* consistent.
|
|
47
|
-
*/
|
|
48
|
-
const make = (run) => ({
|
|
49
|
-
[fxTypeId]: {
|
|
50
|
-
_A: (_) => undefined,
|
|
51
|
-
_E: (_) => undefined,
|
|
52
|
-
_R: (_) => undefined
|
|
53
|
-
},
|
|
54
|
-
run
|
|
55
|
-
});
|
|
56
|
-
/**
|
|
57
|
-
* Creates an effect that immediately succeeds with a value.
|
|
58
|
-
*
|
|
59
|
-
* Use this for pure values that should still participate in the typed effect
|
|
60
|
-
* composition model.
|
|
61
|
-
*/
|
|
62
|
-
export const succeed = (value) => make(() => Result.success(value));
|
|
63
|
-
/**
|
|
64
|
-
* Wraps a synchronous computation in an `Fx`.
|
|
65
|
-
*
|
|
66
|
-
* This is the most common constructor for system implementations in the current
|
|
67
|
-
* runtime because systems are executed synchronously.
|
|
68
|
-
*/
|
|
69
|
-
export const sync = (evaluate) => make(() => Result.success(evaluate()));
|
|
70
|
-
/**
|
|
71
|
-
* Creates an effect that returns one expected failure when run.
|
|
72
|
-
*/
|
|
73
|
-
export const fail = (error) => make(() => Result.failure(error));
|
|
74
|
-
/**
|
|
75
|
-
* Transforms the success value of an effect.
|
|
76
|
-
*/
|
|
77
|
-
export const map = (self, f) => make((environment) => {
|
|
78
|
-
const result = self.run(environment);
|
|
79
|
-
return result.ok ? Result.success(f(result.value)) : result;
|
|
80
|
-
});
|
|
81
|
-
/**
|
|
82
|
-
* Sequences two effects, allowing the second one to depend on the first result.
|
|
83
|
-
*/
|
|
84
|
-
export const flatMap = (self, f) => make((environment) => {
|
|
85
|
-
const first = self.run(environment);
|
|
86
|
-
return first.ok ? f(first.value).run(environment) : first;
|
|
87
|
-
});
|
|
88
|
-
/**
|
|
89
|
-
* Reads the whole effect environment.
|
|
90
|
-
*
|
|
91
|
-
* Use this when a system helper wants access to all declared services at once.
|
|
92
|
-
*/
|
|
93
|
-
export const access = () => make((environment) => Result.success(environment));
|
|
94
|
-
/**
|
|
95
|
-
* Reads a single service from the environment by key.
|
|
96
|
-
*
|
|
97
|
-
* This is useful for small helpers that need one dependency without threading
|
|
98
|
-
* the entire environment type manually.
|
|
99
|
-
*/
|
|
100
|
-
export const accessService = (key) => make((environment) => Result.success(environment[key]));
|
|
101
|
-
/**
|
|
102
|
-
* Supplies the environment needed by an effect.
|
|
103
|
-
*/
|
|
104
|
-
export const provide = (self, environment) => make(() => self.run(environment));
|
|
105
|
-
/**
|
|
106
|
-
* Runs an effect that no longer requires any environment.
|
|
107
|
-
*
|
|
108
|
-
* The runtime uses this at the edge after it has provided the services declared
|
|
109
|
-
* by a system spec.
|
|
110
|
-
*/
|
|
111
|
-
export const runSync = (self) => self.run(undefined);
|
|
112
|
-
//# sourceMappingURL=Fx.js.map
|
package/dist/Fx.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Fx.js","sourceRoot":"","sources":["../src/Fx.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAOrC;;GAEG;AACH,MAAM,QAAQ,GAAa,WAAW,CAAA;AAmCtC;;;;;GAKG;AACH,MAAM,IAAI,GAAG,CAAU,GAA4C,EAAe,EAA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E;IACtE,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,WAAiB,CAAC,CAAA;IACzC,OAAO,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,WAAiB,CAAC,CAAC,CAAC,CAAC,KAAK,CAAA;AACjE,CAAC,CAAC,CAAA;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,GAAuB,EAAE,CAC7C,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAA;AAEpD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAuB,GAAM,EAAsB,EAAE,CAChF,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;AAEzD;;GAEG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CACrB,IAAiB,EACjB,WAAc,EACK,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAA;AAEzD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAO,IAAuB,EAAuB,EAAE,CAC5E,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import * as Result from "../Result.ts";
|
|
2
|
-
export type Entry<Value, Error> = Result.Result<Value, Error>;
|
|
3
|
-
export type ResultConstructor<Value, Raw, Error> = {
|
|
4
|
-
readonly result: (raw: Raw) => Result.Result<Value, Error>;
|
|
5
|
-
};
|
|
6
|
-
type AnyEntry = Result.Result<any, any>;
|
|
7
|
-
export type Entries = Readonly<Record<string, AnyEntry>>;
|
|
8
|
-
export type SuccessOf<Input extends Entries> = {
|
|
9
|
-
readonly [Key in keyof Input]: Input[Key] extends Result.Result<infer Value, any> ? Value : never;
|
|
10
|
-
};
|
|
11
|
-
export type ErrorOf<Input extends Entries> = {
|
|
12
|
-
readonly [Key in keyof Input]: Input[Key] extends Result.Result<any, infer Error> ? Error | null : never;
|
|
13
|
-
};
|
|
14
|
-
export declare const entry: <Value, Raw, Error>(constructor: ResultConstructor<Value, Raw, Error>, raw: Raw) => Entry<Value, Error>;
|
|
15
|
-
export declare const all: <Input extends Entries>(input: Input) => Result.Result<SuccessOf<Input>, ErrorOf<Input>>;
|
|
16
|
-
export {};
|
|
17
|
-
//# sourceMappingURL=definition.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"definition.d.ts","sourceRoot":"","sources":["../../src/internal/definition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,cAAc,CAAA;AAEtC,MAAM,MAAM,KAAK,CAAC,KAAK,EAAE,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;AAE7D,MAAM,MAAM,iBAAiB,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,IAAI;IACjD,QAAQ,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;CAC3D,CAAA;AAED,KAAK,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;AAEvC,MAAM,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAA;AAExD,MAAM,MAAM,SAAS,CAAC,KAAK,SAAS,OAAO,IAAI;IAC7C,QAAQ,EAAE,GAAG,IAAI,MAAM,KAAK,GAC1B,KAAK,CAAC,GAAG,CAAC,SAAS,MAAM,CAAC,MAAM,CAAC,MAAM,KAAK,EAAE,GAAG,CAAC,GAAG,KAAK,GAAG,KAAK;CACrE,CAAA;AAED,MAAM,MAAM,OAAO,CAAC,KAAK,SAAS,OAAO,IAAI;IAC3C,QAAQ,EAAE,GAAG,IAAI,MAAM,KAAK,GAC1B,KAAK,CAAC,GAAG,CAAC,SAAS,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,KAAK,CAAC,GAAG,KAAK,GAAG,IAAI,GAAG,KAAK;CAC5E,CAAA;AAED,eAAO,MAAM,KAAK,GAAI,KAAK,EAAE,GAAG,EAAE,KAAK,eACxB,iBAAiB,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,CAAC,OAC5C,GAAG,KACP,KAAK,CAAC,KAAK,EAAE,KAAK,CAA4B,CAAA;AAEjD,eAAO,MAAM,GAAG,GAAI,KAAK,SAAS,OAAO,SAChC,KAAK,KACX,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,CA0BhD,CAAA"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import * as Result from "../Result.js";
|
|
2
|
-
export const entry = (constructor, raw) => constructor.result(raw);
|
|
3
|
-
export const all = (input) => {
|
|
4
|
-
const values = {};
|
|
5
|
-
const errors = {};
|
|
6
|
-
let hasFailure = false;
|
|
7
|
-
for (const key of Object.keys(input)) {
|
|
8
|
-
const entry = input[key];
|
|
9
|
-
if (entry === undefined) {
|
|
10
|
-
continue;
|
|
11
|
-
}
|
|
12
|
-
if (entry.ok) {
|
|
13
|
-
values[key] = entry.value;
|
|
14
|
-
errors[key] = null;
|
|
15
|
-
continue;
|
|
16
|
-
}
|
|
17
|
-
hasFailure = true;
|
|
18
|
-
errors[key] = entry.error;
|
|
19
|
-
}
|
|
20
|
-
if (hasFailure) {
|
|
21
|
-
return Result.failure(errors);
|
|
22
|
-
}
|
|
23
|
-
return Result.success(values);
|
|
24
|
-
};
|
|
25
|
-
//# sourceMappingURL=definition.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"definition.js","sourceRoot":"","sources":["../../src/internal/definition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,cAAc,CAAA;AAsBtC,MAAM,CAAC,MAAM,KAAK,GAAG,CACnB,WAAiD,EACjD,GAAQ,EACa,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;AAEjD,MAAM,CAAC,MAAM,GAAG,GAAG,CACjB,KAAY,EACqC,EAAE;IACnD,MAAM,MAAM,GAA4B,EAAE,CAAA;IAC1C,MAAM,MAAM,GAA4B,EAAE,CAAA;IAC1C,IAAI,UAAU,GAAG,KAAK,CAAA;IAEtB,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACrC,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAA;QACxB,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,SAAQ;QACV,CAAC;QAED,IAAI,KAAK,CAAC,EAAE,EAAE,CAAC;YACb,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,KAAK,CAAA;YACzB,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAA;YAClB,SAAQ;QACV,CAAC;QAED,UAAU,GAAG,IAAI,CAAA;QACjB,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,KAAK,CAAA;IAC3B,CAAC;IAED,IAAI,UAAU,EAAE,CAAC;QACf,OAAO,MAAM,CAAC,OAAO,CAAC,MAAwB,CAAC,CAAA;IACjD,CAAC;IAED,OAAO,MAAM,CAAC,OAAO,CAAC,MAA0B,CAAC,CAAA;AACnD,CAAC,CAAA"}
|
package/src/Definition.ts
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Helpers for validating reusable authored values once and reusing them later.
|
|
3
|
-
*
|
|
4
|
-
* `Definition` is intended for static or rarely changing authored data such as
|
|
5
|
-
* spawn points, collider sizes, arena bounds, or other constants that should
|
|
6
|
-
* cross the validation boundary once and then remain branded afterward.
|
|
7
|
-
*
|
|
8
|
-
* In game code this is the "content setup" companion to runtime/world setup:
|
|
9
|
-
* validate authored constants early, keep them in carried form, and then reuse
|
|
10
|
-
* them from setup systems, reset systems, or content modules without
|
|
11
|
-
* revalidating on every frame.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```ts
|
|
15
|
-
* // Validate authored constants once when defining the content bundle.
|
|
16
|
-
* const player = Definition.all({
|
|
17
|
-
* spawn: Definition.entry(Vector2, { x: 32, y: 48 }),
|
|
18
|
-
* size: Definition.entry(Size2, { width: 16, height: 16 })
|
|
19
|
-
* })
|
|
20
|
-
* ```
|
|
21
|
-
*
|
|
22
|
-
* @module Definition
|
|
23
|
-
* @docGroup core
|
|
24
|
-
*
|
|
25
|
-
* @categoryDescription Definition Types
|
|
26
|
-
* Named reusable shapes used to validate and retain authored values.
|
|
27
|
-
*
|
|
28
|
-
* @categoryDescription Definition Builders
|
|
29
|
-
* Helpers that validate one or several authored values through existing constructors.
|
|
30
|
-
*/
|
|
31
|
-
import * as internal from "./internal/definition.ts"
|
|
32
|
-
import type * as Result from "./Result.ts"
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* One reusable validated definition entry.
|
|
36
|
-
*
|
|
37
|
-
* @category Definition Types
|
|
38
|
-
*/
|
|
39
|
-
export type Entry<Value, Error> = internal.Entry<Value, Error>
|
|
40
|
-
/**
|
|
41
|
-
* Record of named definition entries accepted by {@link all}.
|
|
42
|
-
*
|
|
43
|
-
* @category Definition Types
|
|
44
|
-
*/
|
|
45
|
-
export type Entries = internal.Entries
|
|
46
|
-
/**
|
|
47
|
-
* Minimal constructor contract accepted by {@link entry}.
|
|
48
|
-
*
|
|
49
|
-
* @category Definition Types
|
|
50
|
-
*/
|
|
51
|
-
export type ResultConstructor<Value, Raw, Error> = internal.ResultConstructor<Value, Raw, Error>
|
|
52
|
-
/**
|
|
53
|
-
* Success shape produced by {@link all}.
|
|
54
|
-
*
|
|
55
|
-
* @category Definition Types
|
|
56
|
-
*/
|
|
57
|
-
export type SuccessOf<Input extends Entries> = internal.SuccessOf<Input>
|
|
58
|
-
/**
|
|
59
|
-
* Error shape produced by {@link all}.
|
|
60
|
-
*
|
|
61
|
-
* @category Definition Types
|
|
62
|
-
*/
|
|
63
|
-
export type ErrorOf<Input extends Entries> = internal.ErrorOf<Input>
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Validates one reusable authored value through an existing constructor.
|
|
67
|
-
*
|
|
68
|
-
* Use this for one named authored constant that should cross a constructor
|
|
69
|
-
* boundary now and remain in carried form afterward.
|
|
70
|
-
*
|
|
71
|
-
* @example
|
|
72
|
-
* ```ts
|
|
73
|
-
* // Validate a single authored position once during content setup.
|
|
74
|
-
* const playerSpawn = Definition.entry(Vector2, { x: 32, y: 48 })
|
|
75
|
-
* ```
|
|
76
|
-
*
|
|
77
|
-
* @category Definition Builders
|
|
78
|
-
*/
|
|
79
|
-
export const entry: <Value, Raw, Error>(
|
|
80
|
-
constructor: ResultConstructor<Value, Raw, Error>,
|
|
81
|
-
raw: Raw
|
|
82
|
-
) => Entry<Value, Error> = internal.entry
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Validates a named record of reusable authored values at once.
|
|
86
|
-
*
|
|
87
|
-
* Successful entries are returned under the same keys. Failed entries remain
|
|
88
|
-
* keyed so authored-data setup can report exactly which constant was invalid.
|
|
89
|
-
*
|
|
90
|
-
* Use this when one content bundle or level definition should either validate
|
|
91
|
-
* as a whole or report a structured set of authoring failures.
|
|
92
|
-
*
|
|
93
|
-
* @example
|
|
94
|
-
* ```ts
|
|
95
|
-
* // Validate one authored content bundle and keep failures keyed by field.
|
|
96
|
-
* const definitions = Definition.all({
|
|
97
|
-
* spawn: Definition.entry(Vector2, { x: 32, y: 48 }),
|
|
98
|
-
* collider: Definition.entry(Size2, { width: 16, height: 16 })
|
|
99
|
-
* })
|
|
100
|
-
* ```
|
|
101
|
-
*
|
|
102
|
-
* @category Definition Builders
|
|
103
|
-
*/
|
|
104
|
-
export const all: <Input extends Entries>(
|
|
105
|
-
input: Input
|
|
106
|
-
) => Result.Result<SuccessOf<Input>, ErrorOf<Input>> = internal.all
|