
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
capnp-schema-gen
Advanced tools
A Cap'n Proto schema and setter function generator compatible with Pooya Parsa's capnp-es.
Given an arbitrary JavaScript object:
const data = {
name: 'John',
email: 'john@doe.com',
friends: [
{
name: 'Jane',
email: 'jane@doe.com'
}
]
}
You can generate an inferred Cap'n Proto schema:
const schema = generateSchema('Person', data)
console.log(schema)
@0xe3603ad8685d0f0c;
struct Person {
name @0 :Text;
email @1 :Text;
friends @2 :List(PersonFriendsItem);
}
struct PersonFriendsItem {
name @0 :Text;
email @1 :Text;
}
And an accompanying setter function:
const setter = generateSetterFunction(data)
console.log(setter)
function setter(capnp, schemaClass, data) {
const message = new capnp.Message();
const obj = message.initRoot(schemaClass);
if (typeof data.name !== 'undefined') {
obj.name = data.name;
}
if (typeof data.email !== 'undefined') {
obj.email = data.email;
}
const friendsList = obj._initFriends(data.friends.length);
for (let i = 0; i < data.friends.length; i++) {
if (data.friends[i] !== null && typeof data.friends[i] === 'object') {
const friendsItem = friendsList.get(i);
if (typeof data.friends[i].name !== 'undefined') {
friendsItem.name = data.friends[i].name;
}
if (typeof data.friends[i].email !== 'undefined') {
friendsItem.email = data.friends[i].email;
}
}
}
return message.toArrayBuffer();
}
MIT
FAQs
A Cap'n Proto schema and setter function generator.
We found that capnp-schema-gen demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 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.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.