@pithos/core 2.4.0 → 2.5.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.
@@ -10,7 +10,7 @@
10
10
  * ❌ const distance = math.geometry.distance; // from autocompletion
11
11
  * ✅ import { distance } from 'pithos/math/geometry';
12
12
  *
13
- * Generated on: 2026-03-29T23:24:53.486Z
13
+ * Generated on: 2026-04-03T14:52:39.923Z
14
14
  * */
15
15
 
16
16
  /**
@@ -640,6 +640,9 @@ declare const _autocompletion: {
640
640
  observer: {
641
641
  createObservable: typeof import('./eidos/observer/observer.js')['createObservable'];
642
642
  };
643
+ observer_lite: {
644
+ createLiteObservable: typeof import('./eidos/observer/observer-lite.js')['createLiteObservable'];
645
+ };
643
646
  prototype: {
644
647
  deepClone: typeof import('./eidos/prototype/prototype.js')['deepClone'];
645
648
  deepCloneFull: typeof import('./eidos/prototype/prototype.js')['deepCloneFull'];
@@ -659,6 +662,9 @@ declare const _autocompletion: {
659
662
  state: {
660
663
  createMachine: typeof import('./eidos/state/state.js')['createMachine'];
661
664
  };
665
+ state_lite: {
666
+ createLiteMachine: typeof import('./eidos/state/state-lite.js')['createLiteMachine'];
667
+ };
662
668
  strategy: {
663
669
  createStrategies: typeof import('./eidos/strategy/strategy.js')['createStrategies'];
664
670
  safeStrategy: typeof import('./eidos/strategy/strategy.js')['safeStrategy'];
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Lightweight Observer Pattern — zero external dependencies.
3
+ *
4
+ * Provides the same `subscribe` / `notify` / `clear` API as
5
+ * {@link createObservable}, but without `safeNotify`, `once`, or `size`.
6
+ * This avoids pulling in `@zygos/result` and keeps the bundle minimal
7
+ * for consumers who only need basic pub/sub.
8
+ *
9
+ * @module eidos/observer/observer-lite
10
+ * @since 2.5.0
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import { createLiteObservable } from "@pithos/core/eidos/observer/observer-lite";
15
+ *
16
+ * const onClick = createLiteObservable<{ x: number; y: number }>();
17
+ *
18
+ * const unsub = onClick.subscribe(({ x, y }) => console.log(x, y));
19
+ * onClick.notify({ x: 10, y: 20 }); // logs: 10 20
20
+ * unsub();
21
+ * ```
22
+ */
23
+ /** A listener callback that reacts to emitted values. */
24
+ export type Listener<T> = (value: T) => void;
25
+ /**
26
+ * A function that removes a listener when called.
27
+ *
28
+ * @since 2.5.0
29
+ */
30
+ export type Unsubscribe = () => void;
31
+ /**
32
+ * Creates a lightweight observable (pub/sub emitter).
33
+ *
34
+ * Only exposes `subscribe`, `notify`, and `clear`.
35
+ * No dependency on `@zygos/result` — ideal for size-sensitive bundles.
36
+ *
37
+ * @template T - The type of values emitted to listeners
38
+ * @returns Observable with `subscribe`, `notify`, `clear`
39
+ * @since 2.5.0
40
+ */
41
+ export declare function createLiteObservable<T>(): {
42
+ /** Add a listener. Returns an unsubscribe function. */
43
+ subscribe: (listener: Listener<T>) => Unsubscribe;
44
+ /** Emit a value to all listeners (fail-fast). */
45
+ notify: (value: T) => void;
46
+ /** Remove all listeners. */
47
+ clear: () => void;
48
+ };
49
+ //# sourceMappingURL=observer-lite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"observer-lite.d.ts","sourceRoot":"","sources":["../../../src/eidos/observer/observer-lite.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,yDAAyD;AACzD,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;AAE7C;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC;AAErC;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAAC,CAAC;IAIlC,uDAAuD;0BACjC,QAAQ,CAAC,CAAC,CAAC,KAAG,WAAW;IAO/C,iDAAiD;oBACjC,CAAC,KAAG,IAAI;IAMxB,4BAA4B;iBACjB,IAAI;EAIlB"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Lightweight Observer Pattern — zero external dependencies.
3
+ *
4
+ * Provides the same `subscribe` / `notify` / `clear` API as
5
+ * {@link createObservable}, but without `safeNotify`, `once`, or `size`.
6
+ * This avoids pulling in `@zygos/result` and keeps the bundle minimal
7
+ * for consumers who only need basic pub/sub.
8
+ *
9
+ * @module eidos/observer/observer-lite
10
+ * @since 2.5.0
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import { createLiteObservable } from "@pithos/core/eidos/observer/observer-lite";
15
+ *
16
+ * const onClick = createLiteObservable<{ x: number; y: number }>();
17
+ *
18
+ * const unsub = onClick.subscribe(({ x, y }) => console.log(x, y));
19
+ * onClick.notify({ x: 10, y: 20 }); // logs: 10 20
20
+ * unsub();
21
+ * ```
22
+ */
23
+ /**
24
+ * Creates a lightweight observable (pub/sub emitter).
25
+ *
26
+ * Only exposes `subscribe`, `notify`, and `clear`.
27
+ * No dependency on `@zygos/result` — ideal for size-sensitive bundles.
28
+ *
29
+ * @template T - The type of values emitted to listeners
30
+ * @returns Observable with `subscribe`, `notify`, `clear`
31
+ * @since 2.5.0
32
+ */
33
+ export function createLiteObservable() {
34
+ const listeners = new Set();
35
+ return {
36
+ /** Add a listener. Returns an unsubscribe function. */
37
+ subscribe: (listener) => {
38
+ listeners.add(listener);
39
+ return () => {
40
+ listeners.delete(listener);
41
+ };
42
+ },
43
+ /** Emit a value to all listeners (fail-fast). */
44
+ notify: (value) => {
45
+ for (const listener of listeners) {
46
+ listener(value);
47
+ }
48
+ },
49
+ /** Remove all listeners. */
50
+ clear: () => {
51
+ listeners.clear();
52
+ },
53
+ };
54
+ }
55
+ //# sourceMappingURL=observer-lite.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"observer-lite.js","sourceRoot":"","sources":["../../../src/eidos/observer/observer-lite.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAYH;;;;;;;;;GASG;AACH,MAAM,UAAU,oBAAoB;IAClC,MAAM,SAAS,GAAG,IAAI,GAAG,EAAe,CAAC;IAEzC,OAAO;QACL,uDAAuD;QACvD,SAAS,EAAE,CAAC,QAAqB,EAAe,EAAE;YAChD,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YACxB,OAAO,GAAG,EAAE;gBACV,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YAC7B,CAAC,CAAC;QACJ,CAAC;QAED,iDAAiD;QACjD,MAAM,EAAE,CAAC,KAAQ,EAAQ,EAAE;YACzB,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;gBACjC,QAAQ,CAAC,KAAK,CAAC,CAAC;YAClB,CAAC;QACH,CAAC;QAED,4BAA4B;QAC5B,KAAK,EAAE,GAAS,EAAE;YAChB,SAAS,CAAC,KAAK,EAAE,CAAC;QACpB,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Lightweight State Machine — zero external dependencies.
3
+ *
4
+ * Same core API as {@link createMachine} (`current`, `send`, `matches`,
5
+ * `onTransition`, `reset`) but without `trySend` (which pulls `@zygos/option`).
6
+ *
7
+ * @module eidos/state/state-lite
8
+ * @since 2.5.0
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * import { createLiteMachine } from "@pithos/core/eidos/state/state-lite";
13
+ *
14
+ * const light = createLiteMachine({
15
+ * green: { timer: { to: "yellow" } },
16
+ * yellow: { timer: { to: "red" } },
17
+ * red: { timer: { to: "green" } },
18
+ * }, "green");
19
+ *
20
+ * light.current(); // "green"
21
+ * light.send("timer"); // "yellow"
22
+ * ```
23
+ */
24
+ /** A simple transition to a target state. */
25
+ export interface SimpleTransition<S extends string> {
26
+ readonly to: S;
27
+ }
28
+ /**
29
+ * A transition that also updates context.
30
+ *
31
+ * @since 2.5.0
32
+ */
33
+ export interface ContextTransition<S extends string, C> {
34
+ readonly to: S;
35
+ readonly update: (ctx: C) => C;
36
+ }
37
+ /**
38
+ * A transition is either simple (just target) or with context update.
39
+ *
40
+ * @since 2.5.0
41
+ */
42
+ export type Transition<S extends string, C> = SimpleTransition<S> | ContextTransition<S, C>;
43
+ /**
44
+ * A transition map for a single state.
45
+ *
46
+ * @since 2.5.0
47
+ */
48
+ export type Transitions<S extends string, E extends string, C> = {
49
+ readonly [K in E]?: Transition<S, C>;
50
+ };
51
+ /**
52
+ * Full state machine definition.
53
+ *
54
+ * @since 2.5.0
55
+ */
56
+ export type MachineDefinition<S extends string, E extends string, C> = {
57
+ readonly [K in S]: Transitions<S, E, C>;
58
+ };
59
+ /**
60
+ * A transition listener receives the previous state, the event, and the new state.
61
+ *
62
+ * @since 2.5.0
63
+ */
64
+ export type TransitionListener<S extends string, E extends string> = (from: S, event: E, to: S) => void;
65
+ /**
66
+ * Creates a lightweight finite state machine (no `trySend`, no `@zygos/option` dependency).
67
+ *
68
+ * @template S - Union of state names
69
+ * @template E - Union of event names
70
+ * @param definition - The state/transition map
71
+ * @param initial - The initial state
72
+ * @returns A machine with `current`, `send`, `matches`, `onTransition`, `reset`
73
+ * @since 2.5.0
74
+ */
75
+ export declare function createLiteMachine<S extends string, E extends string>(definition: MachineDefinition<S, E, undefined>, initial: S): {
76
+ current: () => S;
77
+ send: (event: E) => S;
78
+ matches: (state: S) => boolean;
79
+ onTransition: (listener: TransitionListener<S, E>) => () => void;
80
+ reset: () => void;
81
+ };
82
+ /**
83
+ * Creates a lightweight finite state machine with context.
84
+ *
85
+ * @template S - Union of state names
86
+ * @template E - Union of event names
87
+ * @template C - Context type
88
+ * @param definition - The state/transition map
89
+ * @param initial - The initial state
90
+ * @param initialContext - The initial context value
91
+ * @returns A machine with `current`, `context`, `send`, `matches`, `onTransition`, `reset`
92
+ * @since 2.5.0
93
+ */
94
+ export declare function createLiteMachine<S extends string, E extends string, C>(definition: MachineDefinition<S, E, C>, initial: S, initialContext: C): {
95
+ current: () => S;
96
+ context: () => C;
97
+ send: (event: E) => S;
98
+ matches: (state: S) => boolean;
99
+ onTransition: (listener: TransitionListener<S, E>) => () => void;
100
+ reset: () => void;
101
+ };
102
+ //# sourceMappingURL=state-lite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state-lite.d.ts","sourceRoot":"","sources":["../../../src/eidos/state/state-lite.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,6CAA6C;AAC7C,MAAM,WAAW,gBAAgB,CAAC,CAAC,SAAS,MAAM;IAChD,QAAQ,CAAC,EAAE,EAAE,CAAC,CAAC;CAChB;AAED;;;;GAIG;AACH,MAAM,WAAW,iBAAiB,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC;IACpD,QAAQ,CAAC,EAAE,EAAE,CAAC,CAAC;IACf,QAAQ,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC;CAChC;AAED;;;;GAIG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,IACtC,gBAAgB,CAAC,CAAC,CAAC,GACnB,iBAAiB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAE5B;;;;GAIG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,EAAE,CAAC,IAAI;IAC/D,QAAQ,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC;CACrC,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,EAAE,CAAC,IAAI;IACrE,QAAQ,EAAE,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;CACxC,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,IAAI,CACnE,IAAI,EAAE,CAAC,EACP,KAAK,EAAE,CAAC,EACR,EAAE,EAAE,CAAC,KACF,IAAI,CAAC;AAQV;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,EAClE,UAAU,EAAE,iBAAiB,CAAC,CAAC,EAAE,CAAC,EAAE,SAAS,CAAC,EAC9C,OAAO,EAAE,CAAC,GACT;IACD,OAAO,EAAE,MAAM,CAAC,CAAC;IACjB,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC;IACtB,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC;IAC/B,YAAY,EAAE,CAAC,QAAQ,EAAE,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,MAAM,IAAI,CAAC;IACjE,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,EAAE,CAAC,EACrE,UAAU,EAAE,iBAAiB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EACtC,OAAO,EAAE,CAAC,EACV,cAAc,EAAE,CAAC,GAChB;IACD,OAAO,EAAE,MAAM,CAAC,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC,CAAC;IACjB,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC;IACtB,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC;IAC/B,YAAY,EAAE,CAAC,QAAQ,EAAE,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,MAAM,IAAI,CAAC;IACjE,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB,CAAC"}
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Lightweight State Machine — zero external dependencies.
3
+ *
4
+ * Same core API as {@link createMachine} (`current`, `send`, `matches`,
5
+ * `onTransition`, `reset`) but without `trySend` (which pulls `@zygos/option`).
6
+ *
7
+ * @module eidos/state/state-lite
8
+ * @since 2.5.0
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * import { createLiteMachine } from "@pithos/core/eidos/state/state-lite";
13
+ *
14
+ * const light = createLiteMachine({
15
+ * green: { timer: { to: "yellow" } },
16
+ * yellow: { timer: { to: "red" } },
17
+ * red: { timer: { to: "green" } },
18
+ * }, "green");
19
+ *
20
+ * light.current(); // "green"
21
+ * light.send("timer"); // "yellow"
22
+ * ```
23
+ */
24
+ function hasUpdate(t) {
25
+ return "update" in t;
26
+ }
27
+ export function createLiteMachine(definition, initial, initialContext) {
28
+ let state = initial;
29
+ let ctx = initialContext;
30
+ const listeners = new Set();
31
+ const send = (event) => {
32
+ const transitions = definition[state];
33
+ const transition = transitions[event];
34
+ if (transition === undefined)
35
+ return state;
36
+ const from = state;
37
+ state = transition.to;
38
+ // Stryker disable next-line ConditionalExpression: ctx check is defensive - TypeScript prevents update on machines without context
39
+ if (hasUpdate(transition) && ctx !== undefined) {
40
+ ctx = transition.update(ctx);
41
+ }
42
+ for (const listener of listeners) {
43
+ listener(from, event, state);
44
+ }
45
+ return state;
46
+ };
47
+ const onTransition = (listener) => {
48
+ listeners.add(listener);
49
+ return () => { listeners.delete(listener); };
50
+ };
51
+ const base = {
52
+ current: () => state,
53
+ send,
54
+ matches: (s) => state === s,
55
+ onTransition,
56
+ reset: () => {
57
+ state = initial;
58
+ ctx = initialContext;
59
+ },
60
+ };
61
+ if (initialContext !== undefined) {
62
+ return {
63
+ ...base,
64
+ context: () => ctx,
65
+ };
66
+ }
67
+ return base;
68
+ }
69
+ //# sourceMappingURL=state-lite.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state-lite.js","sourceRoot":"","sources":["../../../src/eidos/state/state-lite.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAuDH,SAAS,SAAS,CAChB,CAAmB;IAEnB,OAAO,QAAQ,IAAI,CAAC,CAAC;AACvB,CAA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AC;YAChB,GAAG,GAAG,cAAc,CAAC;QACvB,CAAC;KACF,CAAC;IAEF,IAAI,cAAc,KAAK,SAAS,EAAE,CAAC;QACjC,OAAO;YACL,GAAG,IAAI;YACP,OAAO,EAAE,GAAG,EAAE,CAAC,GAAQ;SACxB,CAAC;IACJ,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pithos/core",
3
- "version": "2.4.0",
3
+ "version": "2.5.0",
4
4
  "description": "Advanced JavaScript/TypeScript superset providing utilities, validation, and functional patterns",
5
5
  "type": "module",
6
6
  "publishConfig": {