
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
yarn add jsbuffer
npm i jsbuffer
npm install -g jsbuffer
jsbuffer schema/src -o schema
jsbuffer schema/src -o schema --extends tsconfig.base.json
jsbuffer is the implementation of a type language. We offer tools for you to generate TypeScript interfaces and functions to encode and decode your data, and more.
You can try jsbuffer online in the online playground, still in very early progress, but it works.
The new jsb command-line tool supports generating code for additional languages, currently, the CLI offer experimental support for the following languages:
npm i -g jsbuffer@^2
jsb -h
Create a schema/main file:
type User {
int id;
string name;
}
Run your terminal:
npx jsbuffer schema/main -o src/schema
npx jsbuffer -h
Or
npx jsbuffer --help
So this:
type user {
int id;
string name;
}
Generate a TypeScript interface:
interface user {
id: number;
name: string;
}
This:
type user {
int id;
string name;
}
Generate an encode function:
export function encodeUser(s: ISerializer, value: user) {
s.writeInt32(-399411702);
/**
* encoding param: id
*/
const __pv0 = value['id'];
s.writeInt32(__pv0);
/**
* encoding param: name
*/
const __pv1 = value['name'];
s.writeString(__pv1);
}
And a decode function:
export function decodeUser(__d: IDeserializer): user | null {
const __id = __d.readInt32();
/**
* decode header
*/
if (__id !== -399411702) return null;
let id: number;
let name: string;
/**
* decoding param: id
*/
id = __d.readInt32();
/**
* decoding param: name
*/
name = __d.readString();
return {
_name: 'schema.user',
id,
name
};
}
Functions that are supposed to initialize these interfaces with default data in it:
This:
type user {
int id;
string name;
}
Generate this function:
export function defaultUser(params: Partial<userInputParams> = {}): user {
return user({
id: 0,
name: '',
...params
});
}
This:
type user {
int id;
string name;
}
Generate a comparison function:
export function compareUser(__a: user, __b: user) {
return (
/**
* compare parameter id
*/
__a['id'] === __b['id'] &&
/**
* compare parameter name
*/
__a['name'] === __b['name']
);
}
Generated update functions uses the deep comparison expressions to make sure the reference of the input object is never changed, if there is no change in the changes argument even if you're using complex objects. To give you an example, let's say you have the following type definition:
type testMap2 {
map<optional<string>,string> a;
map<optional<string>,tuple<string,map<int,int>>> b;
}
The code generator will create an update function with the following signature:
function updateTestMap2(
value: testMap2,
changes: Partial<testMap2InputParams>
): testMap2;
So the following test case would pass without errors:
import assert from 'assert';
import { testMap2, updateTestMap2 } from '../out/schema';
const a1 = testMap2({
a: new Map([
['a', '1'],
['b', '2'],
['c', '3']
]),
b: new Map([['a', ['', new Map([[1, 2]])]]])
});
assert.strict.equal(updateTestMap2(a1, {}), a1);
assert.strict.equal(
updateTestMap2(a1, {
b: new Map([['a', ['', new Map([[1, 2]])]]])
}),
a1
);
assert.strict.notEqual(
updateTestMap2(a1, {
b: new Map([['a', ['', new Map([[1, 3]])]]])
}),
a1
);
assert.strict.deepEqual(
updateTestMap2(a1, {
b: new Map([['a', ['', new Map([[1, 3]])]]])
}),
testMap2({
a: new Map([
['a', '1'],
['b', '2'],
['c', '3']
]),
b: new Map([['a', ['', new Map([[1, 3]])]]])
})
);
trait User {}
type user : User {
ulong id;
}
type userDeleted : User {
ulong deletedAt;
}
Becomes this:
export type User = userDeleted | user;
To me, the most cool part of jsbuffer, is that you can create all sort of complex type structures that involve many parts and we will resolve and generate the code and files accordingly:
import {refUser} from "./Ref";
type comment {
int id;
refUser author;
string comment;
}
type post {
int id;
refUser author;
string title;
string contents;
vector<comment> comments;
}
type user {
int id;
string firstName;
vector<post> posts;
}
set<t>map<k,v>vector<t>tuple<a,b,c,d,e,f,...>null_terminated_stringstringintint32uint32ulonglongint16uint16int8uint8FAQs
## Installation
The npm package jsbuffer receives a total of 7 weekly downloads. As such, jsbuffer popularity was classified as not popular.
We found that jsbuffer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.