payid-rule-engine 0.2.2 → 0.2.4
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/package.json +3 -2
- package/src/index.ts +3 -3
- package/src/sandbox.ts +2 -2
- package/src/wasm/rule_engine.wasm +0 -0
- package/src/wasm.ts +15 -7
- package/tsup.config.ts +11 -0
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "payid-rule-engine",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"
|
|
7
|
+
"buildOld": "tsup src/* --format esm --dts --clean",
|
|
8
|
+
"build": "tsup"
|
|
8
9
|
},
|
|
9
10
|
"dependencies": {
|
|
10
11
|
"@types/lodash": "^4.17.21",
|
package/src/index.ts
CHANGED
|
@@ -13,9 +13,9 @@ export * from "./preprocess";
|
|
|
13
13
|
* @returns RuleResult (ALLOW / REJECT)
|
|
14
14
|
*/
|
|
15
15
|
export async function executeRule(
|
|
16
|
-
wasmBinary: Buffer,
|
|
17
16
|
context: RuleContext,
|
|
18
|
-
ruleConfig: unknown
|
|
17
|
+
ruleConfig: unknown,
|
|
18
|
+
wasmBinary: Buffer,
|
|
19
19
|
): Promise<RuleResult> {
|
|
20
|
-
return runWasmRule(
|
|
20
|
+
return runWasmRule(context, ruleConfig, wasmBinary,);
|
|
21
21
|
}
|
package/src/sandbox.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { RuleContext, RuleResult } from "payid-types";
|
|
2
2
|
import { loadWasm } from "./wasm";
|
|
3
3
|
export async function runWasmRule(
|
|
4
|
-
wasmBinary: Buffer,
|
|
5
4
|
context: RuleContext,
|
|
6
|
-
config: any
|
|
5
|
+
config: any,
|
|
6
|
+
wasmBinary?: Buffer,
|
|
7
7
|
): Promise<RuleResult> {
|
|
8
8
|
const instance = await loadWasm(wasmBinary);
|
|
9
9
|
|
|
Binary file
|
package/src/wasm.ts
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
|
-
export async function loadWasm(binary
|
|
2
|
-
|
|
1
|
+
export async function loadWasm(binary?: Buffer | Uint8Array): Promise<WebAssembly.Instance> {
|
|
2
|
+
let wasmBinary: Buffer | Uint8Array | undefined = binary;
|
|
3
|
+
|
|
4
|
+
if (!wasmBinary || wasmBinary.length === 0) {
|
|
5
|
+
const { readFileSync } = await import(/* webpackIgnore: true */ "fs");
|
|
6
|
+
const { join, dirname } = await import(/* webpackIgnore: true */ "path");
|
|
7
|
+
const { fileURLToPath } = await import(/* webpackIgnore: true */ "url");
|
|
8
|
+
const __dir = dirname(fileURLToPath(import.meta.url));
|
|
9
|
+
wasmBinary = readFileSync(join(__dir, "wasm/rule_engine.wasm"));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const module = await WebAssembly.compile(wasmBinary);
|
|
3
13
|
|
|
4
|
-
// WASI stub — tidak pakai new WASI() karena hang di Bun
|
|
5
|
-
// Rule engine tidak butuh file I/O, stub ini cukup untuk satisfy imports
|
|
6
14
|
const wasiStub: Record<string, (...args: any[]) => any> = {
|
|
7
|
-
fd_write: () => 8,
|
|
15
|
+
fd_write: () => 8,
|
|
8
16
|
fd_read: () => 8,
|
|
9
17
|
fd_close: () => 0,
|
|
10
18
|
fd_seek: () => 8,
|
|
@@ -21,11 +29,11 @@ export async function loadWasm(binary: Buffer): Promise<WebAssembly.Instance> {
|
|
|
21
29
|
};
|
|
22
30
|
|
|
23
31
|
const instance = await WebAssembly.instantiate(module, {
|
|
24
|
-
wasi_snapshot_preview1: wasiStub
|
|
32
|
+
wasi_snapshot_preview1: wasiStub,
|
|
25
33
|
});
|
|
26
34
|
|
|
27
35
|
const _init = instance.exports._initialize as (() => void) | undefined;
|
|
28
36
|
if (_init) _init();
|
|
29
37
|
|
|
30
38
|
return instance;
|
|
31
|
-
}
|
|
39
|
+
}
|