Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@thi.ng/wasm-api-bindgen

Package Overview
Dependencies
Maintainers
0
Versions
119
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@thi.ng/wasm-api-bindgen - npm Package Compare versions

Comparing version 0.7.8 to 0.7.9

11

CHANGELOG.md
# Change Log
- **Last updated**: 2024-10-08T20:41:04Z
- **Last updated**: 2024-11-09T16:30:54Z
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)

@@ -12,2 +12,11 @@

### [0.7.9](https://github.com/thi-ng/umbrella/tree/@thi.ng/wasm-api-bindgen@0.7.9) (2024-11-09)
#### ♻️ Refactoring
- update TypeScript codegen ([49d1bc5](https://github.com/thi-ng/umbrella/commit/49d1bc5))
- reduce filesize of generated code by injecting wrapper for string type ctor
if type collection uses strings
- update test snapshots
## [0.7.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/wasm-api-bindgen@0.7.0) (2024-08-21)

@@ -14,0 +23,0 @@

@@ -45,2 +45,15 @@ import type { BigType, Keys, Nullable } from "@thi.ng/api";

/**
* Returns true if `x` is a struct or union and contains string fields.
*
* @param x
*/
export declare const hasStringFields: (x: TopLevelType) => boolean;
/**
* Returns true if the given type collection contains structs or unions with
* string fields.
*
* @param coll
*/
export declare const usesStrings: (coll: TypeColl) => boolean;
/**
* Returns filtered array of struct fields of with "ptr" tag or function

@@ -47,0 +60,0 @@ * pointers.

@@ -22,2 +22,7 @@ import { isArray } from "@thi.ng/checks/is-array";

const isUnion = (x) => x.type === "union";
const hasStringFields = (x) => {
if (!isStruct(x) || isUnion(x)) return false;
return x.fields.some((f) => f.type === "string");
};
const usesStrings = (coll) => Object.values(coll).some(hasStringFields);
const pointerFields = (fields) => fields.filter((f) => isPointer(f.tag));

@@ -48,2 +53,3 @@ const stringFields = (fields) => fields.filter((f) => isWasmString(f.type) && f.tag !== "ptr");

enumName,
hasStringFields,
injectBody,

@@ -70,3 +76,4 @@ isBigNumeric,

stringFields,
usesStrings,
withIndentation
};

4

package.json
{
"name": "@thi.ng/wasm-api-bindgen",
"version": "0.7.8",
"version": "0.7.9",
"description": "Polyglot bindings code generators (TS/JS, Zig, C11) for hybrid WebAssembly projects",

@@ -128,3 +128,3 @@ "type": "module",

},
"gitHead": "c2c371069911fdae138149fdcf937c4ad7a8c71e\n"
"gitHead": "e84096f55842a5a028d5c5e7b776ddd49b79ea17\n"
}

@@ -23,2 +23,3 @@ import {

prefixLines,
usesStrings,
withIndentation

@@ -33,7 +34,6 @@ } from "./internal/utils.js";

pre: (coll, globalOpts) => {
const str = __stringImpl(globalOpts);
const res = [
"// @ts-ignore possibly includes unused imports",
`import { Pointer, ${__stringImpl(
globalOpts
)}, type IWasmMemoryAccess, type MemorySlice, type MemoryView, type WasmType, type WasmTypeBase, type WasmTypeConstructor } from "@thi.ng/wasm-api";`
`import { Pointer, ${str}, type IWasmMemoryAccess, type MemorySlice, type MemoryView, type WasmType, type WasmTypeBase, type WasmTypeConstructor } from "@thi.ng/wasm-api";`
];

@@ -49,2 +49,9 @@ if (Object.values(coll).some(

}
if (usesStrings(coll)) {
res.push(
"",
"// @ts-ignore possibly unused",
`const __str = (mem: IWasmMemoryAccess, base: number, isConst = true) => new ${str}(mem, base, isConst);`
);
}
if (opts.pre) res.push("", ...ensureStringArray(opts.pre));

@@ -169,3 +176,3 @@ return res.join("\n");

isLocal ? `const $${name}: ${type}[] = [];` : `$${name} = [];`,
`for(let i = 0; i < ${len}; i++) $${name}.push(new ${type}(mem, addr + i * ${target.sizeBytes * (type === "WasmStringSlice" ? 2 : 1)}, ${isConst}));`,
`for(let i = 0; i < ${len}; i++) $${name}.push(__str(mem, addr + i * ${target.sizeBytes * (type === "WasmStringSlice" ? 2 : 1)}${isConst ? "" : ", false"}));`,
`return $${name};`

@@ -215,5 +222,3 @@ ];

getter = [
`return $${name} || ($${name} = new ${strType}(mem, ${__addr(
offset
)}, ${isConst}));`
`return $${name} || ($${name} = __str(mem, ${__addr(offset)}${isConst ? "" : ", false"}));`
];

@@ -225,3 +230,3 @@ break;

getter = __ptrBody(type, name, offset, [
`(addr) => new ${strType}(mem, addr, ${isConst})`
`(addr) => __str(mem, addr, ${isConst})`
]);

@@ -228,0 +233,0 @@ break;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc