in src/web/src/views/workspace/WSEditorCommandArgumentsContent.tsx [2221:2391]
function decodeArgBase(response: any): {
argBase: CMDArgBase;
clsDefineMap: ClsArgDefinitionMap;
} {
let argBase: any = {
type: response.type,
nullable: (response.nullable ?? false) as boolean,
};
let clsDefineMap: ClsArgDefinitionMap = {};
switch (response.type) {
case "byte":
case "binary":
case "duration":
case "date":
case "dateTime":
case "time":
case "uuid":
case "password":
case "SubscriptionId":
case "ResourceGroupName":
case "ResourceId":
case "ResourceLocation":
case "string":
if (response.enum) {
argBase = {
...argBase,
enum: decodeArgEnum<string>(response.enum),
};
}
if (response.blank) {
argBase = {
...argBase,
blank: decodeArgBlank<string>(response.blank),
};
}
break;
case "integer32":
case "integer64":
case "integer":
if (response.enum) {
argBase = {
...argBase,
enum: decodeArgEnum<number>(response.enum),
};
}
if (response.blank) {
argBase = {
...argBase,
blank: decodeArgBlank<number>(response.blank),
};
}
break;
case "float32":
case "float64":
case "float":
if (response.enum) {
argBase = {
...argBase,
enum: decodeArgEnum<number>(response.enum),
};
}
if (response.blank) {
argBase = {
...argBase,
blank: decodeArgBlank<number>(response.blank),
};
}
break;
case "boolean":
if (response.blank) {
argBase = {
...argBase,
blank: decodeArgBlank<boolean>(response.blank),
};
}
break;
case "any":
if (response.blank) {
argBase = {
...argBase,
blank: decodeArgBlank<boolean>(response.blank),
};
}
break;
case "object":
if (response.args && Array.isArray(response.args) && response.args.length > 0) {
const args: CMDArg[] = response.args.map((resSubArg: any) => {
const subArgParse = decodeArg(resSubArg);
clsDefineMap = {
...clsDefineMap,
...subArgParse.clsDefineMap,
};
return subArgParse.arg;
});
argBase = {
...argBase,
args: args,
};
} else if (response.additionalProps && response.additionalProps.item) {
// Convert additionalProps to dict argBaseType
const itemArgBaseParse = decodeArgBase(response.additionalProps.item);
clsDefineMap = {
...clsDefineMap,
...itemArgBaseParse.clsDefineMap,
};
const argBaseType = `dict<string, ${itemArgBaseParse.argBase.type}>`;
argBase = {
...argBase,
type: argBaseType,
item: itemArgBaseParse.argBase,
anyType: false,
};
} else if (response.additionalProps && response.additionalProps.anyType) {
const argBaseType = `dict<string, Any>`;
argBase = {
...argBase,
type: argBaseType,
anyType: true,
};
}
if (response.cls) {
const clsName = response.cls;
clsDefineMap[clsName] = argBase;
argBase = {
type: `@${response.cls}`,
clsName: clsName,
};
}
break;
default:
if (response.type.startsWith("array<")) {
if (response.item) {
const itemArgBaseParse = decodeArgBase(response.item);
clsDefineMap = {
...clsDefineMap,
...itemArgBaseParse.clsDefineMap,
};
const argBaseType = `array<${itemArgBaseParse.argBase.type}>`;
argBase = {
...argBase,
type: argBaseType,
item: itemArgBaseParse.argBase,
};
} else {
throw Error("Invalid array object. Item is not defined");
}
if (response.cls) {
const clsName = response.cls;
clsDefineMap[clsName] = argBase;
argBase = {
type: `@${response.cls}`,
clsName: clsName,
};
}
} else if (response.type.startsWith("@")) {
argBase["clsName"] = response.type.slice(1);
} else {
console.error(`Unknown type '${response.type}'`);
throw Error(`Unknown type '${response.type}'`);
}
}
return {
argBase: argBase,
clsDefineMap: clsDefineMap,
};
}