@procedures/client 0.2.0 → 0.2.1

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 (236) hide show
  1. package/CHANGELOG.md +6 -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/server/host-policy.d.ts +3 -3
  12. package/dist/server/host-policy.d.ts.map +1 -1
  13. package/dist/server/procedure-server.d.ts +2 -2
  14. package/dist/server/procedure-server.d.ts.map +1 -1
  15. package/dist/server/procedure-server.js.map +1 -1
  16. package/package.json +1 -1
  17. package/src/browser.ts +1 -0
  18. package/src/procedures/invoke.ts +10 -4
  19. package/src/server/host-policy.ts +3 -3
  20. package/src/server/procedure-server.ts +2 -2
  21. package/dist/client/middleware/batching.d.ts +0 -102
  22. package/dist/client/middleware/batching.d.ts.map +0 -1
  23. package/dist/client/middleware/batching.js +0 -245
  24. package/dist/client/middleware/batching.js.map +0 -1
  25. package/dist/collections/async/async-queue.d.ts +0 -144
  26. package/dist/collections/async/async-queue.d.ts.map +0 -1
  27. package/dist/collections/async/async-queue.js +0 -347
  28. package/dist/collections/async/async-queue.js.map +0 -1
  29. package/dist/collections/async/channels.d.ts +0 -188
  30. package/dist/collections/async/channels.d.ts.map +0 -1
  31. package/dist/collections/async/channels.js +0 -312
  32. package/dist/collections/async/channels.js.map +0 -1
  33. package/dist/collections/behaviors/bounded.d.ts +0 -79
  34. package/dist/collections/behaviors/bounded.d.ts.map +0 -1
  35. package/dist/collections/behaviors/bounded.js +0 -384
  36. package/dist/collections/behaviors/bounded.js.map +0 -1
  37. package/dist/collections/behaviors/evented.d.ts +0 -154
  38. package/dist/collections/behaviors/evented.d.ts.map +0 -1
  39. package/dist/collections/behaviors/evented.js +0 -299
  40. package/dist/collections/behaviors/evented.js.map +0 -1
  41. package/dist/collections/behaviors/lru.d.ts +0 -84
  42. package/dist/collections/behaviors/lru.d.ts.map +0 -1
  43. package/dist/collections/behaviors/lru.js +0 -330
  44. package/dist/collections/behaviors/lru.js.map +0 -1
  45. package/dist/collections/behaviors/readonly.d.ts +0 -73
  46. package/dist/collections/behaviors/readonly.d.ts.map +0 -1
  47. package/dist/collections/behaviors/readonly.js +0 -158
  48. package/dist/collections/behaviors/readonly.js.map +0 -1
  49. package/dist/collections/behaviors/safe.d.ts +0 -163
  50. package/dist/collections/behaviors/safe.d.ts.map +0 -1
  51. package/dist/collections/behaviors/safe.js +0 -172
  52. package/dist/collections/behaviors/safe.js.map +0 -1
  53. package/dist/collections/behaviors/synchronized.d.ts +0 -88
  54. package/dist/collections/behaviors/synchronized.d.ts.map +0 -1
  55. package/dist/collections/behaviors/synchronized.js +0 -294
  56. package/dist/collections/behaviors/synchronized.js.map +0 -1
  57. package/dist/collections/behaviors/ttl.d.ts +0 -118
  58. package/dist/collections/behaviors/ttl.d.ts.map +0 -1
  59. package/dist/collections/behaviors/ttl.js +0 -338
  60. package/dist/collections/behaviors/ttl.js.map +0 -1
  61. package/dist/collections/core/effects.d.ts +0 -176
  62. package/dist/collections/core/effects.d.ts.map +0 -1
  63. package/dist/collections/core/effects.js +0 -180
  64. package/dist/collections/core/effects.js.map +0 -1
  65. package/dist/collections/core/events.d.ts +0 -192
  66. package/dist/collections/core/events.d.ts.map +0 -1
  67. package/dist/collections/core/events.js +0 -291
  68. package/dist/collections/core/events.js.map +0 -1
  69. package/dist/collections/core/middleware.d.ts +0 -231
  70. package/dist/collections/core/middleware.d.ts.map +0 -1
  71. package/dist/collections/core/middleware.js +0 -161
  72. package/dist/collections/core/middleware.js.map +0 -1
  73. package/dist/collections/core/policies.d.ts +0 -220
  74. package/dist/collections/core/policies.d.ts.map +0 -1
  75. package/dist/collections/core/policies.js +0 -48
  76. package/dist/collections/core/policies.js.map +0 -1
  77. package/dist/collections/core/traits.d.ts +0 -142
  78. package/dist/collections/core/traits.d.ts.map +0 -1
  79. package/dist/collections/core/traits.js +0 -8
  80. package/dist/collections/core/traits.js.map +0 -1
  81. package/dist/collections/examples.d.ts +0 -13
  82. package/dist/collections/examples.d.ts.map +0 -1
  83. package/dist/collections/examples.js +0 -302
  84. package/dist/collections/examples.js.map +0 -1
  85. package/dist/collections/fx/collectors.d.ts +0 -190
  86. package/dist/collections/fx/collectors.d.ts.map +0 -1
  87. package/dist/collections/fx/collectors.js +0 -369
  88. package/dist/collections/fx/collectors.js.map +0 -1
  89. package/dist/collections/fx/iter.d.ts +0 -166
  90. package/dist/collections/fx/iter.d.ts.map +0 -1
  91. package/dist/collections/fx/iter.js +0 -421
  92. package/dist/collections/fx/iter.js.map +0 -1
  93. package/dist/collections/impl/array-deque.d.ts +0 -107
  94. package/dist/collections/impl/array-deque.d.ts.map +0 -1
  95. package/dist/collections/impl/array-deque.js +0 -381
  96. package/dist/collections/impl/array-deque.js.map +0 -1
  97. package/dist/collections/impl/array-list.d.ts +0 -101
  98. package/dist/collections/impl/array-list.d.ts.map +0 -1
  99. package/dist/collections/impl/array-list.js +0 -387
  100. package/dist/collections/impl/array-list.js.map +0 -1
  101. package/dist/collections/impl/hash-map.d.ts +0 -141
  102. package/dist/collections/impl/hash-map.d.ts.map +0 -1
  103. package/dist/collections/impl/hash-map.js +0 -450
  104. package/dist/collections/impl/hash-map.js.map +0 -1
  105. package/dist/collections/impl/hash-set.d.ts +0 -125
  106. package/dist/collections/impl/hash-set.d.ts.map +0 -1
  107. package/dist/collections/impl/hash-set.js +0 -264
  108. package/dist/collections/impl/hash-set.js.map +0 -1
  109. package/dist/collections/impl/linked-hash-map.d.ts +0 -141
  110. package/dist/collections/impl/linked-hash-map.d.ts.map +0 -1
  111. package/dist/collections/impl/linked-hash-map.js +0 -472
  112. package/dist/collections/impl/linked-hash-map.js.map +0 -1
  113. package/dist/collections/impl/linked-list.d.ts +0 -109
  114. package/dist/collections/impl/linked-list.d.ts.map +0 -1
  115. package/dist/collections/impl/linked-list.js +0 -491
  116. package/dist/collections/impl/linked-list.js.map +0 -1
  117. package/dist/collections/impl/priority-queue.d.ts +0 -134
  118. package/dist/collections/impl/priority-queue.d.ts.map +0 -1
  119. package/dist/collections/impl/priority-queue.js +0 -336
  120. package/dist/collections/impl/priority-queue.js.map +0 -1
  121. package/dist/collections/impl/tree-map.d.ts +0 -146
  122. package/dist/collections/impl/tree-map.d.ts.map +0 -1
  123. package/dist/collections/impl/tree-map.js +0 -781
  124. package/dist/collections/impl/tree-map.js.map +0 -1
  125. package/dist/collections/impl/tree-set.d.ts +0 -112
  126. package/dist/collections/impl/tree-set.d.ts.map +0 -1
  127. package/dist/collections/impl/tree-set.js +0 -374
  128. package/dist/collections/impl/tree-set.js.map +0 -1
  129. package/dist/collections/index.d.ts +0 -105
  130. package/dist/collections/index.d.ts.map +0 -1
  131. package/dist/collections/index.js +0 -135
  132. package/dist/collections/index.js.map +0 -1
  133. package/dist/collections/interfaces/collection.d.ts +0 -119
  134. package/dist/collections/interfaces/collection.d.ts.map +0 -1
  135. package/dist/collections/interfaces/collection.js +0 -8
  136. package/dist/collections/interfaces/collection.js.map +0 -1
  137. package/dist/collections/interfaces/list.d.ts +0 -247
  138. package/dist/collections/interfaces/list.d.ts.map +0 -1
  139. package/dist/collections/interfaces/list.js +0 -8
  140. package/dist/collections/interfaces/list.js.map +0 -1
  141. package/dist/collections/interfaces/map.d.ts +0 -344
  142. package/dist/collections/interfaces/map.d.ts.map +0 -1
  143. package/dist/collections/interfaces/map.js +0 -8
  144. package/dist/collections/interfaces/map.js.map +0 -1
  145. package/dist/collections/interfaces/queue.d.ts +0 -304
  146. package/dist/collections/interfaces/queue.d.ts.map +0 -1
  147. package/dist/collections/interfaces/queue.js +0 -8
  148. package/dist/collections/interfaces/queue.js.map +0 -1
  149. package/dist/collections/interfaces/set.d.ts +0 -137
  150. package/dist/collections/interfaces/set.d.ts.map +0 -1
  151. package/dist/collections/interfaces/set.js +0 -8
  152. package/dist/collections/interfaces/set.js.map +0 -1
  153. package/dist/collections/storage/api.d.ts +0 -109
  154. package/dist/collections/storage/api.d.ts.map +0 -1
  155. package/dist/collections/storage/api.js +0 -182
  156. package/dist/collections/storage/api.js.map +0 -1
  157. package/dist/collections/storage/hybrid.d.ts +0 -164
  158. package/dist/collections/storage/hybrid.d.ts.map +0 -1
  159. package/dist/collections/storage/hybrid.js +0 -416
  160. package/dist/collections/storage/hybrid.js.map +0 -1
  161. package/dist/collections/storage/index.d.ts +0 -16
  162. package/dist/collections/storage/index.d.ts.map +0 -1
  163. package/dist/collections/storage/index.js +0 -13
  164. package/dist/collections/storage/index.js.map +0 -1
  165. package/dist/collections/storage/interface.d.ts +0 -141
  166. package/dist/collections/storage/interface.d.ts.map +0 -1
  167. package/dist/collections/storage/interface.js +0 -23
  168. package/dist/collections/storage/interface.js.map +0 -1
  169. package/dist/collections/storage/memory.d.ts +0 -68
  170. package/dist/collections/storage/memory.d.ts.map +0 -1
  171. package/dist/collections/storage/memory.js +0 -154
  172. package/dist/collections/storage/memory.js.map +0 -1
  173. package/dist/collections/utils/defaults.d.ts +0 -135
  174. package/dist/collections/utils/defaults.d.ts.map +0 -1
  175. package/dist/collections/utils/defaults.js +0 -322
  176. package/dist/collections/utils/defaults.js.map +0 -1
  177. package/dist/collections/utils/factories.d.ts +0 -144
  178. package/dist/collections/utils/factories.d.ts.map +0 -1
  179. package/dist/collections/utils/factories.js +0 -293
  180. package/dist/collections/utils/factories.js.map +0 -1
  181. package/dist/collections/utils/helpers.d.ts +0 -137
  182. package/dist/collections/utils/helpers.d.ts.map +0 -1
  183. package/dist/collections/utils/helpers.js +0 -221
  184. package/dist/collections/utils/helpers.js.map +0 -1
  185. package/dist/collections.d.ts +0 -12
  186. package/dist/collections.d.ts.map +0 -1
  187. package/dist/collections.js +0 -10
  188. package/dist/collections.js.map +0 -1
  189. package/dist/components/define.d.ts +0 -134
  190. package/dist/components/define.d.ts.map +0 -1
  191. package/dist/components/define.js +0 -486
  192. package/dist/components/define.js.map +0 -1
  193. package/dist/components/index.d.ts +0 -39
  194. package/dist/components/index.d.ts.map +0 -1
  195. package/dist/components/index.js +0 -38
  196. package/dist/components/index.js.map +0 -1
  197. package/dist/components/types.d.ts +0 -264
  198. package/dist/components/types.d.ts.map +0 -1
  199. package/dist/components/types.js +0 -46
  200. package/dist/components/types.js.map +0 -1
  201. package/dist/procedures/storage/adapter.d.ts +0 -148
  202. package/dist/procedures/storage/adapter.d.ts.map +0 -1
  203. package/dist/procedures/storage/adapter.js +0 -214
  204. package/dist/procedures/storage/adapter.js.map +0 -1
  205. package/dist/procedures/storage/api.d.ts +0 -125
  206. package/dist/procedures/storage/api.d.ts.map +0 -1
  207. package/dist/procedures/storage/api.js +0 -220
  208. package/dist/procedures/storage/api.js.map +0 -1
  209. package/dist/procedures/storage/factory.d.ts +0 -134
  210. package/dist/procedures/storage/factory.d.ts.map +0 -1
  211. package/dist/procedures/storage/factory.js +0 -166
  212. package/dist/procedures/storage/factory.js.map +0 -1
  213. package/dist/procedures/storage/hybrid.d.ts +0 -193
  214. package/dist/procedures/storage/hybrid.d.ts.map +0 -1
  215. package/dist/procedures/storage/hybrid.js +0 -519
  216. package/dist/procedures/storage/hybrid.js.map +0 -1
  217. package/dist/procedures/storage/index.d.ts +0 -17
  218. package/dist/procedures/storage/index.d.ts.map +0 -1
  219. package/dist/procedures/storage/index.js +0 -17
  220. package/dist/procedures/storage/index.js.map +0 -1
  221. package/dist/procedures/storage/procedures.d.ts +0 -39
  222. package/dist/procedures/storage/procedures.d.ts.map +0 -1
  223. package/dist/procedures/storage/procedures.js +0 -261
  224. package/dist/procedures/storage/procedures.js.map +0 -1
  225. package/dist/procedures/storage/serialization.d.ts +0 -123
  226. package/dist/procedures/storage/serialization.d.ts.map +0 -1
  227. package/dist/procedures/storage/serialization.js +0 -216
  228. package/dist/procedures/storage/serialization.js.map +0 -1
  229. package/dist/procedures/storage/synced-registry.d.ts +0 -246
  230. package/dist/procedures/storage/synced-registry.d.ts.map +0 -1
  231. package/dist/procedures/storage/synced-registry.js +0 -575
  232. package/dist/procedures/storage/synced-registry.js.map +0 -1
  233. package/dist/procedures/storage/types.d.ts +0 -130
  234. package/dist/procedures/storage/types.d.ts.map +0 -1
  235. package/dist/procedures/storage/types.js +0 -8
  236. package/dist/procedures/storage/types.js.map +0 -1
@@ -1,68 +0,0 @@
1
- /**
2
- * In-Memory Storage Implementation
3
- *
4
- * Fast, volatile storage using JavaScript Map.
5
- * All operations return Promises for interface consistency.
6
- */
7
- import type { CollectionStorage, StorageMetadata } from "./interface.js";
8
- /**
9
- * In-memory storage backed by JavaScript Map.
10
- *
11
- * Features:
12
- * - Fast lookups O(1)
13
- * - No persistence (data lost on restart)
14
- * - Memory-bound (limited by available RAM)
15
- * - Returns Promises for API consistency with remote storage
16
- *
17
- * @example
18
- * ```typescript
19
- * const storage = new InMemoryStorage<User>();
20
- * await storage.set("123", { id: "123", name: "John" });
21
- * const user = await storage.get("123"); // { id: "123", name: "John" }
22
- * ```
23
- */
24
- export declare class InMemoryStorage<T> implements CollectionStorage<T> {
25
- private data;
26
- get(id: string): Promise<T | undefined>;
27
- getAll(): Promise<T[]>;
28
- find(predicate: (item: T) => boolean): Promise<T[]>;
29
- has(id: string): Promise<boolean>;
30
- size(): Promise<number>;
31
- set(id: string, value: T): Promise<void>;
32
- delete(id: string): Promise<boolean>;
33
- clear(): Promise<void>;
34
- setBatch(items: Array<[string, T]>): Promise<void>;
35
- deleteBatch(ids: string[]): Promise<number>;
36
- getBatch(ids: string[]): Promise<Map<string, T>>;
37
- close(): Promise<void>;
38
- getMetadata(): Promise<StorageMetadata>;
39
- /**
40
- * Get all keys in storage.
41
- *
42
- * @returns Iterator of keys
43
- */
44
- keys(): IterableIterator<string>;
45
- /**
46
- * Get all values in storage.
47
- *
48
- * @returns Iterator of values
49
- */
50
- values(): IterableIterator<T>;
51
- /**
52
- * Get all entries in storage.
53
- *
54
- * @returns Iterator of [id, value] tuples
55
- */
56
- entries(): IterableIterator<[string, T]>;
57
- /**
58
- * Iterate over storage entries.
59
- *
60
- * @param callback - Function to call for each entry
61
- */
62
- forEach(callback: (value: T, key: string, map: Map<string, T>) => void): void;
63
- /**
64
- * Make storage iterable.
65
- */
66
- [Symbol.iterator](): IterableIterator<[string, T]>;
67
- }
68
- //# sourceMappingURL=memory.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../../src/collections/storage/memory.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEzE;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,eAAe,CAAC,CAAC,CAAE,YAAW,iBAAiB,CAAC,CAAC,CAAC;IAC7D,OAAO,CAAC,IAAI,CAAwB;IAMpC,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAIvC,MAAM,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC;IAItB,IAAI,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC;IAUnD,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAIjC,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC;IAQvB,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAKxC,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAIpC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAStB,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAOlD,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAU3C,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IAehD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAMtB,WAAW,IAAI,OAAO,CAAC,eAAe,CAAC;IAmBvC;;;;OAIG;IACH,IAAI,IAAI,gBAAgB,CAAC,MAAM,CAAC;IAIhC;;;;OAIG;IACH,MAAM,IAAI,gBAAgB,CAAC,CAAC,CAAC;IAI7B;;;;OAIG;IACH,OAAO,IAAI,gBAAgB,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IAIxC;;;;OAIG;IACH,OAAO,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,KAAK,IAAI,GAAG,IAAI;IAI7E;;OAEG;IACH,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,gBAAgB,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;CAGnD"}
@@ -1,154 +0,0 @@
1
- /**
2
- * In-Memory Storage Implementation
3
- *
4
- * Fast, volatile storage using JavaScript Map.
5
- * All operations return Promises for interface consistency.
6
- */
7
- /**
8
- * In-memory storage backed by JavaScript Map.
9
- *
10
- * Features:
11
- * - Fast lookups O(1)
12
- * - No persistence (data lost on restart)
13
- * - Memory-bound (limited by available RAM)
14
- * - Returns Promises for API consistency with remote storage
15
- *
16
- * @example
17
- * ```typescript
18
- * const storage = new InMemoryStorage<User>();
19
- * await storage.set("123", { id: "123", name: "John" });
20
- * const user = await storage.get("123"); // { id: "123", name: "John" }
21
- * ```
22
- */
23
- export class InMemoryStorage {
24
- data = new Map();
25
- //
26
- // ═══ Read Operations ═══
27
- //
28
- get(id) {
29
- return Promise.resolve(this.data.get(id));
30
- }
31
- getAll() {
32
- return Promise.resolve(Array.from(this.data.values()));
33
- }
34
- find(predicate) {
35
- const results = [];
36
- for (const item of this.data.values()) {
37
- if (predicate(item)) {
38
- results.push(item);
39
- }
40
- }
41
- return Promise.resolve(results);
42
- }
43
- has(id) {
44
- return Promise.resolve(this.data.has(id));
45
- }
46
- size() {
47
- return Promise.resolve(this.data.size);
48
- }
49
- //
50
- // ═══ Write Operations ═══
51
- //
52
- set(id, value) {
53
- this.data.set(id, value);
54
- return Promise.resolve();
55
- }
56
- delete(id) {
57
- return Promise.resolve(this.data.delete(id));
58
- }
59
- clear() {
60
- this.data.clear();
61
- return Promise.resolve();
62
- }
63
- //
64
- // ═══ Bulk Operations ═══
65
- //
66
- setBatch(items) {
67
- for (const [id, value] of items) {
68
- this.data.set(id, value);
69
- }
70
- return Promise.resolve();
71
- }
72
- deleteBatch(ids) {
73
- let deleted = 0;
74
- for (const id of ids) {
75
- if (this.data.delete(id)) {
76
- deleted++;
77
- }
78
- }
79
- return Promise.resolve(deleted);
80
- }
81
- getBatch(ids) {
82
- const result = new Map();
83
- for (const id of ids) {
84
- const value = this.data.get(id);
85
- if (value !== undefined) {
86
- result.set(id, value);
87
- }
88
- }
89
- return Promise.resolve(result);
90
- }
91
- //
92
- // ═══ Lifecycle & Metadata ═══
93
- //
94
- close() {
95
- // No cleanup needed for in-memory storage
96
- this.data.clear();
97
- return Promise.resolve();
98
- }
99
- getMetadata() {
100
- // Rough memory estimation:
101
- // Each entry has ~overhead of 100 bytes (key string + Map entry overhead)
102
- const estimatedEntrySize = 100;
103
- const memoryUsage = this.data.size * estimatedEntrySize;
104
- return Promise.resolve({
105
- type: "memory",
106
- size: this.data.size,
107
- stats: {
108
- memoryUsage,
109
- },
110
- });
111
- }
112
- //
113
- // ═══ Additional Methods (Map compatibility) ═══
114
- //
115
- /**
116
- * Get all keys in storage.
117
- *
118
- * @returns Iterator of keys
119
- */
120
- keys() {
121
- return this.data.keys();
122
- }
123
- /**
124
- * Get all values in storage.
125
- *
126
- * @returns Iterator of values
127
- */
128
- values() {
129
- return this.data.values();
130
- }
131
- /**
132
- * Get all entries in storage.
133
- *
134
- * @returns Iterator of [id, value] tuples
135
- */
136
- entries() {
137
- return this.data.entries();
138
- }
139
- /**
140
- * Iterate over storage entries.
141
- *
142
- * @param callback - Function to call for each entry
143
- */
144
- forEach(callback) {
145
- this.data.forEach(callback);
146
- }
147
- /**
148
- * Make storage iterable.
149
- */
150
- [Symbol.iterator]() {
151
- return this.data.entries();
152
- }
153
- }
154
- //# sourceMappingURL=memory.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"memory.js","sourceRoot":"","sources":["../../../src/collections/storage/memory.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH;;;;;;;;;;;;;;;GAeG;AACH,MAAM,OAAO,eAAe;IAClB,IAAI,GAAG,IAAI,GAAG,EAAa,CAAC;IAEpC,EAAE;IACF,0BAA0B;IAC1B,EAAE;IAEF,GAAG,CAAC,EAAU;QACZ,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;IAC5C,CAAC;IAED,MAAM;QACJ,OAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IACzD,CAAC;IAED,IAAI,CAAC,SAA+B;QAClC,MAAM,OAAO,GAAQ,EAAE,CAAC;QACxB,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC;YACtC,IAAI,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;gBACpB,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACrB,CAAC;QACH,CAAC;QACD,OAAO,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC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AED;;;;OAIG;IACH,OAAO,CAAC,QAA8D;QACpE,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC9B,CAAC;IAED;;OAEG;IACH,CAAC,MAAM,CAAC,QAAQ,CAAC;QACf,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;IAC7B,CAAC;CACF"}
@@ -1,135 +0,0 @@
1
- /**
2
- * Default implementations of equality, hashing, and comparison functions.
3
- *
4
- * Provides sensible defaults for primitive types and utilities for
5
- * creating custom comparators.
6
- */
7
- import type { Eq, Hash, Compare } from "../core/traits.js";
8
- /**
9
- * Default equality using strict equality (===).
10
- * Works for primitives and reference equality for objects.
11
- */
12
- export declare const defaultEq: Eq<any>;
13
- /**
14
- * Structural equality for objects (shallow comparison of properties).
15
- * Compares own enumerable properties using ===.
16
- */
17
- export declare const shallowEq: Eq<any>;
18
- /**
19
- * Deep structural equality (recursive comparison).
20
- * Handles nested objects and arrays.
21
- */
22
- export declare const deepEq: Eq<any>;
23
- /**
24
- * Equality by comparing a specific property.
25
- *
26
- * @example
27
- * const userEq = eqBy<User, 'id'>('id')
28
- * // or with accessor function:
29
- * const userEq = eqBy<User>((u) => u.id)
30
- */
31
- export declare const eqBy: <T, K extends keyof T = keyof T>(keyOrFn: K | ((value: T) => any)) => Eq<T>;
32
- /**
33
- * Default hash function for primitives and objects.
34
- * For objects, hashes the JSON string representation.
35
- */
36
- export declare const defaultHash: Hash<any>;
37
- /**
38
- * Hash function for strings using djb2 algorithm.
39
- */
40
- export declare const hashString: (str: string) => number;
41
- /**
42
- * Hash function for numbers.
43
- */
44
- export declare const hashNumber: (num: number) => number;
45
- /**
46
- * Combine multiple hash values.
47
- * Useful for hashing objects with multiple fields.
48
- *
49
- * @example
50
- * const pointHash: Hash<Point> = (p) =>
51
- * combineHashes(hashNumber(p.x), hashNumber(p.y))
52
- */
53
- export declare const combineHashes: (...hashes: number[]) => number;
54
- /**
55
- * Create a hash function that hashes by a specific property.
56
- *
57
- * @example
58
- * const userHash = hashBy<User>((u) => u.id)
59
- */
60
- export declare const hashBy: <T>(accessor: (value: T) => any) => Hash<T>;
61
- /**
62
- * Natural ordering comparison for primitives.
63
- * Numbers, strings, booleans, dates are compared naturally.
64
- */
65
- export declare const defaultCompare: Compare<any>;
66
- /**
67
- * Numeric comparison (for numbers).
68
- */
69
- export declare const numberCompare: Compare<number>;
70
- /**
71
- * String comparison using locale-aware sorting.
72
- */
73
- export declare const stringCompare: Compare<string>;
74
- /**
75
- * Case-insensitive string comparison.
76
- */
77
- export declare const stringCompareIgnoreCase: Compare<string>;
78
- /**
79
- * Date comparison.
80
- */
81
- export declare const dateCompare: Compare<Date>;
82
- /**
83
- * Boolean comparison (false < true).
84
- */
85
- export declare const booleanCompare: Compare<boolean>;
86
- /**
87
- * Reverses a comparator.
88
- *
89
- * @example
90
- * const descending = reversed(numberCompare)
91
- */
92
- export declare const reversed: <T>(compare: Compare<T>) => Compare<T>;
93
- /**
94
- * Creates a comparator that compares by a specific property or function.
95
- *
96
- * @example
97
- * const byAge = comparing<Person>((p) => p.age)
98
- * const byName = comparing<Person, 'name'>('name')
99
- */
100
- export declare const comparing: <T, K extends keyof T = keyof T>(keyOrFn: K | ((value: T) => any), compare?: Compare<any>) => Compare<T>;
101
- /**
102
- * Chains comparators. If the first comparator returns 0 (equal),
103
- * tries the next comparator, and so on.
104
- *
105
- * @example
106
- * const userCompare = thenComparing(
107
- * comparing<User>('lastName'),
108
- * comparing<User>('firstName'),
109
- * comparing<User>('age')
110
- * )
111
- */
112
- export declare const thenComparing: <T>(...comparators: Compare<T>[]) => Compare<T>;
113
- /**
114
- * Creates a comparator that treats null/undefined as less than all other values.
115
- *
116
- * @example
117
- * const compare = nullsFirst(numberCompare)
118
- */
119
- export declare const nullsFirst: <T>(compare: Compare<T>) => Compare<T | null | undefined>;
120
- /**
121
- * Creates a comparator that treats null/undefined as greater than all other values.
122
- *
123
- * @example
124
- * const compare = nullsLast(numberCompare)
125
- */
126
- export declare const nullsLast: <T>(compare: Compare<T>) => Compare<T | null | undefined>;
127
- /**
128
- * Creates a comparator from a key extraction function.
129
- * Elements are compared by their extracted keys.
130
- *
131
- * @example
132
- * const byLength = comparingKey<string>((s) => s.length)
133
- */
134
- export declare const comparingKey: <T, K>(keyExtractor: (value: T) => K, keyCompare?: Compare<K>) => Compare<T>;
135
- //# sourceMappingURL=defaults.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../../../src/collections/utils/defaults.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAM3D;;;GAGG;AACH,eAAO,MAAM,SAAS,EAAE,EAAE,CAAC,GAAG,CAAqB,CAAC;AAEpD;;;GAGG;AACH,eAAO,MAAM,SAAS,EAAE,EAAE,CAAC,GAAG,CAgB7B,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,MAAM,EAAE,EAAE,CAAC,GAAG,CA0B1B,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,IAAI,GAAI,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,GAAG,MAAM,CAAC,EACjD,SAAS,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,KAAK,GAAG,CAAC,KAC/B,EAAE,CAAC,CAAC,CAGN,CAAC;AAMF;;;GAGG;AACH,eAAO,MAAM,WAAW,EAAE,IAAI,CAAC,GAAG,CA6BjC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,UAAU,GAAI,KAAK,MAAM,KAAG,MAOxC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,UAAU,GAAI,KAAK,MAAM,KAAG,MAWxC,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,GAAI,GAAG,QAAQ,MAAM,EAAE,KAAG,MAOnD,CAAC;AAEF;;;;;GAKG;AACH,e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;;;GAKG;AACH,eAAO,MAAM,SAAS,GAAI,CAAC,EAAE,SAAS,OAAO,CAAC,CAAC,CAAC,KAAG,OAAO,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,CAO9E,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,GAAI,CAAC,EAAE,CAAC,EAC/B,cAAc,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,EAC7B,aAAY,OAAO,CAAC,CAAC,CAAkB,KACtC,OAAO,CAAC,CAAC,CAEX,CAAC"}
@@ -1,322 +0,0 @@
1
- /**
2
- * Default implementations of equality, hashing, and comparison functions.
3
- *
4
- * Provides sensible defaults for primitive types and utilities for
5
- * creating custom comparators.
6
- */
7
- // ============================================================================
8
- // Default Equality
9
- // ============================================================================
10
- /**
11
- * Default equality using strict equality (===).
12
- * Works for primitives and reference equality for objects.
13
- */
14
- export const defaultEq = (a, b) => a === b;
15
- /**
16
- * Structural equality for objects (shallow comparison of properties).
17
- * Compares own enumerable properties using ===.
18
- */
19
- export const shallowEq = (a, b) => {
20
- if (a === b)
21
- return true;
22
- if (typeof a !== "object" || typeof b !== "object")
23
- return false;
24
- if (a === null || b === null)
25
- return false;
26
- const keysA = Object.keys(a);
27
- const keysB = Object.keys(b);
28
- if (keysA.length !== keysB.length)
29
- return false;
30
- for (const key of keysA) {
31
- if (!Object.prototype.hasOwnProperty.call(b, key))
32
- return false;
33
- if (a[key] !== b[key])
34
- return false;
35
- }
36
- return true;
37
- };
38
- /**
39
- * Deep structural equality (recursive comparison).
40
- * Handles nested objects and arrays.
41
- */
42
- export const deepEq = (a, b) => {
43
- if (a === b)
44
- return true;
45
- if (typeof a !== typeof b)
46
- return false;
47
- if (typeof a !== "object" || a === null || b === null)
48
- return false;
49
- if (Array.isArray(a) && Array.isArray(b)) {
50
- if (a.length !== b.length)
51
- return false;
52
- for (let i = 0; i < a.length; i++) {
53
- if (!deepEq(a[i], b[i]))
54
- return false;
55
- }
56
- return true;
57
- }
58
- if (Array.isArray(a) !== Array.isArray(b))
59
- return false;
60
- const keysA = Object.keys(a);
61
- const keysB = Object.keys(b);
62
- if (keysA.length !== keysB.length)
63
- return false;
64
- for (const key of keysA) {
65
- if (!Object.prototype.hasOwnProperty.call(b, key))
66
- return false;
67
- if (!deepEq(a[key], b[key]))
68
- return false;
69
- }
70
- return true;
71
- };
72
- /**
73
- * Equality by comparing a specific property.
74
- *
75
- * @example
76
- * const userEq = eqBy<User, 'id'>('id')
77
- * // or with accessor function:
78
- * const userEq = eqBy<User>((u) => u.id)
79
- */
80
- export const eqBy = (keyOrFn) => {
81
- const accessor = typeof keyOrFn === "function" ? keyOrFn : (v) => v[keyOrFn];
82
- return (a, b) => accessor(a) === accessor(b);
83
- };
84
- // ============================================================================
85
- // Default Hashing
86
- // ============================================================================
87
- /**
88
- * Default hash function for primitives and objects.
89
- * For objects, hashes the JSON string representation.
90
- */
91
- export const defaultHash = (value) => {
92
- if (value === null)
93
- return 0;
94
- if (value === undefined)
95
- return 1;
96
- const type = typeof value;
97
- switch (type) {
98
- case "boolean":
99
- return value ? 1 : 0;
100
- case "number":
101
- return hashNumber(value);
102
- case "string":
103
- return hashString(value);
104
- case "symbol":
105
- return hashString(value.toString());
106
- case "bigint":
107
- return hashString(value.toString());
108
- case "object":
109
- // For objects, hash their JSON representation
110
- // This is not ideal for all cases but provides a reasonable default
111
- try {
112
- return hashString(JSON.stringify(value));
113
- }
114
- catch {
115
- // If JSON.stringify fails, fall back to toString
116
- return hashString(value.toString());
117
- }
118
- default:
119
- return 2;
120
- }
121
- };
122
- /**
123
- * Hash function for strings using djb2 algorithm.
124
- */
125
- export const hashString = (str) => {
126
- let hash = 5381;
127
- for (let i = 0; i < str.length; i++) {
128
- hash = ((hash << 5) + hash) + str.charCodeAt(i); // hash * 33 + c
129
- hash = hash & hash; // Convert to 32-bit integer
130
- }
131
- return hash >>> 0; // Convert to unsigned
132
- };
133
- /**
134
- * Hash function for numbers.
135
- */
136
- export const hashNumber = (num) => {
137
- if (Number.isNaN(num))
138
- return 0;
139
- if (!Number.isFinite(num))
140
- return num > 0 ? 1 : -1;
141
- // For integers, use the number itself
142
- if (Number.isInteger(num)) {
143
- return num | 0; // Convert to 32-bit int
144
- }
145
- // For floats, hash the string representation
146
- return hashString(num.toString());
147
- };
148
- /**
149
- * Combine multiple hash values.
150
- * Useful for hashing objects with multiple fields.
151
- *
152
- * @example
153
- * const pointHash: Hash<Point> = (p) =>
154
- * combineHashes(hashNumber(p.x), hashNumber(p.y))
155
- */
156
- export const combineHashes = (...hashes) => {
157
- let combined = 0;
158
- for (const hash of hashes) {
159
- combined = ((combined << 5) - combined) + hash;
160
- combined = combined & combined; // Convert to 32-bit int
161
- }
162
- return combined >>> 0; // Convert to unsigned
163
- };
164
- /**
165
- * Create a hash function that hashes by a specific property.
166
- *
167
- * @example
168
- * const userHash = hashBy<User>((u) => u.id)
169
- */
170
- export const hashBy = (accessor) => {
171
- return (value) => defaultHash(accessor(value));
172
- };
173
- // ============================================================================
174
- // Default Comparison
175
- // ============================================================================
176
- /**
177
- * Natural ordering comparison for primitives.
178
- * Numbers, strings, booleans, dates are compared naturally.
179
- */
180
- export const defaultCompare = (a, b) => {
181
- if (a === b)
182
- return 0;
183
- if (a === null || a === undefined)
184
- return -1;
185
- if (b === null || b === undefined)
186
- return 1;
187
- // Handle dates
188
- if (a instanceof Date && b instanceof Date) {
189
- return a.getTime() - b.getTime();
190
- }
191
- // Handle numbers
192
- if (typeof a === "number" && typeof b === "number") {
193
- if (Number.isNaN(a))
194
- return Number.isNaN(b) ? 0 : -1;
195
- if (Number.isNaN(b))
196
- return 1;
197
- return a - b;
198
- }
199
- // Handle strings
200
- if (typeof a === "string" && typeof b === "string") {
201
- return a.localeCompare(b);
202
- }
203
- // Handle booleans
204
- if (typeof a === "boolean" && typeof b === "boolean") {
205
- return a === b ? 0 : a ? 1 : -1;
206
- }
207
- // Fallback: convert to string and compare
208
- return String(a).localeCompare(String(b));
209
- };
210
- /**
211
- * Numeric comparison (for numbers).
212
- */
213
- export const numberCompare = (a, b) => {
214
- if (Number.isNaN(a))
215
- return Number.isNaN(b) ? 0 : -1;
216
- if (Number.isNaN(b))
217
- return 1;
218
- return a - b;
219
- };
220
- /**
221
- * String comparison using locale-aware sorting.
222
- */
223
- export const stringCompare = (a, b) => a.localeCompare(b);
224
- /**
225
- * Case-insensitive string comparison.
226
- */
227
- export const stringCompareIgnoreCase = (a, b) => a.toLowerCase().localeCompare(b.toLowerCase());
228
- /**
229
- * Date comparison.
230
- */
231
- export const dateCompare = (a, b) => a.getTime() - b.getTime();
232
- /**
233
- * Boolean comparison (false < true).
234
- */
235
- export const booleanCompare = (a, b) => a === b ? 0 : a ? 1 : -1;
236
- // ============================================================================
237
- // Comparator Combinators
238
- // ============================================================================
239
- /**
240
- * Reverses a comparator.
241
- *
242
- * @example
243
- * const descending = reversed(numberCompare)
244
- */
245
- export const reversed = (compare) => (a, b) => compare(b, a);
246
- /**
247
- * Creates a comparator that compares by a specific property or function.
248
- *
249
- * @example
250
- * const byAge = comparing<Person>((p) => p.age)
251
- * const byName = comparing<Person, 'name'>('name')
252
- */
253
- export const comparing = (keyOrFn, compare = defaultCompare) => {
254
- const accessor = typeof keyOrFn === "function" ? keyOrFn : (v) => v[keyOrFn];
255
- return (a, b) => compare(accessor(a), accessor(b));
256
- };
257
- /**
258
- * Chains comparators. If the first comparator returns 0 (equal),
259
- * tries the next comparator, and so on.
260
- *
261
- * @example
262
- * const userCompare = thenComparing(
263
- * comparing<User>('lastName'),
264
- * comparing<User>('firstName'),
265
- * comparing<User>('age')
266
- * )
267
- */
268
- export const thenComparing = (...comparators) => {
269
- return (a, b) => {
270
- for (const compare of comparators) {
271
- const result = compare(a, b);
272
- if (result !== 0)
273
- return result;
274
- }
275
- return 0;
276
- };
277
- };
278
- /**
279
- * Creates a comparator that treats null/undefined as less than all other values.
280
- *
281
- * @example
282
- * const compare = nullsFirst(numberCompare)
283
- */
284
- export const nullsFirst = (compare) => {
285
- return (a, b) => {
286
- if (a == null && b == null)
287
- return 0;
288
- if (a == null)
289
- return -1;
290
- if (b == null)
291
- return 1;
292
- return compare(a, b);
293
- };
294
- };
295
- /**
296
- * Creates a comparator that treats null/undefined as greater than all other values.
297
- *
298
- * @example
299
- * const compare = nullsLast(numberCompare)
300
- */
301
- export const nullsLast = (compare) => {
302
- return (a, b) => {
303
- if (a == null && b == null)
304
- return 0;
305
- if (a == null)
306
- return 1;
307
- if (b == null)
308
- return -1;
309
- return compare(a, b);
310
- };
311
- };
312
- /**
313
- * Creates a comparator from a key extraction function.
314
- * Elements are compared by their extracted keys.
315
- *
316
- * @example
317
- * const byLength = comparingKey<string>((s) => s.length)
318
- */
319
- export const comparingKey = (keyExtractor, keyCompare = defaultCompare) => {
320
- return (a, b) => keyCompare(keyExtractor(a), keyExtractor(b));
321
- };
322
- //# sourceMappingURL=defaults.js.map