From 326dfaef03bc35492132262b43353e0cec55897e Mon Sep 17 00:00:00 2001 From: HaseenaSainul Date: Tue, 5 Mar 2024 09:05:36 -0500 Subject: [PATCH] CPP: update based on merge with next branch --- .../sub-property/array.cpp | 12 ++++++------ languages/cpp/templates/methods/property.cpp | 1 + languages/cpp/templates/sdk/scripts/install.sh | 3 +-- .../javascript/templates/declarations/default.js | 2 +- languages/javascript/templates/schemas/default.js | 1 - languages/javascript/templates/types/default.mjs | 5 +---- languages/javascript/templates/types/enum.mjs | 3 --- languages/javascript/templates/types/enum.ts | 3 --- languages/javascript/templates/types/property.mjs | 2 +- src/macrofier/types.mjs | 10 ++++------ 10 files changed, 15 insertions(+), 27 deletions(-) diff --git a/languages/cpp/templates/callback-result-instantiation/sub-property/array.cpp b/languages/cpp/templates/callback-result-instantiation/sub-property/array.cpp index b2131f27..c9775b99 100644 --- a/languages/cpp/templates/callback-result-instantiation/sub-property/array.cpp +++ b/languages/cpp/templates/callback-result-instantiation/sub-property/array.cpp @@ -1,10 +1,10 @@ - ${if.optional}if (proxyResponse->${Property}.IsSet()) { - ${base.title}.${property} = std::make_optional<${type}>(); - auto index(proxyResponse->${Property}.Elements()); + ${if.optional}if ((*proxyResponse)${Property.dependency}.${Property}.IsSet()) { + ${base.title}${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property} = std::make_optional<${type}>(); + auto index((*proxyResponse)${Property.dependency}.${Property}.Elements()); while (index.Next() == true) { - ${if.object}${items.with.indent}${end.if.object}${if.non.object} ${base.title}.${property}.value().push_back(index.Current().Value());${end.if.non.object} + ${if.object}${items.with.indent}${end.if.object}${if.non.object} ${base.title}${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property}.value().push_back(index.Current().Value());${end.if.non.object} } - }${end.if.optional}${if.non.optional}auto index(proxyResponse->${Property}.Elements()); + }${end.if.optional}${if.non.optional}auto index((*proxyResponse)${Property.dependency}.${Property}.Elements()); while (index.Next() == true) { -${if.object}${items.with.indent}${end.if.object}${if.non.object} ${base.title}.${property}.value().push_back(index.Current().Value());${end.if.non.object} +${if.object}${items.with.indent}${end.if.object}${if.non.object} ${base.title}${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property}.value().push_back(index.Current().Value());${end.if.non.object} }${end.if.non.optional} diff --git a/languages/cpp/templates/methods/property.cpp b/languages/cpp/templates/methods/property.cpp index 607a6527..ce38ebd0 100644 --- a/languages/cpp/templates/methods/property.cpp +++ b/languages/cpp/templates/methods/property.cpp @@ -2,6 +2,7 @@ ${method.signature.result} ${info.Title}Impl::${method.name}( ${method.signature.params}${if.params}, ${end.if.params}Firebolt::Error *err ) const { const string method = _T("${info.title.lowercase}.${method.name}"); + ${if.params}JsonObject jsonParameters;${end.if.params} ${if.params}${method.params.serialization}${end.if.params} ${method.result.json} jsonResult; ${method.result.initialization} diff --git a/languages/cpp/templates/sdk/scripts/install.sh b/languages/cpp/templates/sdk/scripts/install.sh index b1aa8892..5d54a783 100755 --- a/languages/cpp/templates/sdk/scripts/install.sh +++ b/languages/cpp/templates/sdk/scripts/install.sh @@ -26,9 +26,8 @@ done GetVersion() { PackagePath=${SdkPath}/../../../../../../package-lock.json - InputKey="name\": \"@firebolt-js/openrpc" + InputKey="\"@firebolt-js/openrpc" LineNo="$(grep -n "${InputKey}" ${PackagePath} | head -n 1 | cut -d: -f1)" - VersionLine=$((LineNo++)) eval "array=(`sed -n "${LineNo}p" < ${PackagePath} | sed 's/\"/\n/g'`)" Version=${array[2]} } diff --git a/languages/javascript/templates/declarations/default.js b/languages/javascript/templates/declarations/default.js index 6eb4d88d..950ffac9 100644 --- a/languages/javascript/templates/declarations/default.js +++ b/languages/javascript/templates/declarations/default.js @@ -3,4 +3,4 @@ * ${method.params.annotations}${if.deprecated} * @deprecated ${method.deprecation} ${end.if.deprecated} */ -function ${method.name}(${method.signature.params}): Promise<${method.result.type}> + function ${method.name}(${method.signature.params}): Promise<${method.result.type}> diff --git a/languages/javascript/templates/schemas/default.js b/languages/javascript/templates/schemas/default.js index bc9ab873..f00b1e37 100644 --- a/languages/javascript/templates/schemas/default.js +++ b/languages/javascript/templates/schemas/default.js @@ -1,5 +1,4 @@ /** * ${schema.description} */ - ${schema.shape} diff --git a/languages/javascript/templates/types/default.mjs b/languages/javascript/templates/types/default.mjs index 8723ec3a..3d9103b2 100644 --- a/languages/javascript/templates/types/default.mjs +++ b/languages/javascript/templates/types/default.mjs @@ -1,4 +1 @@ -/* - * ${title} - ${description} - */ -type ${title} = ${shape} +type ${title} = ${shape} \ No newline at end of file diff --git a/languages/javascript/templates/types/enum.mjs b/languages/javascript/templates/types/enum.mjs index 35529071..ae4a06b6 100644 --- a/languages/javascript/templates/types/enum.mjs +++ b/languages/javascript/templates/types/enum.mjs @@ -1,6 +1,3 @@ -/* - * ${title} - ${description} - */ ${title}: { ${key}: '${value}', }, diff --git a/languages/javascript/templates/types/enum.ts b/languages/javascript/templates/types/enum.ts index 16c14463..0743ba85 100644 --- a/languages/javascript/templates/types/enum.ts +++ b/languages/javascript/templates/types/enum.ts @@ -1,6 +1,3 @@ -/* - * ${title} - ${description} - */ enum ${title} { ${key} = '${value}', } diff --git a/languages/javascript/templates/types/property.mjs b/languages/javascript/templates/types/property.mjs index 2fc6076f..fac92c94 100644 --- a/languages/javascript/templates/types/property.mjs +++ b/languages/javascript/templates/types/property.mjs @@ -1 +1 @@ - ${property}${if.optional}?${end.if.optional}: ${title} // ${summary} \ No newline at end of file + ${property}${if.optional}?${end.if.optional}: ${title} // ${summary} diff --git a/src/macrofier/types.mjs b/src/macrofier/types.mjs index 632d0b11..9d22fe49 100644 --- a/src/macrofier/types.mjs +++ b/src/macrofier/types.mjs @@ -17,7 +17,7 @@ */ import deepmerge from 'deepmerge' -import { getPath, localizeDependencies } from '../shared/json-schema.mjs' +import { getPath, localizeDependencies, getSafeEnumKeyName } from '../shared/json-schema.mjs' import path from "path" let convertTuplesToArraysOrObjects = false @@ -69,8 +69,6 @@ const indent = (str, padding) => { } } -const safeName = value => value.split(':').pop().replace(/[\.\-]/g, '_').replace(/\+/g, '_plus').replace(/([a-z])([A-Z0-9])/g, '$1_$2').toUpperCase() - // TODO: This is what's left of getMethodSignatureParams. We need to figure out / handle C's `FireboltTypes_StringHandle` function getMethodSignatureParams(method, module, { destination, callback }) { const paramOptional = getTemplate('/parameters/optional') @@ -215,7 +213,7 @@ const insertEnumMacros = (content, schema, module, name, suffix, templateDir = " if (!value) { value = getTemplate(path.join(templateDir, 'unset' + suffix)) } - value ? values.push(template[i].replace(/\$\{key\}/g, safeName(value)) + value ? values.push(template[i].replace(/\$\{key\}/g, getSafeEnumKeyName(value)) .replace(/\$\{value\}/g, value)) : '' }) template[i] = values.map((value, id) => { @@ -401,8 +399,8 @@ const insertObjectMacros = (content, schema, module, title, property, options) = options2.property = prop const schemaShape = getSchemaShape(type, module, options2) properties.push(template - .replace(/\$\{property\}/g, safeName(prop)) - .replace(/\$\{Property\}/g, capitalize(safeName(prop))) + .replace(/\$\{property\}/g, getSafeEnumKeyName(prop)) + .replace(/\$\{Property\}/g, capitalize(getSafeEnumKeyName(prop))) .replace(/\$\{parent\.title\}/g, title) .replace(/\$\{title\}/g, getSchemaType(type, module, options2)) .replace(/\$\{shape\}/g, schemaShape)