@packvium/engine 0.1.3 → 1.1.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.
- package/README.md +8 -1
- package/SECURITY.md +2 -2
- package/contact-graph.js +143 -29
- package/examples/constraints.mjs +97 -0
- package/examples/shapes.mjs +155 -0
- package/examples/units.mjs +115 -0
- package/fallback.js +925 -59
- package/index.js +52 -12
- package/package.json +4 -4
package/index.js
CHANGED
|
@@ -16,20 +16,60 @@ export {
|
|
|
16
16
|
export { UnsupportedFeatureError };
|
|
17
17
|
import * as commerceFallback from './commerce.js';
|
|
18
18
|
export { CommerceInputError } from './commerce.js';
|
|
19
|
-
const require=createRequire(import.meta.url);
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
19
|
+
const require = createRequire(import.meta.url);
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Every module this package can load as a compiled backend, in probe order: a binary
|
|
23
|
+
* built beside this file first, then the `@packvium/native` optional dependency.
|
|
24
|
+
*
|
|
25
|
+
* `test/force-fallback.cjs` blocks exactly this list, and asserts it stays identical to
|
|
26
|
+
* the specifiers `loadNative` passes.
|
|
27
|
+
*/
|
|
28
|
+
const NATIVE_CANDIDATES = ['./packvium-native.node', '@packvium/native'];
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Resolve the compiled backend, or report that there is none.
|
|
32
|
+
*
|
|
33
|
+
* Each candidate is required by a *literal* specifier rather than through a loop
|
|
34
|
+
* variable, so every module this package is able to load can be resolved by reading it.
|
|
35
|
+
* A probe that misses is not an error: absent, unbuilt and ABI-incompatible addons all
|
|
36
|
+
* land here, and every one of them means the same thing -- answer from the JavaScript
|
|
37
|
+
* fallback, which returns the same result more slowly.
|
|
38
|
+
*/
|
|
39
|
+
function loadNative() {
|
|
40
|
+
try {
|
|
41
|
+
return require('./packvium-native.node');
|
|
42
|
+
} catch { /* no addon beside this file */ }
|
|
43
|
+
try {
|
|
44
|
+
return require('@packvium/native');
|
|
45
|
+
} catch { /* optional dependency absent or unloadable */ }
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const native = loadNative();
|
|
50
|
+
|
|
51
|
+
export const backend = () => (native ? 'rust' : 'javascript');
|
|
52
|
+
|
|
53
|
+
export function packJson(input) {
|
|
54
|
+
if (native?.packJson) return native.packJson(input);
|
|
55
|
+
return JSON.stringify(packFallback(JSON.parse(input)));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function pack(request) {
|
|
59
|
+
return JSON.parse(packJson(JSON.stringify(request)));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function rebalanceWeight(request, result, { maxMoves = 64 } = {}) {
|
|
63
|
+
if (!Number.isSafeInteger(maxMoves) || maxMoves < 0) {
|
|
64
|
+
throw new RangeError('maxMoves must be a non-negative safe integer');
|
|
29
65
|
}
|
|
30
|
-
|
|
66
|
+
if (native?.rebalanceJson) {
|
|
67
|
+
return JSON.parse(native.rebalanceJson(JSON.stringify(request), JSON.stringify(result), maxMoves));
|
|
68
|
+
}
|
|
69
|
+
return rebalanceFallback(request, result, { maxMoves });
|
|
31
70
|
}
|
|
32
|
-
|
|
71
|
+
|
|
72
|
+
export const version = () => native?.version?.() ?? '1.1.0-js-fallback';
|
|
33
73
|
|
|
34
74
|
/**
|
|
35
75
|
* The exported commercial and control-plane API: a quote, a policy decision and catalog
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name":"@packvium/engine",
|
|
3
|
-
"version":"
|
|
3
|
+
"version":"1.1.0",
|
|
4
4
|
"description":"Native-first 3D cartonization with deterministic JS fallback",
|
|
5
|
+
"author":{"name":"Packvium","url":"https://packvium.com"},
|
|
5
6
|
"keywords":["3d-bin-packing","bin-packing","cartonization","packing","container-loading","logistics","shipping","deterministic"],
|
|
6
7
|
"homepage":"https://packvium.com",
|
|
7
8
|
"repository":{"type":"git","url":"git+https://github.com/toxakara/packvium-node.git"},
|
|
@@ -12,10 +13,9 @@
|
|
|
12
13
|
"exports":{".":{"types":"./index.d.ts","import":"./index.js"}},
|
|
13
14
|
"files":["index.js","fallback.js","contact-graph.js","policy.js","commerce.js","commerce-model.js","examples","index.d.ts","README.md","SECURITY.md"],
|
|
14
15
|
"engines":{"node":">=16"},
|
|
15
|
-
"optionalDependencies":{"@packvium/native":"0.1.3"},
|
|
16
16
|
"scripts":{
|
|
17
|
-
"test":"node
|
|
18
|
-
"test:legacy":"node test/legacy-
|
|
17
|
+
"test":"node test/run-tests.mjs",
|
|
18
|
+
"test:legacy":"node test/legacy-smoke.mjs"
|
|
19
19
|
},
|
|
20
20
|
"license":"MIT"
|
|
21
21
|
}
|