@procedures/collections 0.46.0 → 0.47.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 (233) hide show
  1. package/CHANGELOG.md +42 -8
  2. package/README.md +30 -0
  3. package/dist/.tsbuildinfo +1 -1
  4. package/dist/index.d.ts +1 -58
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +3 -94
  7. package/dist/index.js.map +1 -1
  8. package/dist/storage/index.d.ts +2 -2
  9. package/dist/storage/index.d.ts.map +1 -1
  10. package/dist/storage/index.js +1 -1
  11. package/dist/storage/index.js.map +1 -1
  12. package/dist/storage/memory.d.ts +1 -1
  13. package/dist/storage/memory.d.ts.map +1 -1
  14. package/dist/storage/memory.js +1 -1
  15. package/dist/storage/memory.js.map +1 -1
  16. package/dist/testing/index.d.ts +1 -1
  17. package/dist/testing/index.d.ts.map +1 -1
  18. package/dist/testing/index.js +1 -1
  19. package/dist/testing/index.js.map +1 -1
  20. package/dist/testing/storage-contract.js +1 -1
  21. package/dist/testing/storage-contract.js.map +1 -1
  22. package/dist/undo/index.d.ts +1 -1
  23. package/dist/undo/index.js +1 -1
  24. package/dist/undo/undo-log.d.ts +1 -1
  25. package/dist/undo/undo-log.js +1 -1
  26. package/package.json +6 -6
  27. package/src/index.ts +338 -213
  28. package/src/storage/index.ts +2 -2
  29. package/src/storage/memory.ts +1 -1
  30. package/src/testing/index.ts +1 -1
  31. package/src/testing/storage-contract.ts +1 -1
  32. package/src/undo/index.ts +1 -1
  33. package/src/undo/undo-log.ts +1 -1
  34. package/dist/async/async-queue.d.ts +0 -170
  35. package/dist/async/async-queue.d.ts.map +0 -1
  36. package/dist/async/async-queue.js +0 -404
  37. package/dist/async/async-queue.js.map +0 -1
  38. package/dist/async/channels.d.ts +0 -211
  39. package/dist/async/channels.d.ts.map +0 -1
  40. package/dist/async/channels.js +0 -393
  41. package/dist/async/channels.js.map +0 -1
  42. package/dist/async/settled.d.ts +0 -23
  43. package/dist/async/settled.d.ts.map +0 -1
  44. package/dist/async/settled.js +0 -32
  45. package/dist/async/settled.js.map +0 -1
  46. package/dist/behaviors/bounded.d.ts +0 -79
  47. package/dist/behaviors/bounded.d.ts.map +0 -1
  48. package/dist/behaviors/bounded.js +0 -393
  49. package/dist/behaviors/bounded.js.map +0 -1
  50. package/dist/behaviors/composite.d.ts +0 -17
  51. package/dist/behaviors/composite.d.ts.map +0 -1
  52. package/dist/behaviors/composite.js +0 -93
  53. package/dist/behaviors/composite.js.map +0 -1
  54. package/dist/behaviors/evented.d.ts +0 -154
  55. package/dist/behaviors/evented.d.ts.map +0 -1
  56. package/dist/behaviors/evented.js +0 -299
  57. package/dist/behaviors/evented.js.map +0 -1
  58. package/dist/behaviors/lru.d.ts +0 -84
  59. package/dist/behaviors/lru.d.ts.map +0 -1
  60. package/dist/behaviors/lru.js +0 -376
  61. package/dist/behaviors/lru.js.map +0 -1
  62. package/dist/behaviors/readonly.d.ts +0 -73
  63. package/dist/behaviors/readonly.d.ts.map +0 -1
  64. package/dist/behaviors/readonly.js +0 -189
  65. package/dist/behaviors/readonly.js.map +0 -1
  66. package/dist/behaviors/safe.d.ts +0 -163
  67. package/dist/behaviors/safe.d.ts.map +0 -1
  68. package/dist/behaviors/safe.js +0 -176
  69. package/dist/behaviors/safe.js.map +0 -1
  70. package/dist/behaviors/synchronized.d.ts +0 -88
  71. package/dist/behaviors/synchronized.d.ts.map +0 -1
  72. package/dist/behaviors/synchronized.js +0 -285
  73. package/dist/behaviors/synchronized.js.map +0 -1
  74. package/dist/behaviors/ttl.d.ts +0 -118
  75. package/dist/behaviors/ttl.d.ts.map +0 -1
  76. package/dist/behaviors/ttl.js +0 -354
  77. package/dist/behaviors/ttl.js.map +0 -1
  78. package/dist/contracts/model.d.ts +0 -29
  79. package/dist/contracts/model.d.ts.map +0 -1
  80. package/dist/contracts/model.js +0 -26
  81. package/dist/contracts/model.js.map +0 -1
  82. package/dist/core/effects.d.ts +0 -176
  83. package/dist/core/effects.d.ts.map +0 -1
  84. package/dist/core/effects.js +0 -180
  85. package/dist/core/effects.js.map +0 -1
  86. package/dist/core/events.d.ts +0 -192
  87. package/dist/core/events.d.ts.map +0 -1
  88. package/dist/core/events.js +0 -291
  89. package/dist/core/events.js.map +0 -1
  90. package/dist/core/middleware.d.ts +0 -231
  91. package/dist/core/middleware.d.ts.map +0 -1
  92. package/dist/core/middleware.js +0 -161
  93. package/dist/core/middleware.js.map +0 -1
  94. package/dist/core/policies.d.ts +0 -220
  95. package/dist/core/policies.d.ts.map +0 -1
  96. package/dist/core/policies.js +0 -48
  97. package/dist/core/policies.js.map +0 -1
  98. package/dist/core/traits.d.ts +0 -142
  99. package/dist/core/traits.d.ts.map +0 -1
  100. package/dist/core/traits.js +0 -8
  101. package/dist/core/traits.js.map +0 -1
  102. package/dist/fx/collectors.d.ts +0 -193
  103. package/dist/fx/collectors.d.ts.map +0 -1
  104. package/dist/fx/collectors.js +0 -375
  105. package/dist/fx/collectors.js.map +0 -1
  106. package/dist/fx/iter.d.ts +0 -166
  107. package/dist/fx/iter.d.ts.map +0 -1
  108. package/dist/fx/iter.js +0 -421
  109. package/dist/fx/iter.js.map +0 -1
  110. package/dist/impl/array-deque.d.ts +0 -112
  111. package/dist/impl/array-deque.d.ts.map +0 -1
  112. package/dist/impl/array-deque.js +0 -380
  113. package/dist/impl/array-deque.js.map +0 -1
  114. package/dist/impl/array-list.d.ts +0 -101
  115. package/dist/impl/array-list.d.ts.map +0 -1
  116. package/dist/impl/array-list.js +0 -387
  117. package/dist/impl/array-list.js.map +0 -1
  118. package/dist/impl/hash-map.d.ts +0 -149
  119. package/dist/impl/hash-map.d.ts.map +0 -1
  120. package/dist/impl/hash-map.js +0 -473
  121. package/dist/impl/hash-map.js.map +0 -1
  122. package/dist/impl/hash-set.d.ts +0 -125
  123. package/dist/impl/hash-set.d.ts.map +0 -1
  124. package/dist/impl/hash-set.js +0 -264
  125. package/dist/impl/hash-set.js.map +0 -1
  126. package/dist/impl/linked-hash-map.d.ts +0 -141
  127. package/dist/impl/linked-hash-map.d.ts.map +0 -1
  128. package/dist/impl/linked-hash-map.js +0 -442
  129. package/dist/impl/linked-hash-map.js.map +0 -1
  130. package/dist/impl/linked-list.d.ts +0 -109
  131. package/dist/impl/linked-list.d.ts.map +0 -1
  132. package/dist/impl/linked-list.js +0 -494
  133. package/dist/impl/linked-list.js.map +0 -1
  134. package/dist/impl/priority-queue.d.ts +0 -139
  135. package/dist/impl/priority-queue.d.ts.map +0 -1
  136. package/dist/impl/priority-queue.js +0 -343
  137. package/dist/impl/priority-queue.js.map +0 -1
  138. package/dist/impl/tree-map.d.ts +0 -153
  139. package/dist/impl/tree-map.d.ts.map +0 -1
  140. package/dist/impl/tree-map.js +0 -788
  141. package/dist/impl/tree-map.js.map +0 -1
  142. package/dist/impl/tree-set.d.ts +0 -112
  143. package/dist/impl/tree-set.d.ts.map +0 -1
  144. package/dist/impl/tree-set.js +0 -374
  145. package/dist/impl/tree-set.js.map +0 -1
  146. package/dist/interfaces/collection.d.ts +0 -119
  147. package/dist/interfaces/collection.d.ts.map +0 -1
  148. package/dist/interfaces/collection.js +0 -8
  149. package/dist/interfaces/collection.js.map +0 -1
  150. package/dist/interfaces/list.d.ts +0 -247
  151. package/dist/interfaces/list.d.ts.map +0 -1
  152. package/dist/interfaces/list.js +0 -8
  153. package/dist/interfaces/list.js.map +0 -1
  154. package/dist/interfaces/map.d.ts +0 -344
  155. package/dist/interfaces/map.d.ts.map +0 -1
  156. package/dist/interfaces/map.js +0 -8
  157. package/dist/interfaces/map.js.map +0 -1
  158. package/dist/interfaces/queue.d.ts +0 -304
  159. package/dist/interfaces/queue.d.ts.map +0 -1
  160. package/dist/interfaces/queue.js +0 -8
  161. package/dist/interfaces/queue.js.map +0 -1
  162. package/dist/interfaces/set.d.ts +0 -137
  163. package/dist/interfaces/set.d.ts.map +0 -1
  164. package/dist/interfaces/set.js +0 -8
  165. package/dist/interfaces/set.js.map +0 -1
  166. package/dist/order/index.d.ts +0 -7
  167. package/dist/order/index.d.ts.map +0 -1
  168. package/dist/order/index.js +0 -7
  169. package/dist/order/index.js.map +0 -1
  170. package/dist/order/rank.d.ts +0 -100
  171. package/dist/order/rank.d.ts.map +0 -1
  172. package/dist/order/rank.js +0 -286
  173. package/dist/order/rank.js.map +0 -1
  174. package/dist/storage/listeners.d.ts +0 -39
  175. package/dist/storage/listeners.d.ts.map +0 -1
  176. package/dist/storage/listeners.js +0 -65
  177. package/dist/storage/listeners.js.map +0 -1
  178. package/dist/testing/check.d.ts +0 -25
  179. package/dist/testing/check.d.ts.map +0 -1
  180. package/dist/testing/check.js +0 -85
  181. package/dist/testing/check.js.map +0 -1
  182. package/dist/utils/defaults.d.ts +0 -135
  183. package/dist/utils/defaults.d.ts.map +0 -1
  184. package/dist/utils/defaults.js +0 -322
  185. package/dist/utils/defaults.js.map +0 -1
  186. package/dist/utils/factories.d.ts +0 -144
  187. package/dist/utils/factories.d.ts.map +0 -1
  188. package/dist/utils/factories.js +0 -293
  189. package/dist/utils/factories.js.map +0 -1
  190. package/dist/utils/helpers.d.ts +0 -137
  191. package/dist/utils/helpers.d.ts.map +0 -1
  192. package/dist/utils/helpers.js +0 -221
  193. package/dist/utils/helpers.js.map +0 -1
  194. package/src/async/async-queue.ts +0 -481
  195. package/src/async/channels.ts +0 -450
  196. package/src/async/settled.ts +0 -41
  197. package/src/behaviors/bounded.ts +0 -485
  198. package/src/behaviors/composite.ts +0 -99
  199. package/src/behaviors/evented.ts +0 -464
  200. package/src/behaviors/lru.ts +0 -447
  201. package/src/behaviors/readonly.ts +0 -236
  202. package/src/behaviors/safe.ts +0 -372
  203. package/src/behaviors/synchronized.ts +0 -316
  204. package/src/behaviors/ttl.ts +0 -462
  205. package/src/contracts/model.ts +0 -44
  206. package/src/core/effects.ts +0 -323
  207. package/src/core/events.ts +0 -356
  208. package/src/core/middleware.ts +0 -415
  209. package/src/core/policies.ts +0 -316
  210. package/src/core/traits.ts +0 -164
  211. package/src/fx/collectors.ts +0 -500
  212. package/src/fx/iter.ts +0 -536
  213. package/src/impl/array-deque.ts +0 -463
  214. package/src/impl/array-list.ts +0 -490
  215. package/src/impl/hash-map.ts +0 -623
  216. package/src/impl/hash-set.ts +0 -342
  217. package/src/impl/linked-hash-map.ts +0 -572
  218. package/src/impl/linked-list.ts +0 -606
  219. package/src/impl/priority-queue.ts +0 -448
  220. package/src/impl/tree-map.ts +0 -912
  221. package/src/impl/tree-set.ts +0 -469
  222. package/src/interfaces/collection.ts +0 -141
  223. package/src/interfaces/list.ts +0 -281
  224. package/src/interfaces/map.ts +0 -405
  225. package/src/interfaces/queue.ts +0 -353
  226. package/src/interfaces/set.ts +0 -158
  227. package/src/order/index.ts +0 -6
  228. package/src/order/rank.ts +0 -271
  229. package/src/storage/listeners.ts +0 -72
  230. package/src/testing/check.ts +0 -81
  231. package/src/utils/defaults.ts +0 -345
  232. package/src/utils/factories.ts +0 -357
  233. package/src/utils/helpers.ts +0 -248
@@ -1,248 +0,0 @@
1
- /**
2
- * Common helper utilities for collections.
3
- *
4
- * Provides shared functionality to reduce code duplication across implementations.
5
- */
6
-
7
- import type { Eq } from "../core/traits.js";
8
-
9
- // ============================================================================
10
- // Bounds checking utilities
11
- // ============================================================================
12
-
13
- /**
14
- * Checks if an index is within valid bounds [0, size).
15
- * Throws RangeError if out of bounds.
16
- *
17
- * @param index The index to check
18
- * @param size The size of the collection
19
- * @param collectionName Optional name for error message
20
- * @throws RangeError if index is out of bounds
21
- */
22
- export function checkBounds(index: number, size: number, collectionName: string = "Collection"): void {
23
- if (index < 0 || index >= size) {
24
- throw new RangeError(`${collectionName}: Index ${index} out of bounds [0, ${size})`);
25
- }
26
- }
27
-
28
- /**
29
- * Checks if an index is valid for insertion [0, size].
30
- * Allows index === size for append operations.
31
- *
32
- * @param index The index to check
33
- * @param size The size of the collection
34
- * @param collectionName Optional name for error message
35
- * @throws RangeError if index is out of bounds
36
- */
37
- export function checkInsertBounds(index: number, size: number, collectionName: string = "Collection"): void {
38
- if (index < 0 || index > size) {
39
- throw new RangeError(`${collectionName}: Index ${index} out of bounds [0, ${size}]`);
40
- }
41
- }
42
-
43
- /**
44
- * Checks if a range [start, end) is valid.
45
- *
46
- * @param start Start index (inclusive)
47
- * @param end End index (exclusive)
48
- * @param size The size of the collection
49
- * @param collectionName Optional name for error message
50
- * @throws RangeError if range is invalid
51
- */
52
- export function checkRangeBounds(
53
- start: number,
54
- end: number,
55
- size: number,
56
- collectionName: string = "Collection"
57
- ): void {
58
- if (start < 0 || end > size || start > end) {
59
- throw new RangeError(
60
- `${collectionName}: Invalid range [${start}, ${end}) for size ${size}`
61
- );
62
- }
63
- }
64
-
65
- // ============================================================================
66
- // Equality and search utilities
67
- // ============================================================================
68
-
69
- /**
70
- * Finds the index of an element in an array using custom equality.
71
- *
72
- * @param array The array to search
73
- * @param element The element to find
74
- * @param eq Equality function
75
- * @returns Index of element, or -1 if not found
76
- */
77
- export function findIndex<T>(array: T[], element: T, eq: Eq<T>): number {
78
- for (let i = 0; i < array.length; i++) {
79
- if (eq(array[i]!, element)) {
80
- return i;
81
- }
82
- }
83
- return -1;
84
- }
85
-
86
- /**
87
- * Finds the last index of an element in an array using custom equality.
88
- *
89
- * @param array The array to search
90
- * @param element The element to find
91
- * @param eq Equality function
92
- * @returns Last index of element, or -1 if not found
93
- */
94
- export function findLastIndex<T>(array: T[], element: T, eq: Eq<T>): number {
95
- for (let i = array.length - 1; i >= 0; i--) {
96
- if (eq(array[i]!, element)) {
97
- return i;
98
- }
99
- }
100
- return -1;
101
- }
102
-
103
- /**
104
- * Checks if an array contains an element using custom equality.
105
- *
106
- * @param array The array to search
107
- * @param element The element to find
108
- * @param eq Equality function
109
- * @returns true if element is found
110
- */
111
- export function arrayContains<T>(array: T[], element: T, eq: Eq<T>): boolean {
112
- return findIndex(array, element, eq) !== -1;
113
- }
114
-
115
- /**
116
- * Removes the first occurrence of an element from an array.
117
- *
118
- * @param array The array to modify
119
- * @param element The element to remove
120
- * @param eq Equality function
121
- * @returns true if element was found and removed
122
- */
123
- export function arrayRemove<T>(array: T[], element: T, eq: Eq<T>): boolean {
124
- const index = findIndex(array, element, eq);
125
- if (index === -1) return false;
126
- array.splice(index, 1);
127
- return true;
128
- }
129
-
130
- /**
131
- * Removes all occurrences of an element from an array.
132
- *
133
- * @param array The array to modify
134
- * @param element The element to remove
135
- * @param eq Equality function
136
- * @returns Number of elements removed
137
- */
138
- export function arrayRemoveAll<T>(array: T[], element: T, eq: Eq<T>): number {
139
- let count = 0;
140
- for (let i = array.length - 1; i >= 0; i--) {
141
- if (eq(array[i]!, element)) {
142
- array.splice(i, 1);
143
- count++;
144
- }
145
- }
146
- return count;
147
- }
148
-
149
- // ============================================================================
150
- // Iterator utilities
151
- // ============================================================================
152
-
153
- /**
154
- * Creates a simple iterator for an array.
155
- *
156
- * @param array The array to iterate
157
- * @returns Iterator over the array
158
- */
159
- export function* arrayIterator<T>(array: T[]): Iterator<T> {
160
- yield* array;
161
- }
162
-
163
- /**
164
- * Creates a reversed iterator for an array.
165
- *
166
- * @param array The array to iterate
167
- * @returns Reversed iterator over the array
168
- */
169
- export function* reverseArrayIterator<T>(array: T[]): Iterator<T> {
170
- for (let i = array.length - 1; i >= 0; i--) {
171
- yield array[i]!;
172
- }
173
- }
174
-
175
- /**
176
- * Converts an iterable to an array.
177
- *
178
- * @param iterable The iterable to convert
179
- * @returns Array containing all elements
180
- */
181
- export function toArray<T>(iterable: Iterable<T>): T[] {
182
- return Array.from(iterable);
183
- }
184
-
185
- // ============================================================================
186
- // Validation utilities
187
- // ============================================================================
188
-
189
- /**
190
- * Ensures a value is not null or undefined.
191
- *
192
- * @param value The value to check
193
- * @param message Error message
194
- * @returns The non-null value
195
- * @throws Error if value is null or undefined
196
- */
197
- export function requireNonNull<T>(value: T | null | undefined, message: string = "Value cannot be null or undefined"): T {
198
- if (value === null || value === undefined) {
199
- throw new Error(message);
200
- }
201
- return value;
202
- }
203
-
204
- /**
205
- * Ensures a collection is not empty.
206
- *
207
- * @param size Current size
208
- * @param collectionName Optional name for error message
209
- * @throws Error if collection is empty
210
- */
211
- export function requireNonEmpty(size: number, collectionName: string = "Collection"): void {
212
- if (size === 0) {
213
- throw new Error(`${collectionName} is empty`);
214
- }
215
- }
216
-
217
- // ============================================================================
218
- // Math utilities
219
- // ============================================================================
220
-
221
- /**
222
- * Clamps a value between min and max.
223
- *
224
- * @param value The value to clamp
225
- * @param min Minimum value
226
- * @param max Maximum value
227
- * @returns Clamped value
228
- */
229
- export function clamp(value: number, min: number, max: number): number {
230
- return Math.max(min, Math.min(max, value));
231
- }
232
-
233
- /**
234
- * Calculates hash code for a string.
235
- * Uses Java's String.hashCode() algorithm.
236
- *
237
- * @param str The string to hash
238
- * @returns Hash code
239
- */
240
- export function stringHashCode(str: string): number {
241
- let hash = 0;
242
- for (let i = 0; i < str.length; i++) {
243
- const char = str.charCodeAt(i);
244
- hash = ((hash << 5) - hash) + char;
245
- hash = hash & hash; // Convert to 32-bit integer
246
- }
247
- return hash;
248
- }