@storm-stack/core
Version:
A build toolkit and runtime used by Storm Software in TypeScript applications
136 lines (132 loc) • 7.69 kB
JavaScript
'use strict';
var chunkKUFKLCJS_cjs = require('./chunk-KUFKLCJS.cjs');
var chunkGRNJVY7I_cjs = require('./chunk-GRNJVY7I.cjs');
var getUnique = require('@stryke/helpers/get-unique');
var stormJson = require('@stryke/json/storm-json');
var isNull = require('@stryke/type-checks/is-null');
var isString = require('@stryke/type-checks/is-string');
var isUndefined = require('@stryke/type-checks/is-undefined');
function stringifyDefaultValue(property, value) {
return stringifyValue(property.type, value ?? property.getDefaultValue());
}
chunkGRNJVY7I_cjs.__name(stringifyDefaultValue, "stringifyDefaultValue");
function stringifyStringValue(value) {
return `"${String(value).replaceAll('"', '\\"')}"`;
}
chunkGRNJVY7I_cjs.__name(stringifyStringValue, "stringifyStringValue");
function stringifyValue(type, value) {
return isUndefined.isUndefined(value) ? "undefined" : isNull.isNull(value) ? "null" : type.kind === chunkKUFKLCJS_cjs.type_exports.ReflectionKind.boolean ? String(value).trim().toLowerCase() === "true" ? "true" : "false" : type.kind === chunkKUFKLCJS_cjs.type_exports.ReflectionKind.string || type.kind === chunkKUFKLCJS_cjs.type_exports.ReflectionKind.literal && isString.isString(type.literal) ? stringifyStringValue(value) : type.kind === chunkKUFKLCJS_cjs.type_exports.ReflectionKind.enum ? getEnumReflectionType(type).kind === chunkKUFKLCJS_cjs.type_exports.ReflectionKind.string ? stringifyStringValue(value) : `${String(value)}` : type.kind === chunkKUFKLCJS_cjs.type_exports.ReflectionKind.union ? isStringUnion(type) ? stringifyStringValue(value) : `${String(value)}` : type.kind === chunkKUFKLCJS_cjs.type_exports.ReflectionKind.array ? stringifyStringValue(stormJson.StormJSON.stringify(value)) : type.kind === chunkKUFKLCJS_cjs.type_exports.ReflectionKind.object || type.kind === chunkKUFKLCJS_cjs.type_exports.ReflectionKind.objectLiteral ? stormJson.StormJSON.stringify(value) : type.kind === chunkKUFKLCJS_cjs.type_exports.ReflectionKind.property || type.kind === chunkKUFKLCJS_cjs.type_exports.ReflectionKind.parameter ? stringifyValue(type.type, value) : String(value);
}
chunkGRNJVY7I_cjs.__name(stringifyValue, "stringifyValue");
function getEnumReflectionType(type) {
if (type.kind !== chunkKUFKLCJS_cjs.type_exports.ReflectionKind.enum) {
throw new Error(`Expected a TypeEnum, but received ${type.kind}.`);
}
const unique = getUnique.getUniqueBy(type.values.filter((value) => value !== void 0 && value !== null), (enumMember) => isString.isString(enumMember) ? {
kind: chunkKUFKLCJS_cjs.type_exports.ReflectionKind.string
} : {
kind: chunkKUFKLCJS_cjs.type_exports.ReflectionKind.number
});
if (unique.length === 0) {
throw new Error(`No valid enum members could be found.`);
}
return unique[0] && isString.isString(unique[0]) ? {
kind: chunkKUFKLCJS_cjs.type_exports.ReflectionKind.string
} : {
kind: chunkKUFKLCJS_cjs.type_exports.ReflectionKind.number
};
}
chunkGRNJVY7I_cjs.__name(getEnumReflectionType, "getEnumReflectionType");
function getUnionTypes(type) {
if (type.kind === chunkKUFKLCJS_cjs.type_exports.ReflectionKind.union && type.types.length > 0) {
return getUnique.getUniqueBy(type.types, (member) => member.kind);
}
throw new Error(`Expected a TypeUnion, but received ${type.kind}.`);
}
chunkGRNJVY7I_cjs.__name(getUnionTypes, "getUnionTypes");
function isStringUnion(type) {
return getUnionTypes(type).some((member) => member.kind === chunkKUFKLCJS_cjs.type_exports.ReflectionKind.string || member.kind === chunkKUFKLCJS_cjs.type_exports.ReflectionKind.literal && isString.isString(member.literal));
}
chunkGRNJVY7I_cjs.__name(isStringUnion, "isStringUnion");
function kindToName(kind) {
if (kind === chunkKUFKLCJS_cjs.type_exports.ReflectionKind.void) {
return "void";
} else if (kind === chunkKUFKLCJS_cjs.type_exports.ReflectionKind.never) {
return "never";
} else if (kind === chunkKUFKLCJS_cjs.type_exports.ReflectionKind.null) {
return "null";
} else if (kind === chunkKUFKLCJS_cjs.type_exports.ReflectionKind.undefined) {
return "undefined";
} else if (kind === chunkKUFKLCJS_cjs.type_exports.ReflectionKind.symbol) {
return "symbol";
} else if (kind === chunkKUFKLCJS_cjs.type_exports.ReflectionKind.bigint) {
return "bigint";
} else if (kind === chunkKUFKLCJS_cjs.type_exports.ReflectionKind.number) {
return "number";
} else if (kind === chunkKUFKLCJS_cjs.type_exports.ReflectionKind.string) {
return "string";
} else if (kind === chunkKUFKLCJS_cjs.type_exports.ReflectionKind.boolean) {
return "boolean";
} else if (kind === chunkKUFKLCJS_cjs.type_exports.ReflectionKind.literal) {
return "literal";
} else if (kind === chunkKUFKLCJS_cjs.type_exports.ReflectionKind.class) {
return "class";
} else if (kind === chunkKUFKLCJS_cjs.type_exports.ReflectionKind.array) {
return "array";
} else if (kind === chunkKUFKLCJS_cjs.type_exports.ReflectionKind.object) {
return "object";
} else if (kind === chunkKUFKLCJS_cjs.type_exports.ReflectionKind.objectLiteral) {
return "objectLiteral";
} else if (kind === chunkKUFKLCJS_cjs.type_exports.ReflectionKind.union) {
return "union";
} else if (kind === chunkKUFKLCJS_cjs.type_exports.ReflectionKind.enum) {
return "enum";
} else if (kind === chunkKUFKLCJS_cjs.type_exports.ReflectionKind.regexp) {
return "regexp";
} else if (kind === chunkKUFKLCJS_cjs.type_exports.ReflectionKind.templateLiteral) {
return "templateLiteral";
} else if (kind === chunkKUFKLCJS_cjs.type_exports.ReflectionKind.property) {
return "property";
} else if (kind === chunkKUFKLCJS_cjs.type_exports.ReflectionKind.method) {
return "method";
} else if (kind === chunkKUFKLCJS_cjs.type_exports.ReflectionKind.function) {
return "function";
} else if (kind === chunkKUFKLCJS_cjs.type_exports.ReflectionKind.parameter) {
return "parameter";
} else if (kind === chunkKUFKLCJS_cjs.type_exports.ReflectionKind.promise) {
return "promise";
} else if (kind === chunkKUFKLCJS_cjs.type_exports.ReflectionKind.typeParameter) {
return "typeParameter";
} else if (kind === chunkKUFKLCJS_cjs.type_exports.ReflectionKind.tuple) {
return "tuple";
} else if (kind === chunkKUFKLCJS_cjs.type_exports.ReflectionKind.tupleMember) {
return "tupleMember";
} else if (kind === chunkKUFKLCJS_cjs.type_exports.ReflectionKind.enumMember) {
return "enumMember";
} else if (kind === chunkKUFKLCJS_cjs.type_exports.ReflectionKind.rest) {
return "rest";
} else if (kind === chunkKUFKLCJS_cjs.type_exports.ReflectionKind.indexSignature) {
return "indexSignature";
} else if (kind === chunkKUFKLCJS_cjs.type_exports.ReflectionKind.propertySignature) {
return "propertySignature";
} else if (kind === chunkKUFKLCJS_cjs.type_exports.ReflectionKind.methodSignature) {
return "methodSignature";
} else if (kind === chunkKUFKLCJS_cjs.type_exports.ReflectionKind.infer) {
return "infer";
} else if (kind === chunkKUFKLCJS_cjs.type_exports.ReflectionKind.callSignature) {
return "callSignature";
} else if (kind === chunkKUFKLCJS_cjs.type_exports.ReflectionKind.any) {
return "any";
} else if (kind === chunkKUFKLCJS_cjs.type_exports.ReflectionKind.intersection) {
return "intersection";
}
return "unknown";
}
chunkGRNJVY7I_cjs.__name(kindToName, "kindToName");
exports.getEnumReflectionType = getEnumReflectionType;
exports.getUnionTypes = getUnionTypes;
exports.isStringUnion = isStringUnion;
exports.kindToName = kindToName;
exports.stringifyDefaultValue = stringifyDefaultValue;
exports.stringifyStringValue = stringifyStringValue;
exports.stringifyValue = stringifyValue;