@hpx7/delta-pack-cli 0.2.0 → 0.2.2
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/dist/codegen/index.js +7 -7
- package/dist/index.js +12 -12
- package/package.json +2 -2
package/dist/codegen/index.js
CHANGED
|
@@ -9789,13 +9789,13 @@ ${fromJsonBody}
|
|
|
9789
9789
|
}`;
|
|
9790
9790
|
const toJsonBody = props.map(([propName, propType]) => {
|
|
9791
9791
|
if (propType.type === "optional") {
|
|
9792
|
-
const nullCheck = isValueType(propType.value) ?
|
|
9793
|
-
return ` if (${nullCheck}) result["${propName}"] = ${renderToJson(propType, propName, toPascalCase(propName))};`;
|
|
9792
|
+
const nullCheck = isValueType(propType.value) ? `obj.${toPascalCase(propName)}.HasValue` : `obj.${toPascalCase(propName)} != null`;
|
|
9793
|
+
return ` if (${nullCheck}) result["${propName}"] = ${renderToJson(propType, propName, `obj.${toPascalCase(propName)}`)};`;
|
|
9794
9794
|
}
|
|
9795
|
-
return ` result["${propName}"] = ${renderToJson(propType, propName, toPascalCase(propName))};`;
|
|
9795
|
+
return ` result["${propName}"] = ${renderToJson(propType, propName, `obj.${toPascalCase(propName)}`)};`;
|
|
9796
9796
|
}).join(`
|
|
9797
9797
|
`);
|
|
9798
|
-
const toJsonMethod = ` public JsonObject ToJson()
|
|
9798
|
+
const toJsonMethod = ` public static JsonObject ToJson(${name} obj)
|
|
9799
9799
|
{
|
|
9800
9800
|
var result = new JsonObject();
|
|
9801
9801
|
${toJsonBody}
|
|
@@ -9988,7 +9988,7 @@ ${decodeDiffInternalMethod}
|
|
|
9988
9988
|
const toJsonCases = options.map((opt, i) => {
|
|
9989
9989
|
const variantName = opt.name;
|
|
9990
9990
|
const varName = toCamelCase(variantName);
|
|
9991
|
-
return ` ${i > 0 ? "else " : ""}if (obj is ${variantName} ${varName}) return new JsonObject { ["${variantName}"] = ${
|
|
9991
|
+
return ` ${i > 0 ? "else " : ""}if (obj is ${variantName} ${varName}) return new JsonObject { ["${variantName}"] = ${variantName}.ToJson(${varName}) };`;
|
|
9992
9992
|
}).join(`
|
|
9993
9993
|
`);
|
|
9994
9994
|
const baseClass = ` public abstract class ${name}
|
|
@@ -10202,12 +10202,12 @@ ${decodeDiffNewTypeCases}
|
|
|
10202
10202
|
} else if (type.type === "reference") {
|
|
10203
10203
|
return renderToJson(type.ref, type.ref.name, key);
|
|
10204
10204
|
} else if (type.type === "self-reference") {
|
|
10205
|
-
return `${
|
|
10205
|
+
return `${qualifyType(currentTypeName)}.ToJson(${key})`;
|
|
10206
10206
|
}
|
|
10207
10207
|
if (type.type === "union") {
|
|
10208
10208
|
return `${qualifyType(type.name)}.ToJson(${key})`;
|
|
10209
10209
|
}
|
|
10210
|
-
return `${
|
|
10210
|
+
return `${qualifyType(name)}.ToJson(${key})`;
|
|
10211
10211
|
}
|
|
10212
10212
|
function renderClone(type, name, key) {
|
|
10213
10213
|
if (type.type === "string" || type.type === "int" || type.type === "float" || type.type === "boolean" || type.type === "enum") {
|
package/dist/index.js
CHANGED
|
@@ -9790,13 +9790,13 @@ ${fromJsonBody}
|
|
|
9790
9790
|
}`;
|
|
9791
9791
|
const toJsonBody = props.map(([propName, propType]) => {
|
|
9792
9792
|
if (propType.type === "optional") {
|
|
9793
|
-
const nullCheck = isValueType(propType.value) ?
|
|
9794
|
-
return ` if (${nullCheck}) result["${propName}"] = ${renderToJson(propType, propName, toPascalCase(propName))};`;
|
|
9793
|
+
const nullCheck = isValueType(propType.value) ? `obj.${toPascalCase(propName)}.HasValue` : `obj.${toPascalCase(propName)} != null`;
|
|
9794
|
+
return ` if (${nullCheck}) result["${propName}"] = ${renderToJson(propType, propName, `obj.${toPascalCase(propName)}`)};`;
|
|
9795
9795
|
}
|
|
9796
|
-
return ` result["${propName}"] = ${renderToJson(propType, propName, toPascalCase(propName))};`;
|
|
9796
|
+
return ` result["${propName}"] = ${renderToJson(propType, propName, `obj.${toPascalCase(propName)}`)};`;
|
|
9797
9797
|
}).join(`
|
|
9798
9798
|
`);
|
|
9799
|
-
const toJsonMethod = ` public JsonObject ToJson()
|
|
9799
|
+
const toJsonMethod = ` public static JsonObject ToJson(${name} obj)
|
|
9800
9800
|
{
|
|
9801
9801
|
var result = new JsonObject();
|
|
9802
9802
|
${toJsonBody}
|
|
@@ -9989,7 +9989,7 @@ ${decodeDiffInternalMethod}
|
|
|
9989
9989
|
const toJsonCases = options.map((opt, i) => {
|
|
9990
9990
|
const variantName = opt.name;
|
|
9991
9991
|
const varName = toCamelCase(variantName);
|
|
9992
|
-
return ` ${i > 0 ? "else " : ""}if (obj is ${variantName} ${varName}) return new JsonObject { ["${variantName}"] = ${
|
|
9992
|
+
return ` ${i > 0 ? "else " : ""}if (obj is ${variantName} ${varName}) return new JsonObject { ["${variantName}"] = ${variantName}.ToJson(${varName}) };`;
|
|
9993
9993
|
}).join(`
|
|
9994
9994
|
`);
|
|
9995
9995
|
const baseClass = ` public abstract class ${name}
|
|
@@ -10203,12 +10203,12 @@ ${decodeDiffNewTypeCases}
|
|
|
10203
10203
|
} else if (type.type === "reference") {
|
|
10204
10204
|
return renderToJson(type.ref, type.ref.name, key);
|
|
10205
10205
|
} else if (type.type === "self-reference") {
|
|
10206
|
-
return `${
|
|
10206
|
+
return `${qualifyType(currentTypeName)}.ToJson(${key})`;
|
|
10207
10207
|
}
|
|
10208
10208
|
if (type.type === "union") {
|
|
10209
10209
|
return `${qualifyType(type.name)}.ToJson(${key})`;
|
|
10210
10210
|
}
|
|
10211
|
-
return `${
|
|
10211
|
+
return `${qualifyType(name)}.ToJson(${key})`;
|
|
10212
10212
|
}
|
|
10213
10213
|
function renderClone(type, name, key) {
|
|
10214
10214
|
if (type.type === "string" || type.type === "int" || type.type === "float" || type.type === "boolean" || type.type === "enum") {
|
|
@@ -11129,7 +11129,7 @@ var languages = {
|
|
|
11129
11129
|
// package.json
|
|
11130
11130
|
var package_default = {
|
|
11131
11131
|
name: "@hpx7/delta-pack-cli",
|
|
11132
|
-
version: "0.2.
|
|
11132
|
+
version: "0.2.2",
|
|
11133
11133
|
license: "MIT",
|
|
11134
11134
|
author: "hpx7",
|
|
11135
11135
|
repository: {
|
|
@@ -11159,7 +11159,7 @@ var package_default = {
|
|
|
11159
11159
|
test: "bun test"
|
|
11160
11160
|
},
|
|
11161
11161
|
dependencies: {
|
|
11162
|
-
"@hpx7/delta-pack": "^0.2.
|
|
11162
|
+
"@hpx7/delta-pack": "^0.2.5",
|
|
11163
11163
|
yaml: "^2.3.4"
|
|
11164
11164
|
},
|
|
11165
11165
|
devDependencies: {
|
|
@@ -11216,12 +11216,12 @@ async function generate(schemaPath, flags) {
|
|
|
11216
11216
|
}
|
|
11217
11217
|
const content = await readFile2(schemaPath, "utf-8");
|
|
11218
11218
|
const schema2 = parseSchemaYml(content);
|
|
11219
|
-
const
|
|
11220
|
-
if (!
|
|
11219
|
+
const codegen = languages[lang];
|
|
11220
|
+
if (!codegen) {
|
|
11221
11221
|
throw new ArgError(`generate: unknown language '${lang}'`);
|
|
11222
11222
|
}
|
|
11223
11223
|
const ns = flags.get("n") ?? flags.get("namespace");
|
|
11224
|
-
const code =
|
|
11224
|
+
const code = codegen(schema2, typeof ns === "string" ? ns : undefined);
|
|
11225
11225
|
await writeOutput(output === true ? undefined : output, code);
|
|
11226
11226
|
}
|
|
11227
11227
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hpx7/delta-pack-cli",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "hpx7",
|
|
6
6
|
"repository": {
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"test": "bun test"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@hpx7/delta-pack": "^0.2.
|
|
33
|
+
"@hpx7/delta-pack": "^0.2.5",
|
|
34
34
|
"yaml": "^2.3.4"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|