libp2r2p 0.12.4 → 0.12.5

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.
package/README.md CHANGED
@@ -1166,11 +1166,14 @@ the old token: its `ack`, `nack` and `renew` return false. Successful writes wak
1166
1166
  local waiting consumers. Like the other indexed methods, `putBy` is exclusive
1167
1167
  to `idb-queue`; the Web Storage queue's common API is unchanged.
1168
1168
 
1169
- `createQueue({ prefix, evictionPolicy: 'reject', maxBytes })` opts out of
1169
+ Both queue implementations support
1170
+ `createQueue({ prefix, evictionPolicy: 'reject', maxBytes })` to opt out of
1170
1171
  capacity eviction. Oversized items reject with `QUEUE_ITEM_TOO_LARGE`, full
1171
1172
  queues with `QUEUE_CAPACITY_EXCEEDED`; browser quota errors propagate without
1172
1173
  trimming existing records. Other eviction policies retain their cache behavior.
1173
1174
  Opening a reject-policy queue under a smaller budget preserves existing items.
1175
+ Positional replacement and insertion follow the same rule: they reject instead
1176
+ of evicting when the resulting queue would exceed the limit.
1174
1177
 
1175
1178
  `queue.reserve({ leaseMs = 30000 })` returns `null` or
1176
1179
  `{ item, ack, nack, renew }`. Reservation token/deadline are internal record
@@ -1180,8 +1183,11 @@ PrivateMessenger supplies both. Do not mix reservations with destructive or
1180
1183
  position-shifting queue operations on the same queue except explicit removal.
1181
1184
  A stale token cannot acknowledge a newly reserved or replaced record.
1182
1185
 
1183
- `queue.getCapacity()` returns `{ usedBytes, maxBytes }`; capacity rejections
1184
- also expose `requiredBytes` and `maxBytes`, without retaining the rejected item.
1186
+ `queue.getCapacity()` is part of the common API and returns
1187
+ `{ usedBytes, maxBytes }`; capacity rejections also expose `requiredBytes` and
1188
+ `maxBytes`, without retaining the rejected item. IDB queues return a Promise,
1189
+ while Web Storage queues return the object synchronously according to their
1190
+ respective operation conventions; callers can await either form.
1185
1191
 
1186
1192
 
1187
1193
  ### Publication acknowledgement deadlines
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libp2r2p",
3
- "version": "0.12.4",
3
+ "version": "0.12.5",
4
4
  "description": "Peer-to-relay-to-peer",
5
5
  "keywords": [
6
6
  "p2r2p",
@@ -53,6 +53,7 @@ export function createQueue ({
53
53
 
54
54
  function normalizeEvictionPolicy (policy) {
55
55
  if (policy === 'opposite-end' || policy === undefined || policy === null) return 'opposite-end'
56
+ if (policy === 'reject') return 'reject'
56
57
  if (policy === 'fifo' || policy === 'head') return 'head'
57
58
  if (policy === 'lifo' || policy === 'tail') return 'tail'
58
59
  throw new ValidationError('QUEUE_INVALID_EVICTION_POLICY')
@@ -223,6 +224,12 @@ export function createQueue ({
223
224
  if (!hasByteLimit()) return state
224
225
  const { direction = 'head' } = options
225
226
  if (requiredBytes > sessionMaxBytes) throw new Error('QUEUE_ITEM_TOO_LARGE')
227
+ if (configuredEvictionPolicy === 'reject') {
228
+ if (state.usedBytes + requiredBytes > sessionMaxBytes) {
229
+ throw capacityError(requiredBytes, state.usedBytes, sessionMaxBytes)
230
+ }
231
+ return state
232
+ }
226
233
  // Make room for the write and retain eviction headroom for the next one.
227
234
  const targetBytes = targetBytesAfterWrite(requiredBytes)
228
235
  while (state.usedBytes + requiredBytes > targetBytes) {
@@ -236,7 +243,7 @@ export function createQueue ({
236
243
  }
237
244
 
238
245
  function recoverByteLimit (state) {
239
- if (!hasByteLimit()) return state
246
+ if (!hasByteLimit() || configuredEvictionPolicy === 'reject') return state
240
247
  return evictToBytes(state, Math.min(sessionMaxBytes, targetBytesAfterWrite(0)), { direction: evictionDirectionFor('recover') })
241
248
  }
242
249
 
@@ -284,6 +291,7 @@ export function createQueue ({
284
291
  storage().setItem(key, raw)
285
292
  } catch (err) {
286
293
  if (!isQuotaExceeded(err) || !hasByteLimit()) throw err
294
+ if (configuredEvictionPolicy === 'reject') throw err
287
295
  // Actual browser quota can be lower than the configured logical budget.
288
296
  lowerSessionMaxBytes(requiredBytes)
289
297
  if (options.evict === false) throw err
@@ -643,6 +651,10 @@ export function createQueue ({
643
651
  readState()
644
652
 
645
653
  return {
654
+ getCapacity: () => {
655
+ const state = readState()
656
+ return { usedBytes: state.usedBytes, maxBytes: sessionMaxBytes }
657
+ },
646
658
  enqueue: push,
647
659
  push,
648
660
  pop,