Skip to content

Commit 50d437f

Browse files
committed
fix: PascalCase identifiers in all cases, bump xtp bindgen, js pdk
1 parent 6cb8191 commit 50d437f

File tree

5 files changed

+32
-25
lines changed

5 files changed

+32
-25
lines changed

package-lock.json

Lines changed: 18 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
"author": "Dylibso, Inc.",
1111
"license": "BSD-3-Clause",
1212
"devDependencies": {
13-
"@extism/js-pdk": "^1.0.1",
13+
"@extism/js-pdk": "^1.1.1",
1414
"@types/ejs": "^3.1.5",
1515
"const": "^1.0.0",
1616
"esbuild": "^0.19.6",
1717
"typescript": "^5.3.2"
1818
},
1919
"dependencies": {
20-
"@dylibso/xtp-bindgen": "1.0.0-rc.5",
20+
"@dylibso/xtp-bindgen": "1.0.0-rc.8",
2121
"ejs": "^3.1.10"
2222
}
2323
}

src/index.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import ejs from "ejs";
22
import { getContext, helpers, Property, Import, Export, Parameter, Schema } from "@dylibso/xtp-bindgen";
33

4-
function makePublic(s: string) {
5-
const cap = s.charAt(0).toUpperCase();
6-
if (s.charAt(0) === cap) {
7-
return s;
8-
}
4+
function snakeToPascalCase(s: string) {
5+
return helpers.capitalize(helpers.snakeToCamelCase(s));
6+
}
97

10-
const pub = cap + s.slice(1);
11-
return pub;
8+
function cppIdentifer(s: string) {
9+
return snakeToPascalCase(s);
1210
}
1311

1412
function objectReferencesObject(existing: any, name: string) {
@@ -23,7 +21,7 @@ function objectReferencesObject(existing: any, name: string) {
2321
type PropertyLike = Property | Parameter;
2422

2523
function toCppTypeInner(property: PropertyLike, refnamespace: string): string {
26-
if (property.$ref) return refnamespace + property.$ref.name;
24+
if (property.$ref) return refnamespace + cppIdentifer(property.$ref.name);
2725
switch (property.type) {
2826
case "string":
2927
if (property.format === "date-time") {
@@ -328,7 +326,7 @@ export function render() {
328326
const ctx = {
329327
...helpers,
330328
...prevctx,
331-
makePublic,
329+
cppIdentifer,
332330
enums,
333331
objects,
334332
toCppType,

template/pdk.gen.cpp.ejs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ static jsoncons::json toJSONFromByteBuffer(const std::vector<uint8_t> &val) {
1919
2020
<%# encode enums -%>
2121
<% for (const schema of enums) { -%>
22-
JSONCONS_ENUM_TRAITS( <%- 'pdk::'+makePublic(schema.name) -%>,
22+
JSONCONS_ENUM_TRAITS( <%- 'pdk::'+cppIdentifer(schema.name) -%>,
2323
<%- schema.enum.join(', ') -%> )
2424
<% } -%>
2525
<%# encode structs -%>
2626
<% for (const schema of objects) { -%>
2727
<% if (!objectHasBuffer(schema)) { -%>
28-
JSONCONS_ALL_MEMBER_TRAITS( <%- 'pdk::'+makePublic(schema.name) -%>,
28+
JSONCONS_ALL_MEMBER_TRAITS( <%- 'pdk::'+cppIdentifer(schema.name) -%>,
2929
<%- getPropertyNames(schema) -%> )
3030
<% } else {-%>
31-
JSONCONS_ALL_MEMBER_NAME_TRAITS( <%- 'pdk::'+makePublic(schema.name) -%>
31+
JSONCONS_ALL_MEMBER_NAME_TRAITS( <%- 'pdk::'+cppIdentifer(schema.name) -%>
3232
<% for (const prop of schema.properties) { -%>
3333
<% if (!isBuffer(prop)) { -%>
3434
, (<%- prop.name -%>, "<%- prop.name -%>")

template/pdk.gen.hpp.ejs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ namespace pdk {
1515
<%# encode enums -%>
1616
<% for (const schema of enums) { %>
1717
// <%- formatCommentLine(schema.description) %>
18-
enum class <%- makePublic(schema.name) %> {
18+
enum class <%- cppIdentifer(schema.name) %> {
1919
<%- schema.enum.join(', ') %>
2020
};
2121
<% } %>
2222

2323
<%# encode structs -%>
2424
<% for (const schema of objects) { %>
2525
// <%- formatCommentLine(schema.description) %>
26-
struct <%- makePublic(schema.name) %> {
26+
struct <%- cppIdentifer(schema.name) %> {
2727
<% for (const prop of schema.properties) { -%>
2828
// <%- formatCommentLine(prop.description) %>
2929
<%-toCppType(prop, '') %> <%- prop.name -%>;

0 commit comments

Comments
 (0)