@cloudbitmaps/roaring 0.16.0 → 0.17.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.
@@ -0,0 +1,34 @@
1
+ /**
2
+ * The checks a stream makes of a lease: before its first pull, and each time it reads a chunk. Kept apart from the store
3
+ * so each can be held on its own, and so a stream of another shape (a rank read, a plain iterable of ids) is wrapped by
4
+ * the same function.
5
+ */
6
+ import type { CodecBitmap } from '@cloudbitmaps/core';
7
+ /** What an id stream is, as far as a guard is concerned: ids, and the same ids a chunk at a time. */
8
+ interface IdStream extends AsyncIterable<number> {
9
+ batches(): AsyncIterable<Uint32Array>;
10
+ }
11
+ /** A combine's chunks, as an `*Into` writes them. */
12
+ type ChunkStream = AsyncIterable<{
13
+ chunkKey: number;
14
+ bitmap: CodecBitmap;
15
+ }>;
16
+ /**
17
+ * A stream of ascending ids that checks a lease before it first pulls, and each time it reads a chunk after that: once
18
+ * the engine has the next chunk and before an id of it is yielded, so nothing of a chunk fetched past the lease is
19
+ * served. Ids ascend, so a chunk is entered when `id >>> 16` changes. The check before the first pull is what stops a
20
+ * stream built while the lease was live, and pulled after it ended, ending empty without ever checking. A throw ends the
21
+ * engine's reads. Used only when a handle in the call holds a lease: a call with none returns the engine's stream
22
+ * untouched. It takes any async iterable of ids, so a stream with no `.batches()` (a rank read) is wrapped the same way.
23
+ */
24
+ export declare const guardIdIterable: (inner: AsyncIterable<number>, check: () => void) => AsyncIterable<number>;
25
+ /** {@link guardIdIterable} for an `IdStream`, whose `.batches()` is guarded too. */
26
+ export declare const guardIds: (inner: IdStream, check: () => void) => IdStream;
27
+ /**
28
+ * A stream of chunks (a batch of ids, or a chunk an `*Into` writes) that checks a lease before the first pull and before
29
+ * each item is handed on: an item is one chunk.
30
+ */
31
+ export declare const guardItems: <T>(inner: AsyncIterable<T>, check: () => void) => AsyncIterable<T>;
32
+ /** A chunk stream (what an `*Into` writes) that checks a lease before the first pull and before each chunk. */
33
+ export declare const guardChunks: (inner: ChunkStream, check: () => void) => ChunkStream;
34
+ export {};
@@ -1,4 +1,16 @@
1
+ /**
2
+ * SafeBitmap — the thin wrapper around the `roaring` (CRoaring) engine that owns the
3
+ * untrusted-bytes boundary.
4
+ *
5
+ * All (de)serialization uses the **portable** format — the stable, bounds-checked one. The
6
+ * `unsafe_frozen_*` formats are never used (they are explicitly documented as crash/attack
7
+ * vectors). Every deserialize is preceded by a hard size cap and a structural check, because the native
8
+ * portable deserializer bounds its reads and checks nothing else (see `portable/layout.ts`).
9
+ */
10
+ import roaring from 'roaring';
1
11
  import type { CodecBitmap, CodecInterface, EncodedChunk, LoadInput } from '@cloudbitmaps/core';
12
+ declare const RoaringBitmap32: typeof roaring.RoaringBitmap32;
13
+ type RoaringBitmap32 = InstanceType<typeof RoaringBitmap32>;
2
14
  export declare class SafeBitmap implements CodecBitmap {
3
15
  private readonly bitmap;
4
16
  private constructor();
@@ -19,6 +31,8 @@ export declare class SafeBitmap implements CodecBitmap {
19
31
  static safeDeserialize(bytes: Uint8Array, maxBytes: number, options?: {
20
32
  readonly whole?: boolean;
21
33
  }): SafeBitmap;
34
+ /** The `roaring` bitmap this wraps, for a caller that was handed it once and keeps no wrapper. */
35
+ unwrap(): RoaringBitmap32;
22
36
  serialize(): Uint8Array;
23
37
  /**
24
38
  * Convert containers to run-encoding where that is smaller. Representation only — membership is untouched, and
@@ -93,3 +107,12 @@ export declare function bitmapAsLoadInput(input: LoadInput): LoadInput;
93
107
  * caller supplies a codec.
94
108
  */
95
109
  export declare const roaringCodec: CodecInterface;
110
+ /**
111
+ * Decode portable Roaring bytes you hold into a `RoaringBitmap32`, through the check a `{ serialized }` load makes
112
+ * first: a size cap, a structural check, one whole bitmap, and only then the native decoder.
113
+ *
114
+ * @param bytes a `Uint8Array`, which a Node `Buffer` is.
115
+ * @throws {ValidationError} for bytes that are not exactly one well-formed portable bitmap, as a load refuses them.
116
+ */
117
+ export declare function deserializePortable(bytes: Uint8Array): RoaringBitmap32;
118
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbitmaps/roaring",
3
- "version": "0.16.0",
3
+ "version": "0.17.0",
4
4
  "description": "Distributed, cloud-native Roaring Bitmaps — query and intersect billion-scale integer sets straight out of object storage, from a bounded RAM cache over immutable objects in your own bucket, at a fraction of an always-on cache.",
5
5
  "keywords": [
6
6
  "roaring",
@@ -65,7 +65,7 @@
65
65
  },
66
66
  "dependencies": {
67
67
  "roaring": "2.7.0",
68
- "@cloudbitmaps/core": "^0.16.0"
68
+ "@cloudbitmaps/core": "^0.17.0"
69
69
  },
70
70
  "devDependencies": {
71
71
  "@types/node": "^22.0.0",