@pithos/core 2.3.0 → 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,81 @@
1
+ /**
2
+ * Functional Bridge Pattern.
3
+ *
4
+ * In OOP, the Bridge pattern requires an Abstraction class hierarchy and a
5
+ * separate Implementation interface hierarchy, linked via composition.
6
+ *
7
+ * In functional TypeScript, a bridge is just a function `(impl) => abstraction`.
8
+ * The pattern is absorbed by the language — no wrapper needed.
9
+ *
10
+ * This module exists for documentation and discoverability. The functions are
11
+ * identity wrappers marked `@deprecated` to guide developers toward idiomatic
12
+ * functional code.
13
+ *
14
+ * @module eidos/bridge
15
+ * @since 2.4.0
16
+ *
17
+ * @see {@link https://pithos.dev/api/eidos/bridge/ | Explanations, examples and live demo}
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * // No import needed — just write a function:
22
+ * type Renderer = {
23
+ * drawCircle: (x: number, y: number, r: number) => void;
24
+ * drawRect: (x: number, y: number, w: number, h: number) => void;
25
+ * };
26
+ *
27
+ * const shapes = (impl: Renderer) => ({
28
+ * icon: (x: number, y: number) => {
29
+ * impl.drawCircle(x, y, 10);
30
+ * impl.drawRect(x - 5, y + 15, 10, 5);
31
+ * },
32
+ * button: (x: number, y: number) => {
33
+ * impl.drawRect(x, y, 100, 30);
34
+ * impl.drawCircle(x + 10, y + 15, 5);
35
+ * },
36
+ * });
37
+ *
38
+ * // Swap implementations freely
39
+ * const svgShapes = shapes(svgRenderer);
40
+ * const canvasShapes = shapes(canvasRenderer);
41
+ * ```
42
+ */
43
+ /**
44
+ * A Bridge is a function that takes an implementation and returns an abstraction.
45
+ * This is just a type alias for documentation — use `(impl: I) => A` directly.
46
+ *
47
+ * @internal Not exported in API docs — use inline `(impl: I) => A` instead
48
+ * @template Impl - The implementation type
49
+ * @template Abs - The abstraction type
50
+ * @since 2.4.0
51
+ */
52
+ export type Bridge<Impl, Abs> = (impl: Impl) => Abs;
53
+ /**
54
+ * @deprecated **Pattern absorbed by the language.**
55
+ *
56
+ * In functional TypeScript, a bridge is just `(impl) => abstraction`.
57
+ * This function is the identity — it exists only so you find this message.
58
+ *
59
+ * Write your bridge directly:
60
+ * ```ts
61
+ * const repo = (db: DbDriver) => ({
62
+ * findById: (id) => db.query(`SELECT * FROM users WHERE id = '${id}'`),
63
+ * save: (user) => db.execute(`INSERT INTO users ...`),
64
+ * });
65
+ * ```
66
+ *
67
+ * @see {@link https://pithos.dev/api/eidos/bridge/ | Full explanation, examples and live demo}
68
+ * @since 2.4.0
69
+ */
70
+ export declare function createBridge<Impl, Abs>(factory: (impl: Impl) => Abs): (impl: Impl) => Abs;
71
+ /**
72
+ * @deprecated **Pattern absorbed by the language.**
73
+ *
74
+ * Compose two bridges: `(impl) => mid` and `(mid) => abs` into `(impl) => abs`.
75
+ * This is just function composition — use `(impl) => b(a(impl))` directly.
76
+ *
77
+ * @see {@link https://pithos.dev/api/eidos/bridge/ | Full explanation, examples and live demo}
78
+ * @since 2.4.0
79
+ */
80
+ export declare function composeBridges<Impl, Mid, Abs>(a: (impl: Impl) => Mid, b: (mid: Mid) => Abs): (impl: Impl) => Abs;
81
+ //# sourceMappingURL=bridge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bridge.d.ts","sourceRoot":"","sources":["../../../src/eidos/bridge/bridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAEH;;;;;;;;GAQG;AACH,MAAM,MAAM,MAAM,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,IAAI,EAAE,IAAI,KAAK,GAAG,CAAC;AAEpD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,GAAG,EACpC,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,GAAG,GAC3B,CAAC,IAAI,EAAE,IAAI,KAAK,GAAG,CAErB;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,EAC3C,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,GAAG,EACtB,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,GAAG,GACnB,CAAC,IAAI,EAAE,IAAI,KAAK,GAAG,CAErB"}
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Functional Bridge Pattern.
3
+ *
4
+ * In OOP, the Bridge pattern requires an Abstraction class hierarchy and a
5
+ * separate Implementation interface hierarchy, linked via composition.
6
+ *
7
+ * In functional TypeScript, a bridge is just a function `(impl) => abstraction`.
8
+ * The pattern is absorbed by the language — no wrapper needed.
9
+ *
10
+ * This module exists for documentation and discoverability. The functions are
11
+ * identity wrappers marked `@deprecated` to guide developers toward idiomatic
12
+ * functional code.
13
+ *
14
+ * @module eidos/bridge
15
+ * @since 2.4.0
16
+ *
17
+ * @see {@link https://pithos.dev/api/eidos/bridge/ | Explanations, examples and live demo}
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * // No import needed — just write a function:
22
+ * type Renderer = {
23
+ * drawCircle: (x: number, y: number, r: number) => void;
24
+ * drawRect: (x: number, y: number, w: number, h: number) => void;
25
+ * };
26
+ *
27
+ * const shapes = (impl: Renderer) => ({
28
+ * icon: (x: number, y: number) => {
29
+ * impl.drawCircle(x, y, 10);
30
+ * impl.drawRect(x - 5, y + 15, 10, 5);
31
+ * },
32
+ * button: (x: number, y: number) => {
33
+ * impl.drawRect(x, y, 100, 30);
34
+ * impl.drawCircle(x + 10, y + 15, 5);
35
+ * },
36
+ * });
37
+ *
38
+ * // Swap implementations freely
39
+ * const svgShapes = shapes(svgRenderer);
40
+ * const canvasShapes = shapes(canvasRenderer);
41
+ * ```
42
+ */
43
+ /**
44
+ * @deprecated **Pattern absorbed by the language.**
45
+ *
46
+ * In functional TypeScript, a bridge is just `(impl) => abstraction`.
47
+ * This function is the identity — it exists only so you find this message.
48
+ *
49
+ * Write your bridge directly:
50
+ * ```ts
51
+ * const repo = (db: DbDriver) => ({
52
+ * findById: (id) => db.query(`SELECT * FROM users WHERE id = '${id}'`),
53
+ * save: (user) => db.execute(`INSERT INTO users ...`),
54
+ * });
55
+ * ```
56
+ *
57
+ * @see {@link https://pithos.dev/api/eidos/bridge/ | Full explanation, examples and live demo}
58
+ * @since 2.4.0
59
+ */
60
+ export function createBridge(factory) {
61
+ return factory;
62
+ }
63
+ /**
64
+ * @deprecated **Pattern absorbed by the language.**
65
+ *
66
+ * Compose two bridges: `(impl) => mid` and `(mid) => abs` into `(impl) => abs`.
67
+ * This is just function composition — use `(impl) => b(a(impl))` directly.
68
+ *
69
+ * @see {@link https://pithos.dev/api/eidos/bridge/ | Full explanation, examples and live demo}
70
+ * @since 2.4.0
71
+ */
72
+ export function composeBridges(a, b) {
73
+ return (impl) => b(a(impl));
74
+ }
75
+ //# sourceMappingURL=bridge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bridge.js","sourceRoot":"","sources":["../../../src/eidos/bridge/bridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAaH;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,YAAY,CAC1B,OAA4B;IAE5B,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,cAAc,CAC5B,CAAsB,EACtB,CAAoB;IAEpB,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;AAC9B,CAAC"}
@@ -0,0 +1,181 @@
1
+ /**
2
+ * Functional Builder Pattern.
3
+ *
4
+ * In OOP, the Builder pattern requires a Builder interface, ConcreteBuilder
5
+ * classes with mutable state, a Product class, and optionally a Director class
6
+ * to orchestrate construction steps.
7
+ * In functional TypeScript, a builder is a function that returns an object
8
+ * with chainable step methods and a final `build()`. Each step returns a new
9
+ * builder (immutable).
10
+ *
11
+ * The Director concept maps to a simple function that takes a builder and
12
+ * calls steps in a specific sequence — no class needed.
13
+ *
14
+ * @module eidos/builder
15
+ * @since 2.4.0
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * import { createBuilder } from "@pithos/core/eidos/builder/builder";
20
+ *
21
+ * const carBuilder = createBuilder({ engine: "", wheels: 0, color: "white" })
22
+ * .step("engine", (s, engine: string) => ({ ...s, engine }))
23
+ * .step("wheels", (s, wheels: number) => ({ ...s, wheels }))
24
+ * .step("color", (s, color: string) => ({ ...s, color }))
25
+ * .done();
26
+ *
27
+ * const car = carBuilder()
28
+ * .engine("V8")
29
+ * .wheels(4)
30
+ * .color("red")
31
+ * .build();
32
+ * // { engine: "V8", wheels: 4, color: "red" }
33
+ * ```
34
+ */
35
+ import type { Result } from "../../zygos/result/result.js";
36
+ /**
37
+ * Intermediate builder definition that accumulates steps.
38
+ *
39
+ * @template State - The product state being built
40
+ * @template Methods - Accumulated method signatures
41
+ * @since 2.4.0
42
+ */
43
+ export interface BuilderDefinition<State, Methods extends object> {
44
+ /**
45
+ * Adds a step to the builder.
46
+ *
47
+ * @template K - The method name
48
+ * @template Arg - The argument type for this step
49
+ * @param name - The method name
50
+ * @param fn - The step function
51
+ */
52
+ step<K extends string, Arg>(name: K, fn: (state: State, arg: Arg) => State): BuilderDefinition<State, Methods & {
53
+ [P in K]: (arg: Arg) => unknown;
54
+ }>;
55
+ /**
56
+ * Finalizes the definition and returns a builder factory.
57
+ */
58
+ done(): () => FinalBuilder<State, Methods>;
59
+ }
60
+ /**
61
+ * The final builder object with chainable step methods.
62
+ *
63
+ * @template State - The product state being built
64
+ * @template Methods - The step method signatures
65
+ * @since 2.4.0
66
+ */
67
+ export type FinalBuilder<State, Methods extends object> = {
68
+ [K in keyof Methods]: Methods[K] extends (arg: infer Arg) => unknown ? (arg: Arg) => FinalBuilder<State, Methods> : never;
69
+ } & {
70
+ /** Returns the built product. */
71
+ build: () => State;
72
+ /** Returns the current state without finalizing. */
73
+ current: () => State;
74
+ };
75
+ /**
76
+ * Creates an immutable builder definition.
77
+ *
78
+ * Use `.step(name, fn)` to add steps, then `.done()` to get the factory.
79
+ * Each step method on the final builder returns a new builder (immutable).
80
+ *
81
+ * @template State - The product type being built
82
+ * @param initial - The initial state
83
+ * @returns A builder definition to chain `.step()` calls
84
+ * @since 2.4.0
85
+ *
86
+ * @example
87
+ * ```ts
88
+ * const queryBuilder = createBuilder({ table: "", where: [] as string[], limit: 100 })
89
+ * .step("from", (s, table: string) => ({ ...s, table }))
90
+ * .step("where", (s, clause: string) => ({ ...s, where: [...s.where, clause] }))
91
+ * .step("limit", (s, n: number) => ({ ...s, limit: n }))
92
+ * .done();
93
+ *
94
+ * const q = queryBuilder()
95
+ * .from("users")
96
+ * .where("active = true")
97
+ * .limit(10)
98
+ * .build();
99
+ * ```
100
+ */
101
+ export declare function createBuilder<State>(initial: State): BuilderDefinition<State, object>;
102
+ /**
103
+ * Validated builder definition that accumulates steps.
104
+ *
105
+ * @template State - The product state being built
106
+ * @template Methods - Accumulated method signatures
107
+ * @since 2.4.0
108
+ */
109
+ export interface ValidatedBuilderDefinition<State, Methods extends object> {
110
+ /**
111
+ * Adds a step to the builder.
112
+ */
113
+ step<K extends string, Arg>(name: K, fn: (state: State, arg: Arg) => State): ValidatedBuilderDefinition<State, Methods & {
114
+ [P in K]: (arg: Arg) => unknown;
115
+ }>;
116
+ /**
117
+ * Finalizes with a validator. `build()` returns `Result<State, string>`.
118
+ *
119
+ * @param validate - Returns `true` if valid, or an error message string
120
+ */
121
+ done(validate: (state: State) => true | string): () => ValidatedFinalBuilder<State, Methods>;
122
+ }
123
+ /**
124
+ * Builder with validated build() returning Result.
125
+ *
126
+ * @template State - The product state being built
127
+ * @template Methods - The step method signatures
128
+ * @since 2.4.0
129
+ */
130
+ export type ValidatedFinalBuilder<State, Methods extends object> = {
131
+ [K in keyof Methods]: Methods[K] extends (arg: infer Arg) => unknown ? (arg: Arg) => ValidatedFinalBuilder<State, Methods> : never;
132
+ } & {
133
+ /** Returns Ok(state) if valid, Err(message) otherwise. */
134
+ build: () => Result<State, string>;
135
+ /** Returns the current state without validation. */
136
+ current: () => State;
137
+ };
138
+ /**
139
+ * Creates a builder with validation on `build()`.
140
+ *
141
+ * Same as `createBuilder`, but `.done(validate)` takes a validator.
142
+ * `build()` returns `Result<State, string>`.
143
+ *
144
+ * @template State - The product type being built
145
+ * @param initial - The initial state
146
+ * @returns A validated builder definition
147
+ * @since 2.4.0
148
+ *
149
+ * @example
150
+ * ```ts
151
+ * const configBuilder = createValidatedBuilder({ host: "", port: 0 })
152
+ * .step("host", (s, host: string) => ({ ...s, host }))
153
+ * .step("port", (s, port: number) => ({ ...s, port }))
154
+ * .done((s) => s.host ? true : "host is required");
155
+ *
156
+ * configBuilder().port(8080).build(); // Err("host is required")
157
+ * configBuilder().host("localhost").build(); // Ok({ host: "localhost", port: 0 })
158
+ * ```
159
+ */
160
+ export declare function createValidatedBuilder<State>(initial: State): ValidatedBuilderDefinition<State, object>;
161
+ /**
162
+ * A Director is a function that orchestrates builder steps in a specific sequence.
163
+ * This is the functional equivalent of the GoF Director class.
164
+ *
165
+ * @template B - The builder type
166
+ * @template State - The product type
167
+ * @since 2.4.0
168
+ *
169
+ * @example
170
+ * ```ts
171
+ * // Director as a simple function
172
+ * const buildSportsCar: Director<ReturnType<typeof carBuilder>, Car> = (b) =>
173
+ * b.engine("V8").wheels(4).color("red");
174
+ *
175
+ * const car = buildSportsCar(carBuilder()).build();
176
+ * ```
177
+ */
178
+ export type Director<B, State> = (builder: B) => {
179
+ build: () => State;
180
+ };
181
+ //# sourceMappingURL=builder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../../../src/eidos/builder/builder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAEnD;;;;;;GAMG;AACH,MAAM,WAAW,iBAAiB,CAAC,KAAK,EAAE,OAAO,SAAS,MAAM;IAC9D;;;;;;;OAOG;IACH,IAAI,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,EACxB,IAAI,EAAE,CAAC,EACP,EAAE,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,KAAK,KAAK,GACpC,iBAAiB,CAAC,KAAK,E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AE,OAAO,CAAC,CAAC;CAChD;AAED;;;;;;GAMG;AACH,MAAM,MAAM,qBAAqB,CAAC,KAAK,EAAE,OAAO,SAAS,MAAM,IAAI;KAChE,CAAC,IAAI,MAAM,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,OAAO,GAChE,CAAC,GAAG,EAAE,GAAG,KAAK,qBAAqB,CAAC,KAAK,EAAE,OAAO,CAAC,GACnD,KAAK;CACV,GAAG;IACF,0DAA0D;IAC1D,KAAK,EAAE,MAAM,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IACnC,oDAAoD;IACpD,OAAO,EAAE,MAAM,KAAK,CAAC;CACtB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAC1C,OAAO,EAAE,KAAK,GACb,0BAA0B,CAAC,KAAK,EAAE,MAAM,CAAC,CAwC3C;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,EAAE,KAAK,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK;IAAE,KAAK,EAAE,MAAM,KAAK,CAAA;CAAE,CAAC"}
@@ -0,0 +1,139 @@
1
+ /**
2
+ * Functional Builder Pattern.
3
+ *
4
+ * In OOP, the Builder pattern requires a Builder interface, ConcreteBuilder
5
+ * classes with mutable state, a Product class, and optionally a Director class
6
+ * to orchestrate construction steps.
7
+ * In functional TypeScript, a builder is a function that returns an object
8
+ * with chainable step methods and a final `build()`. Each step returns a new
9
+ * builder (immutable).
10
+ *
11
+ * The Director concept maps to a simple function that takes a builder and
12
+ * calls steps in a specific sequence — no class needed.
13
+ *
14
+ * @module eidos/builder
15
+ * @since 2.4.0
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * import { createBuilder } from "@pithos/core/eidos/builder/builder";
20
+ *
21
+ * const carBuilder = createBuilder({ engine: "", wheels: 0, color: "white" })
22
+ * .step("engine", (s, engine: string) => ({ ...s, engine }))
23
+ * .step("wheels", (s, wheels: number) => ({ ...s, wheels }))
24
+ * .step("color", (s, color: string) => ({ ...s, color }))
25
+ * .done();
26
+ *
27
+ * const car = carBuilder()
28
+ * .engine("V8")
29
+ * .wheels(4)
30
+ * .color("red")
31
+ * .build();
32
+ * // { engine: "V8", wheels: 4, color: "red" }
33
+ * ```
34
+ */
35
+ import { ok, err } from "../../zygos/result/result.js";
36
+ /**
37
+ * Creates an immutable builder definition.
38
+ *
39
+ * Use `.step(name, fn)` to add steps, then `.done()` to get the factory.
40
+ * Each step method on the final builder returns a new builder (immutable).
41
+ *
42
+ * @template State - The product type being built
43
+ * @param initial - The initial state
44
+ * @returns A builder definition to chain `.step()` calls
45
+ * @since 2.4.0
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * const queryBuilder = createBuilder({ table: "", where: [] as string[], limit: 100 })
50
+ * .step("from", (s, table: string) => ({ ...s, table }))
51
+ * .step("where", (s, clause: string) => ({ ...s, where: [...s.where, clause] }))
52
+ * .step("limit", (s, n: number) => ({ ...s, limit: n }))
53
+ * .done();
54
+ *
55
+ * const q = queryBuilder()
56
+ * .from("users")
57
+ * .where("active = true")
58
+ * .limit(10)
59
+ * .build();
60
+ * ```
61
+ */
62
+ export function createBuilder(initial) {
63
+ const steps = new Map();
64
+ const definition = {
65
+ step(name, fn) {
66
+ // INTENTIONAL: runtime metaprogramming, type safety via generics
67
+ steps.set(name, fn);
68
+ // INTENTIONAL: accumulate method types via intersection, TS can't track dynamically
69
+ return definition;
70
+ },
71
+ done() {
72
+ const makeBuilder = (state) => {
73
+ const builder = {
74
+ build: () => state,
75
+ current: () => state,
76
+ };
77
+ for (const [name, fn] of steps) {
78
+ builder[name] = (arg) => makeBuilder(fn(state, arg));
79
+ }
80
+ // INTENTIONAL: dynamic object, type enforced by steps Map
81
+ return builder;
82
+ };
83
+ return () => makeBuilder(initial);
84
+ },
85
+ };
86
+ return definition;
87
+ }
88
+ /**
89
+ * Creates a builder with validation on `build()`.
90
+ *
91
+ * Same as `createBuilder`, but `.done(validate)` takes a validator.
92
+ * `build()` returns `Result<State, string>`.
93
+ *
94
+ * @template State - The product type being built
95
+ * @param initial - The initial state
96
+ * @returns A validated builder definition
97
+ * @since 2.4.0
98
+ *
99
+ * @example
100
+ * ```ts
101
+ * const configBuilder = createValidatedBuilder({ host: "", port: 0 })
102
+ * .step("host", (s, host: string) => ({ ...s, host }))
103
+ * .step("port", (s, port: number) => ({ ...s, port }))
104
+ * .done((s) => s.host ? true : "host is required");
105
+ *
106
+ * configBuilder().port(8080).build(); // Err("host is required")
107
+ * configBuilder().host("localhost").build(); // Ok({ host: "localhost", port: 0 })
108
+ * ```
109
+ */
110
+ export function createValidatedBuilder(initial) {
111
+ const steps = new Map();
112
+ const definition = {
113
+ step(name, fn) {
114
+ // INTENTIONAL: runtime metaprogramming
115
+ steps.set(name, fn);
116
+ // INTENTIONAL: dynamic type accumulation
117
+ return definition;
118
+ },
119
+ done(validate) {
120
+ const makeBuilder = (state) => {
121
+ const builder = {
122
+ build: () => {
123
+ const result = validate(state);
124
+ return result === true ? ok(state) : err(result);
125
+ },
126
+ current: () => state,
127
+ };
128
+ for (const [name, fn] of steps) {
129
+ builder[name] = (arg) => makeBuilder(fn(state, arg));
130
+ }
131
+ // INTENTIONAL: dynamic object construction
132
+ return builder;
133
+ };
134
+ return () => makeBuilder(initial);
135
+ },
136
+ };
137
+ return definition;
138
+ }
139
+ //# sourceMappingURL=builder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builder.js","sourceRoot":"","sources":["../../../src/eidos/builder/builder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAC;AAgD/C;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,aAAa,CAC3B,OAAc;IAGd,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AAK,EAAE,GAAG,EAAE;wBACV,MAAM,MAAM,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;wBAC/B,OAAO,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;oBACnD,CAAC;oBACD,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK;iBACrB,CAAC;gBAEF,KAAK,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC;oBAC/B,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,GAAY,EAAE,EAAE,CAAC,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC;gBAChE,CAAC;gBACD,2CAA2C;gBAC3C,OAAO,OAA+C,CAAC;YACzD,CAAC,CAAC;YAEF,OAAO,GAAG,EAAE,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QACpC,CAAC;KACF,CAAC;IAEF,OAAO,UAAU,CAAC;AACpB,CAAC"}
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Functional Chain of Responsibility Pattern.
3
+ *
4
+ * In OOP, Chain of Responsibility requires a Handler interface, a BaseHandler
5
+ * class with a `next` reference, and concrete handler subclasses linked together.
6
+ * In functional TypeScript, a handler is a function that either returns a result
7
+ * or delegates to the next handler. The chain is built by composing handlers.
8
+ *
9
+ * @module eidos/chain
10
+ * @since 2.4.0
11
+ *
12
+ * @see {@link https://pithos.dev/api/eidos/chain/ | Explanations, examples and live demo}
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * import { createChain, type Handler } from "@pithos/core/eidos/chain/chain";
17
+ *
18
+ * const auth: Handler<Request, Response> = (req, next) =>
19
+ * req.token ? next(req) : { status: 401 };
20
+ *
21
+ * const validate: Handler<Request, Response> = (req, next) =>
22
+ * req.body ? next(req) : { status: 400 };
23
+ *
24
+ * const handle: Handler<Request, Response> = (req) =>
25
+ * { status: 200, data: process(req) };
26
+ *
27
+ * const pipeline = createChain(auth, validate, handle);
28
+ * pipeline({ token: "abc", body: "data" }); // { status: 200, ... }
29
+ * ```
30
+ */
31
+ import type { Result } from "../../zygos/result/result.js";
32
+ /**
33
+ * A Handler receives an input and a `next` function.
34
+ * It can either return a result directly (stopping the chain)
35
+ * or call `next(input)` to delegate to the next handler.
36
+ *
37
+ * The last handler in the chain receives a `next` that is never called -
38
+ * it must produce a result on its own.
39
+ *
40
+ * @template In - The request/input type
41
+ * @template Out - The response/output type
42
+ * @since 2.4.0
43
+ */
44
+ export type Handler<In, Out> = (input: In, next: (input: In) => Out) => Out;
45
+ /**
46
+ * Creates a chain from an ordered list of handlers.
47
+ * Each handler can inspect the input and either:
48
+ * - return a result (short-circuit)
49
+ * - call `next(input)` to pass to the next handler
50
+ *
51
+ * The last handler's `next` throws if called, since there is
52
+ * nothing after it. The last handler should always produce a result.
53
+ *
54
+ * @template In - The request/input type
55
+ * @template Out - The response/output type
56
+ * @param handlers - Ordered list of handlers (first = outermost)
57
+ * @returns A function that runs the chain
58
+ * @since 2.4.0
59
+ *
60
+ * @example
61
+ * ```ts
62
+ * const log: Handler<number, string> = (n, next) => {
63
+ * console.log(`processing ${n}`);
64
+ * return next(n);
65
+ * };
66
+ *
67
+ * const double: Handler<number, string> = (n) => String(n * 2);
68
+ *
69
+ * const chain = createChain(log, double);
70
+ * chain(21); // logs "processing 21", returns "42"
71
+ * ```
72
+ */
73
+ export declare function createChain<In, Out>(...handlers: Handler<In, Out>[]): (input: In) => Out;
74
+ /**
75
+ * Creates a safe chain that catches errors and returns a zygos `Result`.
76
+ * Behaves like `createChain`, but wraps the execution in a try/catch.
77
+ *
78
+ * @deprecated Use `Result.fromThrowable` from `@zygos/result/result` instead.
79
+ *
80
+ * ```ts
81
+ * import { Result } from "../../zygos/result/result.js";
82
+ *
83
+ * const chain = createChain(auth, validate, handle);
84
+ * const safeRun = Result.fromThrowable(
85
+ * (input: Request) => chain(input),
86
+ * (e) => e instanceof Error ? e : new Error(String(e)),
87
+ * );
88
+ * const result = safeRun(request);
89
+ * ```
90
+ *
91
+ * @see {@link https://pithos.dev/api/eidos/chain/ | Full explanation, examples and live demo}
92
+ * @template In - The request/input type
93
+ * @template Out - The response/output type
94
+ * @param handlers - Ordered list of handlers
95
+ * @returns A function returning `Result<Out, Error>`
96
+ * @since 2.4.0
97
+ */
98
+ export declare function safeChain<In, Out>(...handlers: Handler<In, Out>[]): (input: In) => Result<Out, Error>;
99
+ //# sourceMappingURL=chain.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chain.d.ts","sourceRoot":"","sources":["../../../src/eidos/chain/chain.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAEnD;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,OAAO,CAAC,EAAE,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE,KAAK,GAAG,KAAK,GAAG,CAAC;AAE5E;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,WAAW,CAAC,EAAE,EAAE,GAAG,EACjC,GAAG,QAAQ,EAAE,OAAO,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,GAC9B,CAAC,KAAK,EAAE,EAAE,KAAK,GAAG,CAkBpB;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,SAAS,CAAC,EAAE,EAAE,GAAG,EAC/B,GAAG,QAAQ,EAAE,OAAO,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,GAC9B,CAAC,KAAK,EAAE,EAAE,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,CASnC"}