@procedures/client 0.2.0 → 0.2.2

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 (241) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +4 -4
  3. package/dist/.tsbuildinfo +1 -1
  4. package/dist/browser.d.ts +1 -1
  5. package/dist/browser.d.ts.map +1 -1
  6. package/dist/browser.js.map +1 -1
  7. package/dist/procedures/invoke.d.ts +6 -1
  8. package/dist/procedures/invoke.d.ts.map +1 -1
  9. package/dist/procedures/invoke.js +2 -2
  10. package/dist/procedures/invoke.js.map +1 -1
  11. package/dist/procedures/schema.d.ts +4 -1
  12. package/dist/procedures/schema.d.ts.map +1 -1
  13. package/dist/procedures/schema.js +27 -2
  14. package/dist/procedures/schema.js.map +1 -1
  15. package/dist/server/host-policy.d.ts +3 -3
  16. package/dist/server/host-policy.d.ts.map +1 -1
  17. package/dist/server/procedure-server.d.ts +2 -2
  18. package/dist/server/procedure-server.d.ts.map +1 -1
  19. package/dist/server/procedure-server.js.map +1 -1
  20. package/package.json +1 -1
  21. package/src/browser.ts +1 -0
  22. package/src/procedures/invoke.ts +10 -4
  23. package/src/procedures/schema.ts +27 -2
  24. package/src/server/host-policy.ts +3 -3
  25. package/src/server/procedure-server.ts +2 -2
  26. package/dist/client/middleware/batching.d.ts +0 -102
  27. package/dist/client/middleware/batching.d.ts.map +0 -1
  28. package/dist/client/middleware/batching.js +0 -245
  29. package/dist/client/middleware/batching.js.map +0 -1
  30. package/dist/collections/async/async-queue.d.ts +0 -144
  31. package/dist/collections/async/async-queue.d.ts.map +0 -1
  32. package/dist/collections/async/async-queue.js +0 -347
  33. package/dist/collections/async/async-queue.js.map +0 -1
  34. package/dist/collections/async/channels.d.ts +0 -188
  35. package/dist/collections/async/channels.d.ts.map +0 -1
  36. package/dist/collections/async/channels.js +0 -312
  37. package/dist/collections/async/channels.js.map +0 -1
  38. package/dist/collections/behaviors/bounded.d.ts +0 -79
  39. package/dist/collections/behaviors/bounded.d.ts.map +0 -1
  40. package/dist/collections/behaviors/bounded.js +0 -384
  41. package/dist/collections/behaviors/bounded.js.map +0 -1
  42. package/dist/collections/behaviors/evented.d.ts +0 -154
  43. package/dist/collections/behaviors/evented.d.ts.map +0 -1
  44. package/dist/collections/behaviors/evented.js +0 -299
  45. package/dist/collections/behaviors/evented.js.map +0 -1
  46. package/dist/collections/behaviors/lru.d.ts +0 -84
  47. package/dist/collections/behaviors/lru.d.ts.map +0 -1
  48. package/dist/collections/behaviors/lru.js +0 -330
  49. package/dist/collections/behaviors/lru.js.map +0 -1
  50. package/dist/collections/behaviors/readonly.d.ts +0 -73
  51. package/dist/collections/behaviors/readonly.d.ts.map +0 -1
  52. package/dist/collections/behaviors/readonly.js +0 -158
  53. package/dist/collections/behaviors/readonly.js.map +0 -1
  54. package/dist/collections/behaviors/safe.d.ts +0 -163
  55. package/dist/collections/behaviors/safe.d.ts.map +0 -1
  56. package/dist/collections/behaviors/safe.js +0 -172
  57. package/dist/collections/behaviors/safe.js.map +0 -1
  58. package/dist/collections/behaviors/synchronized.d.ts +0 -88
  59. package/dist/collections/behaviors/synchronized.d.ts.map +0 -1
  60. package/dist/collections/behaviors/synchronized.js +0 -294
  61. package/dist/collections/behaviors/synchronized.js.map +0 -1
  62. package/dist/collections/behaviors/ttl.d.ts +0 -118
  63. package/dist/collections/behaviors/ttl.d.ts.map +0 -1
  64. package/dist/collections/behaviors/ttl.js +0 -338
  65. package/dist/collections/behaviors/ttl.js.map +0 -1
  66. package/dist/collections/core/effects.d.ts +0 -176
  67. package/dist/collections/core/effects.d.ts.map +0 -1
  68. package/dist/collections/core/effects.js +0 -180
  69. package/dist/collections/core/effects.js.map +0 -1
  70. package/dist/collections/core/events.d.ts +0 -192
  71. package/dist/collections/core/events.d.ts.map +0 -1
  72. package/dist/collections/core/events.js +0 -291
  73. package/dist/collections/core/events.js.map +0 -1
  74. package/dist/collections/core/middleware.d.ts +0 -231
  75. package/dist/collections/core/middleware.d.ts.map +0 -1
  76. package/dist/collections/core/middleware.js +0 -161
  77. package/dist/collections/core/middleware.js.map +0 -1
  78. package/dist/collections/core/policies.d.ts +0 -220
  79. package/dist/collections/core/policies.d.ts.map +0 -1
  80. package/dist/collections/core/policies.js +0 -48
  81. package/dist/collections/core/policies.js.map +0 -1
  82. package/dist/collections/core/traits.d.ts +0 -142
  83. package/dist/collections/core/traits.d.ts.map +0 -1
  84. package/dist/collections/core/traits.js +0 -8
  85. package/dist/collections/core/traits.js.map +0 -1
  86. package/dist/collections/examples.d.ts +0 -13
  87. package/dist/collections/examples.d.ts.map +0 -1
  88. package/dist/collections/examples.js +0 -302
  89. package/dist/collections/examples.js.map +0 -1
  90. package/dist/collections/fx/collectors.d.ts +0 -190
  91. package/dist/collections/fx/collectors.d.ts.map +0 -1
  92. package/dist/collections/fx/collectors.js +0 -369
  93. package/dist/collections/fx/collectors.js.map +0 -1
  94. package/dist/collections/fx/iter.d.ts +0 -166
  95. package/dist/collections/fx/iter.d.ts.map +0 -1
  96. package/dist/collections/fx/iter.js +0 -421
  97. package/dist/collections/fx/iter.js.map +0 -1
  98. package/dist/collections/impl/array-deque.d.ts +0 -107
  99. package/dist/collections/impl/array-deque.d.ts.map +0 -1
  100. package/dist/collections/impl/array-deque.js +0 -381
  101. package/dist/collections/impl/array-deque.js.map +0 -1
  102. package/dist/collections/impl/array-list.d.ts +0 -101
  103. package/dist/collections/impl/array-list.d.ts.map +0 -1
  104. package/dist/collections/impl/array-list.js +0 -387
  105. package/dist/collections/impl/array-list.js.map +0 -1
  106. package/dist/collections/impl/hash-map.d.ts +0 -141
  107. package/dist/collections/impl/hash-map.d.ts.map +0 -1
  108. package/dist/collections/impl/hash-map.js +0 -450
  109. package/dist/collections/impl/hash-map.js.map +0 -1
  110. package/dist/collections/impl/hash-set.d.ts +0 -125
  111. package/dist/collections/impl/hash-set.d.ts.map +0 -1
  112. package/dist/collections/impl/hash-set.js +0 -264
  113. package/dist/collections/impl/hash-set.js.map +0 -1
  114. package/dist/collections/impl/linked-hash-map.d.ts +0 -141
  115. package/dist/collections/impl/linked-hash-map.d.ts.map +0 -1
  116. package/dist/collections/impl/linked-hash-map.js +0 -472
  117. package/dist/collections/impl/linked-hash-map.js.map +0 -1
  118. package/dist/collections/impl/linked-list.d.ts +0 -109
  119. package/dist/collections/impl/linked-list.d.ts.map +0 -1
  120. package/dist/collections/impl/linked-list.js +0 -491
  121. package/dist/collections/impl/linked-list.js.map +0 -1
  122. package/dist/collections/impl/priority-queue.d.ts +0 -134
  123. package/dist/collections/impl/priority-queue.d.ts.map +0 -1
  124. package/dist/collections/impl/priority-queue.js +0 -336
  125. package/dist/collections/impl/priority-queue.js.map +0 -1
  126. package/dist/collections/impl/tree-map.d.ts +0 -146
  127. package/dist/collections/impl/tree-map.d.ts.map +0 -1
  128. package/dist/collections/impl/tree-map.js +0 -781
  129. package/dist/collections/impl/tree-map.js.map +0 -1
  130. package/dist/collections/impl/tree-set.d.ts +0 -112
  131. package/dist/collections/impl/tree-set.d.ts.map +0 -1
  132. package/dist/collections/impl/tree-set.js +0 -374
  133. package/dist/collections/impl/tree-set.js.map +0 -1
  134. package/dist/collections/index.d.ts +0 -105
  135. package/dist/collections/index.d.ts.map +0 -1
  136. package/dist/collections/index.js +0 -135
  137. package/dist/collections/index.js.map +0 -1
  138. package/dist/collections/interfaces/collection.d.ts +0 -119
  139. package/dist/collections/interfaces/collection.d.ts.map +0 -1
  140. package/dist/collections/interfaces/collection.js +0 -8
  141. package/dist/collections/interfaces/collection.js.map +0 -1
  142. package/dist/collections/interfaces/list.d.ts +0 -247
  143. package/dist/collections/interfaces/list.d.ts.map +0 -1
  144. package/dist/collections/interfaces/list.js +0 -8
  145. package/dist/collections/interfaces/list.js.map +0 -1
  146. package/dist/collections/interfaces/map.d.ts +0 -344
  147. package/dist/collections/interfaces/map.d.ts.map +0 -1
  148. package/dist/collections/interfaces/map.js +0 -8
  149. package/dist/collections/interfaces/map.js.map +0 -1
  150. package/dist/collections/interfaces/queue.d.ts +0 -304
  151. package/dist/collections/interfaces/queue.d.ts.map +0 -1
  152. package/dist/collections/interfaces/queue.js +0 -8
  153. package/dist/collections/interfaces/queue.js.map +0 -1
  154. package/dist/collections/interfaces/set.d.ts +0 -137
  155. package/dist/collections/interfaces/set.d.ts.map +0 -1
  156. package/dist/collections/interfaces/set.js +0 -8
  157. package/dist/collections/interfaces/set.js.map +0 -1
  158. package/dist/collections/storage/api.d.ts +0 -109
  159. package/dist/collections/storage/api.d.ts.map +0 -1
  160. package/dist/collections/storage/api.js +0 -182
  161. package/dist/collections/storage/api.js.map +0 -1
  162. package/dist/collections/storage/hybrid.d.ts +0 -164
  163. package/dist/collections/storage/hybrid.d.ts.map +0 -1
  164. package/dist/collections/storage/hybrid.js +0 -416
  165. package/dist/collections/storage/hybrid.js.map +0 -1
  166. package/dist/collections/storage/index.d.ts +0 -16
  167. package/dist/collections/storage/index.d.ts.map +0 -1
  168. package/dist/collections/storage/index.js +0 -13
  169. package/dist/collections/storage/index.js.map +0 -1
  170. package/dist/collections/storage/interface.d.ts +0 -141
  171. package/dist/collections/storage/interface.d.ts.map +0 -1
  172. package/dist/collections/storage/interface.js +0 -23
  173. package/dist/collections/storage/interface.js.map +0 -1
  174. package/dist/collections/storage/memory.d.ts +0 -68
  175. package/dist/collections/storage/memory.d.ts.map +0 -1
  176. package/dist/collections/storage/memory.js +0 -154
  177. package/dist/collections/storage/memory.js.map +0 -1
  178. package/dist/collections/utils/defaults.d.ts +0 -135
  179. package/dist/collections/utils/defaults.d.ts.map +0 -1
  180. package/dist/collections/utils/defaults.js +0 -322
  181. package/dist/collections/utils/defaults.js.map +0 -1
  182. package/dist/collections/utils/factories.d.ts +0 -144
  183. package/dist/collections/utils/factories.d.ts.map +0 -1
  184. package/dist/collections/utils/factories.js +0 -293
  185. package/dist/collections/utils/factories.js.map +0 -1
  186. package/dist/collections/utils/helpers.d.ts +0 -137
  187. package/dist/collections/utils/helpers.d.ts.map +0 -1
  188. package/dist/collections/utils/helpers.js +0 -221
  189. package/dist/collections/utils/helpers.js.map +0 -1
  190. package/dist/collections.d.ts +0 -12
  191. package/dist/collections.d.ts.map +0 -1
  192. package/dist/collections.js +0 -10
  193. package/dist/collections.js.map +0 -1
  194. package/dist/components/define.d.ts +0 -134
  195. package/dist/components/define.d.ts.map +0 -1
  196. package/dist/components/define.js +0 -486
  197. package/dist/components/define.js.map +0 -1
  198. package/dist/components/index.d.ts +0 -39
  199. package/dist/components/index.d.ts.map +0 -1
  200. package/dist/components/index.js +0 -38
  201. package/dist/components/index.js.map +0 -1
  202. package/dist/components/types.d.ts +0 -264
  203. package/dist/components/types.d.ts.map +0 -1
  204. package/dist/components/types.js +0 -46
  205. package/dist/components/types.js.map +0 -1
  206. package/dist/procedures/storage/adapter.d.ts +0 -148
  207. package/dist/procedures/storage/adapter.d.ts.map +0 -1
  208. package/dist/procedures/storage/adapter.js +0 -214
  209. package/dist/procedures/storage/adapter.js.map +0 -1
  210. package/dist/procedures/storage/api.d.ts +0 -125
  211. package/dist/procedures/storage/api.d.ts.map +0 -1
  212. package/dist/procedures/storage/api.js +0 -220
  213. package/dist/procedures/storage/api.js.map +0 -1
  214. package/dist/procedures/storage/factory.d.ts +0 -134
  215. package/dist/procedures/storage/factory.d.ts.map +0 -1
  216. package/dist/procedures/storage/factory.js +0 -166
  217. package/dist/procedures/storage/factory.js.map +0 -1
  218. package/dist/procedures/storage/hybrid.d.ts +0 -193
  219. package/dist/procedures/storage/hybrid.d.ts.map +0 -1
  220. package/dist/procedures/storage/hybrid.js +0 -519
  221. package/dist/procedures/storage/hybrid.js.map +0 -1
  222. package/dist/procedures/storage/index.d.ts +0 -17
  223. package/dist/procedures/storage/index.d.ts.map +0 -1
  224. package/dist/procedures/storage/index.js +0 -17
  225. package/dist/procedures/storage/index.js.map +0 -1
  226. package/dist/procedures/storage/procedures.d.ts +0 -39
  227. package/dist/procedures/storage/procedures.d.ts.map +0 -1
  228. package/dist/procedures/storage/procedures.js +0 -261
  229. package/dist/procedures/storage/procedures.js.map +0 -1
  230. package/dist/procedures/storage/serialization.d.ts +0 -123
  231. package/dist/procedures/storage/serialization.d.ts.map +0 -1
  232. package/dist/procedures/storage/serialization.js +0 -216
  233. package/dist/procedures/storage/serialization.js.map +0 -1
  234. package/dist/procedures/storage/synced-registry.d.ts +0 -246
  235. package/dist/procedures/storage/synced-registry.d.ts.map +0 -1
  236. package/dist/procedures/storage/synced-registry.js +0 -575
  237. package/dist/procedures/storage/synced-registry.js.map +0 -1
  238. package/dist/procedures/storage/types.d.ts +0 -130
  239. package/dist/procedures/storage/types.d.ts.map +0 -1
  240. package/dist/procedures/storage/types.js +0 -8
  241. package/dist/procedures/storage/types.js.map +0 -1
@@ -1,231 +0,0 @@
1
- /**
2
- * Middleware composition system for collections.
3
- *
4
- * Provides the core composition mechanism that allows behaviors to be
5
- * layered on top of collections using the decorator pattern.
6
- *
7
- * This is a specialized form of the unified middleware system (common/src/middleware)
8
- * optimized for synchronous collection operations. While the unified system supports
9
- * both sync and async with explicit context objects, collections use a simpler pattern
10
- * where the collection instance itself serves as the context.
11
- *
12
- * @example
13
- * const list = compose(
14
- * safeList(),
15
- * eventedList(),
16
- * boundedList({ capacity: 100 })
17
- * )(arrayList<number>())
18
- */
19
- import type { Collection } from "../interfaces/collection.js";
20
- /**
21
- * A middleware is a function that takes a collection and returns
22
- * an enhanced version of that collection.
23
- *
24
- * This maps to the unified middleware pattern where:
25
- * - The "context" is the collection itself (passed directly, not in a context object)
26
- * - Execution is synchronous (no Promises)
27
- * - Type transformation is tracked through In -> Out
28
- *
29
- * Middleware can:
30
- * - Intercept method calls
31
- * - Add new capabilities
32
- * - Transform inputs/outputs
33
- * - Delegate to the next layer
34
- *
35
- * @template In The input collection type
36
- * @template Out The output collection type (defaults to In if not specified)
37
- */
38
- export type Middleware<In = any, Out extends In = In> = (next: In) => Out;
39
- /**
40
- * Composes multiple middleware layers into a single enhancer function.
41
- *
42
- * Uses reduceRight to create an "onion" pattern where the first middleware
43
- * is the outermost layer (runs first when calling into the collection).
44
- *
45
- * The type system properly tracks capability additions through composition.
46
- *
47
- * @example
48
- * // Layer order (outer to inner):
49
- * // 1. safe - converts throws to Option/Result
50
- * // 2. evented - emits events on mutations
51
- * // 3. bounded - enforces capacity limits
52
- * // 4. base - the underlying ArrayList
53
- * const enhancer = compose(
54
- * safeList(),
55
- * eventedList(),
56
- * boundedList({ capacity: 100 })
57
- * )
58
- * const list = enhancer(arrayList<number>())
59
- * // Type: List<number> & SafeCollection & EventedCollection & BoundedCollection
60
- *
61
- * @param layers The middleware layers to compose
62
- * @returns A function that applies all layers to a base collection
63
- */
64
- export declare function compose<C, R1 extends C>(m1: Middleware<C, R1>): (base: C) => R1;
65
- export declare function compose<C, R1 extends C, R2 extends R1>(m1: Middleware<R1, R2>, m2: Middleware<C, R1>): (base: C) => R2;
66
- export declare function compose<C, R1 extends C, R2 extends R1, R3 extends R2>(m1: Middleware<R2, R3>, m2: Middleware<R1, R2>, m3: Middleware<C, R1>): (base: C) => R3;
67
- export declare function compose<C, R1 extends C, R2 extends R1, R3 extends R2, R4 extends R3>(m1: Middleware<R3, R4>, m2: Middleware<R2, R3>, m3: Middleware<R1, R2>, m4: Middleware<C, R1>): (base: C) => R4;
68
- export declare function compose<C, R1 extends C, R2 extends R1, R3 extends R2, R4 extends R3, R5 extends R4>(m1: Middleware<R4, R5>, m2: Middleware<R3, R4>, m3: Middleware<R2, R3>, m4: Middleware<R1, R2>, m5: Middleware<C, R1>): (base: C) => R5;
69
- export declare function compose<C>(...layers: Middleware<any, any>[]): (base: C) => any;
70
- /**
71
- * Utility to check if a collection has a specific capability.
72
- * Useful for middleware that wants to conditionally enhance behavior.
73
- *
74
- * @example
75
- * if (hasCapability(collection, 'on')) {
76
- * // Collection supports events
77
- * collection.on('add', handler)
78
- * }
79
- */
80
- export declare const hasCapability: <C extends Collection<any>, K extends keyof any>(collection: C, capability: K) => collection is C & Record<K, unknown>;
81
- /**
82
- * Marker interface for collections that support events.
83
- * Middleware can use this to detect event capability.
84
- */
85
- export interface Evented<E extends Record<string, any>> {
86
- /**
87
- * Subscribe to an event.
88
- * @returns Unsubscribe function
89
- */
90
- on<K extends keyof E>(event: K, handler: (payload: E[K]) => void): () => void;
91
- }
92
- /**
93
- * Marker interface for collections that support async operations.
94
- */
95
- export interface Async<T> {
96
- /**
97
- * Async iterator for consuming elements.
98
- */
99
- [Symbol.asyncIterator](): AsyncIterator<T>;
100
- }
101
- /**
102
- * Marker interface for collections that are bounded.
103
- */
104
- export interface BoundedCollection {
105
- /** Maximum capacity */
106
- readonly capacity: number;
107
- /** Whether collection is at capacity */
108
- readonly isFull: boolean;
109
- /** Remaining space */
110
- readonly remainingCapacity: number;
111
- }
112
- /**
113
- * Marker interface for collections that support safe (Option/Result) operations.
114
- */
115
- export interface SafeCollection {
116
- /**
117
- * Namespace for safe operations that return Option/Result instead of throwing.
118
- */
119
- readonly safe: unknown;
120
- }
121
- /**
122
- * Type helper to extract the element type from a collection.
123
- */
124
- export type ElementType<C> = C extends {
125
- [Symbol.iterator](): Iterator<infer T>;
126
- } ? T : C extends {
127
- get(index: number): infer T;
128
- } ? T : C extends {
129
- peek(): infer T;
130
- } ? T : never;
131
- /**
132
- * Type helper to make all methods of a type return their async equivalents.
133
- */
134
- export type Asyncify<C> = {
135
- [K in keyof C]: C[K] extends (...args: infer Args) => infer R ? (...args: Args) => Promise<R> : C[K];
136
- };
137
- /**
138
- * Helper to create a proxy that intercepts method calls.
139
- * Useful for implementing middleware that needs to wrap method invocations.
140
- *
141
- * @example
142
- * const logged = interceptMethods(collection, (target, method, args) => {
143
- * console.log(`Calling ${String(method)} with`, args)
144
- * const result = Reflect.apply(target[method], target, args)
145
- * console.log(`Result:`, result)
146
- * return result
147
- * })
148
- */
149
- export declare const interceptMethods: <C extends object>(target: C, interceptor: (target: C, method: keyof C, args: unknown[]) => unknown) => C;
150
- /**
151
- * Helper to create a readonly view of a collection by blocking mutating methods.
152
- *
153
- * @param mutatingMethods Set of method names that should be blocked
154
- * @param errorMessage Custom error message to throw
155
- */
156
- export declare const blockMethods: <C extends object>(target: C, mutatingMethods: Set<string | symbol>, errorMessage?: string) => C;
157
- /**
158
- * Helper to delegate method calls to a target while maintaining correct context.
159
- * Useful when wrapping collections.
160
- */
161
- export declare const delegate: <C extends object, T extends C>(target: T, wrapper: Partial<C>) => C;
162
- /**
163
- * Utility type to add optional capabilities to a collection type.
164
- */
165
- export type WithCapability<C, Cap> = C & Cap;
166
- /**
167
- * Builder pattern helper for fluent API construction.
168
- *
169
- * @example
170
- * class ListBuilder<T> {
171
- * private middleware: Middleware<List<T>>[] = []
172
- *
173
- * bounded(capacity: number) {
174
- * this.middleware.push(boundedList({ capacity }))
175
- * return this
176
- * }
177
- *
178
- * evented() {
179
- * this.middleware.push(eventedList())
180
- * return this
181
- * }
182
- *
183
- * build(): List<T> {
184
- * return compose(...this.middleware)(arrayList<T>())
185
- * }
186
- * }
187
- */
188
- export declare abstract class CollectionBuilder<C> {
189
- protected middleware: Middleware<C>[];
190
- /**
191
- * Apply a custom middleware.
192
- */
193
- use(middleware: Middleware<C>): this;
194
- /**
195
- * Build the final collection by composing all middleware with the base.
196
- */
197
- abstract build(): C;
198
- }
199
- /**
200
- * Utility to create a middleware that only enhances specific methods.
201
- *
202
- * @example
203
- * const logAdd = enhanceMethod('add', (original, args) => {
204
- * console.log('Adding:', args[0])
205
- * return original(...args)
206
- * })
207
- */
208
- export declare const enhanceMethod: <C extends object, K extends keyof C & string>(methodName: K, enhancer: (original: C[K] extends (...args: infer Args) => infer R ? (...args: Args) => R : never, args: C[K] extends (...args: infer Args) => any ? Args : never) => C[K] extends (...args: any[]) => infer R_1 ? R_1 : never) => Middleware<C>;
209
- /**
210
- * Combines multiple middleware into a single middleware.
211
- * Useful for creating reusable middleware bundles.
212
- *
213
- * Bundle has the same composition semantics as compose - the first middleware
214
- * is the outermost layer, and types are tracked through the chain.
215
- *
216
- * @example
217
- * const standardBehaviors = bundle(
218
- * boundedList({ capacity: 1000 }),
219
- * eventedList(),
220
- * safeList()
221
- * )
222
- *
223
- * const list = compose(standardBehaviors)(arrayList<number>())
224
- */
225
- export declare function bundle<C, R1 extends C>(m1: Middleware<C, R1>): Middleware<C, R1>;
226
- export declare function bundle<C, R1 extends C, R2 extends R1>(m1: Middleware<R1, R2>, m2: Middleware<C, R1>): Middleware<C, R2>;
227
- export declare function bundle<C, R1 extends C, R2 extends R1, R3 extends R2>(m1: Middleware<R2, R3>, m2: Middleware<R1, R2>, m3: Middleware<C, R1>): Middleware<C, R3>;
228
- export declare function bundle<C, R1 extends C, R2 extends R1, R3 extends R2, R4 extends R3>(m1: Middleware<R3, R4>, m2: Middleware<R2, R3>, m3: Middleware<R1, R2>, m4: Middleware<C, R1>): Middleware<C, R4>;
229
- export declare function bundle<C, R1 extends C, R2 extends R1, R3 extends R2, R4 extends R3, R5 extends R4>(m1: Middleware<R4, R5>, m2: Middleware<R3, R4>, m3: Middleware<R2, R3>, m4: Middleware<R1, R2>, m5: Middleware<C, R1>): Middleware<C, R5>;
230
- export declare function bundle<C>(...middleware: Middleware<any, any>[]): Middleware<C, any>;
231
- //# sourceMappingURL=middleware.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../../src/collections/core/middleware.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAE9D;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,UAAU,CAAC,EAAE,GAAG,GAAG,EAAE,GAAG,SAAS,EAAE,GAAG,EAAE,IAAI,CAAC,IAAI,EAAE,EAAE,KAAK,GAAG,CAAC;AAE1E;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAGH,wBAAgB,OAAO,CAAC,CAAC,EAAE,EAAE,SAAS,CAAC,EACrC,EAAE,EAAE,UAAU,CAAC,CAAC,EA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ACtB,EAAE,EAAE,UAAU,CAAC,EAAE,EAAE,EAAE,CAAC,EACtB,EAAE,EAAE,UAAU,CAAC,CAAC,EAAE,EAAE,CAAC,GACpB,UAAU,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAGrB,wBAAgB,MAAM,CAAC,CAAC,EAAE,GAAG,UAAU,EAAE,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,GAAG,UAAU,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC"}
@@ -1,161 +0,0 @@
1
- /**
2
- * Middleware composition system for collections.
3
- *
4
- * Provides the core composition mechanism that allows behaviors to be
5
- * layered on top of collections using the decorator pattern.
6
- *
7
- * This is a specialized form of the unified middleware system (common/src/middleware)
8
- * optimized for synchronous collection operations. While the unified system supports
9
- * both sync and async with explicit context objects, collections use a simpler pattern
10
- * where the collection instance itself serves as the context.
11
- *
12
- * @example
13
- * const list = compose(
14
- * safeList(),
15
- * eventedList(),
16
- * boundedList({ capacity: 100 })
17
- * )(arrayList<number>())
18
- */
19
- // Implementation
20
- export function compose(...layers) {
21
- return (base) => layers.reduceRight((acc, layer) => layer(acc), base);
22
- }
23
- /**
24
- * Utility to check if a collection has a specific capability.
25
- * Useful for middleware that wants to conditionally enhance behavior.
26
- *
27
- * @example
28
- * if (hasCapability(collection, 'on')) {
29
- * // Collection supports events
30
- * collection.on('add', handler)
31
- * }
32
- */
33
- export const hasCapability = (collection, capability) => {
34
- return capability in collection;
35
- };
36
- /**
37
- * Helper to create a proxy that intercepts method calls.
38
- * Useful for implementing middleware that needs to wrap method invocations.
39
- *
40
- * @example
41
- * const logged = interceptMethods(collection, (target, method, args) => {
42
- * console.log(`Calling ${String(method)} with`, args)
43
- * const result = Reflect.apply(target[method], target, args)
44
- * console.log(`Result:`, result)
45
- * return result
46
- * })
47
- */
48
- export const interceptMethods = (target, interceptor) => {
49
- return new Proxy(target, {
50
- get(t, prop, receiver) {
51
- const value = Reflect.get(t, prop, receiver);
52
- if (typeof value === "function" && typeof prop === "string") {
53
- return function (...args) {
54
- return interceptor(t, prop, args);
55
- };
56
- }
57
- return value;
58
- },
59
- });
60
- };
61
- /**
62
- * Helper to create a readonly view of a collection by blocking mutating methods.
63
- *
64
- * @param mutatingMethods Set of method names that should be blocked
65
- * @param errorMessage Custom error message to throw
66
- */
67
- export const blockMethods = (target, mutatingMethods, errorMessage = "Operation not allowed") => {
68
- return new Proxy(target, {
69
- get(t, prop, receiver) {
70
- const value = Reflect.get(t, prop, receiver);
71
- if (typeof value === "function" && mutatingMethods.has(prop)) {
72
- return () => {
73
- throw new Error(errorMessage);
74
- };
75
- }
76
- return value;
77
- },
78
- });
79
- };
80
- /**
81
- * Helper to delegate method calls to a target while maintaining correct context.
82
- * Useful when wrapping collections.
83
- */
84
- export const delegate = (target, wrapper) => {
85
- return new Proxy(target, {
86
- get(t, prop, receiver) {
87
- // If wrapper has the property, use it
88
- if (prop in wrapper) {
89
- return Reflect.get(wrapper, prop, receiver);
90
- }
91
- // Otherwise delegate to target
92
- const value = Reflect.get(t, prop, receiver);
93
- // Bind methods to maintain correct 'this' context
94
- if (typeof value === "function") {
95
- return value.bind(t);
96
- }
97
- return value;
98
- },
99
- });
100
- };
101
- /**
102
- * Builder pattern helper for fluent API construction.
103
- *
104
- * @example
105
- * class ListBuilder<T> {
106
- * private middleware: Middleware<List<T>>[] = []
107
- *
108
- * bounded(capacity: number) {
109
- * this.middleware.push(boundedList({ capacity }))
110
- * return this
111
- * }
112
- *
113
- * evented() {
114
- * this.middleware.push(eventedList())
115
- * return this
116
- * }
117
- *
118
- * build(): List<T> {
119
- * return compose(...this.middleware)(arrayList<T>())
120
- * }
121
- * }
122
- */
123
- export class CollectionBuilder {
124
- middleware = [];
125
- /**
126
- * Apply a custom middleware.
127
- */
128
- use(middleware) {
129
- this.middleware.push(middleware);
130
- return this;
131
- }
132
- }
133
- /**
134
- * Utility to create a middleware that only enhances specific methods.
135
- *
136
- * @example
137
- * const logAdd = enhanceMethod('add', (original, args) => {
138
- * console.log('Adding:', args[0])
139
- * return original(...args)
140
- * })
141
- */
142
- export const enhanceMethod = (methodName, enhancer) => {
143
- return (next) => {
144
- return new Proxy(next, {
145
- get(target, prop, receiver) {
146
- const value = Reflect.get(target, prop, receiver);
147
- if (prop === methodName && typeof value === "function") {
148
- return function (...args) {
149
- return enhancer(value.bind(target), args);
150
- };
151
- }
152
- return value;
153
- },
154
- });
155
- };
156
- };
157
- // Implementation
158
- export function bundle(...middleware) {
159
- return (next) => compose(...middleware)(next);
160
- }
161
- //# sourceMappingURL=middleware.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../../src/collections/core/middleware.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAwFH,iBAAiB;AACjB,MAAM,UAAU,OAAO,CAAC,GAAG,MAA8B;IACvD,OAAO,CAAC,IAAS,EAAO,EAAE,CACxB,MAAM,CAAC,WAAW,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,CAAC;AACzD,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,UAAa,EACb,UAAa,EACyB,EAAE;IACxC,OAAO,UAAU,IAAI,UAAU,CAAC;AAClC,CAAC,CAAC;AA0EF;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,MAAS,EACT,WAAqE,EAClE,EAAE;IACL,OAAO,IAAI,KAAK,CAAC,MAAM,EAAE;QACvB,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ;YACnB,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;YAC7C,IAAI,OAAO,KAAK,KAAK,UAAU,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;gBAC5D,OAAO,UAAyB,GA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* Policies define how collections handle edge cases like overflow,
5
- * underflow, and eviction. These are used by behavior decorators
6
- * to provide flexible, composable behavior.
7
- */
8
- /**
9
- * Policy for handling overflow when adding to a full bounded collection.
10
- *
11
- * - 'throw': Throw an error when attempting to add to a full collection
12
- * - 'drop-oldest': Remove the oldest element and add the new one
13
- * - 'drop-newest': Ignore the new element (don't add it)
14
- * - 'reject': Return false/None but don't throw (graceful failure)
15
- * - 'grow': Automatically increase capacity (becomes unbounded)
16
- * - 'block': For async collections, wait until space is available
17
- */
18
- export type OverflowPolicy = "throw" | "drop-oldest" | "drop-newest" | "reject" | "grow" | "block";
19
- /**
20
- * Context information provided when overflow occurs.
21
- */
22
- export interface OverflowContext<T> {
23
- /** The element that triggered the overflow. */
24
- readonly newElement: T;
25
- /** Current size of the collection. */
26
- readonly currentSize: number;
27
- /** Maximum capacity of the collection. */
28
- readonly capacity: number;
29
- /** Timestamp when overflow occurred. */
30
- readonly timestamp: number;
31
- }
32
- /**
33
- * Callback invoked when overflow occurs.
34
- * Can be used for logging, metrics, or custom handling.
35
- */
36
- export type OverflowHandler<T> = (context: OverflowContext<T>) => void;
37
- /**
38
- * Policy for handling underflow when removing from an empty collection.
39
- *
40
- * - 'throw': Throw an error when attempting to remove from empty collection
41
- * - 'return-none': Return None/undefined (graceful failure)
42
- * - 'return-default': Return a default value provided by user
43
- * - 'block': For async collections, wait until an element is available
44
- */
45
- export type UnderflowPolicy = "throw" | "return-none" | "return-default" | "block";
46
- /**
47
- * Context information provided when underflow occurs.
48
- */
49
- export interface UnderflowContext {
50
- /** The operation that triggered the underflow. */
51
- readonly operation: string;
52
- /** Timestamp when underflow occurred. */
53
- readonly timestamp: number;
54
- }
55
- /**
56
- * Callback invoked when underflow occurs.
57
- */
58
- export type UnderflowHandler = (context: UnderflowContext) => void;
59
- /**
60
- * Policy for choosing which element to evict from a bounded collection.
61
- *
62
- * - 'lru': Least Recently Used - evict element not accessed for longest time
63
- * - 'lfu': Least Frequently Used - evict element accessed least often
64
- * - 'fifo': First In First Out - evict oldest inserted element
65
- * - 'lifo': Last In First Out - evict newest inserted element (stack-like)
66
- * - 'random': Evict a random element
67
- * - 'ttl': Time To Live - evict elements that have expired
68
- * - 'priority': Evict element with lowest priority
69
- * - 'custom': User-provided eviction function
70
- */
71
- export type EvictionPolicy = "lru" | "lfu" | "fifo" | "lifo" | "random" | "ttl" | "priority" | "custom";
72
- /**
73
- * Metadata tracked for eviction decisions.
74
- */
75
- export interface EvictionMetadata {
76
- /** When the element was inserted. */
77
- readonly insertedAt: number;
78
- /** When the element was last accessed. */
79
- lastAccessedAt: number;
80
- /** How many times the element has been accessed. */
81
- accessCount: number;
82
- /** Time-to-live expiration timestamp (if applicable). */
83
- readonly expiresAt?: number;
84
- /** Priority value (higher = more important, if applicable). */
85
- readonly priority?: number;
86
- }
87
- /**
88
- * Information about an element that can be evicted.
89
- */
90
- export interface EvictionCandidate<T> {
91
- /** The element value. */
92
- readonly element: T;
93
- /** Eviction metadata for this element. */
94
- readonly metadata: EvictionMetadata;
95
- }
96
- /**
97
- * Custom eviction function.
98
- * Given candidates, returns the element to evict.
99
- */
100
- export type EvictionSelector<T> = (candidates: EvictionCandidate<T>[]) => T | undefined;
101
- /**
102
- * Policy for retrying failed async operations.
103
- */
104
- export interface RetryPolicy {
105
- /** Maximum number of retry attempts. */
106
- readonly maxAttempts: number;
107
- /** Initial delay in milliseconds. */
108
- readonly initialDelay: number;
109
- /** Backoff strategy. */
110
- readonly backoff: "none" | "linear" | "exponential";
111
- /** Maximum delay cap (for backoff). */
112
- readonly maxDelay?: number;
113
- /** Jitter to add randomness and avoid thundering herd. */
114
- readonly jitter?: boolean;
115
- }
116
- /**
117
- * Context for retry decisions.
118
- */
119
- export interface RetryContext {
120
- /** Current attempt number (1-indexed). */
121
- readonly attempt: number;
122
- /** The error that caused the retry. */
123
- readonly error: unknown;
124
- /** Elapsed time since first attempt. */
125
- readonly elapsedMs: number;
126
- }
127
- /**
128
- * Callback to determine if an error is retryable.
129
- */
130
- export type RetryPredicate = (context: RetryContext) => boolean;
131
- /**
132
- * Policy for resolving conflicts when same key is modified concurrently.
133
- *
134
- * - 'last-write-wins': Most recent write takes precedence
135
- * - 'first-write-wins': First write takes precedence
136
- * - 'merge': Call merge function to combine values
137
- * - 'throw': Throw an error on conflict
138
- */
139
- export type ConflictResolutionPolicy = "last-write-wins" | "first-write-wins" | "merge" | "throw";
140
- /**
141
- * Function to merge conflicting values.
142
- */
143
- export type MergeFunction<T> = (current: T, incoming: T) => T;
144
- /**
145
- * Policy for when to compact internal storage.
146
- */
147
- export interface CompactionPolicy {
148
- /** Compact when capacity utilization drops below this ratio (0-1). */
149
- readonly minLoadFactor?: number;
150
- /** Compact when wasted space exceeds this many elements. */
151
- readonly maxWastedSpace?: number;
152
- /** Automatically compact on every removal. */
153
- readonly autoCompact?: boolean;
154
- }
155
- /**
156
- * Policy for how to grow capacity when needed.
157
- */
158
- export interface GrowthPolicy {
159
- /** Growth strategy. */
160
- readonly strategy: "double" | "linear" | "golden-ratio" | "custom";
161
- /** For linear growth, how many elements to add. */
162
- readonly linearIncrement?: number;
163
- /** For custom growth, a function to calculate new capacity. */
164
- readonly customGrowth?: (currentCapacity: number) => number;
165
- /** Maximum capacity limit (prevent unbounded growth). */
166
- readonly maxCapacity?: number;
167
- }
168
- /**
169
- * Validation action when an invalid element is encountered.
170
- *
171
- * - 'throw': Throw an error
172
- * - 'drop': Silently drop the invalid element
173
- * - 'coerce': Attempt to coerce to valid type
174
- * - 'log': Log warning but allow
175
- */
176
- export type ValidationPolicy = "throw" | "drop" | "coerce" | "log";
177
- /**
178
- * Context for validation failures.
179
- */
180
- export interface ValidationContext<T> {
181
- /** The invalid element. */
182
- readonly element: T;
183
- /** Validation error message/details. */
184
- readonly error: unknown;
185
- /** The operation that triggered validation. */
186
- readonly operation: string;
187
- }
188
- /**
189
- * Callback invoked on validation failures.
190
- */
191
- export type ValidationHandler<T> = (context: ValidationContext<T>) => void;
192
- /**
193
- * Default overflow policy: throw an error.
194
- */
195
- export declare const DEFAULT_OVERFLOW_POLICY: OverflowPolicy;
196
- /**
197
- * Default underflow policy: throw an error.
198
- */
199
- export declare const DEFAULT_UNDERFLOW_POLICY: UnderflowPolicy;
200
- /**
201
- * Default eviction policy: FIFO (oldest first).
202
- */
203
- export declare const DEFAULT_EVICTION_POLICY: EvictionPolicy;
204
- /**
205
- * Default retry policy: 3 attempts with exponential backoff.
206
- */
207
- export declare const DEFAULT_RETRY_POLICY: RetryPolicy;
208
- /**
209
- * Default conflict resolution: last write wins.
210
- */
211
- export declare const DEFAULT_CONFLICT_POLICY: ConflictResolutionPolicy;
212
- /**
213
- * Default growth policy: double capacity.
214
- */
215
- export declare const DEFAULT_GROWTH_POLICY: GrowthPolicy;
216
- /**
217
- * Default validation policy: throw on invalid.
218
- */
219
- export declare const DEFAULT_VALIDATION_POLICY: ValidationPolicy;
220
- //# sourceMappingURL=policies.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"policies.d.ts","sourceRoot":"","sources":["../../../src/collections/core/policies.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH;;;;;;;;;GASG;AACH,MAAM,MAAM,cAAc,GACtB,OAAO,GACP,aAAa,GACb,aAAa,GACb,QAAQ,GACR,MAAM,GACN,OAAO,CAAC;AAEZ;;GAEG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC;IAChC,+CAA+C;IAC/C,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC;IACvB,sCAAsC;IACtC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,0CAA0C;IAC1C,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,wCAAwC;IACxC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED;;;GAGG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;AAMvE;;;;;;;GAOG;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