@pithos/core 2.2.2 → 2.4.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.
Files changed (99) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/autocompletion.d.ts +129 -1
  3. package/dist/eidos/abstract-factory/abstract-factory.d.ts +125 -0
  4. package/dist/eidos/abstract-factory/abstract-factory.d.ts.map +1 -0
  5. package/dist/eidos/abstract-factory/abstract-factory.js +128 -0
  6. package/dist/eidos/abstract-factory/abstract-factory.js.map +1 -0
  7. package/dist/eidos/adapter/adapter.d.ts +97 -0
  8. package/dist/eidos/adapter/adapter.d.ts.map +1 -0
  9. package/dist/eidos/adapter/adapter.js +90 -0
  10. package/dist/eidos/adapter/adapter.js.map +1 -0
  11. package/dist/eidos/bridge/bridge.d.ts +81 -0
  12. package/dist/eidos/bridge/bridge.d.ts.map +1 -0
  13. package/dist/eidos/bridge/bridge.js +75 -0
  14. package/dist/eidos/bridge/bridge.js.map +1 -0
  15. package/dist/eidos/builder/builder.d.ts +181 -0
  16. package/dist/eidos/builder/builder.d.ts.map +1 -0
  17. package/dist/eidos/builder/builder.js +139 -0
  18. package/dist/eidos/builder/builder.js.map +1 -0
  19. package/dist/eidos/chain/chain.d.ts +99 -0
  20. package/dist/eidos/chain/chain.d.ts.map +1 -0
  21. package/dist/eidos/chain/chain.js +111 -0
  22. package/dist/eidos/chain/chain.js.map +1 -0
  23. package/dist/eidos/command/command.d.ts +267 -0
  24. package/dist/eidos/command/command.d.ts.map +1 -0
  25. package/dist/eidos/command/command.js +298 -0
  26. package/dist/eidos/command/command.js.map +1 -0
  27. package/dist/eidos/composite/composite.d.ts +168 -0
  28. package/dist/eidos/composite/composite.d.ts.map +1 -0
  29. package/dist/eidos/composite/composite.js +157 -0
  30. package/dist/eidos/composite/composite.js.map +1 -0
  31. package/dist/eidos/decorator/decorator.d.ts +138 -0
  32. package/dist/eidos/decorator/decorator.d.ts.map +1 -0
  33. package/dist/eidos/decorator/decorator.js +143 -0
  34. package/dist/eidos/decorator/decorator.js.map +1 -0
  35. package/dist/eidos/facade/facade.d.ts +61 -0
  36. package/dist/eidos/facade/facade.d.ts.map +1 -0
  37. package/dist/eidos/facade/facade.js +63 -0
  38. package/dist/eidos/facade/facade.js.map +1 -0
  39. package/dist/eidos/factory-method/factory-method.d.ts +76 -0
  40. package/dist/eidos/factory-method/factory-method.d.ts.map +1 -0
  41. package/dist/eidos/factory-method/factory-method.js +60 -0
  42. package/dist/eidos/factory-method/factory-method.js.map +1 -0
  43. package/dist/eidos/flyweight/flyweight.d.ts +40 -0
  44. package/dist/eidos/flyweight/flyweight.d.ts.map +1 -0
  45. package/dist/eidos/flyweight/flyweight.js +41 -0
  46. package/dist/eidos/flyweight/flyweight.js.map +1 -0
  47. package/dist/eidos/interpreter/interpreter.d.ts +82 -0
  48. package/dist/eidos/interpreter/interpreter.d.ts.map +1 -0
  49. package/dist/eidos/interpreter/interpreter.js +84 -0
  50. package/dist/eidos/interpreter/interpreter.js.map +1 -0
  51. package/dist/eidos/iterator/iterator.d.ts +164 -0
  52. package/dist/eidos/iterator/iterator.d.ts.map +1 -0
  53. package/dist/eidos/iterator/iterator.js +258 -0
  54. package/dist/eidos/iterator/iterator.js.map +1 -0
  55. package/dist/eidos/mediator/mediator.d.ts +102 -0
  56. package/dist/eidos/mediator/mediator.d.ts.map +1 -0
  57. package/dist/eidos/mediator/mediator.js +112 -0
  58. package/dist/eidos/mediator/mediator.js.map +1 -0
  59. package/dist/eidos/memento/memento.d.ts +103 -0
  60. package/dist/eidos/memento/memento.d.ts.map +1 -0
  61. package/dist/eidos/memento/memento.js +114 -0
  62. package/dist/eidos/memento/memento.js.map +1 -0
  63. package/dist/eidos/observer/observer.d.ts +96 -0
  64. package/dist/eidos/observer/observer.d.ts.map +1 -0
  65. package/dist/eidos/observer/observer.js +117 -0
  66. package/dist/eidos/observer/observer.js.map +1 -0
  67. package/dist/eidos/prototype/prototype.d.ts +32 -0
  68. package/dist/eidos/prototype/prototype.d.ts.map +1 -0
  69. package/dist/eidos/prototype/prototype.js +33 -0
  70. package/dist/eidos/prototype/prototype.js.map +1 -0
  71. package/dist/eidos/proxy/proxy.d.ts +108 -0
  72. package/dist/eidos/proxy/proxy.d.ts.map +1 -0
  73. package/dist/eidos/proxy/proxy.js +121 -0
  74. package/dist/eidos/proxy/proxy.js.map +1 -0
  75. package/dist/eidos/singleton/singleton.d.ts +76 -0
  76. package/dist/eidos/singleton/singleton.d.ts.map +1 -0
  77. package/dist/eidos/singleton/singleton.js +77 -0
  78. package/dist/eidos/singleton/singleton.js.map +1 -0
  79. package/dist/eidos/state/state.d.ts +152 -0
  80. package/dist/eidos/state/state.d.ts.map +1 -0
  81. package/dist/eidos/state/state.js +85 -0
  82. package/dist/eidos/state/state.js.map +1 -0
  83. package/dist/eidos/strategy/strategy.d.ts +148 -0
  84. package/dist/eidos/strategy/strategy.d.ts.map +1 -0
  85. package/dist/eidos/strategy/strategy.js +167 -0
  86. package/dist/eidos/strategy/strategy.js.map +1 -0
  87. package/dist/eidos/template/template.d.ts +95 -0
  88. package/dist/eidos/template/template.d.ts.map +1 -0
  89. package/dist/eidos/template/template.js +110 -0
  90. package/dist/eidos/template/template.js.map +1 -0
  91. package/dist/eidos/visitor/visitor.d.ts +78 -0
  92. package/dist/eidos/visitor/visitor.d.ts.map +1 -0
  93. package/dist/eidos/visitor/visitor.js +80 -0
  94. package/dist/eidos/visitor/visitor.js.map +1 -0
  95. package/dist/zygos/result/index.d.ts +19 -0
  96. package/dist/zygos/result/index.d.ts.map +1 -0
  97. package/dist/zygos/result/index.js +29 -0
  98. package/dist/zygos/result/index.js.map +1 -0
  99. package/package.json +28 -3
@@ -0,0 +1,168 @@
1
+ /**
2
+ * Functional Composite Pattern.
3
+ *
4
+ * In OOP, the Composite pattern requires a Component interface, Leaf classes,
5
+ * and Composite classes that hold children and delegate operations recursively.
6
+ * In functional TypeScript, a composite is a discriminated union (leaf | branch)
7
+ * with a fold function that traverses the tree.
8
+ *
9
+ * The key insight: treat leaves and branches uniformly via pattern matching,
10
+ * not inheritance. The fold function replaces the recursive `operation()` method.
11
+ *
12
+ * @module eidos/composite
13
+ * @since 2.4.0
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import { leaf, branch, fold, map } from "@pithos/core/eidos/composite/composite";
18
+ *
19
+ * // File system tree
20
+ * type FSNode = Composite<{ name: string; size: number }>;
21
+ *
22
+ * const tree: FSNode = branch({ name: "root", size: 0 }, [
23
+ * leaf({ name: "file1.txt", size: 100 }),
24
+ * branch({ name: "docs", size: 0 }, [
25
+ * leaf({ name: "readme.md", size: 50 }),
26
+ * ]),
27
+ * ]);
28
+ *
29
+ * // Calculate total size
30
+ * const totalSize = fold(tree, {
31
+ * leaf: (data) => data.size,
32
+ * branch: (data, childResults) => childResults.reduce((a, b) => a + b, 0),
33
+ * });
34
+ * ```
35
+ */
36
+ import type { Option } from "../../zygos/option.js";
37
+ /**
38
+ * A Leaf node contains data but no children.
39
+ *
40
+ * @template T - The data type stored in nodes
41
+ * @since 2.4.0
42
+ */
43
+ export type Leaf<T> = {
44
+ readonly type: "leaf";
45
+ readonly data: T;
46
+ };
47
+ /**
48
+ * A Branch node contains data and children.
49
+ *
50
+ * @template T - The data type stored in nodes
51
+ * @since 2.4.0
52
+ */
53
+ export type Branch<T> = {
54
+ readonly type: "branch";
55
+ readonly data: T;
56
+ readonly children: ReadonlyArray<Composite<T>>;
57
+ };
58
+ /**
59
+ * A Composite is either a Leaf or a Branch.
60
+ * This discriminated union replaces the OOP Component/Leaf/Composite hierarchy.
61
+ *
62
+ * @template T - The data type stored in nodes
63
+ * @since 2.4.0
64
+ */
65
+ export type Composite<T> = Leaf<T> | Branch<T>;
66
+ /**
67
+ * Creates a leaf node.
68
+ *
69
+ * @template T - The data type
70
+ * @param data - The leaf's data
71
+ * @returns A Leaf node
72
+ * @since 2.4.0
73
+ */
74
+ export declare function leaf<T>(data: T): Leaf<T>;
75
+ /**
76
+ * Creates a branch node with children.
77
+ *
78
+ * @template T - The data type
79
+ * @param data - The branch's data
80
+ * @param children - Child nodes
81
+ * @returns A Branch node
82
+ * @since 2.4.0
83
+ */
84
+ export declare function branch<T>(data: T, children: Composite<T>[]): Branch<T>;
85
+ /**
86
+ * Handlers for folding over a composite tree.
87
+ *
88
+ * @template T - The data type in nodes
89
+ * @template R - The result type
90
+ * @since 2.4.0
91
+ */
92
+ export type FoldHandlers<T, R> = {
93
+ /** Handle a leaf node. Receives the leaf's data. */
94
+ leaf: (data: T) => R;
95
+ /** Handle a branch node. Receives the branch's data and results from children. */
96
+ branch: (data: T, childResults: R[]) => R;
97
+ };
98
+ /**
99
+ * Folds over a composite tree, reducing it to a single value.
100
+ * This replaces the recursive `operation()` method from OOP Composite.
101
+ *
102
+ * @template T - The data type in nodes
103
+ * @template R - The result type
104
+ * @param node - The root node to fold
105
+ * @param handlers - Functions to handle leaf and branch nodes
106
+ * @returns The folded result
107
+ * @since 2.4.0
108
+ *
109
+ * @example
110
+ * ```ts
111
+ * // Count all nodes
112
+ * const count = fold(tree, {
113
+ * leaf: () => 1,
114
+ * branch: (_, children) => 1 + children.reduce((a, b) => a + b, 0),
115
+ * });
116
+ *
117
+ * // Render to string
118
+ * const render = fold(tree, {
119
+ * leaf: (data) => data.name,
120
+ * branch: (data, children) => `${data.name}(${children.join(", ")})`,
121
+ * });
122
+ * ```
123
+ */
124
+ export declare function fold<T, R>(node: Composite<T>, handlers: FoldHandlers<T, R>): R;
125
+ /**
126
+ * Maps over a composite tree, transforming each node's data.
127
+ *
128
+ * @template T - The source data type
129
+ * @template U - The target data type
130
+ * @param node - The root node to map
131
+ * @param fn - Function to transform node data
132
+ * @returns A new tree with transformed data
133
+ * @since 2.4.0
134
+ *
135
+ * @example
136
+ * ```ts
137
+ * const doubled = map(tree, (data) => ({ ...data, size: data.size * 2 }));
138
+ * ```
139
+ */
140
+ export declare function map<T, U>(node: Composite<T>, fn: (data: T) => U): Composite<U>;
141
+ /**
142
+ * Flattens a composite tree into an array of all node data.
143
+ * Traverses depth-first, pre-order (parent before children).
144
+ *
145
+ * @template T - The data type
146
+ * @param node - The root node to flatten
147
+ * @returns Array of all node data
148
+ * @since 2.4.0
149
+ *
150
+ * @example
151
+ * ```ts
152
+ * const allFiles = flatten(tree);
153
+ * // [{ name: "root", ... }, { name: "file1.txt", ... }, ...]
154
+ * ```
155
+ */
156
+ export declare function flatten<T>(node: Composite<T>): T[];
157
+ /**
158
+ * Finds the first node matching a predicate (depth-first).
159
+ * Short-circuits on first match.
160
+ *
161
+ * @template T - The data type
162
+ * @param node - The root node to search
163
+ * @param predicate - Function to test each node
164
+ * @returns Option containing the matching node data
165
+ * @since 2.4.0
166
+ */
167
+ export declare function find<T>(node: Composite<T>, predicate: (data: T) => boolean): Option<T>;
168
+ //# sourceMappingURL=composite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"composite.d.ts","sourceRoot":"","sources":["../../../src/eidos/composite/composite.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAE5C;;;;;GAKG;AACH,MAAM,MAAM,IAAI,CAAC,CAAC,IAAI;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;CAClB,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI;IACtB,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;IACjB,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;CAChD,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CA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AC9B,MAAM,CAAC,CAAC,CAAC,CASX"}
@@ -0,0 +1,157 @@
1
+ /**
2
+ * Functional Composite Pattern.
3
+ *
4
+ * In OOP, the Composite pattern requires a Component interface, Leaf classes,
5
+ * and Composite classes that hold children and delegate operations recursively.
6
+ * In functional TypeScript, a composite is a discriminated union (leaf | branch)
7
+ * with a fold function that traverses the tree.
8
+ *
9
+ * The key insight: treat leaves and branches uniformly via pattern matching,
10
+ * not inheritance. The fold function replaces the recursive `operation()` method.
11
+ *
12
+ * @module eidos/composite
13
+ * @since 2.4.0
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import { leaf, branch, fold, map } from "@pithos/core/eidos/composite/composite";
18
+ *
19
+ * // File system tree
20
+ * type FSNode = Composite<{ name: string; size: number }>;
21
+ *
22
+ * const tree: FSNode = branch({ name: "root", size: 0 }, [
23
+ * leaf({ name: "file1.txt", size: 100 }),
24
+ * branch({ name: "docs", size: 0 }, [
25
+ * leaf({ name: "readme.md", size: 50 }),
26
+ * ]),
27
+ * ]);
28
+ *
29
+ * // Calculate total size
30
+ * const totalSize = fold(tree, {
31
+ * leaf: (data) => data.size,
32
+ * branch: (data, childResults) => childResults.reduce((a, b) => a + b, 0),
33
+ * });
34
+ * ```
35
+ */
36
+ import { some, none } from "../../zygos/option.js";
37
+ /**
38
+ * Creates a leaf node.
39
+ *
40
+ * @template T - The data type
41
+ * @param data - The leaf's data
42
+ * @returns A Leaf node
43
+ * @since 2.4.0
44
+ */
45
+ export function leaf(data) {
46
+ return { type: "leaf", data };
47
+ }
48
+ /**
49
+ * Creates a branch node with children.
50
+ *
51
+ * @template T - The data type
52
+ * @param data - The branch's data
53
+ * @param children - Child nodes
54
+ * @returns A Branch node
55
+ * @since 2.4.0
56
+ */
57
+ export function branch(data, children) {
58
+ return { type: "branch", data, children };
59
+ }
60
+ /**
61
+ * Folds over a composite tree, reducing it to a single value.
62
+ * This replaces the recursive `operation()` method from OOP Composite.
63
+ *
64
+ * @template T - The data type in nodes
65
+ * @template R - The result type
66
+ * @param node - The root node to fold
67
+ * @param handlers - Functions to handle leaf and branch nodes
68
+ * @returns The folded result
69
+ * @since 2.4.0
70
+ *
71
+ * @example
72
+ * ```ts
73
+ * // Count all nodes
74
+ * const count = fold(tree, {
75
+ * leaf: () => 1,
76
+ * branch: (_, children) => 1 + children.reduce((a, b) => a + b, 0),
77
+ * });
78
+ *
79
+ * // Render to string
80
+ * const render = fold(tree, {
81
+ * leaf: (data) => data.name,
82
+ * branch: (data, children) => `${data.name}(${children.join(", ")})`,
83
+ * });
84
+ * ```
85
+ */
86
+ export function fold(node, handlers) {
87
+ if (node.type === "leaf") {
88
+ return handlers.leaf(node.data);
89
+ }
90
+ const childResults = node.children.map((child) => fold(child, handlers));
91
+ return handlers.branch(node.data, childResults);
92
+ }
93
+ /**
94
+ * Maps over a composite tree, transforming each node's data.
95
+ *
96
+ * @template T - The source data type
97
+ * @template U - The target data type
98
+ * @param node - The root node to map
99
+ * @param fn - Function to transform node data
100
+ * @returns A new tree with transformed data
101
+ * @since 2.4.0
102
+ *
103
+ * @example
104
+ * ```ts
105
+ * const doubled = map(tree, (data) => ({ ...data, size: data.size * 2 }));
106
+ * ```
107
+ */
108
+ export function map(node, fn) {
109
+ if (node.type === "leaf") {
110
+ return leaf(fn(node.data));
111
+ }
112
+ return branch(fn(node.data), node.children.map((child) => map(child, fn)));
113
+ }
114
+ /**
115
+ * Flattens a composite tree into an array of all node data.
116
+ * Traverses depth-first, pre-order (parent before children).
117
+ *
118
+ * @template T - The data type
119
+ * @param node - The root node to flatten
120
+ * @returns Array of all node data
121
+ * @since 2.4.0
122
+ *
123
+ * @example
124
+ * ```ts
125
+ * const allFiles = flatten(tree);
126
+ * // [{ name: "root", ... }, { name: "file1.txt", ... }, ...]
127
+ * ```
128
+ */
129
+ export function flatten(node) {
130
+ return fold(node, {
131
+ leaf: (data) => [data],
132
+ branch: (data, childResults) => [data, ...childResults.flat()],
133
+ });
134
+ }
135
+ /**
136
+ * Finds the first node matching a predicate (depth-first).
137
+ * Short-circuits on first match.
138
+ *
139
+ * @template T - The data type
140
+ * @param node - The root node to search
141
+ * @param predicate - Function to test each node
142
+ * @returns Option containing the matching node data
143
+ * @since 2.4.0
144
+ */
145
+ export function find(node, predicate) {
146
+ if (predicate(node.data))
147
+ return some(node.data);
148
+ if (node.type === "branch") {
149
+ for (const child of node.children) {
150
+ const found = find(child, predicate);
151
+ if (found._tag === "Some")
152
+ return found;
153
+ }
154
+ }
155
+ return none;
156
+ }
157
+ //# sourceMappingURL=composite.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"composite.js","sourceRoot":"","sources":["../../../src/eidos/composite/composite.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAmC3C;;;;;;;GAOG;AACH,MAAM,UAAU,IAAI,CAAI,IAAO;IAC7B,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;AAChC,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,MAAM,CAAI,IAAO,EAAE,QAAwB;IACzD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;AAC5C,CAAC;AAgBD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,IAAI,CAAO,IAAkB,EAAE,QAA4B;IACzE,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;QACzB,OAAO,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;IACD,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC;IACzE,OAAO,QAAQ,CAAC,MAAM,CAAC,I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AO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,138 @@
1
+ /**
2
+ * Functional Decorator Pattern.
3
+ *
4
+ * In OOP, the Decorator pattern requires a Component interface, an abstract
5
+ * Decorator class, and concrete decorator subclasses with inheritance.
6
+ * In functional TypeScript, a decorator is a higher-order function that
7
+ * wraps another function while preserving its signature.
8
+ *
9
+ * @module eidos/decorator
10
+ * @since 2.4.0
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import { decorate, before, after } from "@pithos/core/eidos/decorator/decorator";
15
+ *
16
+ * const greet = (name: string) => `Hello, ${name}!`;
17
+ *
18
+ * const enhanced = decorate(
19
+ * greet,
20
+ * before((name) => console.log(`calling with: ${name}`)),
21
+ * after((_name, result) => console.log(`returned: ${result}`)),
22
+ * );
23
+ *
24
+ * enhanced("Alice");
25
+ * // logs: calling with: Alice
26
+ * // logs: returned: Hello, Alice!
27
+ * // returns: "Hello, Alice!"
28
+ * ```
29
+ */
30
+ /**
31
+ * A Decorator is a higher-order function that wraps a function,
32
+ * adding behavior while preserving its signature.
33
+ * Replaces the GoF abstract Decorator class + inheritance chain.
34
+ *
35
+ * @template In - The input type
36
+ * @template Out - The output type
37
+ * @since 2.4.0
38
+ */
39
+ export type Decorator<In, Out> = (fn: (input: In) => Out) => (input: In) => Out;
40
+ /**
41
+ * Applies one or more decorators to a function.
42
+ * Decorators are applied left-to-right: the first decorator is the
43
+ * innermost wrapper, the last is the outermost.
44
+ *
45
+ * @template In - The input type
46
+ * @template Out - The output type
47
+ * @param fn - The function to decorate
48
+ * @param decorators - Decorators to apply
49
+ * @returns The decorated function
50
+ * @since 2.4.0
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * const add = (n: number) => n + 1;
55
+ *
56
+ * const enhanced = decorate(
57
+ * add,
58
+ * before((n) => console.log("input:", n)),
59
+ * after((_n, result) => console.log("output:", result)),
60
+ * );
61
+ *
62
+ * enhanced(5); // logs: input: 5, output: 6, returns 6
63
+ * ```
64
+ */
65
+ export declare function decorate<In, Out>(fn: (input: In) => Out, ...decorators: Decorator<In, Out>[]): (input: In) => Out;
66
+ /**
67
+ * Creates a decorator that runs a hook before the function executes.
68
+ *
69
+ * @template In - The input type
70
+ * @template Out - The output type
71
+ * @param hook - Function to run before, receives the input
72
+ * @returns A Decorator
73
+ * @since 2.4.0
74
+ *
75
+ * @example
76
+ * ```ts
77
+ * const withLog = before<string, string>((name) => {
78
+ * console.log(`calling greet with: ${name}`);
79
+ * });
80
+ *
81
+ * const greet = withLog((name) => `Hello, ${name}!`);
82
+ * greet("Alice"); // logs then returns "Hello, Alice!"
83
+ * ```
84
+ */
85
+ export declare function before<In, Out>(hook: (input: In) => void): Decorator<In, Out>;
86
+ /**
87
+ * Creates a decorator that runs a hook after the function executes.
88
+ *
89
+ * @template In - The input type
90
+ * @template Out - The output type
91
+ * @param hook - Function to run after, receives input and output
92
+ * @returns A Decorator
93
+ * @since 2.4.0
94
+ *
95
+ * @example
96
+ * ```ts
97
+ * const withAudit = after<number, number>((input, output) => {
98
+ * auditLog.record({ input, output });
99
+ * });
100
+ *
101
+ * const double = withAudit((n) => n * 2);
102
+ * double(5); // returns 10, audit log records { input: 5, output: 10 }
103
+ * ```
104
+ */
105
+ export declare function after<In, Out>(hook: (input: In, output: Out) => void): Decorator<In, Out>;
106
+ /**
107
+ * Creates a decorator with full control over execution.
108
+ * The wrapper receives both the original function and the input,
109
+ * and decides how (or whether) to call it. This is the most
110
+ * powerful form - `before` and `after` are special cases of `around`.
111
+ *
112
+ * @template In - The input type
113
+ * @template Out - The output type
114
+ * @param wrapper - Function that controls execution
115
+ * @returns A Decorator
116
+ * @since 2.4.0
117
+ *
118
+ * @example
119
+ * ```ts
120
+ * // Retry decorator
121
+ * const withRetry = around<string, Response>((fn, input) => {
122
+ * try { return fn(input); }
123
+ * catch { return fn(input); } // one retry
124
+ * });
125
+ *
126
+ * // Caching decorator
127
+ * const cache = new Map<string, Data>();
128
+ * const withCache = around<string, Data>((fn, key) => {
129
+ * const cached = cache.get(key);
130
+ * if (cached) return cached;
131
+ * const result = fn(key);
132
+ * cache.set(key, result);
133
+ * return result;
134
+ * });
135
+ * ```
136
+ */
137
+ export declare function around<In, Out>(wrapper: (fn: (input: In) => Out, input: In) => Out): Decorator<In, Out>;
138
+ //# sourceMappingURL=decorator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decorator.d.ts","sourceRoot":"","sources":["../../../src/eidos/decorator/decorator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH;;;;;;;;GAQG;AACH,MAAM,MAAM,SAAS,CAAC,EAAE,EAAE,GAAG,IAAI,CAC/B,EAAE,EAAE,CAAC,KAAK,EAAE,EAAE,KAAK,GAAG,KACnB,CAAC,KAAK,EAAE,EAAE,KAAK,GAAG,CAAC;AAExB;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,QAAQ,CAAC,EAAE,EAAE,GAAG,EAC9B,EAAE,EAAE,CAAC,KAAK,EAAE,EAAE,KAAK,GAAG,EACtB,GAAG,UAAU,EAAE,SAAS,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,GAClC,CAAC,KAAK,EAAE,EAAE,KAAK,GAAG,CAEpB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,MAAM,CAAC,EAAE,EAAE,GAAG,EAC5B,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE,KAAK,IAAI,GACxB,SAAS,CAAC,EAAE,EAAE,GAAG,CAAC,CAKpB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,KAAK,CAAC,EAAE,EAAE,GAAG,EAC3B,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,KAAK,IAAI,GACrC,SAAS,CAAC,EAAE,EAAE,GAAG,CAAC,CAMpB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,MAAM,CAAC,EAAE,EAAE,GAAG,EAC5B,OAAO,EAAE,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,EAAE,KAAK,GAAG,EAAE,KAAK,EAAE,EAAE,KAAK,GAAG,GAClD,SAAS,CAAC,EAAE,EAAE,GAAG,CAAC,CAEpB"}
@@ -0,0 +1,143 @@
1
+ /**
2
+ * Functional Decorator Pattern.
3
+ *
4
+ * In OOP, the Decorator pattern requires a Component interface, an abstract
5
+ * Decorator class, and concrete decorator subclasses with inheritance.
6
+ * In functional TypeScript, a decorator is a higher-order function that
7
+ * wraps another function while preserving its signature.
8
+ *
9
+ * @module eidos/decorator
10
+ * @since 2.4.0
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import { decorate, before, after } from "@pithos/core/eidos/decorator/decorator";
15
+ *
16
+ * const greet = (name: string) => `Hello, ${name}!`;
17
+ *
18
+ * const enhanced = decorate(
19
+ * greet,
20
+ * before((name) => console.log(`calling with: ${name}`)),
21
+ * after((_name, result) => console.log(`returned: ${result}`)),
22
+ * );
23
+ *
24
+ * enhanced("Alice");
25
+ * // logs: calling with: Alice
26
+ * // logs: returned: Hello, Alice!
27
+ * // returns: "Hello, Alice!"
28
+ * ```
29
+ */
30
+ /**
31
+ * Applies one or more decorators to a function.
32
+ * Decorators are applied left-to-right: the first decorator is the
33
+ * innermost wrapper, the last is the outermost.
34
+ *
35
+ * @template In - The input type
36
+ * @template Out - The output type
37
+ * @param fn - The function to decorate
38
+ * @param decorators - Decorators to apply
39
+ * @returns The decorated function
40
+ * @since 2.4.0
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * const add = (n: number) => n + 1;
45
+ *
46
+ * const enhanced = decorate(
47
+ * add,
48
+ * before((n) => console.log("input:", n)),
49
+ * after((_n, result) => console.log("output:", result)),
50
+ * );
51
+ *
52
+ * enhanced(5); // logs: input: 5, output: 6, returns 6
53
+ * ```
54
+ */
55
+ export function decorate(fn, ...decorators) {
56
+ return decorators.reduce((acc, dec) => dec(acc), fn);
57
+ }
58
+ /**
59
+ * Creates a decorator that runs a hook before the function executes.
60
+ *
61
+ * @template In - The input type
62
+ * @template Out - The output type
63
+ * @param hook - Function to run before, receives the input
64
+ * @returns A Decorator
65
+ * @since 2.4.0
66
+ *
67
+ * @example
68
+ * ```ts
69
+ * const withLog = before<string, string>((name) => {
70
+ * console.log(`calling greet with: ${name}`);
71
+ * });
72
+ *
73
+ * const greet = withLog((name) => `Hello, ${name}!`);
74
+ * greet("Alice"); // logs then returns "Hello, Alice!"
75
+ * ```
76
+ */
77
+ export function before(hook) {
78
+ return (fn) => (input) => {
79
+ hook(input);
80
+ return fn(input);
81
+ };
82
+ }
83
+ /**
84
+ * Creates a decorator that runs a hook after the function executes.
85
+ *
86
+ * @template In - The input type
87
+ * @template Out - The output type
88
+ * @param hook - Function to run after, receives input and output
89
+ * @returns A Decorator
90
+ * @since 2.4.0
91
+ *
92
+ * @example
93
+ * ```ts
94
+ * const withAudit = after<number, number>((input, output) => {
95
+ * auditLog.record({ input, output });
96
+ * });
97
+ *
98
+ * const double = withAudit((n) => n * 2);
99
+ * double(5); // returns 10, audit log records { input: 5, output: 10 }
100
+ * ```
101
+ */
102
+ export function after(hook) {
103
+ return (fn) => (input) => {
104
+ const output = fn(input);
105
+ hook(input, output);
106
+ return output;
107
+ };
108
+ }
109
+ /**
110
+ * Creates a decorator with full control over execution.
111
+ * The wrapper receives both the original function and the input,
112
+ * and decides how (or whether) to call it. This is the most
113
+ * powerful form - `before` and `after` are special cases of `around`.
114
+ *
115
+ * @template In - The input type
116
+ * @template Out - The output type
117
+ * @param wrapper - Function that controls execution
118
+ * @returns A Decorator
119
+ * @since 2.4.0
120
+ *
121
+ * @example
122
+ * ```ts
123
+ * // Retry decorator
124
+ * const withRetry = around<string, Response>((fn, input) => {
125
+ * try { return fn(input); }
126
+ * catch { return fn(input); } // one retry
127
+ * });
128
+ *
129
+ * // Caching decorator
130
+ * const cache = new Map<string, Data>();
131
+ * const withCache = around<string, Data>((fn, key) => {
132
+ * const cached = cache.get(key);
133
+ * if (cached) return cached;
134
+ * const result = fn(key);
135
+ * cache.set(key, result);
136
+ * return result;
137
+ * });
138
+ * ```
139
+ */
140
+ export function around(wrapper) {
141
+ return (fn) => (input) => wrapper(fn, input);
142
+ }
143
+ //# sourceMappingURL=decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decorator.js","sourceRoot":"","sources":["../../../src/eidos/decorator/decorator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAeH;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,QAAQ,CACtB,EAAsB,EACtB,GAAG,UAAgC;IAEnC,OAAO,UAAU,CAAC,MAAM,CAAqB,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC;AAC3E,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,MAAM,CACpB,IAAyB;IAEzB,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,EAAE;QACvB,IAAI,CAAC,KAAK,CAAC,CAAC;QACZ,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC;IACnB,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,KAAK,CACnB,IAAsC;IAEtC,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,EAAE;QACvB,MAAM,MAAM,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC;QACzB,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QACpB,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,UAAU,MAAM,CACpB,OAAmD;IAEnD,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;AAC/C,CAAC"}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Functional Facade Pattern.
3
+ *
4
+ * In OOP, the Facade pattern requires a class that encapsulates multiple
5
+ * subsystems and exposes a simplified interface to clients.
6
+ *
7
+ * In functional TypeScript, this is absorbed by the language:
8
+ * a facade is just a function that orchestrates other functions.
9
+ * No wrapper needed — it's what functions naturally do.
10
+ *
11
+ * This module exists for documentation and discoverability. The function is
12
+ * marked `@deprecated` to guide developers toward idiomatic functional code.
13
+ *
14
+ * @module eidos/facade
15
+ * @since 2.4.0
16
+ *
17
+ * @see {@link https://pithos.dev/api/eidos/facade/ | Explanations, examples and live demo}
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * // No import needed — just write a function:
22
+ *
23
+ * // Subsystems (could be from different modules)
24
+ * const validateUser = (data: UserInput) => { ... };
25
+ * const hashPassword = (password: string) => { ... };
26
+ * const saveToDb = (user: User) => { ... };
27
+ * const sendWelcomeEmail = (email: string) => { ... };
28
+ *
29
+ * // Facade: simplified interface hiding the complexity
30
+ * const registerUser = async (data: UserInput) => {
31
+ * const validated = validateUser(data);
32
+ * const hashedPassword = await hashPassword(validated.password);
33
+ * const user = await saveToDb({ ...validated, password: hashedPassword });
34
+ * await sendWelcomeEmail(user.email);
35
+ * return user;
36
+ * };
37
+ *
38
+ * // Client only sees registerUser, not the subsystems
39
+ * await registerUser({ name: "Alice", email: "alice@example.com", password: "..." });
40
+ * ```
41
+ *
42
+ * @deprecated **Pattern absorbed by the language.**
43
+ *
44
+ * In functional TypeScript, a facade is just a function that calls other functions.
45
+ * This function is the identity — it exists only so you find this message.
46
+ *
47
+ * Write your facade directly:
48
+ * ```ts
49
+ * const checkout = (cart: Cart, payment: Payment) => {
50
+ * const validated = validateCart(cart);
51
+ * const charged = processPayment(payment, validated.total);
52
+ * const order = createOrder(validated, charged);
53
+ * sendConfirmation(order);
54
+ * return order;
55
+ * };
56
+ * ```
57
+ *
58
+ * @see {@link https://pithos.dev/api/eidos/facade/ | Full explanation, examples and live demo}
59
+ */
60
+ export declare function createFacade<Args extends unknown[], Result>(fn: (...args: Args) => Result): (...args: Args) => Result;
61
+ //# sourceMappingURL=facade.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"facade.d.ts","sourceRoot":"","sources":["../../../src/eidos/facade/facade.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AACH,wBAAgB,YAAY,CAAC,IAAI,SAAS,OAAO,EAAE,EAAE,MAAM,EACzD,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,IAAI,KAAK,MAAM,GAC5B,CAAC,GAAG,IAAI,EAAE,IAAI,KAAK,MAAM,CAE3B"}