@procedures/collections 0.47.1 → 0.48.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (238) hide show
  1. package/CHANGELOG.md +32 -8
  2. package/README.md +3 -1
  3. package/dist/.tsbuildinfo +1 -1
  4. package/dist/index.d.ts +1 -59
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +3 -95
  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 +5 -5
  27. package/src/index.ts +338 -214
  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/summary-tree.d.ts +0 -146
  139. package/dist/impl/summary-tree.d.ts.map +0 -1
  140. package/dist/impl/summary-tree.js +0 -524
  141. package/dist/impl/summary-tree.js.map +0 -1
  142. package/dist/impl/tree-map.d.ts +0 -153
  143. package/dist/impl/tree-map.d.ts.map +0 -1
  144. package/dist/impl/tree-map.js +0 -788
  145. package/dist/impl/tree-map.js.map +0 -1
  146. package/dist/impl/tree-set.d.ts +0 -112
  147. package/dist/impl/tree-set.d.ts.map +0 -1
  148. package/dist/impl/tree-set.js +0 -374
  149. package/dist/impl/tree-set.js.map +0 -1
  150. package/dist/interfaces/collection.d.ts +0 -119
  151. package/dist/interfaces/collection.d.ts.map +0 -1
  152. package/dist/interfaces/collection.js +0 -8
  153. package/dist/interfaces/collection.js.map +0 -1
  154. package/dist/interfaces/list.d.ts +0 -247
  155. package/dist/interfaces/list.d.ts.map +0 -1
  156. package/dist/interfaces/list.js +0 -8
  157. package/dist/interfaces/list.js.map +0 -1
  158. package/dist/interfaces/map.d.ts +0 -344
  159. package/dist/interfaces/map.d.ts.map +0 -1
  160. package/dist/interfaces/map.js +0 -8
  161. package/dist/interfaces/map.js.map +0 -1
  162. package/dist/interfaces/queue.d.ts +0 -304
  163. package/dist/interfaces/queue.d.ts.map +0 -1
  164. package/dist/interfaces/queue.js +0 -8
  165. package/dist/interfaces/queue.js.map +0 -1
  166. package/dist/interfaces/set.d.ts +0 -137
  167. package/dist/interfaces/set.d.ts.map +0 -1
  168. package/dist/interfaces/set.js +0 -8
  169. package/dist/interfaces/set.js.map +0 -1
  170. package/dist/order/index.d.ts +0 -7
  171. package/dist/order/index.d.ts.map +0 -1
  172. package/dist/order/index.js +0 -7
  173. package/dist/order/index.js.map +0 -1
  174. package/dist/order/rank.d.ts +0 -100
  175. package/dist/order/rank.d.ts.map +0 -1
  176. package/dist/order/rank.js +0 -286
  177. package/dist/order/rank.js.map +0 -1
  178. package/dist/storage/listeners.d.ts +0 -39
  179. package/dist/storage/listeners.d.ts.map +0 -1
  180. package/dist/storage/listeners.js +0 -65
  181. package/dist/storage/listeners.js.map +0 -1
  182. package/dist/testing/check.d.ts +0 -25
  183. package/dist/testing/check.d.ts.map +0 -1
  184. package/dist/testing/check.js +0 -85
  185. package/dist/testing/check.js.map +0 -1
  186. package/dist/utils/defaults.d.ts +0 -135
  187. package/dist/utils/defaults.d.ts.map +0 -1
  188. package/dist/utils/defaults.js +0 -322
  189. package/dist/utils/defaults.js.map +0 -1
  190. package/dist/utils/factories.d.ts +0 -144
  191. package/dist/utils/factories.d.ts.map +0 -1
  192. package/dist/utils/factories.js +0 -293
  193. package/dist/utils/factories.js.map +0 -1
  194. package/dist/utils/helpers.d.ts +0 -137
  195. package/dist/utils/helpers.d.ts.map +0 -1
  196. package/dist/utils/helpers.js +0 -221
  197. package/dist/utils/helpers.js.map +0 -1
  198. package/src/async/async-queue.ts +0 -481
  199. package/src/async/channels.ts +0 -450
  200. package/src/async/settled.ts +0 -41
  201. package/src/behaviors/bounded.ts +0 -485
  202. package/src/behaviors/composite.ts +0 -99
  203. package/src/behaviors/evented.ts +0 -464
  204. package/src/behaviors/lru.ts +0 -447
  205. package/src/behaviors/readonly.ts +0 -236
  206. package/src/behaviors/safe.ts +0 -372
  207. package/src/behaviors/synchronized.ts +0 -316
  208. package/src/behaviors/ttl.ts +0 -462
  209. package/src/contracts/model.ts +0 -44
  210. package/src/core/effects.ts +0 -323
  211. package/src/core/events.ts +0 -356
  212. package/src/core/middleware.ts +0 -415
  213. package/src/core/policies.ts +0 -316
  214. package/src/core/traits.ts +0 -164
  215. package/src/fx/collectors.ts +0 -500
  216. package/src/fx/iter.ts +0 -536
  217. package/src/impl/array-deque.ts +0 -463
  218. package/src/impl/array-list.ts +0 -490
  219. package/src/impl/hash-map.ts +0 -623
  220. package/src/impl/hash-set.ts +0 -342
  221. package/src/impl/linked-hash-map.ts +0 -572
  222. package/src/impl/linked-list.ts +0 -606
  223. package/src/impl/priority-queue.ts +0 -448
  224. package/src/impl/summary-tree.ts +0 -586
  225. package/src/impl/tree-map.ts +0 -912
  226. package/src/impl/tree-set.ts +0 -469
  227. package/src/interfaces/collection.ts +0 -141
  228. package/src/interfaces/list.ts +0 -281
  229. package/src/interfaces/map.ts +0 -405
  230. package/src/interfaces/queue.ts +0 -353
  231. package/src/interfaces/set.ts +0 -158
  232. package/src/order/index.ts +0 -6
  233. package/src/order/rank.ts +0 -271
  234. package/src/storage/listeners.ts +0 -72
  235. package/src/testing/check.ts +0 -81
  236. package/src/utils/defaults.ts +0 -345
  237. package/src/utils/factories.ts +0 -357
  238. package/src/utils/helpers.ts +0 -248
@@ -1,286 +0,0 @@
1
- /**
2
- * The keys of an ordered list (Graph's split, wave 2, W1): fractional indexing with base-62 keys. A
3
- * key is a string. Each item of the list keeps one, and the list sorts by it. An item that moves
4
- * between two others gets a key between theirs, so a move writes one item and no other.
5
- *
6
- * - A key has an integer part and a fraction part. The first character of the integer part gives its
7
- * length. An insertion at an end changes the integer part, so the keys stay short. An insertion
8
- * between two keys uses the fraction part, which can grow without a limit: the keys never run out,
9
- * and the list needs no rebalance.
10
- * - Compare two keys by the code units of the strings (`a < b`), never with `localeCompare`.
11
- * - Two writers that move items into the same gap at the same time can get the same key. Sort by the
12
- * key, then by the id of the item, so each reader sees one order.
13
- *
14
- * The algorithm is the one of the `fractional-indexing` package of Rocicorp (CC0), after the article
15
- * "Implementing Fractional Indexing" of David Greenspan.
16
- */
17
- /** The digits of a key, in ascending order of their code units. */
18
- export const KEY_DIGITS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
19
- const ZERO = KEY_DIGITS[0];
20
- const LAST = KEY_DIGITS[KEY_DIGITS.length - 1];
21
- /** The smallest integer part. No key comes before it. */
22
- const SMALLEST_INTEGER = `A${ZERO.repeat(26)}`;
23
- function invalid(message) {
24
- return new RangeError(message);
25
- }
26
- /** The length of the integer part that starts with a head character: a to z give 2 to 27, Z to A give 2 to 27. */
27
- function integerLength(head) {
28
- if (head >= "a" && head <= "z")
29
- return head.charCodeAt(0) - "a".charCodeAt(0) + 2;
30
- if (head >= "A" && head <= "Z")
31
- return "Z".charCodeAt(0) - head.charCodeAt(0) + 2;
32
- throw invalid(`A key cannot start with "${head}"`);
33
- }
34
- function integerPart(key) {
35
- const length = integerLength(key[0] ?? "");
36
- if (length > key.length)
37
- throw invalid(`The key "${key}" is too short for its integer part`);
38
- return key.slice(0, length);
39
- }
40
- function validateKey(key) {
41
- if (typeof key !== "string" || key === "")
42
- throw invalid("A key is a string that is not empty");
43
- for (const c of key)
44
- if (!KEY_DIGITS.includes(c))
45
- throw invalid(`The key "${key}" has a character that is no digit of a key`);
46
- if (key === SMALLEST_INTEGER)
47
- throw invalid(`The key "${key}" is reserved`);
48
- const fraction = key.slice(integerPart(key).length);
49
- if (fraction.endsWith(ZERO))
50
- throw invalid(`The fraction part of the key "${key}" ends with ${ZERO}`);
51
- }
52
- /** A fraction strictly between two fractions. `b` null is the end. Neither one ends with the zero digit. */
53
- function midpoint(a, b) {
54
- if (b !== null) {
55
- let n = 0;
56
- while ((a[n] ?? ZERO) === b[n])
57
- n++;
58
- if (n > 0)
59
- return b.slice(0, n) + midpoint(a.slice(n), b.slice(n));
60
- }
61
- const digitA = a ? KEY_DIGITS.indexOf(a[0]) : 0;
62
- const digitB = b !== null ? KEY_DIGITS.indexOf(b[0]) : KEY_DIGITS.length;
63
- if (digitB - digitA > 1)
64
- return KEY_DIGITS[Math.round((digitA + digitB) / 2)];
65
- // The first digits are next to each other
66
- if (b !== null && b.length > 1)
67
- return b.slice(0, 1);
68
- return KEY_DIGITS[digitA] + midpoint(a.slice(1), null);
69
- }
70
- function incrementInteger(x) {
71
- const [head, ...digits] = x.split("");
72
- let carry = true;
73
- for (let i = digits.length - 1; carry && i >= 0; i--) {
74
- const d = KEY_DIGITS.indexOf(digits[i]) + 1;
75
- if (d === KEY_DIGITS.length)
76
- digits[i] = ZERO;
77
- else {
78
- digits[i] = KEY_DIGITS[d];
79
- carry = false;
80
- }
81
- }
82
- if (!carry)
83
- return head + digits.join("");
84
- if (head === "Z")
85
- return `a${ZERO}`;
86
- if (head === "z")
87
- return null;
88
- const next = String.fromCharCode(head.charCodeAt(0) + 1);
89
- if (next > "a")
90
- digits.push(ZERO);
91
- else
92
- digits.pop();
93
- return next + digits.join("");
94
- }
95
- function decrementInteger(x) {
96
- const [head, ...digits] = x.split("");
97
- let borrow = true;
98
- for (let i = digits.length - 1; borrow && i >= 0; i--) {
99
- const d = KEY_DIGITS.indexOf(digits[i]) - 1;
100
- if (d === -1)
101
- digits[i] = LAST;
102
- else {
103
- digits[i] = KEY_DIGITS[d];
104
- borrow = false;
105
- }
106
- }
107
- if (!borrow)
108
- return head + digits.join("");
109
- if (head === "a")
110
- return `Z${LAST}`;
111
- if (head === "A")
112
- return null;
113
- const next = String.fromCharCode(head.charCodeAt(0) - 1);
114
- if (next < "Z")
115
- digits.push(LAST);
116
- else
117
- digits.pop();
118
- return next + digits.join("");
119
- }
120
- /**
121
- * This function gives a key strictly between two keys. Without `prev`, the key comes before `next`.
122
- * Without `next`, it comes after `prev`. Without both, it gives the first key of a list ("a0").
123
- *
124
- * @throws RangeError when a key is not valid, or when `prev` is not before `next`
125
- *
126
- * @example
127
- * ```ts
128
- * keyBetween(undefined, undefined); // "a0"
129
- * keyBetween("a0", undefined); // "a1", after a0
130
- * keyBetween("a0", "a1"); // "a0V"
131
- * ```
132
- */
133
- export function keyBetween(prev, next) {
134
- const a = prev ?? null;
135
- const b = next ?? null;
136
- if (a !== null)
137
- validateKey(a);
138
- if (b !== null)
139
- validateKey(b);
140
- if (a !== null && b !== null && a >= b)
141
- throw invalid(`The key "${a}" is not before the key "${b}"`);
142
- if (a === null) {
143
- if (b === null)
144
- return `a${ZERO}`;
145
- const ib = integerPart(b);
146
- const fb = b.slice(ib.length);
147
- if (ib === SMALLEST_INTEGER)
148
- return ib + midpoint("", fb);
149
- if (ib < b)
150
- return ib;
151
- const decremented = decrementInteger(ib);
152
- if (decremented === null)
153
- throw invalid("No key comes before this one");
154
- return decremented;
155
- }
156
- const ia = integerPart(a);
157
- const fa = a.slice(ia.length);
158
- if (b === null) {
159
- const incremented = incrementInteger(ia);
160
- return incremented === null ? ia + midpoint(fa, null) : incremented;
161
- }
162
- const ib = integerPart(b);
163
- const fb = b.slice(ib.length);
164
- if (ia === ib)
165
- return ia + midpoint(fa, fb);
166
- const incremented = incrementInteger(ia);
167
- if (incremented === null)
168
- throw invalid("No key comes after this one");
169
- if (incremented < b)
170
- return incremented;
171
- return ia + midpoint(fa, null);
172
- }
173
- /**
174
- * This function gives `count` keys in ascending order, strictly between two keys, for example to put
175
- * several items at one place, or to give keys to the items of a list for the first time.
176
- *
177
- * @throws RangeError as `keyBetween`, or when `count` is not an integer of 0 or more
178
- */
179
- export function keysBetween(prev, next, count) {
180
- if (!Number.isInteger(count) || count < 0)
181
- throw invalid(`A count of keys is an integer of 0 or more, not ${count}`);
182
- const a = prev ?? null;
183
- const b = next ?? null;
184
- if (count === 0)
185
- return [];
186
- if (count === 1)
187
- return [keyBetween(a, b)];
188
- if (b === null) {
189
- const keys = [keyBetween(a, null)];
190
- for (let i = 1; i < count; i++)
191
- keys.push(keyBetween(keys[i - 1], null));
192
- return keys;
193
- }
194
- if (a === null) {
195
- const keys = [keyBetween(null, b)];
196
- for (let i = 1; i < count; i++)
197
- keys.push(keyBetween(null, keys[i - 1]));
198
- return keys.reverse();
199
- }
200
- const half = Math.floor(count / 2);
201
- const middle = keyBetween(a, b);
202
- return [...keysBetween(a, middle, half), middle, ...keysBetween(middle, b, count - half - 1)];
203
- }
204
- /**
205
- * This function tells if a value is a valid key, for example a key that a client writes. A key that
206
- * is longer than `maxLength` is not valid.
207
- */
208
- export function isValidKey(key, options = {}) {
209
- if (typeof key !== "string" || key.length > (options.maxLength ?? 1024))
210
- return false;
211
- try {
212
- validateKey(key);
213
- return true;
214
- }
215
- catch {
216
- return false;
217
- }
218
- }
219
- /**
220
- * This function gives the writes of a move: the new key of the item that moves, and new keys for the
221
- * neighbors that need them. Give the other items of the list in order (by key, then by id), without
222
- * the item that moves, and the index of the drop from 0 to their number (`dropIndex`).
223
- *
224
- * Two writers can give two items one key. A drop between two such items has no key between them, so
225
- * the helper first gives new keys to the items after the drop that have the key of the item before
226
- * it. Each write is `{ id, key }`. The writes of the neighbors come first, and the write of the item
227
- * that moves comes last.
228
- *
229
- * @throws RangeError when the index is outside the list, when the list holds the item that moves, or
230
- * when a key is not valid
231
- *
232
- * @example
233
- * ```ts
234
- * const index = dropIndex(pointer, others.map(centerOf));
235
- * for (const { id, key } of keysForDrop(others, index, dragged.id)) await save(id, { rank: key });
236
- * ```
237
- */
238
- export function keysForDrop(items, index, movingId) {
239
- if (!Number.isInteger(index) || index < 0 || index > items.length)
240
- throw invalid(`The index ${index} is outside the list of ${items.length} items`);
241
- if (items.some((item) => item.id === movingId))
242
- throw invalid(`The list holds the item that moves (${movingId})`);
243
- const prev = items[index - 1]?.key ?? null;
244
- // The items from the index on that do not come after the item before the drop need new keys
245
- let end = index;
246
- while (end < items.length && prev !== null && items[end].key <= prev)
247
- end++;
248
- const writes = [];
249
- if (end > index) {
250
- const keys = keysBetween(prev, items[end]?.key ?? null, end - index);
251
- for (let i = index; i < end; i++)
252
- writes.push({ id: items[i].id, key: keys[i - index] });
253
- }
254
- const next = writes.length > 0 ? writes[0].key : (items[index]?.key ?? null);
255
- writes.push({ id: movingId, key: keyBetween(prev, next) });
256
- return writes;
257
- }
258
- /** The order of two keys: the code units of the strings, as the keys need (never `localeCompare`). */
259
- export function compareKeys(a, b) {
260
- return a < b ? -1 : a > b ? 1 : 0;
261
- }
262
- /**
263
- * This function gives the index at which a point goes among the items of a list on the screen, in
264
- * reading order: the rows from top to bottom, and each row from left to right. It is the index of the
265
- * first item whose center comes after the point, from 0 to the number of items. A center within
266
- * `rowTolerance` of the point on the vertical axis is in the row of the point.
267
- *
268
- * Give the centers in reading order, the same order as the keys, and without the item that moves.
269
- *
270
- * @example
271
- * ```ts
272
- * const index = dropIndex(pointer, others.map(centerOf));
273
- * const key = keyBetween(keys[index - 1], keys[index]);
274
- * ```
275
- */
276
- export function dropIndex(point, centers, rowTolerance = 24) {
277
- for (let i = 0; i < centers.length; i++) {
278
- const c = centers[i];
279
- if (point.y < c.y - rowTolerance)
280
- return i;
281
- if (Math.abs(point.y - c.y) <= rowTolerance && point.x < c.x)
282
- return i;
283
- }
284
- return centers.length;
285
- }
286
- //# sourceMappingURL=rank.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rank.js","sourceRoot":"","sources":["../../src/order/rank.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,mEAAmE;AACnE,MAAM,CAAC,MAAM,UAAU,GAAG,gEAAgE,CAAC;AAE3F,MAAM,IAAI,GAAG,UAAU,CAAC,CAAC,CAAE,CAAC;AAC5B,MAAM,IAAI,GAAG,UAAU,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAE,CAAC;AAChD,yDAAyD;AACzD,MAAM,gBAAgB,GAAG,IAAI,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC;AAE/C,SAAS,OAAO,CAAC,OAAe;IAC9B,OAAO,IAAI,UAAU,CAAC,OAAO,CAAC,CAAC;AACjC,CAAC;AAED,kHAAkH;AAClH,SAAS,aAAa,CAAC,IAAY;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E,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;IAC3D,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,sGAAsG;AACtG,MAAM,UAAU,WAAW,CAAC,CAAS,EAAE,CAAS;IAC9C,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACpC,CAAC;AAQD;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,SAAS,CAAC,KAAY,EAAE,OAAyB,EAAE,YAAY,GAAG,EAAE;IAClF,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACxC,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAE,CAAC;QACtB,IAAI,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,YAAY;YAAE,OAAO,CAAC,CAAC;QAC3C,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,YAAY,IAAI,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YAAE,OAAO,CAAC,CAAC;IACzE,CAAC;IACD,OAAO,OAAO,CAAC,MAAM,CAAC;AACxB,CAAC"}
@@ -1,39 +0,0 @@
1
- /**
2
- * A set of listeners for the events of a storage: the change batches of `observe()`, or the status
3
- * of a sync. A storage package uses it, so each storage treats its listeners in the same way.
4
- */
5
- /** The function that gets the error of a listener. */
6
- export type ListenerErrorHandler = (error: unknown) => void;
7
- /**
8
- * The default handler of the error of a listener. It throws the error again in a microtask, as an
9
- * `EventTarget` reports the error of a listener. Thus the error is not lost, and the write that
10
- * sent the event does not fail.
11
- */
12
- export declare const reportListenerError: ListenerErrorHandler;
13
- /**
14
- * The listeners of one kind of event.
15
- *
16
- * - `emit()` gives the event to each listener, in the order of `add()`.
17
- * - A listener that `add()` gets during an `emit()` gets the next event, not this one.
18
- * - The error of a listener goes to the error handler. The other listeners get the event.
19
- * - The same function can be added two times. Each `add()` gives its own function that removes it.
20
- */
21
- export declare class StorageListeners<E> {
22
- private readonly listeners;
23
- private readonly onError;
24
- /** @param onError - The function that gets the error of a listener. The default is `reportListenerError`. */
25
- constructor(onError?: ListenerErrorHandler);
26
- /** The number of listeners. */
27
- get size(): number;
28
- /**
29
- * This method adds a listener.
30
- *
31
- * @returns The function that removes the listener. A second use of it does nothing.
32
- */
33
- add(listener: (event: E) => void): () => void;
34
- /** This method gives the event to each listener. */
35
- emit(event: E): void;
36
- /** This method removes each listener. */
37
- clear(): void;
38
- }
39
- //# sourceMappingURL=listeners.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"listeners.d.ts","sourceRoot":"","sources":["../../src/storage/listeners.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,sDAAsD;AACtD,MAAM,MAAM,oBAAoB,GAAG,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;AAE5D;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,EAAE,oBAIjC,CAAC;AAEF;;;;;;;GAOG;AACH,qBAAa,gBAAgB,CAAC,CAAC;IAC7B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAwD;IAClF,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAuB;IAE/C,6GAA6G;IAC7G,YAAY,OAAO,GAAE,oBAA0C,EAE9D;IAED,+BAA+B;IAC/B,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;;;OAIG;IACH,GAAG,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAAG,MAAM,IAAI,CAM5C;IAED,oDAAoD;IACpD,IAAI,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,CAUnB;IAED,yCAAyC;IACzC,KAAK,IAAI,IAAI,CAEZ;CACF"}
@@ -1,65 +0,0 @@
1
- /**
2
- * A set of listeners for the events of a storage: the change batches of `observe()`, or the status
3
- * of a sync. A storage package uses it, so each storage treats its listeners in the same way.
4
- */
5
- /**
6
- * The default handler of the error of a listener. It throws the error again in a microtask, as an
7
- * `EventTarget` reports the error of a listener. Thus the error is not lost, and the write that
8
- * sent the event does not fail.
9
- */
10
- export const reportListenerError = (error) => {
11
- queueMicrotask(() => {
12
- throw error;
13
- });
14
- };
15
- /**
16
- * The listeners of one kind of event.
17
- *
18
- * - `emit()` gives the event to each listener, in the order of `add()`.
19
- * - A listener that `add()` gets during an `emit()` gets the next event, not this one.
20
- * - The error of a listener goes to the error handler. The other listeners get the event.
21
- * - The same function can be added two times. Each `add()` gives its own function that removes it.
22
- */
23
- export class StorageListeners {
24
- listeners = new Set();
25
- onError;
26
- /** @param onError - The function that gets the error of a listener. The default is `reportListenerError`. */
27
- constructor(onError = reportListenerError) {
28
- this.onError = onError;
29
- }
30
- /** The number of listeners. */
31
- get size() {
32
- return this.listeners.size;
33
- }
34
- /**
35
- * This method adds a listener.
36
- *
37
- * @returns The function that removes the listener. A second use of it does nothing.
38
- */
39
- add(listener) {
40
- const entry = { listener };
41
- this.listeners.add(entry);
42
- return () => {
43
- this.listeners.delete(entry);
44
- };
45
- }
46
- /** This method gives the event to each listener. */
47
- emit(event) {
48
- for (const entry of [...this.listeners]) {
49
- // A listener that a listener before it removed gets no event
50
- if (!this.listeners.has(entry))
51
- continue;
52
- try {
53
- entry.listener(event);
54
- }
55
- catch (error) {
56
- this.onError(error);
57
- }
58
- }
59
- }
60
- /** This method removes each listener. */
61
- clear() {
62
- this.listeners.clear();
63
- }
64
- }
65
- //# sourceMappingURL=listeners.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"listeners.js","sourceRoot":"","sources":["../../src/storage/listeners.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA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
@@ -1,25 +0,0 @@
1
- /**
2
- * The checks of the contract suite. The suite does not import a test framework, so a runtime
3
- * entry of this package never loads one. A failed check throws `ContractViolation`.
4
- */
5
- /** The error of a failed check of the contract suite. */
6
- export declare class ContractViolation extends Error {
7
- readonly name = "ContractViolation";
8
- }
9
- /** This function gives the text of a value for a message: JSON, with a `Map` as its entries. */
10
- export declare function show(value: unknown): string;
11
- /**
12
- * This function compares two values deeply: JSON values, arrays, plain objects and maps. Two maps
13
- * are equal when they have the same keys with equal values, in any order.
14
- */
15
- export declare function deepEqual(actual: unknown, expected: unknown): boolean;
16
- /** This function throws `ContractViolation` when the two values are not deeply equal. */
17
- export declare function same(actual: unknown, expected: unknown, what: string): void;
18
- /** This function throws `ContractViolation` when the condition is false. */
19
- export declare function holds(condition: boolean, what: string): void;
20
- /**
21
- * This function starts an operation that must fail with a rejected promise, and gives the error.
22
- * A synchronous throw breaks the contract too: each method of a storage gives a promise.
23
- */
24
- export declare function rejects(start: () => Promise<unknown>, what: string): Promise<unknown>;
25
- //# sourceMappingURL=check.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../../src/testing/check.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,yDAAyD;AACzD,qBAAa,iBAAkB,SAAQ,KAAK;IAC1C,SAAkB,IAAI,uBAAuB;CAC9C;AAED,gGAAgG;AAChG,wBAAgB,IAAI,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAO3C;AAQD;;;GAGG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,GAAG,OAAO,CAkBrE;AAED,yFAAyF;AACzF,wBAAgB,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAI3E;AAED,4EAA4E;AAC5E,wBAAgB,KAAK,CAAC,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAE5D;AAED;;;GAGG;AACH,wBAAsB,OAAO,CAAC,KAAK,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAc3F"}
@@ -1,85 +0,0 @@
1
- /**
2
- * The checks of the contract suite. The suite does not import a test framework, so a runtime
3
- * entry of this package never loads one. A failed check throws `ContractViolation`.
4
- */
5
- /** The error of a failed check of the contract suite. */
6
- export class ContractViolation extends Error {
7
- name = "ContractViolation";
8
- }
9
- /** This function gives the text of a value for a message: JSON, with a `Map` as its entries. */
10
- export function show(value) {
11
- if (value === undefined)
12
- return "undefined";
13
- try {
14
- return JSON.stringify(value, (_key, item) => (item instanceof Map ? { Map: [...item.entries()] } : item === undefined ? "<undefined>" : item));
15
- }
16
- catch {
17
- return String(value);
18
- }
19
- }
20
- function isPlainObject(value) {
21
- if (typeof value !== "object" || value === null)
22
- return false;
23
- const prototype = Object.getPrototypeOf(value);
24
- return prototype === Object.prototype || prototype === null;
25
- }
26
- /**
27
- * This function compares two values deeply: JSON values, arrays, plain objects and maps. Two maps
28
- * are equal when they have the same keys with equal values, in any order.
29
- */
30
- export function deepEqual(actual, expected) {
31
- if (Object.is(actual, expected))
32
- return true;
33
- if (actual instanceof Map && expected instanceof Map) {
34
- if (actual.size !== expected.size)
35
- return false;
36
- for (const [key, value] of actual) {
37
- if (!expected.has(key) || !deepEqual(value, expected.get(key)))
38
- return false;
39
- }
40
- return true;
41
- }
42
- if (Array.isArray(actual) && Array.isArray(expected)) {
43
- return actual.length === expected.length && actual.every((item, index) => deepEqual(item, expected[index]));
44
- }
45
- if (isPlainObject(actual) && isPlainObject(expected)) {
46
- const keys = Object.keys(actual);
47
- if (keys.length !== Object.keys(expected).length)
48
- return false;
49
- return keys.every((key) => Object.prototype.hasOwnProperty.call(expected, key) && deepEqual(actual[key], expected[key]));
50
- }
51
- return false;
52
- }
53
- /** This function throws `ContractViolation` when the two values are not deeply equal. */
54
- export function same(actual, expected, what) {
55
- if (!deepEqual(actual, expected)) {
56
- throw new ContractViolation(`${what}: expected ${show(expected)}, got ${show(actual)}`);
57
- }
58
- }
59
- /** This function throws `ContractViolation` when the condition is false. */
60
- export function holds(condition, what) {
61
- if (!condition)
62
- throw new ContractViolation(what);
63
- }
64
- /**
65
- * This function starts an operation that must fail with a rejected promise, and gives the error.
66
- * A synchronous throw breaks the contract too: each method of a storage gives a promise.
67
- */
68
- export async function rejects(start, what) {
69
- let promise;
70
- try {
71
- promise = start();
72
- }
73
- catch (error) {
74
- throw new ContractViolation(`${what}: the method threw at once (${show(error instanceof Error ? error.message : error)}), and did not give a rejected promise`);
75
- }
76
- holds(typeof promise?.then === "function", `${what}: the method did not give a promise`);
77
- try {
78
- await promise;
79
- }
80
- catch (error) {
81
- return error;
82
- }
83
- throw new ContractViolation(`${what}: the promise did not reject`);
84
- }
85
- //# sourceMappingURL=check.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"check.js","sourceRoot":"","sources":["../../src/testing/check.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,yDAAyD;AACzD,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IACxB,IAAI,GAAG,mBAAmB,CAAC;CAC9C;AAED,gGAAgG;AAChG,MAAM,UAAU,IAAI,CAAC,KAAc;IACjC,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,WAAW,CAAC;IAC5C,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,IAAa,EAAE,EAAE,CAAC,CAAC,IAAI,YAAY,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IAC1J,CAAC;IAAC,MAAM,CAAC;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