aeon-types 0.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 +28 -0
- package/dist/branded.d.ts +41 -0
- package/dist/branded.d.ts.map +1 -0
- package/dist/hkt.d.ts +32 -0
- package/dist/hkt.d.ts.map +1 -0
- package/dist/index.cjs +53 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +39 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces.d.ts +93 -0
- package/dist/interfaces.d.ts.map +1 -0
- package/package.json +42 -0
package/README.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# aeon-types
|
|
2
|
+
|
|
3
|
+
Core type definitions for [Aeon](https://github.com/joshburgess/aeon), a denotationally-designed reactive programming library for TypeScript.
|
|
4
|
+
|
|
5
|
+
This package contains the foundational types that the rest of Aeon builds on:
|
|
6
|
+
|
|
7
|
+
- Branded `Time`, `Duration`, and `Offset` types
|
|
8
|
+
- The `Event<A, E>` and `Behavior<A, E>` opaque type interfaces
|
|
9
|
+
- `Sink<A, E>`, `Source<A, E>`, `Disposable`, and `Scheduler` interfaces
|
|
10
|
+
- Higher-kinded type encoding (URI-to-Kind map, `Functor`, `Applicative`, `Monad`, `Filterable`)
|
|
11
|
+
|
|
12
|
+
You typically don't depend on `aeon-types` directly — it's a transitive dependency of [`aeon-core`](https://www.npmjs.com/package/aeon-core), [`aeon-scheduler`](https://www.npmjs.com/package/aeon-scheduler), and the other Aeon packages.
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pnpm add aeon-types
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Documentation
|
|
21
|
+
|
|
22
|
+
- [Main README](https://github.com/joshburgess/aeon#readme)
|
|
23
|
+
- [Getting Started](https://github.com/joshburgess/aeon/blob/main/docs/getting-started.md)
|
|
24
|
+
- [Denotational Semantics](https://github.com/joshburgess/aeon/blob/main/docs/semantics.md)
|
|
25
|
+
|
|
26
|
+
## License
|
|
27
|
+
|
|
28
|
+
MIT
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Branded types for temporal values.
|
|
3
|
+
*
|
|
4
|
+
* Branding prevents accidental mixing of Time, Duration, and Offset
|
|
5
|
+
* at the type level while remaining plain numbers at runtime.
|
|
6
|
+
*/
|
|
7
|
+
declare const TimeBrand: unique symbol;
|
|
8
|
+
declare const DurationBrand: unique symbol;
|
|
9
|
+
declare const OffsetBrand: unique symbol;
|
|
10
|
+
/** Absolute point in time (milliseconds). Denotation: a point on the timeline. */
|
|
11
|
+
export type Time = number & {
|
|
12
|
+
readonly [TimeBrand]: typeof TimeBrand;
|
|
13
|
+
};
|
|
14
|
+
/** Relative duration (milliseconds). Denotation: a span between two points. */
|
|
15
|
+
export type Duration = number & {
|
|
16
|
+
readonly [DurationBrand]: typeof DurationBrand;
|
|
17
|
+
};
|
|
18
|
+
/** Scheduler-relative offset (milliseconds). Denotation: displacement from a scheduler's epoch. */
|
|
19
|
+
export type Offset = number & {
|
|
20
|
+
readonly [OffsetBrand]: typeof OffsetBrand;
|
|
21
|
+
};
|
|
22
|
+
/** Wrap a raw millisecond value as a Time. */
|
|
23
|
+
export declare const toTime: (ms: number) => Time;
|
|
24
|
+
/** Wrap a raw millisecond value as a Duration. */
|
|
25
|
+
export declare const toDuration: (ms: number) => Duration;
|
|
26
|
+
/** Wrap a raw millisecond value as an Offset. */
|
|
27
|
+
export declare const toOffset: (ms: number) => Offset;
|
|
28
|
+
/** Compute the Duration between two Time points. */
|
|
29
|
+
export declare const timeDiff: (a: Time, b: Time) => Duration;
|
|
30
|
+
/** Advance a Time by a Duration. */
|
|
31
|
+
export declare const timeAdd: (t: Time, d: Duration) => Time;
|
|
32
|
+
/** Advance a Time by an Offset. */
|
|
33
|
+
export declare const timeShift: (t: Time, o: Offset) => Time;
|
|
34
|
+
/** Time zero — the epoch. */
|
|
35
|
+
export declare const TIME_ZERO: Time;
|
|
36
|
+
/** Zero duration. */
|
|
37
|
+
export declare const DURATION_ZERO: Duration;
|
|
38
|
+
/** Zero offset. */
|
|
39
|
+
export declare const OFFSET_ZERO: Offset;
|
|
40
|
+
export {};
|
|
41
|
+
//# sourceMappingURL=branded.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"branded.d.ts","sourceRoot":"","sources":["../src/branded.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,CAAC,MAAM,SAAS,EAAE,OAAO,MAAM,CAAC;AACvC,OAAO,CAAC,MAAM,aAAa,EAAE,OAAO,MAAM,CAAC;AAC3C,OAAO,CAAC,MAAM,WAAW,EAAE,OAAO,MAAM,CAAC;AAEzC,kFAAkF;AAClF,MAAM,MAAM,IAAI,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,CAAC,SAAS,CAAC,EAAE,OAAO,SAAS,CAAA;CAAE,CAAC;AAEvE,+EAA+E;AAC/E,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,CAAC,aAAa,CAAC,EAAE,OAAO,aAAa,CAAA;CAAE,CAAC;AAEnF,mGAAmG;AACnG,MAAM,MAAM,MAAM,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,CAAC,WAAW,CAAC,EAAE,OAAO,WAAW,CAAA;CAAE,CAAC;AAI7E,8CAA8C;AAC9C,eAAO,MAAM,MAAM,GAAI,IAAI,MAAM,KAAG,IAAkB,CAAC;AAEvD,kDAAkD;AAClD,eAAO,MAAM,UAAU,GAAI,IAAI,MAAM,KAAG,QAA0B,CAAC;AAEnE,iDAAiD;AACjD,eAAO,MAAM,QAAQ,GAAI,IAAI,MAAM,KAAG,MAAsB,CAAC;AAI7D,oDAAoD;AACpD,eAAO,MAAM,QAAQ,GAAI,GAAG,IAAI,EAAE,GAAG,IAAI,KAAG,QAA+B,CAAC;AAE5E,oCAAoC;AACpC,eAAO,MAAM,OAAO,GAAI,GAAG,IAAI,EAAE,GAAG,QAAQ,KAAG,IAAuB,CAAC;AAEvE,mCAAmC;AACnC,eAAO,MAAM,SAAS,GAAI,GAAG,IAAI,EAAE,GAAG,MAAM,KAAG,IAAuB,CAAC;AAIvE,6BAA6B;AAC7B,eAAO,MAAM,SAAS,EAAE,IAAgB,CAAC;AAEzC,qBAAqB;AACrB,eAAO,MAAM,aAAa,EAAE,QAAwB,CAAC;AAErD,mBAAmB;AACnB,eAAO,MAAM,WAAW,EAAE,MAAoB,CAAC"}
|
package/dist/hkt.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Higher-Kinded Type encoding via URI-indexed Kind map.
|
|
3
|
+
*
|
|
4
|
+
* Uses module augmentation (Effect-TS / fp-ts style) so that each
|
|
5
|
+
* package can register its own types without circular imports.
|
|
6
|
+
*/
|
|
7
|
+
export interface URItoKind<A, E> {
|
|
8
|
+
}
|
|
9
|
+
/** Union of all registered type URIs. */
|
|
10
|
+
export type URIS = keyof URItoKind<unknown, unknown>;
|
|
11
|
+
/** Project a registered HKT to its concrete type given A and E. */
|
|
12
|
+
export type Kind<F extends URIS, A, E = never> = URItoKind<A, E>[F];
|
|
13
|
+
export interface Functor<F extends URIS> {
|
|
14
|
+
readonly URI: F;
|
|
15
|
+
readonly map: <A, B, E>(f: (a: A) => B, fa: Kind<F, A, E>) => Kind<F, B, E>;
|
|
16
|
+
}
|
|
17
|
+
export interface Applicative<F extends URIS> extends Functor<F> {
|
|
18
|
+
readonly of: <A>(a: A) => Kind<F, A, never>;
|
|
19
|
+
readonly ap: <A, B, E>(ff: Kind<F, (a: A) => B, E>, fa: Kind<F, A, E>) => Kind<F, B, E>;
|
|
20
|
+
}
|
|
21
|
+
export interface Monad<F extends URIS> extends Applicative<F> {
|
|
22
|
+
readonly chain: <A, B, E>(f: (a: A) => Kind<F, B, E>, fa: Kind<F, A, E>) => Kind<F, B, E>;
|
|
23
|
+
}
|
|
24
|
+
export interface Filterable<F extends URIS> {
|
|
25
|
+
readonly URI: F;
|
|
26
|
+
readonly filter: <A, E>(predicate: (a: A) => boolean, fa: Kind<F, A, E>) => Kind<F, A, E>;
|
|
27
|
+
}
|
|
28
|
+
/** Lift a binary function over two Applicative values. */
|
|
29
|
+
export declare const liftA2: <F extends URIS>(A: Applicative<F>) => <A1, A2, B, E>(f: (a1: A1, a2: A2) => B, fa1: Kind<F, A1, E>, fa2: Kind<F, A2, E>) => Kind<F, B, E>;
|
|
30
|
+
/** Lift a ternary function over three Applicative values. */
|
|
31
|
+
export declare const liftA3: <F extends URIS>(A: Applicative<F>) => <A1, A2, A3, B, E>(f: (a1: A1, a2: A2, a3: A3) => B, fa1: Kind<F, A1, E>, fa2: Kind<F, A2, E>, fa3: Kind<F, A3, E>) => Kind<F, B, E>;
|
|
32
|
+
//# sourceMappingURL=hkt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hkt.d.ts","sourceRoot":"","sources":["../src/hkt.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,MAAM,WAAW,SAAS,CAAC,CAAC,EAAE,CAAC;CAAI;AAEnC,yCAAyC;AACzC,MAAM,MAAM,IAAI,GAAG,MAAM,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAErD,mEAAmE;AACnE,MAAM,MAAM,IAAI,CAAC,CAAC,SAAS,IAAI,EAAE,CAAC,EAAE,CAAC,GAAG,KAAK,IAAI,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAIpE,MAAM,WAAW,OAAO,CAAC,CAAC,SAAS,IAAI;IACrC,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC;IAChB,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC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set
|
|
7
|
+
* at the type level while remaining plain numbers at runtime.
|
|
8
|
+
*/ // --- Constructors ---
|
|
9
|
+
/** Wrap a raw millisecond value as a Time. */ const toTime = (ms)=>ms;
|
|
10
|
+
/** Wrap a raw millisecond value as a Duration. */ const toDuration = (ms)=>ms;
|
|
11
|
+
/** Wrap a raw millisecond value as an Offset. */ const toOffset = (ms)=>ms;
|
|
12
|
+
// --- Arithmetic ---
|
|
13
|
+
/** Compute the Duration between two Time points. */ const timeDiff = (a, b)=>a - b;
|
|
14
|
+
/** Advance a Time by a Duration. */ const timeAdd = (t, d)=>t + d;
|
|
15
|
+
/** Advance a Time by an Offset. */ const timeShift = (t, o)=>t + o;
|
|
16
|
+
// --- Constants ---
|
|
17
|
+
/** Time zero — the epoch. */ const TIME_ZERO = 0;
|
|
18
|
+
/** Zero duration. */ const DURATION_ZERO = 0;
|
|
19
|
+
/** Zero offset. */ const OFFSET_ZERO = 0;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Higher-Kinded Type encoding via URI-indexed Kind map.
|
|
23
|
+
*
|
|
24
|
+
* Uses module augmentation (Effect-TS / fp-ts style) so that each
|
|
25
|
+
* package can register its own types without circular imports.
|
|
26
|
+
*/ // biome-ignore lint/suspicious/noEmptyInterface: open for module augmentation
|
|
27
|
+
// --- Derived combinators ---
|
|
28
|
+
/** Lift a binary function over two Applicative values. */ const liftA2 = (A)=>(f, fa1, fa2)=>A.ap(A.map((a1)=>(a2)=>f(a1, a2), fa1), fa2);
|
|
29
|
+
/** Lift a ternary function over three Applicative values. */ const liftA3 = (A)=>(f, fa1, fa2, fa3)=>A.ap(A.ap(A.map((a1)=>(a2)=>(a3)=>f(a1, a2, a3), fa1), fa2), fa3);
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Core runtime interfaces for the push/pull reactive system.
|
|
33
|
+
*
|
|
34
|
+
* These define the contracts that packages/core and packages/scheduler implement.
|
|
35
|
+
* Denotational meanings are stated in JSDoc.
|
|
36
|
+
*/ // --- URI constants for HKT registration ---
|
|
37
|
+
const EventURI = "Event";
|
|
38
|
+
const BehaviorURI = "Behavior";
|
|
39
|
+
|
|
40
|
+
exports.BehaviorURI = BehaviorURI;
|
|
41
|
+
exports.DURATION_ZERO = DURATION_ZERO;
|
|
42
|
+
exports.EventURI = EventURI;
|
|
43
|
+
exports.OFFSET_ZERO = OFFSET_ZERO;
|
|
44
|
+
exports.TIME_ZERO = TIME_ZERO;
|
|
45
|
+
exports.liftA2 = liftA2;
|
|
46
|
+
exports.liftA3 = liftA3;
|
|
47
|
+
exports.timeAdd = timeAdd;
|
|
48
|
+
exports.timeDiff = timeDiff;
|
|
49
|
+
exports.timeShift = timeShift;
|
|
50
|
+
exports.toDuration = toDuration;
|
|
51
|
+
exports.toOffset = toOffset;
|
|
52
|
+
exports.toTime = toTime;
|
|
53
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/branded.ts","../src/hkt.ts","../src/interfaces.ts"],"sourcesContent":["/**\n * Branded types for temporal values.\n *\n * Branding prevents accidental mixing of Time, Duration, and Offset\n * at the type level while remaining plain numbers at runtime.\n */\n\ndeclare const TimeBrand: unique symbol;\ndeclare const DurationBrand: unique symbol;\ndeclare const OffsetBrand: unique symbol;\n\n/** Absolute point in time (milliseconds). Denotation: a point on the timeline. */\nexport type Time = number & { readonly [TimeBrand]: typeof TimeBrand };\n\n/** Relative duration (milliseconds). Denotation: a span between two points. */\nexport type Duration = number & { readonly [DurationBrand]: typeof DurationBrand };\n\n/** Scheduler-relative offset (milliseconds). Denotation: displacement from a scheduler's epoch. */\nexport type Offset = number & { readonly [OffsetBrand]: typeof OffsetBrand };\n\n// --- Constructors ---\n\n/** Wrap a raw millisecond value as a Time. */\nexport const toTime = (ms: number): Time => ms as Time;\n\n/** Wrap a raw millisecond value as a Duration. */\nexport const toDuration = (ms: number): Duration => ms as Duration;\n\n/** Wrap a raw millisecond value as an Offset. */\nexport const toOffset = (ms: number): Offset => ms as Offset;\n\n// --- Arithmetic ---\n\n/** Compute the Duration between two Time points. */\nexport const timeDiff = (a: Time, b: Time): Duration => (a - b) as Duration;\n\n/** Advance a Time by a Duration. */\nexport const timeAdd = (t: Time, d: Duration): Time => (t + d) as Time;\n\n/** Advance a Time by an Offset. */\nexport const timeShift = (t: Time, o: Offset): Time => (t + o) as Time;\n\n// --- Constants ---\n\n/** Time zero — the epoch. */\nexport const TIME_ZERO: Time = 0 as Time;\n\n/** Zero duration. */\nexport const DURATION_ZERO: Duration = 0 as Duration;\n\n/** Zero offset. */\nexport const OFFSET_ZERO: Offset = 0 as Offset;\n","/**\n * Higher-Kinded Type encoding via URI-indexed Kind map.\n *\n * Uses module augmentation (Effect-TS / fp-ts style) so that each\n * package can register its own types without circular imports.\n */\n\n// biome-ignore lint/suspicious/noEmptyInterface: open for module augmentation\nexport interface URItoKind<A, E> {}\n\n/** Union of all registered type URIs. */\nexport type URIS = keyof URItoKind<unknown, unknown>;\n\n/** Project a registered HKT to its concrete type given A and E. */\nexport type Kind<F extends URIS, A, E = never> = URItoKind<A, E>[F];\n\n// --- Typeclass interfaces ---\n\nexport interface Functor<F extends URIS> {\n readonly URI: F;\n readonly map: <A, B, E>(f: (a: A) => B, fa: Kind<F, A, E>) => Kind<F, B, E>;\n}\n\nexport interface Applicative<F extends URIS> extends Functor<F> {\n readonly of: <A>(a: A) => Kind<F, A, never>;\n readonly ap: <A, B, E>(ff: Kind<F, (a: A) => B, E>, fa: Kind<F, A, E>) => Kind<F, B, E>;\n}\n\nexport interface Monad<F extends URIS> extends Applicative<F> {\n readonly chain: <A, B, E>(f: (a: A) => Kind<F, B, E>, fa: Kind<F, A, E>) => Kind<F, B, E>;\n}\n\nexport interface Filterable<F extends URIS> {\n readonly URI: F;\n readonly filter: <A, E>(predicate: (a: A) => boolean, fa: Kind<F, A, E>) => Kind<F, A, E>;\n}\n\n// --- Derived combinators ---\n\n/** Lift a binary function over two Applicative values. */\nexport const liftA2 =\n <F extends URIS>(A: Applicative<F>) =>\n <A1, A2, B, E>(\n f: (a1: A1, a2: A2) => B,\n fa1: Kind<F, A1, E>,\n fa2: Kind<F, A2, E>,\n ): Kind<F, B, E> =>\n A.ap(\n A.map((a1: A1) => (a2: A2) => f(a1, a2), fa1),\n fa2,\n );\n\n/** Lift a ternary function over three Applicative values. */\nexport const liftA3 =\n <F extends URIS>(A: Applicative<F>) =>\n <A1, A2, A3, B, E>(\n f: (a1: A1, a2: A2, a3: A3) => B,\n fa1: Kind<F, A1, E>,\n fa2: Kind<F, A2, E>,\n fa3: Kind<F, A3, E>,\n ): Kind<F, B, E> =>\n A.ap(\n A.ap(\n A.map((a1: A1) => (a2: A2) => (a3: A3) => f(a1, a2, a3), fa1),\n fa2,\n ),\n fa3,\n );\n","/**\n * Core runtime interfaces for the push/pull reactive system.\n *\n * These define the contracts that packages/core and packages/scheduler implement.\n * Denotational meanings are stated in JSDoc.\n */\n\nimport type { Duration, Offset, Time } from \"./branded.js\";\n\n// --- Disposable ---\n\n/** A handle to a resource that can be released. */\nexport interface Disposable {\n dispose(): void;\n}\n\n// --- Sink ---\n\n/**\n * Consumer of events over time.\n *\n * Denotation: an observer that receives a time-indexed sequence of values,\n * a possible typed error, and a termination signal.\n */\nexport interface Sink<A, E = never> {\n /** Receive a value at a point in time. */\n event(time: Time, value: A): void;\n /** Receive an error at a point in time. */\n error(time: Time, err: E): void;\n /** Signal that no more events will arrive. */\n end(time: Time): void;\n}\n\n// --- Source ---\n\n/**\n * Producer of events over time.\n *\n * Denotation: when run, produces a time-indexed sequence [(Time, A)]\n * that may terminate or error.\n */\nexport interface Source<A, E = never> {\n run(sink: Sink<A, E>, scheduler: Scheduler): Disposable;\n}\n\n// --- Task & ScheduledTask ---\n\n/** A unit of work to be executed by the scheduler. */\nexport interface Task {\n run(time: Time): void;\n error(time: Time, err: unknown): void;\n dispose(): void;\n}\n\n/** A task that has been scheduled for future execution. */\nexport interface ScheduledTask extends Disposable {\n readonly task: Task;\n readonly time: Time;\n}\n\n// --- Scheduler ---\n\n/**\n * Coordinates the execution of tasks over time.\n *\n * The scheduler is the single source of truth for \"what time is it\"\n * within a reactive pipeline.\n */\nexport interface Scheduler {\n /** The current time according to this scheduler. */\n currentTime(): Time;\n\n /** Schedule a task to run after a delay. */\n scheduleTask(delay: Duration, task: Task): ScheduledTask;\n\n /** Create a child scheduler whose time is shifted by an offset. */\n relative(offset: Offset): Scheduler;\n\n /** Cancel a previously scheduled task. */\n cancelTask(task: ScheduledTask): void;\n}\n\n// --- Opaque Event and Behavior types ---\n\ndeclare const EventBrand: unique symbol;\n\n/**\n * A discrete, time-indexed sequence of values.\n *\n * Denotation: `[(Time, A)]` — a list of time-value pairs, possibly\n * terminating with an error of type E.\n */\nexport type Event<A, E = never> = {\n readonly [EventBrand]: [A, E];\n};\n\ndeclare const BehaviorBrand: unique symbol;\n\n/**\n * A continuous, time-varying value.\n *\n * Denotation: `Time -> A` — a function from time to a value,\n * possibly failing with an error of type E.\n */\nexport type Behavior<A, E = never> = {\n readonly [BehaviorBrand]: [A, E];\n};\n\n// --- URI constants for HKT registration ---\n\nexport const EventURI = \"Event\" as const;\nexport type EventURI = typeof EventURI;\n\nexport const BehaviorURI = \"Behavior\" as const;\nexport type BehaviorURI = typeof BehaviorURI;\n\n// --- Module augmentation: register Event and Behavior in the HKT map ---\n\ndeclare module \"./hkt.js\" {\n interface URItoKind<A, E> {\n readonly [EventURI]: Event<A, E>;\n readonly [BehaviorURI]: Behavior<A, E>;\n }\n}\n"],"names":["toTime","ms","toDuration","toOffset","timeDiff","a","b","timeAdd","t","d","timeShift","o","TIME_ZERO","DURATION_ZERO","OFFSET_ZERO","liftA2","A","f","fa1","fa2","ap","map","a1","a2","liftA3","fa3","a3","EventURI","BehaviorURI"],"mappings":";;AAAA;;;;;AAKC;AAiBD,+CACO,MAAMA,MAAAA,GAAS,CAACC,KAAqBA;AAE5C,mDACO,MAAMC,UAAAA,GAAa,CAACD,KAAyBA;AAEpD,kDACO,MAAME,QAAAA,GAAW,CAACF,KAAuBA;AAEhD;AAEA,qDACO,MAAMG,QAAAA,GAAW,CAACC,CAAAA,EAASC,CAAAA,GAAuBD,IAAIC;AAE7D,qCACO,MAAMC,OAAAA,GAAU,CAACC,CAAAA,EAASC,CAAAA,GAAuBD,IAAIC;AAE5D,oCACO,MAAMC,SAAAA,GAAY,CAACF,CAAAA,EAASG,CAAAA,GAAqBH,IAAIG;AAE5D;AAEA,8BACO,MAAMC,SAAAA,GAAkB;AAE/B,sBACO,MAAMC,aAAAA,GAA0B;AAEvC,oBACO,MAAMC,WAAAA,GAAsB;;ACnDnC;;;;;AAKC;AAgCD;AAEA,2DACO,MAAMC,MAAAA,GACX,CAAiBC,IACjB,CACEC,CAAAA,EACAC,GAAAA,EACAC,GAAAA,GAEAH,CAAAA,CAAEI,EAAE,CACFJ,CAAAA,CAAEK,GAAG,CAAC,CAACC,EAAAA,GAAW,CAACC,KAAWN,CAAAA,CAAEK,EAAAA,EAAIC,EAAAA,CAAAA,EAAKL,GAAAA,CAAAA,EACzCC,GAAAA;AAGN,8DACO,MAAMK,MAAAA,GACX,CAAiBR,CAAAA,GACjB,CACEC,CAAAA,EACAC,GAAAA,EACAC,GAAAA,EACAM,GAAAA,GAEAT,CAAAA,CAAEI,EAAE,CACFJ,CAAAA,CAAEI,EAAE,CACFJ,CAAAA,CAAEK,GAAG,CAAC,CAACC,EAAAA,GAAW,CAACC,EAAAA,GAAW,CAACG,EAAAA,GAAWT,CAAAA,CAAEK,EAAAA,EAAIC,EAAAA,EAAIG,EAAAA,CAAAA,EAAKR,GAAAA,CAAAA,EACzDC,MAEFM,GAAAA;;AClEN;;;;;AAKC;AAyGM,MAAME,WAAW;AAGjB,MAAMC,cAAc;;;;;;;;;;;;;;;;"}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { type Time, type Duration, type Offset, toTime, toDuration, toOffset, timeDiff, timeAdd, timeShift, TIME_ZERO, DURATION_ZERO, OFFSET_ZERO, } from "./branded.js";
|
|
2
|
+
export { type URItoKind, type URIS, type Kind, type Functor, type Applicative, type Monad, type Filterable, liftA2, liftA3, } from "./hkt.js";
|
|
3
|
+
export { type Disposable, type Sink, type Source, type Task, type ScheduledTask, type Scheduler, type Event, type Behavior, EventURI, type EventURI as EventURIType, BehaviorURI, type BehaviorURI as BehaviorURIType, } from "./interfaces.js";
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { type Time, type Duration, type Offset, toTime, toDuration, toOffset, timeDiff, timeAdd, timeShift, TIME_ZERO, DURATION_ZERO, OFFSET_ZERO, } from "./branded.js";
|
|
2
|
+
export { type URItoKind, type URIS, type Kind, type Functor, type Applicative, type Monad, type Filterable, liftA2, liftA3, } from "./hkt.js";
|
|
3
|
+
export { type Disposable, type Sink, type Source, type Task, type ScheduledTask, type Scheduler, type Event, type Behavior, EventURI, type EventURI as EventURIType, BehaviorURI, type BehaviorURI as BehaviorURIType, } from "./interfaces.js";
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,IAAI,EACT,KAAK,QAAQ,EACb,KAAK,MAAM,EACX,MAAM,EACN,UAAU,EACV,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,SAAS,EACT,SAAS,EACT,aAAa,EACb,WAAW,GACZ,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,KAAK,SAAS,EACd,KAAK,IAAI,EACT,KAAK,IAAI,EACT,KAAK,OAAO,EACZ,KAAK,WAAW,EAChB,KAAK,KAAK,EACV,KAAK,UAAU,EACf,MAAM,EACN,MAAM,GACP,MAAM,UAAU,CAAC;AAElB,OAAO,EACL,KAAK,UAAU,EACf,KAAK,IAAI,EACT,KAAK,MAAM,EACX,KAAK,IAAI,EACT,KAAK,aAAa,EAClB,KAAK,SAAS,EACd,KAAK,KAAK,EACV,KAAK,QAAQ,EACb,QAAQ,EACR,KAAK,QAAQ,IAAI,YAAY,EAC7B,WAAW,EACX,KAAK,WAAW,IAAI,eAAe,GACpC,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Branded types for temporal values.
|
|
3
|
+
*
|
|
4
|
+
* Branding prevents accidental mixing of Time, Duration, and Offset
|
|
5
|
+
* at the type level while remaining plain numbers at runtime.
|
|
6
|
+
*/ // --- Constructors ---
|
|
7
|
+
/** Wrap a raw millisecond value as a Time. */ const toTime = (ms)=>ms;
|
|
8
|
+
/** Wrap a raw millisecond value as a Duration. */ const toDuration = (ms)=>ms;
|
|
9
|
+
/** Wrap a raw millisecond value as an Offset. */ const toOffset = (ms)=>ms;
|
|
10
|
+
// --- Arithmetic ---
|
|
11
|
+
/** Compute the Duration between two Time points. */ const timeDiff = (a, b)=>a - b;
|
|
12
|
+
/** Advance a Time by a Duration. */ const timeAdd = (t, d)=>t + d;
|
|
13
|
+
/** Advance a Time by an Offset. */ const timeShift = (t, o)=>t + o;
|
|
14
|
+
// --- Constants ---
|
|
15
|
+
/** Time zero — the epoch. */ const TIME_ZERO = 0;
|
|
16
|
+
/** Zero duration. */ const DURATION_ZERO = 0;
|
|
17
|
+
/** Zero offset. */ const OFFSET_ZERO = 0;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Higher-Kinded Type encoding via URI-indexed Kind map.
|
|
21
|
+
*
|
|
22
|
+
* Uses module augmentation (Effect-TS / fp-ts style) so that each
|
|
23
|
+
* package can register its own types without circular imports.
|
|
24
|
+
*/ // biome-ignore lint/suspicious/noEmptyInterface: open for module augmentation
|
|
25
|
+
// --- Derived combinators ---
|
|
26
|
+
/** Lift a binary function over two Applicative values. */ const liftA2 = (A)=>(f, fa1, fa2)=>A.ap(A.map((a1)=>(a2)=>f(a1, a2), fa1), fa2);
|
|
27
|
+
/** Lift a ternary function over three Applicative values. */ const liftA3 = (A)=>(f, fa1, fa2, fa3)=>A.ap(A.ap(A.map((a1)=>(a2)=>(a3)=>f(a1, a2, a3), fa1), fa2), fa3);
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Core runtime interfaces for the push/pull reactive system.
|
|
31
|
+
*
|
|
32
|
+
* These define the contracts that packages/core and packages/scheduler implement.
|
|
33
|
+
* Denotational meanings are stated in JSDoc.
|
|
34
|
+
*/ // --- URI constants for HKT registration ---
|
|
35
|
+
const EventURI = "Event";
|
|
36
|
+
const BehaviorURI = "Behavior";
|
|
37
|
+
|
|
38
|
+
export { BehaviorURI, DURATION_ZERO, EventURI, OFFSET_ZERO, TIME_ZERO, liftA2, liftA3, timeAdd, timeDiff, timeShift, toDuration, toOffset, toTime };
|
|
39
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/branded.ts","../src/hkt.ts","../src/interfaces.ts"],"sourcesContent":["/**\n * Branded types for temporal values.\n *\n * Branding prevents accidental mixing of Time, Duration, and Offset\n * at the type level while remaining plain numbers at runtime.\n */\n\ndeclare const TimeBrand: unique symbol;\ndeclare const DurationBrand: unique symbol;\ndeclare const OffsetBrand: unique symbol;\n\n/** Absolute point in time (milliseconds). Denotation: a point on the timeline. */\nexport type Time = number & { readonly [TimeBrand]: typeof TimeBrand };\n\n/** Relative duration (milliseconds). Denotation: a span between two points. */\nexport type Duration = number & { readonly [DurationBrand]: typeof DurationBrand };\n\n/** Scheduler-relative offset (milliseconds). Denotation: displacement from a scheduler's epoch. */\nexport type Offset = number & { readonly [OffsetBrand]: typeof OffsetBrand };\n\n// --- Constructors ---\n\n/** Wrap a raw millisecond value as a Time. */\nexport const toTime = (ms: number): Time => ms as Time;\n\n/** Wrap a raw millisecond value as a Duration. */\nexport const toDuration = (ms: number): Duration => ms as Duration;\n\n/** Wrap a raw millisecond value as an Offset. */\nexport const toOffset = (ms: number): Offset => ms as Offset;\n\n// --- Arithmetic ---\n\n/** Compute the Duration between two Time points. */\nexport const timeDiff = (a: Time, b: Time): Duration => (a - b) as Duration;\n\n/** Advance a Time by a Duration. */\nexport const timeAdd = (t: Time, d: Duration): Time => (t + d) as Time;\n\n/** Advance a Time by an Offset. */\nexport const timeShift = (t: Time, o: Offset): Time => (t + o) as Time;\n\n// --- Constants ---\n\n/** Time zero — the epoch. */\nexport const TIME_ZERO: Time = 0 as Time;\n\n/** Zero duration. */\nexport const DURATION_ZERO: Duration = 0 as Duration;\n\n/** Zero offset. */\nexport const OFFSET_ZERO: Offset = 0 as Offset;\n","/**\n * Higher-Kinded Type encoding via URI-indexed Kind map.\n *\n * Uses module augmentation (Effect-TS / fp-ts style) so that each\n * package can register its own types without circular imports.\n */\n\n// biome-ignore lint/suspicious/noEmptyInterface: open for module augmentation\nexport interface URItoKind<A, E> {}\n\n/** Union of all registered type URIs. */\nexport type URIS = keyof URItoKind<unknown, unknown>;\n\n/** Project a registered HKT to its concrete type given A and E. */\nexport type Kind<F extends URIS, A, E = never> = URItoKind<A, E>[F];\n\n// --- Typeclass interfaces ---\n\nexport interface Functor<F extends URIS> {\n readonly URI: F;\n readonly map: <A, B, E>(f: (a: A) => B, fa: Kind<F, A, E>) => Kind<F, B, E>;\n}\n\nexport interface Applicative<F extends URIS> extends Functor<F> {\n readonly of: <A>(a: A) => Kind<F, A, never>;\n readonly ap: <A, B, E>(ff: Kind<F, (a: A) => B, E>, fa: Kind<F, A, E>) => Kind<F, B, E>;\n}\n\nexport interface Monad<F extends URIS> extends Applicative<F> {\n readonly chain: <A, B, E>(f: (a: A) => Kind<F, B, E>, fa: Kind<F, A, E>) => Kind<F, B, E>;\n}\n\nexport interface Filterable<F extends URIS> {\n readonly URI: F;\n readonly filter: <A, E>(predicate: (a: A) => boolean, fa: Kind<F, A, E>) => Kind<F, A, E>;\n}\n\n// --- Derived combinators ---\n\n/** Lift a binary function over two Applicative values. */\nexport const liftA2 =\n <F extends URIS>(A: Applicative<F>) =>\n <A1, A2, B, E>(\n f: (a1: A1, a2: A2) => B,\n fa1: Kind<F, A1, E>,\n fa2: Kind<F, A2, E>,\n ): Kind<F, B, E> =>\n A.ap(\n A.map((a1: A1) => (a2: A2) => f(a1, a2), fa1),\n fa2,\n );\n\n/** Lift a ternary function over three Applicative values. */\nexport const liftA3 =\n <F extends URIS>(A: Applicative<F>) =>\n <A1, A2, A3, B, E>(\n f: (a1: A1, a2: A2, a3: A3) => B,\n fa1: Kind<F, A1, E>,\n fa2: Kind<F, A2, E>,\n fa3: Kind<F, A3, E>,\n ): Kind<F, B, E> =>\n A.ap(\n A.ap(\n A.map((a1: A1) => (a2: A2) => (a3: A3) => f(a1, a2, a3), fa1),\n fa2,\n ),\n fa3,\n );\n","/**\n * Core runtime interfaces for the push/pull reactive system.\n *\n * These define the contracts that packages/core and packages/scheduler implement.\n * Denotational meanings are stated in JSDoc.\n */\n\nimport type { Duration, Offset, Time } from \"./branded.js\";\n\n// --- Disposable ---\n\n/** A handle to a resource that can be released. */\nexport interface Disposable {\n dispose(): void;\n}\n\n// --- Sink ---\n\n/**\n * Consumer of events over time.\n *\n * Denotation: an observer that receives a time-indexed sequence of values,\n * a possible typed error, and a termination signal.\n */\nexport interface Sink<A, E = never> {\n /** Receive a value at a point in time. */\n event(time: Time, value: A): void;\n /** Receive an error at a point in time. */\n error(time: Time, err: E): void;\n /** Signal that no more events will arrive. */\n end(time: Time): void;\n}\n\n// --- Source ---\n\n/**\n * Producer of events over time.\n *\n * Denotation: when run, produces a time-indexed sequence [(Time, A)]\n * that may terminate or error.\n */\nexport interface Source<A, E = never> {\n run(sink: Sink<A, E>, scheduler: Scheduler): Disposable;\n}\n\n// --- Task & ScheduledTask ---\n\n/** A unit of work to be executed by the scheduler. */\nexport interface Task {\n run(time: Time): void;\n error(time: Time, err: unknown): void;\n dispose(): void;\n}\n\n/** A task that has been scheduled for future execution. */\nexport interface ScheduledTask extends Disposable {\n readonly task: Task;\n readonly time: Time;\n}\n\n// --- Scheduler ---\n\n/**\n * Coordinates the execution of tasks over time.\n *\n * The scheduler is the single source of truth for \"what time is it\"\n * within a reactive pipeline.\n */\nexport interface Scheduler {\n /** The current time according to this scheduler. */\n currentTime(): Time;\n\n /** Schedule a task to run after a delay. */\n scheduleTask(delay: Duration, task: Task): ScheduledTask;\n\n /** Create a child scheduler whose time is shifted by an offset. */\n relative(offset: Offset): Scheduler;\n\n /** Cancel a previously scheduled task. */\n cancelTask(task: ScheduledTask): void;\n}\n\n// --- Opaque Event and Behavior types ---\n\ndeclare const EventBrand: unique symbol;\n\n/**\n * A discrete, time-indexed sequence of values.\n *\n * Denotation: `[(Time, A)]` — a list of time-value pairs, possibly\n * terminating with an error of type E.\n */\nexport type Event<A, E = never> = {\n readonly [EventBrand]: [A, E];\n};\n\ndeclare const BehaviorBrand: unique symbol;\n\n/**\n * A continuous, time-varying value.\n *\n * Denotation: `Time -> A` — a function from time to a value,\n * possibly failing with an error of type E.\n */\nexport type Behavior<A, E = never> = {\n readonly [BehaviorBrand]: [A, E];\n};\n\n// --- URI constants for HKT registration ---\n\nexport const EventURI = \"Event\" as const;\nexport type EventURI = typeof EventURI;\n\nexport const BehaviorURI = \"Behavior\" as const;\nexport type BehaviorURI = typeof BehaviorURI;\n\n// --- Module augmentation: register Event and Behavior in the HKT map ---\n\ndeclare module \"./hkt.js\" {\n interface URItoKind<A, E> {\n readonly [EventURI]: Event<A, E>;\n readonly [BehaviorURI]: Behavior<A, E>;\n }\n}\n"],"names":["toTime","ms","toDuration","toOffset","timeDiff","a","b","timeAdd","t","d","timeShift","o","TIME_ZERO","DURATION_ZERO","OFFSET_ZERO","liftA2","A","f","fa1","fa2","ap","map","a1","a2","liftA3","fa3","a3","EventURI","BehaviorURI"],"mappings":"AAAA;;;;;AAKC;AAiBD,+CACO,MAAMA,MAAAA,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for the push/pull reactive system.
|
|
3
|
+
*
|
|
4
|
+
* These define the contracts that packages/core and packages/scheduler implement.
|
|
5
|
+
* Denotational meanings are stated in JSDoc.
|
|
6
|
+
*/
|
|
7
|
+
import type { Duration, Offset, Time } from "./branded.js";
|
|
8
|
+
/** A handle to a resource that can be released. */
|
|
9
|
+
export interface Disposable {
|
|
10
|
+
dispose(): void;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Consumer of events over time.
|
|
14
|
+
*
|
|
15
|
+
* Denotation: an observer that receives a time-indexed sequence of values,
|
|
16
|
+
* a possible typed error, and a termination signal.
|
|
17
|
+
*/
|
|
18
|
+
export interface Sink<A, E = never> {
|
|
19
|
+
/** Receive a value at a point in time. */
|
|
20
|
+
event(time: Time, value: A): void;
|
|
21
|
+
/** Receive an error at a point in time. */
|
|
22
|
+
error(time: Time, err: E): void;
|
|
23
|
+
/** Signal that no more events will arrive. */
|
|
24
|
+
end(time: Time): void;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Producer of events over time.
|
|
28
|
+
*
|
|
29
|
+
* Denotation: when run, produces a time-indexed sequence [(Time, A)]
|
|
30
|
+
* that may terminate or error.
|
|
31
|
+
*/
|
|
32
|
+
export interface Source<A, E = never> {
|
|
33
|
+
run(sink: Sink<A, E>, scheduler: Scheduler): Disposable;
|
|
34
|
+
}
|
|
35
|
+
/** A unit of work to be executed by the scheduler. */
|
|
36
|
+
export interface Task {
|
|
37
|
+
run(time: Time): void;
|
|
38
|
+
error(time: Time, err: unknown): void;
|
|
39
|
+
dispose(): void;
|
|
40
|
+
}
|
|
41
|
+
/** A task that has been scheduled for future execution. */
|
|
42
|
+
export interface ScheduledTask extends Disposable {
|
|
43
|
+
readonly task: Task;
|
|
44
|
+
readonly time: Time;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Coordinates the execution of tasks over time.
|
|
48
|
+
*
|
|
49
|
+
* The scheduler is the single source of truth for "what time is it"
|
|
50
|
+
* within a reactive pipeline.
|
|
51
|
+
*/
|
|
52
|
+
export interface Scheduler {
|
|
53
|
+
/** The current time according to this scheduler. */
|
|
54
|
+
currentTime(): Time;
|
|
55
|
+
/** Schedule a task to run after a delay. */
|
|
56
|
+
scheduleTask(delay: Duration, task: Task): ScheduledTask;
|
|
57
|
+
/** Create a child scheduler whose time is shifted by an offset. */
|
|
58
|
+
relative(offset: Offset): Scheduler;
|
|
59
|
+
/** Cancel a previously scheduled task. */
|
|
60
|
+
cancelTask(task: ScheduledTask): void;
|
|
61
|
+
}
|
|
62
|
+
declare const EventBrand: unique symbol;
|
|
63
|
+
/**
|
|
64
|
+
* A discrete, time-indexed sequence of values.
|
|
65
|
+
*
|
|
66
|
+
* Denotation: `[(Time, A)]` — a list of time-value pairs, possibly
|
|
67
|
+
* terminating with an error of type E.
|
|
68
|
+
*/
|
|
69
|
+
export type Event<A, E = never> = {
|
|
70
|
+
readonly [EventBrand]: [A, E];
|
|
71
|
+
};
|
|
72
|
+
declare const BehaviorBrand: unique symbol;
|
|
73
|
+
/**
|
|
74
|
+
* A continuous, time-varying value.
|
|
75
|
+
*
|
|
76
|
+
* Denotation: `Time -> A` — a function from time to a value,
|
|
77
|
+
* possibly failing with an error of type E.
|
|
78
|
+
*/
|
|
79
|
+
export type Behavior<A, E = never> = {
|
|
80
|
+
readonly [BehaviorBrand]: [A, E];
|
|
81
|
+
};
|
|
82
|
+
export declare const EventURI: "Event";
|
|
83
|
+
export type EventURI = typeof EventURI;
|
|
84
|
+
export declare const BehaviorURI: "Behavior";
|
|
85
|
+
export type BehaviorURI = typeof BehaviorURI;
|
|
86
|
+
declare module "./hkt.js" {
|
|
87
|
+
interface URItoKind<A, E> {
|
|
88
|
+
readonly [EventURI]: Event<A, E>;
|
|
89
|
+
readonly [BehaviorURI]: Behavior<A, E>;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
export {};
|
|
93
|
+
//# sourceMappingURL=interfaces.d.ts.map
|
|
@@ -0,0 +1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version": "0.1.0",
|
|
4
|
+
"description": "Core type definitions for Aeon reactive streams",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Josh Burgess",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/joshburgess/aeon",
|
|
10
|
+
"directory": "packages/types"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/joshburgess/aeon#readme",
|
|
13
|
+
"bugs": "https://github.com/joshburgess/aeon/issues",
|
|
14
|
+
"keywords": ["reactive", "streams", "frp", "types", "typescript"],
|
|
15
|
+
"type": "module",
|
|
16
|
+
"sideEffects": false,
|
|
17
|
+
"main": "./dist/index.cjs",
|
|
18
|
+
"module": "./dist/index.js",
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"import": {
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"default": "./dist/index.js"
|
|
25
|
+
},
|
|
26
|
+
"require": {
|
|
27
|
+
"types": "./dist/index.d.cts",
|
|
28
|
+
"default": "./dist/index.cjs"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"files": ["dist"],
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "rm -rf dist && rollup -c rollup.config.mjs && tsc -p tsconfig.build.json && cp dist/index.d.ts dist/index.d.cts",
|
|
35
|
+
"typecheck": "tsc --noEmit",
|
|
36
|
+
"test": "vitest run",
|
|
37
|
+
"clean": "rm -rf dist"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"typescript": "^5.7.2"
|
|
41
|
+
}
|
|
42
|
+
}
|