@orieg/expanse 0.3.0 → 0.4.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.
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  > Native Node.js, Bun, and Deno bindings for **Expanse**: clean-room, pure-Rust Judy arrays and 256-ary digital tries with optimistic concurrency control (OCC).
4
4
 
5
5
  [![npm version](https://img.shields.io/npm/v/@orieg/expanse.svg)](https://www.npmjs.com/package/@orieg/expanse)
6
- [![License](https://img.shields.io/badge/license-MIT%2FApache--2.0-blue.svg)](../../LICENSE-MIT)
6
+ [![License](https://img.shields.io/badge/license-MIT%2FApache--2.0-blue.svg)](https://github.com/orieg/expanse/blob/main/LICENSE-MIT)
7
7
 
8
8
  ## Overview
9
9
 
package/index.d.ts CHANGED
@@ -462,14 +462,18 @@ export class ExpanseBlobMap {
462
462
  compact(): CompactionStatsResult;
463
463
 
464
464
  /**
465
- * Saves the map to a relocatable binary image file. Returns bytes written.
465
+ * Saves the map to a relocatable binary image file. Returns the number of bytes
466
+ * written as a BigInt (an image can exceed 4 GiB, so it does not fit in a 32-bit number).
466
467
  */
467
- saveImage(path: string): number;
468
+ saveImage(path: string): bigint;
468
469
 
469
470
  /**
470
471
  * Loads a map from a relocatable binary image file.
472
+ *
473
+ * The whole file is read into memory and the index is rebuilt; the image is NOT
474
+ * memory-mapped (no lazy-fault SIGBUS hazard, at the cost of the image being resident).
471
475
  */
472
- static openImage(path: string, mmap?: boolean): ExpanseBlobMap;
476
+ static openImage(path: string): ExpanseBlobMap;
473
477
  }
474
478
 
475
479
  /**
package/index.js CHANGED
@@ -1,10 +1,49 @@
1
1
  const path = require('path');
2
2
  const fs = require('fs');
3
3
 
4
+ // Map the current runtime to the napi-style platform name used by the
5
+ // per-platform prebuilt packages (@orieg/expanse-<platform>), published as
6
+ // optionalDependencies of @orieg/expanse.
7
+ function platformName() {
8
+ const { platform, arch } = process;
9
+ if (platform === 'linux') {
10
+ if (arch === 'x64') return 'linux-x64-gnu';
11
+ if (arch === 'arm64') return 'linux-arm64-gnu';
12
+ } else if (platform === 'darwin') {
13
+ if (arch === 'x64') return 'darwin-x64';
14
+ if (arch === 'arm64') return 'darwin-arm64';
15
+ } else if (platform === 'win32') {
16
+ if (arch === 'x64') return 'win32-x64-msvc';
17
+ }
18
+ return null;
19
+ }
20
+
4
21
  function loadBinding() {
5
- const candidates = [
6
- path.join(__dirname, 'index.node'),
7
- path.join(__dirname, 'expanse-node.node'),
22
+ const plat = platformName();
23
+
24
+ // 1. A co-located prebuilt addon (e.g. bundled next to this loader).
25
+ const localCandidates = [];
26
+ if (plat) {
27
+ localCandidates.push(path.join(__dirname, `expanse.${plat}.node`));
28
+ }
29
+ localCandidates.push(path.join(__dirname, 'index.node'));
30
+ for (const candidate of localCandidates) {
31
+ if (fs.existsSync(candidate)) {
32
+ return require(candidate);
33
+ }
34
+ }
35
+
36
+ // 2. The published per-platform package installed via optionalDependencies.
37
+ if (plat) {
38
+ try {
39
+ return require(`@orieg/expanse-${plat}`);
40
+ } catch (err) {
41
+ // fall through to the local development fallbacks below
42
+ }
43
+ }
44
+
45
+ // 3. Development / CI fallback: load straight from `cargo build` output.
46
+ const devCandidates = [
8
47
  path.join(__dirname, '../../target/release/libexpanse_node.dylib'),
9
48
  path.join(__dirname, '../../target/release/libexpanse_node.so'),
10
49
  path.join(__dirname, '../../target/release/expanse_node.dll'),
@@ -12,13 +51,9 @@ function loadBinding() {
12
51
  path.join(__dirname, '../../target/debug/libexpanse_node.so'),
13
52
  path.join(__dirname, '../../target/debug/expanse_node.dll'),
14
53
  ];
15
-
16
- for (const candidate of candidates) {
54
+ for (const candidate of devCandidates) {
17
55
  if (fs.existsSync(candidate)) {
18
56
  try {
19
- if (candidate.endsWith('.node')) {
20
- return require(candidate);
21
- }
22
57
  const mod = { exports: {} };
23
58
  process.dlopen(mod, candidate);
24
59
  return mod.exports;
@@ -29,7 +64,9 @@ function loadBinding() {
29
64
  }
30
65
 
31
66
  throw new Error(
32
- 'Failed to load @orieg/expanse native addon. Please build with `cargo build -p expanse-node`.'
67
+ 'Failed to load the @orieg/expanse native addon. ' +
68
+ 'Ensure the matching @orieg/expanse-<platform> optionalDependency was installed, ' +
69
+ 'or build locally with `cargo build -p expanse-node`.'
33
70
  );
34
71
  }
35
72
 
package/package.json CHANGED
@@ -1,19 +1,25 @@
1
1
  {
2
2
  "name": "@orieg/expanse",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
4
4
  "description": "Clean-room, pure-Rust modern Judy arrays and digital tries with cache-line-tuned node geometries, inline value packing, slab arenas, and OCC concurrency for Node.js, Bun, and Deno.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
7
7
  "files": [
8
8
  "index.js",
9
9
  "index.d.ts",
10
- "index.node",
11
10
  "README.md",
12
11
  "LICENSE-MIT",
13
12
  "LICENSE-APACHE"
14
13
  ],
14
+ "optionalDependencies": {
15
+ "@orieg/expanse-linux-x64-gnu": "0.4.1",
16
+ "@orieg/expanse-darwin-x64": "0.4.1",
17
+ "@orieg/expanse-darwin-arm64": "0.4.1",
18
+ "@orieg/expanse-win32-x64-msvc": "0.4.1"
19
+ },
15
20
  "scripts": {
16
21
  "test": "node test.js",
22
+ "bench": "node bench.js",
17
23
  "build": "cargo build --release -p expanse-node",
18
24
  "build:debug": "cargo build -p expanse-node"
19
25
  },