semver#gte TypeScript Examples
The following examples show how to use
semver#gte.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ast_mapping.ts From solc-typed-ast with Apache License 2.0 | 6 votes |
writeInner(node: ElementaryTypeName, writer: ASTWriter): SrcDesc {
if (satisfies(writer.targetCompilerVersion, "0.4")) {
return [node.name];
}
if (
gte(writer.targetCompilerVersion, "0.6.0") &&
node.name === "address" &&
node.parent instanceof ElementaryTypeNameExpression
) {
return [node.stateMutability === "payable" ? "payable" : "address"];
}
return [node.stateMutability === "payable" ? node.name + " payable" : node.name];
}
Example #2
Source File: ast_mapping.ts From solc-typed-ast with Apache License 2.0 | 6 votes |
writeInner(node: ModifierDefinition, writer: ASTWriter): SrcDesc {
const args: DescArgs = ["modifier ", node.name, node.vParameters];
if (gte(writer.targetCompilerVersion, "0.6.0")) {
if (node.virtual) {
args.push(" virtual");
}
if (node.vOverrideSpecifier) {
args.push(" ", node.vOverrideSpecifier);
}
}
if (node.vBody) {
args.push(" ", node.vBody);
} else {
args.push(";");
}
return writer.desc(...args);
}
Example #3
Source File: ast_mapping.ts From solc-typed-ast with Apache License 2.0 | 6 votes |
private getHeader(node: ContractDefinition, writer: ASTWriter): DescArgs {
const result: DescArgs = [];
if (gte(writer.targetCompilerVersion, "0.6.0") && node.abstract) {
result.push("abstract ");
}
result.push(node.kind, " ", node.name);
if (node.vInheritanceSpecifiers.length) {
result.push(" is ", ...join(node.vInheritanceSpecifiers, ", "));
}
return result;
}
Example #4
Source File: instance-check.ts From orangehrm-os-mobile with GNU General Public License v3.0 | 6 votes |
checkInstanceCompatibility = (openApiDefinition: any): boolean => {
if (major(openApiDefinition.openapi) === 3) {
if (
gte(openApiDefinition?.info?.version, REQUIRED_MINIMUM_ORANGEHRM_API_VER)
) {
return true;
}
throw new InstanceCheckError('Incompatible OrangeHRM API version.');
}
throw new InstanceCheckError('Incompatible OpenAPI version.');
}
Example #5
Source File: platform.ts From orangehrm-os-mobile with GNU General Public License v3.0 | 6 votes |
isAboveIOS14 = () => {
if (Platform.OS === 'ios') {
const platformVer = valid(coerce(Platform.Version.toString()));
if (platformVer) {
return gte(platformVer, '14.0.0');
}
}
return false;
}
Example #6
Source File: definitions.ts From solc-typed-ast with Apache License 2.0 | 5 votes |
/**
* Given any `ASTNode` `node` and a compiler verison `version` return the `ScopeNode` containing `node`, or undefined
* if `node` is a top-level scope. (i.e. a `SourceUnit`)
*/
function getContainingScope(node: ASTNode, version: string): ScopeNode | undefined {
if (node instanceof SourceUnit) {
return undefined;
}
let pt = node.parent;
while (
pt !== undefined &&
!(
pt instanceof SourceUnit ||
pt instanceof ContractDefinition ||
pt instanceof FunctionDefinition ||
pt instanceof ModifierDefinition ||
pt instanceof Block ||
pt instanceof UncheckedBlock ||
pt instanceof ForStatement ||
pt instanceof TryCatchClause
)
) {
node = pt;
pt = pt.parent;
}
if (pt === undefined) {
return undefined;
}
if (pt instanceof ForStatement) {
if (
node !== pt.vInitializationExpression &&
pt.vInitializationExpression instanceof VariableDeclarationStatement
) {
return pt.vInitializationExpression;
}
return getContainingScope(pt, version);
}
if (pt instanceof Block || pt instanceof UncheckedBlock) {
if (gte(version, "0.5.0")) {
const ptChildren = pt.children;
for (let i = ptChildren.indexOf(node) - 1; i >= 0; i--) {
const sibling = ptChildren[i];
if (sibling instanceof VariableDeclarationStatement) {
return sibling;
}
}
// Note that in >=0.5.0 Block/UncheckedBlock IS NOT a scope. VariableDeclarationStatement IS.
return getContainingScope(pt, version);
}
}
return pt;
}
Example #7
Source File: ast_mapping.ts From solc-typed-ast with Apache License 2.0 | 5 votes |
private getHeader(node: FunctionDefinition, writer: ASTWriter): DescArgs {
const isGte06 = gte(writer.targetCompilerVersion, "0.6.0");
const isGte07 = gte(writer.targetCompilerVersion, "0.7.0");
const isFileLevel = node.kind === FunctionKind.Free;
let name: string;
if (isGte06) {
name =
node.kind === FunctionKind.Function || isFileLevel
? `function ${node.name}`
: node.kind;
} else {
name = node.isConstructor && node.name === "" ? "constructor" : `function ${node.name}`;
}
const result: DescArgs = [name, node.vParameters];
if (isGte06) {
if (node.virtual) {
result.push(" virtual");
}
if (node.vOverrideSpecifier) {
result.push(" ", node.vOverrideSpecifier);
}
}
if (!((isGte07 && node.isConstructor) || isFileLevel)) {
result.push(" ", node.visibility);
}
if (node.stateMutability !== FunctionStateMutability.NonPayable) {
result.push(" ", node.stateMutability);
}
if (node.vModifiers.length) {
result.push(" ", ...join(node.vModifiers, " "));
}
if (node.vReturnParameters.vParameters.length) {
result.push(" returns ", node.vReturnParameters);
}
return result;
}
Example #8
Source File: telemetry.controller.ts From ironfish-api with Mozilla Public License 2.0 | 5 votes |
@ApiExcludeEndpoint()
@Post()
async write(
@Req() request: Request,
@Body(
new ValidationPipe({
errorHttpStatusCode: HttpStatus.UNPROCESSABLE_ENTITY,
transform: true,
}),
)
{ points, graffiti }: WriteTelemetryPointsDto,
): Promise<void> {
const options = [];
let nodeVersion;
for (const { fields, measurement, tags, timestamp } of points) {
const version = tags.find((tag) => tag.name === 'version');
if (!version || !this.isValidTelemetryVersion(version.value)) {
continue;
}
nodeVersion = version.value;
options.push({
fields,
measurement,
tags,
timestamp,
});
}
if (options.length) {
this.influxDbService.writePoints(options);
}
this.submitIpWithoutNodeFieldsToTelemetry(request);
if (!graffiti || !nodeVersion) {
return;
}
const nodeUptimeEnabled = this.config.get<boolean>('NODE_UPTIME_ENABLED');
if (!nodeUptimeEnabled) {
return;
}
const oneWeekAgo = new Date();
oneWeekAgo.setDate(oneWeekAgo.getDate() - 7);
const minVersion = await this.versionsService.getLatestAtDate(oneWeekAgo);
// If the API fails to fetch a version, we don't want to punish the user
if (!minVersion || gte(nodeVersion, minVersion.version)) {
const user = await this.usersService.findByGraffiti(graffiti);
if (user) {
await this.nodeUptimes.addUptime(user);
}
}
}
Example #9
Source File: telemetry.controller.ts From ironfish-api with Mozilla Public License 2.0 | 5 votes |
private isValidTelemetryVersion(version: string): boolean {
const parsed = valid(version);
if (!parsed) {
return false;
}
return gte(parsed, this.MINIMUM_TELEMETRY_VERSION);
}
Example #10
Source File: instance-check.ts From orangehrm-os-mobile with GNU General Public License v3.0 | 5 votes |
isApiCompatible = (
currentVersion: string,
requiredMinimumVersion: string,
): boolean => {
return gte(currentVersion, requiredMinimumVersion);
}
Example #11
Source File: typestrings.spec.ts From solc-typed-ast with Apache License 2.0 | 4 votes |
describe("Round-trip tests for typestring parser/printer", () => {
for (const [sample, compilerVersion, astKind] of samples) {
for (const compilerKind of PossibleCompilerKinds) {
it(`[${compilerKind}] ${sample}`, async () => {
const result = await compileSol(
sample,
"auto",
undefined,
undefined,
undefined,
compilerKind as CompilerKind
);
expect(result.compilerVersion).toEqual(compilerVersion);
const errors = detectCompileErrors(result.data);
expect(errors).toHaveLength(0);
const data = result.data;
const reader = new ASTReader();
const sourceUnits = reader.read(data, astKind);
for (const unit of sourceUnits) {
for (const node of unit.getChildrenBySelector(
(child) =>
child instanceof Expression || child instanceof VariableDeclaration
)) {
const typedASTNode = node as Expression | VariableDeclaration;
// typeStrings for Identifiers in ImportDirectives may be undefined.
if (typedASTNode.typeString === undefined) {
continue;
}
// Skip modifier invocations
if (typedASTNode.parent instanceof ModifierInvocation) {
continue;
}
const typeNode = getNodeType(typedASTNode, compilerVersion);
// Edge case: We don't fully model type strings for external function type names.
// External function type strings contain the funtion name as well, which we ignore
// and treat them as normal type names.
if (
typeNode instanceof FunctionTypeName &&
typedASTNode.typeString.includes("SampleInterface.infFunc")
) {
continue;
}
const compTypeString = typeNode.pp();
let skipTypeStringEqCheck = false;
// We disagree with the normal TypeStrings for mappings - we always wrap them in a pointer.
if (typeNode instanceof PointerType && typeNode.to instanceof MappingType) {
skipTypeStringEqCheck = true;
}
// typeStrings shorten some int_const by omitting digits.
// Ignore those as we can't correctly reproduce them.
if (
typedASTNode.typeString.trim() !== compTypeString &&
typedASTNode.typeString.includes("digits omitted")
) {
skipTypeStringEqCheck = true;
}
if (!skipTypeStringEqCheck) {
expect(typedASTNode.typeString.trim()).toEqual(compTypeString.trim());
}
// Check that the conversion from TypeNode ast nodes to
if (
gte(compilerVersion, "0.5.0") &&
typedASTNode instanceof Identifier &&
typedASTNode.vReferencedDeclaration instanceof VariableDeclaration &&
typedASTNode.vReferencedDeclaration.vType !== undefined
) {
const compType2 = variableDeclarationToTypeNode(
typedASTNode.vReferencedDeclaration
);
if (
compType2 instanceof PointerType &&
compType2.location === DataLocation.Default
) {
continue;
}
expect(eq(compType2, typeNode)).toBeTruthy();
// Check that specialize and generalize are inverses
const [generalizedType, loc] = generalizeType(typeNode);
const reSpecializedType = specializeType(
generalizedType,
loc === undefined ? DataLocation.Default : loc
);
expect(eq(typeNode, reSpecializedType)).toBeTruthy();
}
}
}
});
}
}
});