diff --git a/.gitignore b/.gitignore index 9a7f5d51..b2087109 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ coverage/ .vscode/ *.iml .idea +/packages/*/bin/*.reflectable.dart diff --git a/README.md b/README.md index 587a8ee8..6dec29ef 100644 --- a/README.md +++ b/README.md @@ -3,11 +3,15 @@ [![melos](https://img.shields.io/badge/maintained%20with-melos-f700ff.svg?style=flat-square)](https://github.com/invertase/melos) [![codecov](https://codecov.io/gh/codescalers/tfgrid-sdk-dart/graph/badge.svg?token=O34UDTMW5O)](https://codecov.io/gh/codescalers/tfgrid-sdk-dart) This repo contains the dart clients for Threefold grid. + ## Packages - [signer](./packages/signer/README.md) - [tfchain_client](./packages/tfchain_client/README.md) +- [gridproxy_client](./packages/gridproxy_client/README.md) +- [graphql_client](./packages/graphql_client/README.md) - [stellar_client](./packages/stellar_client/README.md) + ## Prerequisites Make sure you have the following tools installed: diff --git a/git_hooks/pre-commit b/git_hooks/pre-commit new file mode 100755 index 00000000..6f2c2bfb --- /dev/null +++ b/git_hooks/pre-commit @@ -0,0 +1,38 @@ +#!/bin/sh + +result=$(dart format .) +exitCode=$? # If the exitCode is zero, then command executed successfully. + +if [ $exitCode -ne 0 ]; then + echo "$result" + echo "Dart format found issues, please fix them." + exit 1 +fi +echo "Finished running dart format command." + +################################################################ + +result=$(dart analyze .) +exitCode=$? # If the exitCode is zero, then command executed successfully. + +if [ $exitCode -ne 0 ]; then + echo "$result" +fi +echo "Finished running dart analyze command." + +################################################################ + +# Run `dart dry --apply` to auto-fix basic issues. +result=$(dart fix --apply) +exitCode=$? + +# Adding the files updated by `dart fix` command to git. +git add . + +echo "$result" + +if [ $exitCode -ne 0 ]; then + echo "dart fix command failed to execute." + exit 1 +fi +echo "Finished running dart fix command." diff --git a/packages/graphql_client/README.md b/packages/graphql_client/README.md new file mode 100644 index 00000000..dd731bf0 --- /dev/null +++ b/packages/graphql_client/README.md @@ -0,0 +1,47 @@ +# Graphql Client + +This is a dart client to send requests to graphql based on network for Threefold grid. + +## Install Dependencies + +``` bash +dart pub get +``` + +## Generate Reflectable code + +```bash +dart run build_runner build +``` + +## Usage + +- Ensure that initializeReflectable() is called at the beginning of your main + +- Example usage: + +```dart +import 'package:graphql_client/graphql_client.dart'; +import 'package:graphql_client/models.dart'; +import 'graphql_client.reflectable.dart'; + +void main() async { + initializeReflectable(); + + final graphQLClient = GraphQLClient('https://graphql.dev.grid.tf/graphql'); + + final FarmsReturnOptions farmsReturnOptions = FarmsReturnOptions( + farmID: true, + publicIps: PublicIpsReturnOptions(ip: true), + ); + final FarmsQueryOptions farmsQueryOptions = FarmsQueryOptions( + idEq: "farm-id", + ); + + Future> farms = await graphQLClient.farms.list(farmsQueryOptions, farmsReturnOptions); + + for (var farm in farms) { + print(farm); + } +} +``` diff --git a/packages/graphql_client/bin/graphql_client.dart b/packages/graphql_client/bin/graphql_client.dart new file mode 100644 index 00000000..1fe82afa --- /dev/null +++ b/packages/graphql_client/bin/graphql_client.dart @@ -0,0 +1,14 @@ +import 'package:graphql_client/graphql_client.dart'; +import 'package:graphql_client/models.dart'; +// import 'graphql_client.reflectable.dart'; + +void main() async { + // initializeReflectable(); + final graphQLClient = GraphQLClient('https://graphql.dev.grid.tf/graphql'); + + final res = await graphQLClient.twins.twinsConnections( + TwinConnectionsReturnOptions(), + TwinConnectionsQueryOptions( + whereOptions: TwinQueryWhereOptions(idEq: "89"))); + print(res); +} diff --git a/packages/graphql_client/build.yaml b/packages/graphql_client/build.yaml new file mode 100644 index 00000000..592b8f52 --- /dev/null +++ b/packages/graphql_client/build.yaml @@ -0,0 +1,6 @@ +targets: + $default: + builders: + graphql_client: + generate_for: + - lib/**/*.dart diff --git a/packages/graphql_client/lib/graphql_client.dart b/packages/graphql_client/lib/graphql_client.dart new file mode 100644 index 00000000..cb5862ae --- /dev/null +++ b/packages/graphql_client/lib/graphql_client.dart @@ -0,0 +1,11 @@ +library client; + +import 'dart:convert'; + +import 'package:graphql_client/src/contracts.dart'; +import 'package:graphql_client/src/farms.dart'; +import 'package:graphql_client/src/nodes.dart'; +import 'package:graphql_client/src/twins.dart'; +import 'package:http/http.dart' as http; + +part 'src/client.dart'; diff --git a/packages/graphql_client/lib/models.dart b/packages/graphql_client/lib/models.dart new file mode 100644 index 00000000..cce9a55a --- /dev/null +++ b/packages/graphql_client/lib/models.dart @@ -0,0 +1,18 @@ +library models; + +import 'package:graphql_client/models/reflector.dart'; +import 'package:reflectable/reflectable.dart'; + +part 'models/public_ips.dart'; +part 'src/query_builder.dart'; +part 'models/twins.dart'; +part 'models/farms.dart'; +part 'models/edges.dart'; +part 'models/node.dart'; +part 'models/page_info.dart'; +part 'models/contracts.dart'; +part 'models/nodes.dart'; +part 'models/location.dart'; +part 'models/public_config.dart'; +part 'models/power.dart'; +part "models/interfaces.dart"; diff --git a/packages/graphql_client/lib/models/contracts.dart b/packages/graphql_client/lib/models/contracts.dart new file mode 100644 index 00000000..9aa846b6 --- /dev/null +++ b/packages/graphql_client/lib/models/contracts.dart @@ -0,0 +1,1644 @@ +// ignore_for_file: constant_identifier_names + +part of '../models.dart'; + +enum ContractStates { + Created, + Deleted, + OutOfFunds, + GracePeriod; + + @override + String toString() { + return name; + } +} + +enum DiscountLevel { + None, + Default, + Bronze, + Silver, + Gold; + + @override + String toString() { + return name; + } +} + +enum ContractsOrderByOptions { + id_ASC, + id_DESC, + gridVersion_ASC, + gridVersion_DESC, + contractID_ASC, + contractID_DESC, + twinID_ASC, + twinID_DESC, + name_ASC, + name_DESC, + state_ASC, + state_DESC, + createdAt_ASC, + createdAt_DESC, + solutionProviderID_ASC, + solutionProviderID_DESC; + + @override + String toString() { + return name; + } +} + +DiscountLevel parseDiscountLevel(String level) { + switch (level.toLowerCase()) { + case 'None': + return DiscountLevel.None; + case 'Default': + return DiscountLevel.Default; + case 'Bronze': + return DiscountLevel.Bronze; + case 'Silver': + return DiscountLevel.Silver; + case 'Gold': + return DiscountLevel.Gold; + default: + return DiscountLevel.None; + } +} + +@reflector +class BaseContractReturnOptions { + bool id; + bool gridVersion; + bool contractID; + bool twinID; + bool state; + bool createdAt; + bool solutionProviderID; + + BaseContractReturnOptions({ + this.id = false, + this.gridVersion = false, + this.contractID = false, + this.twinID = false, + this.state = false, + this.createdAt = false, + this.solutionProviderID = false, + }); + + factory BaseContractReturnOptions.fromJson(Map json) { + return fromJson(json); + } + + @override + String toString() { + return generateToString(this); + } +} + +@reflector +class BaseContract { + String? id; + int? gridVersion; + String? contractID; + int? twinID; + String? state; + String? createdAt; + int? solutionProviderID; + + BaseContract({ + this.id, + this.gridVersion, + this.contractID, + this.twinID, + this.state, + this.createdAt, + this.solutionProviderID, + }); + + factory BaseContract.fromJson(Map json) { + return fromJson(json); + } +} + +@reflector +class NameContractReturnOptions extends BaseContractReturnOptions { + bool name; + + NameContractReturnOptions({ + this.name = false, + super.id = false, + super.gridVersion = false, + super.contractID = false, + super.twinID = false, + super.state = false, + super.createdAt = false, + super.solutionProviderID = false, + }); + + @override + String toString() { + String returnOptions = super.toString(); + returnOptions = _addToReturnList(returnOptions, 'name', name); + return returnOptions; + } +} + +@reflector +class NameContract extends BaseContract { + String? name; + + NameContract({ + super.id, + super.gridVersion, + super.contractID, + super.twinID, + super.state, + super.createdAt, + super.solutionProviderID, + this.name, + }); + + factory NameContract.fromJson(Map json) { + return fromJson(json); + } + + @override + String toString() { + return generateToString(this); + } +} + +@reflector +class NodeContractReturnOptions extends BaseContractReturnOptions { + bool nodeID; + bool deploymentData; + bool deploymentHash; + bool numberOfPublicIPs; + ContractUsedResourcesReturnOptions? resourcesUsed; + + NodeContractReturnOptions({ + this.nodeID = false, + this.deploymentData = false, + this.deploymentHash = false, + this.numberOfPublicIPs = false, + this.resourcesUsed, + super.id = false, + super.gridVersion = false, + super.contractID = false, + super.twinID = false, + super.state = false, + super.createdAt = false, + super.solutionProviderID = false, + }); + + @override + String toString() { + String returnOptions = super.toString(); + returnOptions = _addToReturnList(returnOptions, 'nodeID', nodeID); + returnOptions = + _addToReturnList(returnOptions, 'deploymentData', deploymentData); + returnOptions = + _addToReturnList(returnOptions, 'deploymentHash', deploymentHash); + returnOptions = + _addToReturnList(returnOptions, 'numberOfPublicIPs', numberOfPublicIPs); + returnOptions = _addToReturnList( + returnOptions, 'resourcesUsed{', resourcesUsed != null); + returnOptions = _addToReturnList( + returnOptions, resourcesUsed.toString(), resourcesUsed != null); + returnOptions = _addToReturnList(returnOptions, '}', resourcesUsed != null); + return returnOptions; + } +} + +@reflector +class NodeContract extends BaseContract { + int? nodeID; + String? deploymentData; + String? deploymentHash; + int? numberOfPublicIPs; + ContractUsedResources? resourcesUsed; + + NodeContract({ + super.id, + super.gridVersion, + super.contractID, + super.twinID, + super.state, + super.createdAt, + super.solutionProviderID, + this.nodeID, + this.deploymentData, + this.deploymentHash, + this.numberOfPublicIPs, + this.resourcesUsed, + }); + + factory NodeContract.fromJson(Map json) { + return NodeContract( + contractID: json['contractID'] ?? '', + twinID: json['twinID'] ?? 0, + state: json['state'] ?? '', + createdAt: json['createdAt'] ?? '', + solutionProviderID: json['solutionProviderID'] ?? 0, + nodeID: json['nodeID'] ?? 0, + deploymentData: json['deploymentData'] ?? '', + deploymentHash: json['deploymentHash'] ?? '', + numberOfPublicIPs: json['numberOfPublicIPs'] ?? 0, + gridVersion: json['gridVersion'] ?? 0, + id: json['id'] ?? '', + resourcesUsed: json['resourcesUsed'] != null + ? ContractUsedResources.fromJson(json['resourcesUsed']) + : null, + ); + } + + @override + String toString() { + return generateToString(this); + } +} + +@reflector +class RentContractReturnOptions extends BaseContractReturnOptions { + bool nodeID; + + RentContractReturnOptions({ + this.nodeID = false, + super.id = false, + super.gridVersion = false, + super.contractID = false, + super.twinID = false, + super.state = false, + super.createdAt = false, + super.solutionProviderID = false, + }); + + @override + String toString() { + String returnOptions = super.toString(); + returnOptions = _addToReturnList(returnOptions, 'nodeID', nodeID); + return returnOptions; + } +} + +@reflector +class RentContract extends BaseContract { + int? nodeID; + + RentContract({ + super.id, + super.gridVersion, + super.contractID, + super.twinID, + super.state, + super.createdAt, + super.solutionProviderID, + this.nodeID, + }); + + factory RentContract.fromJson(Map json) { + return fromJson(json); + } + + @override + String toString() { + return generateToString(this); + } +} + +@reflector +class ContractUsedResourcesReturnOptions { + bool hru; + bool sru; + bool cru; + bool mru; + bool id; + + ContractUsedResourcesReturnOptions({ + this.hru = false, + this.sru = false, + this.cru = false, + this.mru = false, + this.id = false, + }); + + @override + String toString() { + return generateToString(this); + } +} + +@reflector +class ContractUsedResources { + String? hru; + String? sru; + String? cru; + String? mru; + String? id; + + ContractUsedResources({ + this.hru, + this.sru, + this.cru, + this.mru, + this.id, + }); + + factory ContractUsedResources.fromJson(Map json) { + return fromJson(json); + } + + @override + String toString() { + return generateToString(this); + } +} + +class Contracts { + List nameContracts; + List nodeContracts; + List rentContracts; + + Contracts({ + required this.nameContracts, + required this.nodeContracts, + required this.rentContracts, + }); +} + +class ListContractByTwinIdOptions { + int twinId; + List? stateList; + String? type; + String? projectName; + int? nodeId; + + ListContractByTwinIdOptions({ + required this.twinId, + this.stateList, + this.type, + this.projectName, + this.nodeId, + }); +} + +class GetConsumptionOptions { + String contractID; + + GetConsumptionOptions({ + required this.contractID, + }); +} + +@reflector +class ContractBillReports { + String? id; + BigInt? contractID; + DiscountLevel? discountLevel; + String? amountBilled; + String? timeStamp; + + ContractBillReports({ + this.id, + this.contractID, + this.discountLevel, + this.amountBilled, + this.timeStamp, + }); + + factory ContractBillReports.fromJson(Map json) { + return ContractBillReports( + id: json['id'] ?? '', + contractID: BigInt.parse(json['contractID'] ?? 0), + discountLevel: parseDiscountLevel(json['discountReceived']), + amountBilled: json['amountBilled'] ?? '', + timeStamp: json['timestamp'] ?? '', + ); + } + + @override + String toString() { + return generateToString(this); + } +} + +@reflector +class ContractBillReportsReturnOptions { + bool id; + bool contractID; + bool discountLevel; + bool amountBilled; + bool timeStamp; + + ContractBillReportsReturnOptions({ + this.id = false, + this.contractID = false, + this.discountLevel = false, + this.amountBilled = false, + this.timeStamp = false, + }); + + @override + String toString() { + return generateToString(this); + } +} + +class Consumption { + Contracts contracts; + List contractBillReports; + + Consumption({ + required this.contracts, + required this.contractBillReports, + }); +} + +@reflector +class BaseContractQueryOptions { + String? contractIDEq; + String? contractIDGt; + String? contractIDGte; + List? contractIDIn; + bool? contractIDIsNull; + String? contractIDLt; + String? contractIDLte; + String? contractIDNotEq; + List? contractIDNotIn; + String? createdAtEq; + String? createdAtGt; + String? createdAtGte; + List? createdAtIn; + bool? createdAtIsNull; + String? createdAtLt; + String? createdAtLte; + String? createdAtNotEq; + List? createdAtNotIn; + bool? gridVersionIsNull; + int? gridVersionEq; + int? gridVersionNotEq; + int? gridVersionGt; + int? gridVersionGte; + int? gridVersionLt; + int? gridVersionLte; + List? gridVersionIn; + List? gridVersionNotIn; + String? idEq; + String? idGt; + String? idGte; + String? idNotEq; + String? idLt; + String? idLte; + String? idContains; + String? idNotContains; + String? idContainsInsensitive; + String? idNotContainsInsensitive; + String? idStartsWith; + String? idNotStartsWith; + String? idEndsWith; + String? idNotEndsWith; + List? idIn; + List? idNotIn; + int? solutionProviderIDEq; + int? solutionProviderIDGt; + int? solutionProviderIDGte; + List? solutionProviderIDIn; + bool? solutionProviderIDIsNull; + int? solutionProviderIDLt; + int? solutionProviderIDLte; + int? solutionProviderIDNotEq; + List? solutionProviderIDNotIn; + ContractStates? stateEq; + List? stateIn; + bool? stateIsNull; + ContractStates? stateNotEq; + List? stateNotIn; + bool? twinIDIsNull; + int? twinIDEq; + int? twinIDNotEq; + int? twinIDGt; + int? twinIDGte; + int? twinIDLt; + int? twinIDLte; + List? twinIDIn; + List? twinIDNotIn; + + int? limit; + int? offset; + ContractsOrderByOptions? orderBy; + + BaseContractQueryOptions.BaseContractQueryOptions({ + this.contractIDEq, + this.contractIDGt, + this.contractIDGte, + this.contractIDIn, + this.contractIDIsNull, + this.contractIDLt, + this.contractIDLte, + this.contractIDNotEq, + this.contractIDNotIn, + this.createdAtEq, + this.createdAtGt, + this.createdAtGte, + this.createdAtIn, + this.createdAtIsNull, + this.createdAtLt, + this.createdAtLte, + this.createdAtNotEq, + this.createdAtNotIn, + this.gridVersionEq, + this.gridVersionGt, + this.gridVersionGte, + this.gridVersionIn, + this.gridVersionIsNull, + this.gridVersionLt, + this.gridVersionLte, + this.gridVersionNotEq, + this.gridVersionNotIn, + this.idEq, + this.idGt, + this.idGte, + this.idNotEq, + this.idLt, + this.idLte, + this.idContains, + this.idNotContains, + this.idContainsInsensitive, + this.idNotContainsInsensitive, + this.idStartsWith, + this.idNotStartsWith, + this.idEndsWith, + this.idNotEndsWith, + this.solutionProviderIDEq, + this.solutionProviderIDGt, + this.solutionProviderIDGte, + this.solutionProviderIDIn, + this.solutionProviderIDLt, + this.solutionProviderIDLte, + this.solutionProviderIDNotEq, + this.solutionProviderIDNotIn, + this.solutionProviderIDIsNull, + this.stateEq, + this.stateIn, + this.stateIsNull, + this.stateNotEq, + this.stateNotIn, + this.twinIDIsNull, + this.twinIDEq, + this.twinIDNotEq, + this.twinIDGt, + this.twinIDGte, + this.twinIDLt, + this.twinIDLte, + this.twinIDIn, + this.twinIDNotIn, + this.limit, + this.offset, + this.orderBy, + }); + + @override + String toString() { + List queryOptions = []; + _addToQueryList(queryOptions, "contractID_eq", contractIDEq); + _addToQueryList(queryOptions, "contractID_gt", contractIDGt); + _addToQueryList(queryOptions, "contractID_gte", contractIDGte); + _addToQueryList(queryOptions, "contractID_in", contractIDIn); + _addToQueryList(queryOptions, "contractID_isNull", contractIDIsNull); + _addToQueryList(queryOptions, "contractID_lt", contractIDLt); + _addToQueryList(queryOptions, "contractID_lte", contractIDLte); + _addToQueryList(queryOptions, "contractID_not_eq", contractIDNotEq); + _addToQueryList(queryOptions, "contractID_not_in", contractIDNotIn); + _addToQueryList(queryOptions, "gridVersion_isNull", gridVersionIsNull); + _addToQueryList(queryOptions, "gridVersion_eq", gridVersionEq); + _addToQueryList(queryOptions, "gridVersion_not_eq", gridVersionNotEq); + _addToQueryList(queryOptions, "gridVersion_gt", gridVersionGt); + _addToQueryList(queryOptions, "gridVersion_gte", gridVersionGte); + _addToQueryList(queryOptions, "gridVersion_lt", gridVersionLt); + _addToQueryList(queryOptions, "gridVersion_lte", gridVersionLte); + _addToQueryList(queryOptions, "gridVersion_in", gridVersionIn); + _addToQueryList(queryOptions, "gridVersion_not_in", gridVersionNotIn); + _addToQueryList(queryOptions, "id_eq", idEq); + _addToQueryList(queryOptions, "id_gt", idGt); + _addToQueryList(queryOptions, "id_gte", idGte); + _addToQueryList(queryOptions, "id_not_eq", idNotEq); + _addToQueryList(queryOptions, "id_lt", idLt); + _addToQueryList(queryOptions, "id_lte", idLte); + _addToQueryList(queryOptions, "id_contains", idContains); + _addToQueryList(queryOptions, "id_not_contains", idNotContains); + _addToQueryList( + queryOptions, "id_containsInsensitive", idContainsInsensitive); + _addToQueryList( + queryOptions, "id_not_containsInsensitive", idNotContainsInsensitive); + _addToQueryList(queryOptions, "id_startsWith", idStartsWith); + _addToQueryList(queryOptions, "id_not_startsWith", idNotStartsWith); + _addToQueryList(queryOptions, "id_endsWith", idEndsWith); + _addToQueryList(queryOptions, "id_not_endsWith", idNotEndsWith); + _addToQueryList(queryOptions, "id_in", idIn); + _addToQueryList(queryOptions, "id_not_in", idNotIn); + _addToQueryList( + queryOptions, "solutionProviderID_eq", solutionProviderIDEq); + _addToQueryList( + queryOptions, "solutionProviderID_gt", solutionProviderIDGt); + _addToQueryList( + queryOptions, "solutionProviderID_gte", solutionProviderIDGte); + _addToQueryList( + queryOptions, "solutionProviderID_in", solutionProviderIDIn); + _addToQueryList( + queryOptions, "solutionProviderID_isNull", solutionProviderIDIsNull); + _addToQueryList( + queryOptions, "solutionProviderID_lt", solutionProviderIDLt); + _addToQueryList( + queryOptions, "solutionProviderID_lte", solutionProviderIDLte); + _addToQueryList( + queryOptions, "solutionProviderID_not_eq", solutionProviderIDNotEq); + _addToQueryList( + queryOptions, "solutionProviderID_not_in", solutionProviderIDNotIn); + _addToQueryList(queryOptions, "state_eq", stateEq); + _addToQueryList(queryOptions, "state_in", stateIn); + _addToQueryList(queryOptions, "state_isNull", stateIsNull); + _addToQueryList(queryOptions, "state_not_eq", stateNotEq); + _addToQueryList(queryOptions, "state_not_in", stateNotIn); + _addToQueryList(queryOptions, "twinID_isNull", twinIDIsNull); + _addToQueryList(queryOptions, "twinID_eq", twinIDEq); + _addToQueryList(queryOptions, "twinID_not_eq", twinIDNotEq); + _addToQueryList(queryOptions, "twinID_gt", twinIDGt); + _addToQueryList(queryOptions, "twinID_gte", twinIDGte); + _addToQueryList(queryOptions, "twinID_lt", twinIDLt); + _addToQueryList(queryOptions, "twinID_lte", twinIDLte); + _addToQueryList(queryOptions, "twinID_in", twinIDIn); + _addToQueryList(queryOptions, "twinID_not_in", twinIDNotIn); + + String queryString = ''; + + if (queryOptions.isNotEmpty) { + queryString += '${queryOptions.join(', ')}'; + } + + return queryString; + } +} + +@reflector +class NameContractQueryOptions extends BaseContractQueryOptions { + String? nameContains; + String? nameContainsInsensitive; + + NameContractQueryOptions({ + this.nameContains, + this.nameContainsInsensitive, + String? contractIDEq, + String? contractIDGt, + String? contractIDGte, + List? contractIDIn, + bool? contractIDIsNull, + String? contractIDLt, + String? contractIDLte, + String? contractIDNotEq, + List? contractIDNotIn, + String? createdAtEq, + String? createdAtGt, + String? createdAtGte, + List? createdAtIn, + bool? createdAtIsNull, + String? createdAtLt, + String? createdAtLte, + String? createdAtNotEq, + List? createdAtNotIn, + bool? gridVersionIsNull, + int? gridVersionEq, + int? gridVersionNotEq, + int? gridVersionGt, + int? gridVersionGte, + int? gridVersionLt, + int? gridVersionLte, + List? gridVersionIn, + List? gridVersionNotIn, + String? idEq, + String? idGt, + String? idGte, + String? idNotEq, + String? idLt, + String? idLte, + String? idContains, + String? idNotContains, + String? idContainsInsensitive, + String? idNotContainsInsensitive, + String? idStartsWith, + String? idNotStartsWith, + String? idEndsWith, + String? idNotEndsWith, + List? idIn, + List? idNotIn, + int? solutionProviderIDEq, + int? solutionProviderIDGt, + int? solutionProviderIDGte, + List? solutionProviderIDIn, + bool? solutionProviderIDIsNull, + int? solutionProviderIDLt, + int? solutionProviderIDLte, + int? solutionProviderIDNotEq, + List? solutionProviderIDNotIn, + ContractStates? stateEq, + List? stateIn, + bool? stateIsNull, + ContractStates? stateNotEq, + List? stateNotIn, + bool? twinIDIsNull, + int? twinIDEq, + int? twinIDNotEq, + int? twinIDGt, + int? twinIDGte, + int? twinIDLt, + int? twinIDLte, + List? twinIDIn, + List? twinIDNotIn, + int? limit, + int? offset, + ContractsOrderByOptions? orderBy, + }) : super.BaseContractQueryOptions( + contractIDEq: contractIDEq, + contractIDGt: contractIDGt, + contractIDGte: contractIDGte, + contractIDIn: contractIDIn, + contractIDIsNull: contractIDIsNull, + contractIDLt: contractIDLt, + contractIDLte: contractIDLte, + contractIDNotEq: contractIDNotEq, + contractIDNotIn: contractIDNotIn, + createdAtEq: createdAtEq, + createdAtGt: createdAtGt, + createdAtGte: createdAtGte, + createdAtIn: createdAtIn, + createdAtIsNull: createdAtIsNull, + createdAtLt: createdAtLt, + createdAtLte: createdAtLte, + createdAtNotEq: createdAtNotEq, + createdAtNotIn: createdAtNotIn, + gridVersionEq: gridVersionEq, + gridVersionGt: gridVersionGt, + gridVersionGte: gridVersionGte, + gridVersionIn: gridVersionIn, + gridVersionIsNull: gridVersionIsNull, + gridVersionLt: gridVersionLt, + gridVersionLte: gridVersionLte, + gridVersionNotEq: gridVersionNotEq, + gridVersionNotIn: gridVersionNotIn, + idContains: idContains, + idContainsInsensitive: idContainsInsensitive, + idEndsWith: idEndsWith, + idEq: idEq, + idGt: idGt, + idGte: idGte, + idLt: idLt, + idLte: idLte, + idNotContains: idNotContains, + idNotContainsInsensitive: idNotContainsInsensitive, + idNotEndsWith: idNotEndsWith, + idNotEq: idNotEq, + idNotStartsWith: idNotStartsWith, + idStartsWith: idStartsWith, + limit: limit, + offset: offset, + orderBy: orderBy, + solutionProviderIDEq: solutionProviderIDEq, + solutionProviderIDGt: solutionProviderIDGt, + solutionProviderIDGte: solutionProviderIDGte, + solutionProviderIDIn: solutionProviderIDIn, + solutionProviderIDIsNull: solutionProviderIDIsNull, + solutionProviderIDLt: solutionProviderIDLt, + solutionProviderIDLte: solutionProviderIDLte, + solutionProviderIDNotEq: solutionProviderIDNotEq, + solutionProviderIDNotIn: solutionProviderIDNotIn, + stateEq: stateEq, + stateIn: stateIn, + stateIsNull: stateIsNull, + stateNotEq: stateNotEq, + stateNotIn: stateNotIn, + twinIDEq: twinIDEq, + twinIDGt: twinIDGt, + twinIDGte: twinIDGte, + twinIDIn: twinIDIn, + twinIDIsNull: twinIDIsNull, + twinIDLt: twinIDLt, + twinIDLte: twinIDLte, + twinIDNotEq: twinIDNotEq, + twinIDNotIn: twinIDNotIn, + ); + + @override + String toString() { + String queryString = super.toString(); + + List queryOptions = []; + _addToQueryList(queryOptions, "name_contains", nameContains); + _addToQueryList( + queryOptions, "name_containsInsensitive", nameContainsInsensitive); + + if (queryOptions.isNotEmpty) { + if (queryString.isNotEmpty) { + queryString += ', ' + queryOptions.join(', '); + } else { + queryString += queryOptions.join(', '); + } + } + + queryString = 'where: {$queryString}'; + + if (limit != null) { + if (queryString.isNotEmpty) { + queryString += ', '; + } + queryString += 'limit: $limit'; + } + + if (offset != null) { + if (queryString.isNotEmpty) { + queryString += ', '; + } + queryString += 'offset: $offset'; + } + + if (orderBy != null) { + if (queryString.isNotEmpty) { + queryString += ', '; + } + queryString += 'orderBy: ${orderBy.toString().split('.').last}'; + } + + if (queryString.isNotEmpty) { + queryString = '($queryString)'; + } + return queryString; + } +} + +@reflector +class NodeContractQueryOptions extends BaseContractQueryOptions { + String? deploymentDataContains; + String? deploymentDataContainsInsensitive; + String? deploymentDataEq; + String? deploymentDataEndsWith; + String? deploymentDataGt; + String? deploymentDataGte; + bool? deploymentDataIsNull; + List? deploymentDataIn; + String? deploymentDataLte; + String? deploymentDataLt; + String? deploymentDataNotContains; + String? deploymentDataNotContainsInsensitive; + String? deploymentDataNotEndsWith; + String? deploymentDataNotEq; + List? deploymentDataNotIn; + String? deploymentDataNotStartsWith; + String? deploymentDataStartsWith; + String? deploymentHashEndsWith; + String? deploymentHashContainsInsensitive; + String? deploymentHashContains; + String? deploymentHashEq; + String? deploymentHashGt; + String? deploymentHashGte; + List? deploymentHashIn; + bool? deploymentHashIsNull; + String? deploymentHashLt; + String? deploymentHashNotContains; + String? deploymentHashNotContainsInsensitive; + String? deploymentHashLte; + String? deploymentHashNotEndsWith; + String? deploymentHashNotEq; + List? deploymentHashNotIn; + String? deploymentHashNotStartsWith; + String? deploymentHashStartsWith; + bool? nodeIDIsNull; + int? nodeIDEq; + int? nodeIDNotEq; + int? nodeIDGt; + int? nodeIDGte; + int? nodeIDLt; + int? nodeIDLte; + List? nodeIDIn; + List? nodeIDNotIn; + int? numberOfPublicIPsEq; + int? numberOfPublicIPsGte; + int? numberOfPublicIPsGt; + List? numberOfPublicIPsIn; + bool? numberOfPublicIPsIsNull; + int? numberOfPublicIPsLt; + int? numberOfPublicIPsLte; + int? numberOfPublicIPsNotEq; + List? numberOfPublicIPsNotIn; + ResourcesUsedQueryOptions? resourcesUsed; + bool? resourcesUsedIsNull; + + NodeContractQueryOptions({ + this.deploymentDataContains, + this.deploymentDataContainsInsensitive, + this.deploymentDataEq, + this.deploymentDataEndsWith, + this.deploymentDataGt, + this.deploymentDataGte, + this.deploymentDataIsNull, + this.deploymentDataIn, + this.deploymentDataLt, + this.deploymentDataLte, + this.deploymentDataNotContains, + this.deploymentDataNotContainsInsensitive, + this.deploymentDataNotEndsWith, + this.deploymentDataNotEq, + this.deploymentDataNotIn, + this.deploymentDataNotStartsWith, + this.deploymentDataStartsWith, + this.deploymentHashEndsWith, + this.deploymentHashContainsInsensitive, + this.deploymentHashContains, + this.deploymentHashEq, + this.deploymentHashGt, + this.deploymentHashGte, + this.deploymentHashIn, + this.deploymentHashIsNull, + this.deploymentHashLt, + this.deploymentHashNotContains, + this.deploymentHashNotContainsInsensitive, + this.deploymentHashLte, + this.deploymentHashNotEndsWith, + this.deploymentHashNotEq, + this.deploymentHashNotIn, + this.deploymentHashNotStartsWith, + this.deploymentHashStartsWith, + this.nodeIDIsNull, + this.nodeIDEq, + this.nodeIDNotEq, + this.nodeIDGt, + this.nodeIDGte, + this.nodeIDLt, + this.nodeIDLte, + this.nodeIDIn, + this.nodeIDNotIn, + this.numberOfPublicIPsEq, + this.numberOfPublicIPsGte, + this.numberOfPublicIPsGt, + this.numberOfPublicIPsIn, + this.numberOfPublicIPsIsNull, + this.numberOfPublicIPsLt, + this.numberOfPublicIPsLte, + this.numberOfPublicIPsNotEq, + this.numberOfPublicIPsNotIn, + this.resourcesUsed, + this.resourcesUsedIsNull, + String? contractIDEq, + String? contractIDGt, + String? contractIDGte, + List? contractIDIn, + bool? contractIDIsNull, + String? contractIDLt, + String? contractIDLte, + String? contractIDNotEq, + List? contractIDNotIn, + String? createdAtEq, + String? createdAtGt, + String? createdAtGte, + List? createdAtIn, + bool? createdAtIsNull, + String? createdAtLt, + String? createdAtLte, + String? createdAtNotEq, + List? createdAtNotIn, + bool? gridVersionIsNull, + int? gridVersionEq, + int? gridVersionNotEq, + int? gridVersionGt, + int? gridVersionGte, + int? gridVersionLt, + int? gridVersionLte, + List? gridVersionIn, + List? gridVersionNotIn, + String? idEq, + String? idGt, + String? idGte, + String? idNotEq, + String? idLt, + String? idLte, + String? idContains, + String? idNotContains, + String? idContainsInsensitive, + String? idNotContainsInsensitive, + String? idStartsWith, + String? idNotStartsWith, + String? idEndsWith, + String? idNotEndsWith, + List? idIn, + List? idNotIn, + int? solutionProviderIDEq, + int? solutionProviderIDGt, + int? solutionProviderIDGte, + List? solutionProviderIDIn, + bool? solutionProviderIDIsNull, + int? solutionProviderIDLt, + int? solutionProviderIDLte, + int? solutionProviderIDNotEq, + List? solutionProviderIDNotIn, + ContractStates? stateEq, + List? stateIn, + bool? stateIsNull, + ContractStates? stateNotEq, + List? stateNotIn, + bool? twinIDIsNull, + int? twinIDEq, + int? twinIDNotEq, + int? twinIDGt, + int? twinIDGte, + int? twinIDLt, + int? twinIDLte, + List? twinIDIn, + List? twinIDNotIn, + int? limit, + int? offset, + ContractsOrderByOptions? orderBy, + }) : super.BaseContractQueryOptions( + contractIDEq: contractIDEq, + contractIDGt: contractIDGt, + contractIDGte: contractIDGte, + contractIDIn: contractIDIn, + contractIDIsNull: contractIDIsNull, + contractIDLt: contractIDLt, + contractIDLte: contractIDLte, + contractIDNotEq: contractIDNotEq, + contractIDNotIn: contractIDNotIn, + createdAtEq: createdAtEq, + createdAtGt: createdAtGt, + createdAtGte: createdAtGte, + createdAtIn: createdAtIn, + createdAtIsNull: createdAtIsNull, + createdAtLt: createdAtLt, + createdAtLte: createdAtLte, + createdAtNotEq: createdAtNotEq, + createdAtNotIn: createdAtNotIn, + gridVersionEq: gridVersionEq, + gridVersionGt: gridVersionGt, + gridVersionGte: gridVersionGte, + gridVersionIn: gridVersionIn, + gridVersionIsNull: gridVersionIsNull, + gridVersionLt: gridVersionLt, + gridVersionLte: gridVersionLte, + gridVersionNotEq: gridVersionNotEq, + gridVersionNotIn: gridVersionNotIn, + idContains: idContains, + idContainsInsensitive: idContainsInsensitive, + idEndsWith: idEndsWith, + idEq: idEq, + idGt: idGt, + idGte: idGte, + idLt: idLt, + idLte: idLte, + idNotContains: idNotContains, + idNotContainsInsensitive: idNotContainsInsensitive, + idNotEndsWith: idNotEndsWith, + idNotEq: idNotEq, + idNotStartsWith: idNotStartsWith, + idStartsWith: idStartsWith, + limit: limit, + offset: offset, + orderBy: orderBy, + solutionProviderIDEq: solutionProviderIDEq, + solutionProviderIDGt: solutionProviderIDGt, + solutionProviderIDGte: solutionProviderIDGte, + solutionProviderIDIn: solutionProviderIDIn, + solutionProviderIDIsNull: solutionProviderIDIsNull, + solutionProviderIDLt: solutionProviderIDLt, + solutionProviderIDLte: solutionProviderIDLte, + solutionProviderIDNotEq: solutionProviderIDNotEq, + solutionProviderIDNotIn: solutionProviderIDNotIn, + stateEq: stateEq, + stateIn: stateIn, + stateIsNull: stateIsNull, + stateNotEq: stateNotEq, + stateNotIn: stateNotIn, + twinIDEq: twinIDEq, + twinIDGt: twinIDGt, + twinIDGte: twinIDGte, + twinIDIn: twinIDIn, + twinIDIsNull: twinIDIsNull, + twinIDLt: twinIDLt, + twinIDLte: twinIDLte, + twinIDNotEq: twinIDNotEq, + twinIDNotIn: twinIDNotIn, + ); + + @override + String toString() { + String queryString = super.toString(); + List queryOptions = []; + + _addToQueryList( + queryOptions, "deploymentData_contains", deploymentDataContains); + _addToQueryList(queryOptions, "deploymentData_containsInsensitive", + deploymentDataContainsInsensitive); + _addToQueryList(queryOptions, "deploymentData_eq", deploymentDataEq); + _addToQueryList( + queryOptions, "deploymentData_endsWith", deploymentDataEndsWith); + _addToQueryList(queryOptions, "deploymentData_gt", deploymentDataGt); + _addToQueryList(queryOptions, "deploymentData_gte", deploymentDataGte); + _addToQueryList( + queryOptions, "deploymentData_isNull", deploymentDataIsNull); + _addToQueryList(queryOptions, "deploymentData_in", deploymentDataIn); + _addToQueryList(queryOptions, "deploymentData_lt", deploymentDataLt); + _addToQueryList(queryOptions, "deploymentData_lte", deploymentDataLte); + _addToQueryList( + queryOptions, "deploymentData_not_contains", deploymentDataNotContains); + _addToQueryList(queryOptions, "deploymentData_not_containsInsensitive", + deploymentDataNotContainsInsensitive); + _addToQueryList( + queryOptions, "deploymentData_not_endsWith", deploymentDataNotEndsWith); + _addToQueryList(queryOptions, "deploymentData_not_eq", deploymentDataNotEq); + _addToQueryList(queryOptions, "deploymentData_not_in", deploymentDataNotIn); + _addToQueryList(queryOptions, "deploymentData_not_startsWith", + deploymentDataNotStartsWith); + _addToQueryList( + queryOptions, "deploymentData_startsWith", deploymentDataStartsWith); + _addToQueryList( + queryOptions, "deploymentHash_endsWith", deploymentHashEndsWith); + _addToQueryList(queryOptions, "deploymentHash_containsInsensitive", + deploymentHashContainsInsensitive); + _addToQueryList( + queryOptions, "deploymentHash_contains", deploymentHashContains); + _addToQueryList(queryOptions, "deploymentHash_eq", deploymentHashEq); + _addToQueryList(queryOptions, "deploymentHash_gt", deploymentHashGt); + _addToQueryList(queryOptions, "deploymentHash_gte", deploymentHashGte); + _addToQueryList(queryOptions, "deploymentHash_in", deploymentHashIn); + _addToQueryList( + queryOptions, "deploymentHash_isNull", deploymentHashIsNull); + _addToQueryList(queryOptions, "deploymentHash_lt", deploymentHashLt); + _addToQueryList( + queryOptions, "deploymentHash_not_contains", deploymentHashNotContains); + _addToQueryList(queryOptions, "deploymentHash_not_containsInsensitive", + deploymentHashNotContainsInsensitive); + _addToQueryList(queryOptions, "deploymentHash_lte", deploymentHashLte); + _addToQueryList( + queryOptions, "deploymentHash_not_endsWith", deploymentHashNotEndsWith); + _addToQueryList(queryOptions, "deploymentHash_not_eq", deploymentHashNotEq); + _addToQueryList(queryOptions, "deploymentHash_not_in", deploymentHashNotIn); + _addToQueryList(queryOptions, "deploymentHash_not_startsWith", + deploymentHashNotStartsWith); + _addToQueryList( + queryOptions, "deploymentHash_startsWith", deploymentHashStartsWith); + _addToQueryList(queryOptions, "nodeID_isNull", nodeIDIsNull); + _addToQueryList(queryOptions, "nodeID_eq", nodeIDEq); + _addToQueryList(queryOptions, "nodeID_not_eq", nodeIDNotEq); + _addToQueryList(queryOptions, "nodeID_gt", nodeIDGt); + _addToQueryList(queryOptions, "nodeID_gte", nodeIDGte); + _addToQueryList(queryOptions, "nodeID_lt", nodeIDLt); + _addToQueryList(queryOptions, "nodeID_lte", nodeIDLte); + _addToQueryList(queryOptions, "nodeID_in", nodeIDIn); + _addToQueryList(queryOptions, "nodeID_not_in", nodeIDNotIn); + _addToQueryList(queryOptions, "numberOfPublicIPs_eq", numberOfPublicIPsEq); + _addToQueryList( + queryOptions, "numberOfPublicIPs_gte", numberOfPublicIPsGte); + _addToQueryList(queryOptions, "numberOfPublicIPs_gt", numberOfPublicIPsGt); + _addToQueryList(queryOptions, "numberOfPublicIPs_in", numberOfPublicIPsIn); + _addToQueryList( + queryOptions, "numberOfPublicIPs_isNull", numberOfPublicIPsIsNull); + _addToQueryList(queryOptions, "numberOfPublicIPs_lt", numberOfPublicIPsLt); + _addToQueryList( + queryOptions, "numberOfPublicIPs_lte", numberOfPublicIPsLte); + _addToQueryList( + queryOptions, "numberOfPublicIPs_not_eq", numberOfPublicIPsNotEq); + _addToQueryList( + queryOptions, "numberOfPublicIPs_not_in", numberOfPublicIPsNotIn); + _addToQueryList(queryOptions, "resourcesUsed_isNull", resourcesUsedIsNull); + if (resourcesUsed != null) { + queryOptions.add('resourcesUsed: {${resourcesUsed.toString()}}'); + } + + if (queryOptions.isNotEmpty) { + if (queryString.isNotEmpty) { + queryString += ', ' + queryOptions.join(', '); + } else { + queryString += queryOptions.join(', '); + } + } + + queryString = 'where: {$queryString}'; + + if (limit != null) { + if (queryString.isNotEmpty) { + queryString += ', '; + } + queryString += 'limit: $limit'; + } + + if (offset != null) { + if (queryString.isNotEmpty) { + queryString += ', '; + } + queryString += 'offset: $offset'; + } + + if (orderBy != null) { + if (queryString.isNotEmpty) { + queryString += ', '; + } + queryString += 'orderBy: ${orderBy.toString().split('.').last}'; + } + + if (queryString.isNotEmpty) { + queryString = '($queryString)'; + } + return queryString; + } +} + +@reflector +class ResourcesUsedQueryOptions { + bool? contractIsNull; + int? cruEq; + int? cruGt; + int? cruGte; + List? cruIn; + bool? cruIsNull; + int? cruLt; + int? cruLte; + int? cruNotEq; + List? cruNotIn; + int? hruEq; + int? hruGt; + int? hruGte; + List? hruIn; + bool? hruIsNull; + int? hruLt; + int? hruLte; + int? hruNotEq; + List? hruNotIn; + int? mruEq; + int? mruGt; + int? mruGte; + List? mruIn; + bool? mruIsNull; + int? mruLt; + int? mruLte; + int? mruNotEq; + List? mruNotIn; + int? sruEq; + int? sruGt; + int? sruGte; + List? sruIn; + bool? sruIsNull; + int? sruLt; + int? sruLte; + int? sruNotEq; + List? sruNotIn; + String? idEq; + String? idGt; + String? idGte; + String? idNotEq; + String? idLt; + String? idLte; + String? idContains; + String? idNotContains; + String? idContainsInsensitive; + String? idNotContainsInsensitive; + String? idStartsWith; + String? idNotStartsWith; + String? idEndsWith; + String? idNotEndsWith; + List? idIn; + List? idNotIn; + bool? idIsNull; + + ResourcesUsedQueryOptions({ + this.contractIsNull, + this.cruEq, + this.cruGt, + this.cruGte, + this.cruIn, + this.cruIsNull, + this.cruLt, + this.cruLte, + this.cruNotEq, + this.cruNotIn, + this.hruEq, + this.hruGt, + this.hruGte, + this.hruIn, + this.hruIsNull, + this.hruLt, + this.hruLte, + this.hruNotEq, + this.hruNotIn, + this.mruEq, + this.mruGt, + this.mruGte, + this.mruIn, + this.mruIsNull, + this.mruLt, + this.mruLte, + this.mruNotEq, + this.mruNotIn, + this.sruEq, + this.sruGt, + this.sruGte, + this.sruIn, + this.sruIsNull, + this.sruLt, + this.sruLte, + this.sruNotEq, + this.sruNotIn, + this.idEq, + this.idGt, + this.idGte, + this.idNotEq, + this.idLt, + this.idLte, + this.idContains, + this.idNotContains, + this.idContainsInsensitive, + this.idNotContainsInsensitive, + this.idStartsWith, + this.idNotStartsWith, + this.idEndsWith, + this.idNotEndsWith, + this.idIn, + this.idNotIn, + this.idIsNull, + }); + + @override + String toString() { + List queryOptions = []; + + _addToQueryList(queryOptions, "id_eq", idEq); + _addToQueryList(queryOptions, "id_gt", idGt); + _addToQueryList(queryOptions, "id_gte", idGte); + _addToQueryList(queryOptions, "id_not_eq", idNotEq); + _addToQueryList(queryOptions, "id_lt", idLt); + _addToQueryList(queryOptions, "id_lte", idLte); + _addToQueryList(queryOptions, "id_contains", idContains); + _addToQueryList(queryOptions, "id_not_contains", idNotContains); + _addToQueryList( + queryOptions, "id_containsInsensitive", idContainsInsensitive); + _addToQueryList( + queryOptions, "id_not_containsInsensitive", idNotContainsInsensitive); + _addToQueryList(queryOptions, "id_startsWith", idStartsWith); + _addToQueryList(queryOptions, "id_not_startsWith", idNotStartsWith); + _addToQueryList(queryOptions, "id_endsWith", idEndsWith); + _addToQueryList(queryOptions, "id_not_endsWith", idNotEndsWith); + _addToQueryList(queryOptions, "id_in", idIn); + _addToQueryList(queryOptions, "id_not_in", idNotIn); + _addToQueryList(queryOptions, "id_isNull", idIsNull); + _addToQueryList(queryOptions, "contract_isNull", contractIsNull); + _addToQueryList(queryOptions, "cru_eq", cruEq); + _addToQueryList(queryOptions, "cru_gt", cruGt); + _addToQueryList(queryOptions, "cru_gte", cruGte); + _addToQueryList(queryOptions, "cru_in", cruIn); + _addToQueryList(queryOptions, "cru_isNull", cruIsNull); + _addToQueryList(queryOptions, "cru_lt", cruLt); + _addToQueryList(queryOptions, "cru_lte", cruLte); + _addToQueryList(queryOptions, "cru_not_eq", cruNotEq); + _addToQueryList(queryOptions, "cru_not_in", cruNotIn); + _addToQueryList(queryOptions, "hru_eq", hruEq); + _addToQueryList(queryOptions, "hru_gt", hruGt); + _addToQueryList(queryOptions, "hru_gte", hruGte); + _addToQueryList(queryOptions, "hru_in", hruIn); + _addToQueryList(queryOptions, "hru_isNull", hruIsNull); + _addToQueryList(queryOptions, "hru_lt", hruLt); + _addToQueryList(queryOptions, "hru_lte", hruLte); + _addToQueryList(queryOptions, "hru_not_eq", hruNotEq); + _addToQueryList(queryOptions, "hru_not_in", hruNotIn); + _addToQueryList(queryOptions, "mru_eq", mruEq); + _addToQueryList(queryOptions, "mru_gt", mruGt); + _addToQueryList(queryOptions, "mru_gte", mruGte); + _addToQueryList(queryOptions, "mru_in", mruIn); + _addToQueryList(queryOptions, "mru_isNull", mruIsNull); + _addToQueryList(queryOptions, "mru_lt", mruLt); + _addToQueryList(queryOptions, "mru_lte", mruLte); + _addToQueryList(queryOptions, "mru_not_eq", mruNotEq); + _addToQueryList(queryOptions, "mru_not_in", mruNotIn); + _addToQueryList(queryOptions, "sru_eq", sruEq); + _addToQueryList(queryOptions, "sru_gt", sruGt); + _addToQueryList(queryOptions, "sru_gte", sruGte); + _addToQueryList(queryOptions, "sru_in", sruIn); + _addToQueryList(queryOptions, "sru_isNull", sruIsNull); + _addToQueryList(queryOptions, "sru_lt", sruLt); + _addToQueryList(queryOptions, "sru_lte", sruLte); + _addToQueryList(queryOptions, "sru_not_eq", sruNotEq); + _addToQueryList(queryOptions, "sru_not_in", sruNotIn); + + return queryOptions.isNotEmpty ? queryOptions.join(', ') : " "; + } +} + +@reflector +class RentContractQueryOptions extends BaseContractQueryOptions { + bool? nodeIDIsNull; + int? nodeIDEq; + int? nodeIDNotEq; + int? nodeIDGt; + int? nodeIDGte; + int? nodeIDLt; + int? nodeIDLte; + List? nodeIDIn; + List? nodeIDNotIn; + + RentContractQueryOptions({ + this.nodeIDIsNull, + this.nodeIDEq, + this.nodeIDNotEq, + this.nodeIDGt, + this.nodeIDGte, + this.nodeIDLt, + this.nodeIDLte, + this.nodeIDIn, + this.nodeIDNotIn, + String? contractIDEq, + String? contractIDGt, + String? contractIDGte, + List? contractIDIn, + bool? contractIDIsNull, + String? contractIDLt, + String? contractIDLte, + String? contractIDNotEq, + List? contractIDNotIn, + String? createdAtEq, + String? createdAtGt, + String? createdAtGte, + List? createdAtIn, + bool? createdAtIsNull, + String? createdAtLt, + String? createdAtLte, + String? createdAtNotEq, + List? createdAtNotIn, + bool? gridVersionIsNull, + int? gridVersionEq, + int? gridVersionNotEq, + int? gridVersionGt, + int? gridVersionGte, + int? gridVersionLt, + int? gridVersionLte, + List? gridVersionIn, + List? gridVersionNotIn, + String? idEq, + String? idGt, + String? idGte, + String? idNotEq, + String? idLt, + String? idLte, + String? idContains, + String? idNotContains, + String? idContainsInsensitive, + String? idNotContainsInsensitive, + String? idStartsWith, + String? idNotStartsWith, + String? idEndsWith, + String? idNotEndsWith, + List? idIn, + List? idNotIn, + int? solutionProviderIDEq, + int? solutionProviderIDGt, + int? solutionProviderIDGte, + List? solutionProviderIDIn, + bool? solutionProviderIDIsNull, + int? solutionProviderIDLt, + int? solutionProviderIDLte, + int? solutionProviderIDNotEq, + List? solutionProviderIDNotIn, + ContractStates? stateEq, + List? stateIn, + bool? stateIsNull, + ContractStates? stateNotEq, + List? stateNotIn, + bool? twinIDIsNull, + int? twinIDEq, + int? twinIDNotEq, + int? twinIDGt, + int? twinIDGte, + int? twinIDLt, + int? twinIDLte, + List? twinIDIn, + List? twinIDNotIn, + int? limit, + int? offset, + ContractsOrderByOptions? orderBy, + }) : super.BaseContractQueryOptions( + contractIDEq: contractIDEq, + contractIDGt: contractIDGt, + contractIDGte: contractIDGte, + contractIDIn: contractIDIn, + contractIDIsNull: contractIDIsNull, + contractIDLt: contractIDLt, + contractIDLte: contractIDLte, + contractIDNotEq: contractIDNotEq, + contractIDNotIn: contractIDNotIn, + createdAtEq: createdAtEq, + createdAtGt: createdAtGt, + createdAtGte: createdAtGte, + createdAtIn: createdAtIn, + createdAtIsNull: createdAtIsNull, + createdAtLt: createdAtLt, + createdAtLte: createdAtLte, + createdAtNotEq: createdAtNotEq, + createdAtNotIn: createdAtNotIn, + gridVersionEq: gridVersionEq, + gridVersionGt: gridVersionGt, + gridVersionGte: gridVersionGte, + gridVersionIn: gridVersionIn, + gridVersionIsNull: gridVersionIsNull, + gridVersionLt: gridVersionLt, + gridVersionLte: gridVersionLte, + gridVersionNotEq: gridVersionNotEq, + gridVersionNotIn: gridVersionNotIn, + idContains: idContains, + idContainsInsensitive: idContainsInsensitive, + idEndsWith: idEndsWith, + idEq: idEq, + idGt: idGt, + idGte: idGte, + idLt: idLt, + idLte: idLte, + idNotContains: idNotContains, + idNotContainsInsensitive: idNotContainsInsensitive, + idNotEndsWith: idNotEndsWith, + idNotEq: idNotEq, + idNotStartsWith: idNotStartsWith, + idStartsWith: idStartsWith, + limit: limit, + offset: offset, + orderBy: orderBy, + solutionProviderIDEq: solutionProviderIDEq, + solutionProviderIDGt: solutionProviderIDGt, + solutionProviderIDGte: solutionProviderIDGte, + solutionProviderIDIn: solutionProviderIDIn, + solutionProviderIDIsNull: solutionProviderIDIsNull, + solutionProviderIDLt: solutionProviderIDLt, + solutionProviderIDLte: solutionProviderIDLte, + solutionProviderIDNotEq: solutionProviderIDNotEq, + solutionProviderIDNotIn: solutionProviderIDNotIn, + stateEq: stateEq, + stateIn: stateIn, + stateIsNull: stateIsNull, + stateNotEq: stateNotEq, + stateNotIn: stateNotIn, + twinIDEq: twinIDEq, + twinIDGt: twinIDGt, + twinIDGte: twinIDGte, + twinIDIn: twinIDIn, + twinIDIsNull: twinIDIsNull, + twinIDLt: twinIDLt, + twinIDLte: twinIDLte, + twinIDNotEq: twinIDNotEq, + twinIDNotIn: twinIDNotIn, + ); + + @override + String toString() { + String queryString = super.toString(); + + List queryOptions = []; + _addToQueryList(queryOptions, "nodeID_isNull", nodeIDIsNull); + _addToQueryList(queryOptions, "nodeID_eq", nodeIDEq); + _addToQueryList(queryOptions, "nodeID_not_eq", nodeIDNotEq); + _addToQueryList(queryOptions, "nodeID_gt", nodeIDGt); + _addToQueryList(queryOptions, "nodeID_gte", nodeIDGte); + _addToQueryList(queryOptions, "nodeID_lt", nodeIDLt); + _addToQueryList(queryOptions, "nodeID_lte", nodeIDLte); + _addToQueryList(queryOptions, "nodeID_in", nodeIDIn); + _addToQueryList(queryOptions, "nodeID_not_in", nodeIDNotIn); + + if (queryOptions.isNotEmpty) { + if (queryString.isNotEmpty) { + queryString += ', ' + queryOptions.join(', '); + } else { + queryString += queryOptions.join(', '); + } + } + + queryString = 'where: {$queryString}'; + + if (limit != null) { + if (queryString.isNotEmpty) { + queryString += ', '; + } + queryString += 'limit: $limit'; + } + + if (offset != null) { + if (queryString.isNotEmpty) { + queryString += ', '; + } + queryString += 'offset: $offset'; + } + + if (orderBy != null) { + if (queryString.isNotEmpty) { + queryString += ', '; + } + queryString += 'orderBy: ${orderBy.toString().split('.').last}'; + } + + if (queryString.isNotEmpty) { + queryString = '($queryString)'; + } + return queryString; + } +} diff --git a/packages/graphql_client/lib/models/edges.dart b/packages/graphql_client/lib/models/edges.dart new file mode 100644 index 00000000..e02dc219 --- /dev/null +++ b/packages/graphql_client/lib/models/edges.dart @@ -0,0 +1,45 @@ +part of '../models.dart'; + +@reflector +class EdgesInfo { + String cursor; + NodeInfo? node; + + EdgesInfo({ + required this.cursor, + this.node, + }); + + factory EdgesInfo.fromJson(Map json) { + return EdgesInfo( + cursor: json['cursor'], + node: json['node'] != null ? NodeInfo.fromJson(json['node']) : null, + ); + } + + @override + String toString() { + return generateToString(this); + } +} + +@reflector +class EdgesReturnOptions { + NodeReturnOptions? nodeReturnOptions; + + EdgesReturnOptions({ + this.nodeReturnOptions, + }); + + @override + String toString() { + String returnOptions = "cursor \n"; + returnOptions = + _addToReturnList(returnOptions, "node {", nodeReturnOptions != null); + returnOptions = _addToReturnList( + returnOptions, nodeReturnOptions.toString(), nodeReturnOptions != null); + returnOptions = + _addToReturnList(returnOptions, "}", nodeReturnOptions != null); + return returnOptions; + } +} diff --git a/packages/graphql_client/lib/models/farms.dart b/packages/graphql_client/lib/models/farms.dart new file mode 100644 index 00000000..cf7c86e3 --- /dev/null +++ b/packages/graphql_client/lib/models/farms.dart @@ -0,0 +1,878 @@ +// ignore_for_file: constant_identifier_names + +part of '../models.dart'; + +enum FarmsOrderByOptions { + id_ASC, + id_DESC, + gridVersion_ASC, + gridVersion_DESC, + farmID_ASC, + farmID_DESC, + name_ASC, + name_DESC, + twinID_ASC, + twinID_DESC, + pricingPolicyID_ASC, + pricingPolicyID_DESC, + certification_ASC, + certification_DESC, + stellarAddress_ASC, + stellarAddress_DESC, + dedicatedFarm_ASC, + dedicatedFarm_DESC; + + @override + String toString() { + return name; + } +} + +enum Certification { + NotCertified, + Gold; + + @override + String toString() { + return name; + } +} + +@reflector +class FarmsReturnOptions { + bool farmID; + bool id; + bool name; + bool certification; + bool dedicatedFarm; + bool pricingPolicyID; + bool stellarAddress; + bool twinID; + PublicIpsReturnOptions? publicIps; + + FarmsReturnOptions({ + this.id = false, + this.farmID = false, + this.name = false, + this.certification = false, + this.dedicatedFarm = false, + this.pricingPolicyID = false, + this.stellarAddress = false, + this.twinID = false, + this.publicIps, + }); + + @override + String toString() { + String returnOptions = ""; + returnOptions = _addToReturnList(returnOptions, "id", id); + returnOptions = _addToReturnList(returnOptions, "farmID", farmID); + returnOptions = _addToReturnList(returnOptions, "name", name); + returnOptions = + _addToReturnList(returnOptions, "certification", certification); + returnOptions = + _addToReturnList(returnOptions, "dedicatedFarm", dedicatedFarm); + returnOptions = + _addToReturnList(returnOptions, "pricingPolicyID", pricingPolicyID); + returnOptions = + _addToReturnList(returnOptions, "stellarAddress", stellarAddress); + returnOptions = _addToReturnList(returnOptions, "twinID", twinID); + returnOptions = + _addToReturnList(returnOptions, "publicIPs {", publicIps != null); + returnOptions = _addToReturnList( + returnOptions, publicIps.toString(), publicIps != null); + returnOptions = _addToReturnList(returnOptions, "}", publicIps != null); + return returnOptions; + } +} + +class FarmsQueryOptions { + String? idEq; + String? idGt; + String? idGte; + String? idNotEq; + String? idLt; + String? idLte; + String? idContains; + String? idNotContains; + String? idContainsInsensitive; + String? idNotContainsInsensitive; + String? idStartsWith; + String? idNotStartsWith; + String? idEndsWith; + String? idNotEndsWith; + List? idIn; + List? idNotIn; + bool? gridVersionIsNull; + int? gridVersionEq; + int? gridVersionNotEq; + int? gridVersionGt; + int? gridVersionGte; + int? gridVersionLt; + int? gridVersionLte; + List? gridVersionIn; + List? gridVersionNotIn; + bool? farmIDIsNull; + int? farmIDEq; + int? farmIDNotEq; + int? farmIDGt; + int? farmIDGte; + int? farmIDLt; + int? farmIDLte; + List? farmIDIn; + List? farmIDNotIn; + bool? nameIsNull; + String? nameEq; + String? nameNotEq; + String? nameGt; + String? nameGte; + String? nameLt; + String? nameLte; + List? nameIn; + List? nameNotIn; + String? nameContains; + String? nameNotContains; + String? nameContainsInsensitive; + String? nameNotContainsInsensitive; + String? nameStartsWith; + String? nameNotStartsWith; + String? nameEndsWith; + String? nameNotEndsWith; + bool? twinIDIsNull; + int? twinIDEq; + int? twinIDNotEq; + int? twinIDGt; + int? twinIDGte; + int? twinIDLt; + int? twinIDLte; + List? twinIDIn; + List? twinIDNotIn; + bool? pricingPolicyIDIsNull; + int? pricingPolicyIDEq; + int? pricingPolicyIDNotEq; + int? pricingPolicyIDGt; + int? pricingPolicyIDGte; + int? pricingPolicyIDLt; + int? pricingPolicyIDLte; + List? pricingPolicyIDIn; + List? pricingPolicyIDNotIn; + bool? certificationIsNull; + Certification? certificationEq; + Certification? certificationNotEq; + List? certificationIn; + List? certificationNotIn; + bool? stellarAddressIsNull; + String? stellarAddressEq; + String? stellarAddressNotEq; + String? stellarAddressGt; + String? stellarAddressGte; + String? stellarAddressLt; + String? stellarAddressLte; + List? stellarAddressIn; + List? stellarAddressNotIn; + String? stellarAddressContains; + String? stellarAddressNotContains; + String? stellarAddressContainsInsensitive; + String? stellarAddressNotContainsInsensitive; + String? stellarAddressStartsWith; + String? stellarAddressNotStartsWith; + String? stellarAddressEndsWith; + String? stellarAddressNotEndsWith; + bool? dedicatedFarmIsNull; + bool? dedicatedFarmEq; + bool? dedicatedFarmNotEq; + int? limit; + int? offset; + FarmsOrderByOptions? orderBy; + + FarmsQueryOptions({ + this.idEq, + this.idGt, + this.idGte, + this.idNotEq, + this.idLt, + this.idLte, + this.idContains, + this.idNotContains, + this.idContainsInsensitive, + this.idNotContainsInsensitive, + this.idStartsWith, + this.idNotStartsWith, + this.idEndsWith, + this.idNotEndsWith, + this.gridVersionIsNull, + this.gridVersionEq, + this.gridVersionNotEq, + this.gridVersionGt, + this.gridVersionGte, + this.gridVersionLt, + this.gridVersionLte, + this.gridVersionIn, + this.gridVersionNotIn, + this.farmIDIsNull, + this.farmIDEq, + this.farmIDNotEq, + this.farmIDGt, + this.farmIDLte, + this.farmIDIn, + this.farmIDNotIn, + this.nameIsNull, + this.nameEq, + this.nameNotEq, + this.nameGt, + this.nameGte, + this.nameLt, + this.nameLte, + this.nameIn, + this.nameNotIn, + this.nameContains, + this.nameNotContains, + this.nameContainsInsensitive, + this.nameNotContainsInsensitive, + this.nameStartsWith, + this.nameNotStartsWith, + this.nameEndsWith, + this.nameNotEndsWith, + this.twinIDIsNull, + this.twinIDEq, + this.twinIDNotEq, + this.twinIDGt, + this.twinIDGte, + this.twinIDLt, + this.twinIDLte, + this.twinIDIn, + this.twinIDNotIn, + this.pricingPolicyIDIsNull, + this.pricingPolicyIDEq, + this.pricingPolicyIDNotEq, + this.pricingPolicyIDGt, + this.pricingPolicyIDGte, + this.pricingPolicyIDLt, + this.pricingPolicyIDLte, + this.pricingPolicyIDIn, + this.pricingPolicyIDNotIn, + this.certificationIsNull, + this.certificationEq, + this.certificationNotEq, + this.certificationIn, + this.certificationNotIn, + this.stellarAddressIsNull, + this.stellarAddressEq, + this.stellarAddressNotEq, + this.stellarAddressGt, + this.stellarAddressGte, + this.stellarAddressLt, + this.stellarAddressLte, + this.stellarAddressIn, + this.stellarAddressNotIn, + this.stellarAddressContains, + this.stellarAddressNotContains, + this.stellarAddressContainsInsensitive, + this.stellarAddressNotContainsInsensitive, + this.stellarAddressStartsWith, + this.stellarAddressNotStartsWith, + this.stellarAddressEndsWith, + this.stellarAddressNotEndsWith, + this.dedicatedFarmIsNull, + this.dedicatedFarmEq, + this.dedicatedFarmNotEq, + this.limit, + this.offset, + this.orderBy, + }); + + @override + String toString() { + List queryOptions = []; + + _addToQueryList(queryOptions, "id_eq", idEq); + _addToQueryList(queryOptions, "id_gt", idGt); + _addToQueryList(queryOptions, "id_gte", idGte); + _addToQueryList(queryOptions, "id_not_eq", idNotEq); + _addToQueryList(queryOptions, "id_lt", idLt); + _addToQueryList(queryOptions, "id_lte", idLte); + _addToQueryList(queryOptions, "id_contains", idContains); + _addToQueryList(queryOptions, "id_not_contains", idNotContains); + _addToQueryList( + queryOptions, "id_containsInsensitive", idContainsInsensitive); + _addToQueryList( + queryOptions, "id_not_containsInsensitive", idNotContainsInsensitive); + _addToQueryList(queryOptions, "id_startsWith", idStartsWith); + _addToQueryList(queryOptions, "id_not_startsWith", idNotStartsWith); + _addToQueryList(queryOptions, "id_endsWith", idEndsWith); + _addToQueryList(queryOptions, "id_not_endsWith", idNotEndsWith); + _addToQueryList(queryOptions, "id_in", idIn); + _addToQueryList(queryOptions, "id_not_in", idNotIn); + _addToQueryList(queryOptions, "gridVersion_is_null", gridVersionIsNull); + _addToQueryList(queryOptions, "gridVersion_eq", gridVersionEq); + _addToQueryList(queryOptions, "gridVersion_not_eq", gridVersionNotEq); + _addToQueryList(queryOptions, "gridVersion_gt", gridVersionGt); + _addToQueryList(queryOptions, "gridVersion_gte", gridVersionGte); + _addToQueryList(queryOptions, "gridVersion_lt", gridVersionLt); + _addToQueryList(queryOptions, "gridVersion_lte", gridVersionLte); + _addToQueryList(queryOptions, "gridVersion_in", gridVersionIn); + _addToQueryList(queryOptions, "gridVersion_not_in", gridVersionNotIn); + _addToQueryList(queryOptions, "farmID_is_null", farmIDIsNull); + _addToQueryList(queryOptions, "farmID_eq", farmIDEq); + _addToQueryList(queryOptions, "farmID_not_eq", farmIDNotEq); + _addToQueryList(queryOptions, "farmID_gt", farmIDGt); + _addToQueryList(queryOptions, "farmID_gte", farmIDGte); + _addToQueryList(queryOptions, "farmID_lt", farmIDLt); + _addToQueryList(queryOptions, "farmID_lte", farmIDLte); + _addToQueryList(queryOptions, "farmID_in", farmIDIn); + _addToQueryList(queryOptions, "farmID_not_in", farmIDNotIn); + _addToQueryList(queryOptions, "name_isNull", nameIsNull); + _addToQueryList(queryOptions, "name_eq", nameEq); + _addToQueryList(queryOptions, "name_not_eq", nameNotEq); + _addToQueryList(queryOptions, "name_gt", nameGt); + _addToQueryList(queryOptions, "name_gte", nameGte); + _addToQueryList(queryOptions, "name_lt", nameLt); + _addToQueryList(queryOptions, "name_lte", nameLte); + _addToQueryList(queryOptions, "name_in", nameIn); + _addToQueryList(queryOptions, "name_not_in", nameNotIn); + _addToQueryList(queryOptions, "name_contains", nameContains); + _addToQueryList(queryOptions, "name_not_contains", nameNotContains); + _addToQueryList( + queryOptions, "name_containsInsensitive", nameContainsInsensitive); + _addToQueryList(queryOptions, "name_not_containsInsensitive", + nameNotContainsInsensitive); + _addToQueryList(queryOptions, "name_startsWith", nameStartsWith); + _addToQueryList(queryOptions, "name_not_startsWith", nameNotStartsWith); + _addToQueryList(queryOptions, "name_endsWith", nameEndsWith); + _addToQueryList(queryOptions, "name_not_endsWith", nameNotEndsWith); + _addToQueryList(queryOptions, "twinID_isNull", twinIDIsNull); + _addToQueryList(queryOptions, "twinID_eq", twinIDEq); + _addToQueryList(queryOptions, "twinID_not_eq", twinIDNotEq); + _addToQueryList(queryOptions, "twinID_gt", twinIDGt); + _addToQueryList(queryOptions, "twinID_gte", twinIDGte); + _addToQueryList(queryOptions, "twinID_lt", twinIDLt); + _addToQueryList(queryOptions, "twinID_lte", twinIDLte); + _addToQueryList(queryOptions, "twinID_in", twinIDIn); + _addToQueryList(queryOptions, "twinID_not_in", twinIDNotIn); + _addToQueryList( + queryOptions, "pricingPolicyID_isNull", pricingPolicyIDIsNull); + _addToQueryList(queryOptions, "pricingPolicyID_eq", pricingPolicyIDEq); + _addToQueryList( + queryOptions, "pricingPolicyID_not_eq", pricingPolicyIDNotEq); + _addToQueryList(queryOptions, "pricingPolicyID_gt", pricingPolicyIDGt); + _addToQueryList(queryOptions, "pricingPolicyID_gte", pricingPolicyIDGte); + _addToQueryList(queryOptions, "pricingPolicyID_lt", pricingPolicyIDLt); + _addToQueryList(queryOptions, "pricingPolicyID_lte", pricingPolicyIDLte); + _addToQueryList(queryOptions, "pricingPolicyID_in", pricingPolicyIDIn); + _addToQueryList( + queryOptions, "pricingPolicyID_not_in", pricingPolicyIDNotIn); + _addToQueryList(queryOptions, "certification_isNull", certificationIsNull); + _addToQueryList(queryOptions, "certification_eq", certificationEq); + _addToQueryList(queryOptions, "certification_not_eq", certificationNotEq); + _addToQueryList(queryOptions, "certification_in", certificationIn); + _addToQueryList(queryOptions, "certification_not_in", certificationNotIn); + _addToQueryList( + queryOptions, "stellarAddress_isNull", stellarAddressIsNull); + _addToQueryList(queryOptions, "stellarAddress_eq", stellarAddressEq); + _addToQueryList(queryOptions, "stellarAddress_not_eq", stellarAddressNotEq); + _addToQueryList(queryOptions, "stellarAddress_gt", stellarAddressGt); + _addToQueryList(queryOptions, "stellarAddress_gte", stellarAddressGte); + _addToQueryList(queryOptions, "stellarAddress_lt", stellarAddressLt); + _addToQueryList(queryOptions, "stellarAddress_lte", stellarAddressLte); + _addToQueryList(queryOptions, "stellarAddress_in", stellarAddressIn); + _addToQueryList(queryOptions, "stellarAddress_not_in", stellarAddressNotIn); + _addToQueryList( + queryOptions, "stellarAddress_contains", stellarAddressContains); + _addToQueryList( + queryOptions, "stellarAddress_not_contains", stellarAddressNotContains); + _addToQueryList(queryOptions, "stellarAddress_containsInsensitive", + stellarAddressContainsInsensitive); + _addToQueryList(queryOptions, "stellarAddress_not_containsInsensitive", + stellarAddressNotContainsInsensitive); + _addToQueryList( + queryOptions, "stellarAddress_startsWith", stellarAddressStartsWith); + _addToQueryList(queryOptions, "stellarAddress_not_startsWith", + stellarAddressNotStartsWith); + _addToQueryList( + queryOptions, "stellarAddress_endsWith", stellarAddressEndsWith); + _addToQueryList( + queryOptions, "stellarAddress_not_endsWith", stellarAddressNotEndsWith); + _addToQueryList(queryOptions, "dedicatedFarm_isNull", dedicatedFarmIsNull); + _addToQueryList(queryOptions, "dedicatedFarm_eq", dedicatedFarmEq); + _addToQueryList(queryOptions, "dedicatedFarm_not_eq", dedicatedFarmNotEq); + + String queryString = ''; + + if (queryOptions.isNotEmpty) { + queryString += 'where: {${queryOptions.join(', ')} }'; + } + + if (limit != null) { + if (queryString.isNotEmpty) { + queryString += ', '; + } + queryString += 'limit: $limit'; + } + + if (offset != null) { + if (queryString.isNotEmpty) { + queryString += ', '; + } + queryString += 'offset: $offset'; + } + + if (orderBy != null) { + if (queryString.isNotEmpty) { + queryString += ', '; + } + queryString += 'orderBy: ${orderBy.toString().split('.').last}'; + } + + if (queryString.isNotEmpty) { + queryString = '($queryString)'; + } + + return queryString; + } +} + +@reflector +class FarmInfo { + String? id; + String? gridVersion; + int? farmID; + String? name; + String? certification; + bool? dedicatedFarm; + int? pricingPolicyID; + String? stellarAddress; + int? twinID; + List? publicIPs; + + FarmInfo({ + this.id, + this.gridVersion, + this.farmID, + this.name, + this.certification, + this.dedicatedFarm, + this.pricingPolicyID, + this.stellarAddress, + this.twinID, + this.publicIPs, + }); + + @override + String toString() { + return generateToString(this); + } + + factory FarmInfo.fromJson(Map json) { + return FarmInfo( + id: json['id'] ?? '', + farmID: json['farmID'] ?? 0, + certification: json['certification'] ?? '', + dedicatedFarm: json['dedicatedFarm'] ?? false, + name: json['name'] ?? '', + pricingPolicyID: json['pricingPolicyID'] ?? 0, + stellarAddress: json['stellarAddress'] ?? '', + twinID: json['twinID'] ?? 0, + publicIPs: json['publicIPs'] != null + ? (json['publicIPs'] as List) + .map((item) => PublicIpsInfo.fromJson(item)) + .toList() + : null, + ); + } +} + +//pageinfo returns all 4 parameters +@reflector +class FarmsConnectionReturnOptions { + bool totalCount; + bool pageInfo; + EdgesReturnOptions? edges; + + FarmsConnectionReturnOptions({ + this.totalCount = false, + this.pageInfo = false, + this.edges, + }); + + @override + String toString() { + String returnOptions = ''; + returnOptions = _addToReturnList(returnOptions, "totalCount", totalCount); + returnOptions = _addToReturnList( + returnOptions, + "pageInfo{\n startCursor \n endCursor \n hasNextPage \n hasPreviousPage \n }", + pageInfo); + returnOptions = _addToReturnList(returnOptions, "edges {", edges != null); + returnOptions = + _addToReturnList(returnOptions, edges.toString(), edges != null); + returnOptions = _addToReturnList(returnOptions, "}", edges != null); + + return returnOptions; + } +} + +class FarmsConnectionQueryOptions { + FarmsOrderByOptions orderBy; + String? idEq; + String? idGt; + String? idGte; + String? idNotEq; + String? idLt; + String? idLte; + String? idContains; + String? idNotContains; + String? idContainsInsensitive; + String? idNotContainsInsensitive; + String? idStartsWith; + String? idNotStartsWith; + String? idEndsWith; + String? idNotEndsWith; + List? idIn; + List? idNotIn; + bool? certificationIsNull; + Certification? certificationEq; + Certification? certificationNotEq; + List? certificationIn; + List? certificationNotIn; + bool? dedicatedFarmIsNull; + bool? dedicatedFarmEq; + bool? dedicatedFarmNotEq; + bool? farmIDIsNull; + int? farmIDEq; + int? farmIDNotEq; + int? farmIDGt; + int? farmIDGte; + int? farmIDLt; + int? farmIDLte; + List? farmIDIn; + List? farmIDNotIn; + bool? gridVersionIsNull; + int? gridVersionEq; + int? gridVersionNotEq; + int? gridVersionGt; + int? gridVersionGte; + int? gridVersionLt; + int? gridVersionLte; + List? gridVersionIn; + List? gridVersionNotIn; + bool? nameIsNull; + String? nameEq; + String? nameNotEq; + String? nameGt; + String? nameGte; + String? nameLt; + String? nameLte; + List? nameIn; + List? nameNotIn; + String? nameContains; + String? nameNotContains; + String? nameContainsInsensitive; + String? nameNotContainsInsensitive; + String? nameStartsWith; + String? nameNotStartsWith; + String? nameEndsWith; + String? nameNotEndsWith; + bool? pricingPolicyIDIsNull; + int? pricingPolicyIDEq; + int? pricingPolicyIDNotEq; + int? pricingPolicyIDGt; + int? pricingPolicyIDGte; + int? pricingPolicyIDLt; + int? pricingPolicyIDLte; + List? pricingPolicyIDIn; + List? pricingPolicyIDNotIn; + bool? stellarAddressIsNull; + String? stellarAddressEq; + String? stellarAddressNotEq; + String? stellarAddressGt; + String? stellarAddressGte; + String? stellarAddressLt; + String? stellarAddressLte; + List? stellarAddressIn; + List? stellarAddressNotIn; + String? stellarAddressContains; + String? stellarAddressNotContains; + String? stellarAddressContainsInsensitive; + String? stellarAddressNotContainsInsensitive; + String? stellarAddressStartsWith; + String? stellarAddressNotStartsWith; + String? stellarAddressEndsWith; + String? stellarAddressNotEndsWith; + bool? twinIDIsNull; + int? twinIDEq; + int? twinIDNotEq; + int? twinIDGt; + int? twinIDGte; + int? twinIDLt; + int? twinIDLte; + List? twinIDIn; + List? twinIDNotIn; + int? first; + String? after; + + FarmsConnectionQueryOptions({ + required this.orderBy, + this.idEq, + this.idGt, + this.idGte, + this.idNotEq, + this.idLt, + this.idLte, + this.idContains, + this.idNotContains, + this.idContainsInsensitive, + this.idNotContainsInsensitive, + this.idStartsWith, + this.idNotStartsWith, + this.idEndsWith, + this.idNotEndsWith, + this.gridVersionIsNull, + this.gridVersionEq, + this.gridVersionNotEq, + this.gridVersionGt, + this.gridVersionGte, + this.gridVersionLt, + this.gridVersionLte, + this.gridVersionIn, + this.gridVersionNotIn, + this.farmIDIsNull, + this.farmIDEq, + this.farmIDNotEq, + this.farmIDGt, + this.farmIDLte, + this.farmIDIn, + this.farmIDNotIn, + this.nameIsNull, + this.nameEq, + this.nameNotEq, + this.nameGt, + this.nameGte, + this.nameLt, + this.nameLte, + this.nameIn, + this.nameNotIn, + this.nameContains, + this.nameNotContains, + this.nameContainsInsensitive, + this.nameNotContainsInsensitive, + this.nameStartsWith, + this.nameNotStartsWith, + this.nameEndsWith, + this.nameNotEndsWith, + this.twinIDIsNull, + this.twinIDEq, + this.twinIDNotEq, + this.twinIDGt, + this.twinIDGte, + this.twinIDLt, + this.twinIDLte, + this.twinIDIn, + this.twinIDNotIn, + this.pricingPolicyIDIsNull, + this.pricingPolicyIDEq, + this.pricingPolicyIDNotEq, + this.pricingPolicyIDGt, + this.pricingPolicyIDGte, + this.pricingPolicyIDLt, + this.pricingPolicyIDLte, + this.pricingPolicyIDIn, + this.pricingPolicyIDNotIn, + this.certificationIsNull, + this.certificationEq, + this.certificationNotEq, + this.certificationIn, + this.certificationNotIn, + this.stellarAddressIsNull, + this.stellarAddressEq, + this.stellarAddressNotEq, + this.stellarAddressGt, + this.stellarAddressGte, + this.stellarAddressLt, + this.stellarAddressLte, + this.stellarAddressIn, + this.stellarAddressNotIn, + this.stellarAddressContains, + this.stellarAddressNotContains, + this.stellarAddressContainsInsensitive, + this.stellarAddressNotContainsInsensitive, + this.stellarAddressStartsWith, + this.stellarAddressNotStartsWith, + this.stellarAddressEndsWith, + this.stellarAddressNotEndsWith, + this.dedicatedFarmIsNull, + this.dedicatedFarmEq, + this.dedicatedFarmNotEq, + this.after, + this.first, + }); + + @override + String toString() { + List queryOptions = []; + _addToQueryList(queryOptions, "id_eq", idEq); + _addToQueryList(queryOptions, "id_gt", idGt); + _addToQueryList(queryOptions, "id_gte", idGte); + _addToQueryList(queryOptions, "id_not_eq", idNotEq); + _addToQueryList(queryOptions, "id_lt", idLt); + _addToQueryList(queryOptions, "id_lte", idLte); + _addToQueryList(queryOptions, "id_contains", idContains); + _addToQueryList(queryOptions, "id_not_contains", idNotContains); + _addToQueryList( + queryOptions, "id_containsInsensitive", idContainsInsensitive); + _addToQueryList( + queryOptions, "id_not_containsInsensitive", idNotContainsInsensitive); + _addToQueryList(queryOptions, "id_startsWith", idStartsWith); + _addToQueryList(queryOptions, "id_not_startsWith", idNotStartsWith); + _addToQueryList(queryOptions, "id_endsWith", idEndsWith); + _addToQueryList(queryOptions, "id_not_endsWith", idNotEndsWith); + _addToQueryList(queryOptions, "id_in", idIn); + _addToQueryList(queryOptions, "id_not_in", idNotIn); + _addToQueryList(queryOptions, "gridVersion_is_null", gridVersionIsNull); + _addToQueryList(queryOptions, "gridVersion_eq", gridVersionEq); + _addToQueryList(queryOptions, "gridVersion_not_eq", gridVersionNotEq); + _addToQueryList(queryOptions, "gridVersion_gt", gridVersionGt); + _addToQueryList(queryOptions, "gridVersion_gte", gridVersionGte); + _addToQueryList(queryOptions, "gridVersion_lt", gridVersionLt); + _addToQueryList(queryOptions, "gridVersion_lte", gridVersionLte); + _addToQueryList(queryOptions, "gridVersion_in", gridVersionIn); + _addToQueryList(queryOptions, "gridVersion_not_in", gridVersionNotIn); + _addToQueryList(queryOptions, "farmID_is_null", farmIDIsNull); + _addToQueryList(queryOptions, "farmID_eq", farmIDEq); + _addToQueryList(queryOptions, "farmID_not_eq", farmIDNotEq); + _addToQueryList(queryOptions, "farmID_gt", farmIDGt); + _addToQueryList(queryOptions, "farmID_gte", farmIDGte); + _addToQueryList(queryOptions, "farmID_lt", farmIDLt); + _addToQueryList(queryOptions, "farmID_lte", farmIDLte); + _addToQueryList(queryOptions, "farmID_in", farmIDIn); + _addToQueryList(queryOptions, "farmID_not_in", farmIDNotIn); + _addToQueryList(queryOptions, "name_isNull", nameIsNull); + _addToQueryList(queryOptions, "name_eq", nameEq); + _addToQueryList(queryOptions, "name_not_eq", nameNotEq); + _addToQueryList(queryOptions, "name_gt", nameGt); + _addToQueryList(queryOptions, "name_gte", nameGte); + _addToQueryList(queryOptions, "name_lt", nameLt); + _addToQueryList(queryOptions, "name_lte", nameLte); + _addToQueryList(queryOptions, "name_in", nameIn); + _addToQueryList(queryOptions, "name_not_in", nameNotIn); + _addToQueryList(queryOptions, "name_contains", nameContains); + _addToQueryList(queryOptions, "name_not_contains", nameNotContains); + _addToQueryList( + queryOptions, "name_containsInsensitive", nameContainsInsensitive); + _addToQueryList(queryOptions, "name_not_containsInsensitive", + nameNotContainsInsensitive); + _addToQueryList(queryOptions, "name_startsWith", nameStartsWith); + _addToQueryList(queryOptions, "name_not_startsWith", nameNotStartsWith); + _addToQueryList(queryOptions, "name_endsWith", nameEndsWith); + _addToQueryList(queryOptions, "name_not_endsWith", nameNotEndsWith); + _addToQueryList(queryOptions, "twinID_isNull", twinIDIsNull); + _addToQueryList(queryOptions, "twinID_eq", twinIDEq); + _addToQueryList(queryOptions, "twinID_not_eq", twinIDNotEq); + _addToQueryList(queryOptions, "twinID_gt", twinIDGt); + _addToQueryList(queryOptions, "twinID_gte", twinIDGte); + _addToQueryList(queryOptions, "twinID_lt", twinIDLt); + _addToQueryList(queryOptions, "twinID_lte", twinIDLte); + _addToQueryList(queryOptions, "twinID_in", twinIDIn); + _addToQueryList(queryOptions, "twinID_not_in", twinIDNotIn); + _addToQueryList( + queryOptions, "pricingPolicyID_isNull", pricingPolicyIDIsNull); + _addToQueryList(queryOptions, "pricingPolicyID_eq", pricingPolicyIDEq); + _addToQueryList( + queryOptions, "pricingPolicyID_not_eq", pricingPolicyIDNotEq); + _addToQueryList(queryOptions, "pricingPolicyID_gt", pricingPolicyIDGt); + _addToQueryList(queryOptions, "pricingPolicyID_gte", pricingPolicyIDGte); + _addToQueryList(queryOptions, "pricingPolicyID_lt", pricingPolicyIDLt); + _addToQueryList(queryOptions, "pricingPolicyID_lte", pricingPolicyIDLte); + _addToQueryList(queryOptions, "pricingPolicyID_in", pricingPolicyIDIn); + _addToQueryList( + queryOptions, "pricingPolicyID_not_in", pricingPolicyIDNotIn); + _addToQueryList(queryOptions, "certification_isNull", certificationIsNull); + _addToQueryList(queryOptions, "certification_eq", certificationEq); + _addToQueryList(queryOptions, "certification_not_eq", certificationNotEq); + _addToQueryList(queryOptions, "certification_in", certificationIn); + _addToQueryList(queryOptions, "certification_not_in", certificationNotIn); + _addToQueryList( + queryOptions, "stellarAddress_isNull", stellarAddressIsNull); + _addToQueryList(queryOptions, "stellarAddress_eq", stellarAddressEq); + _addToQueryList(queryOptions, "stellarAddress_not_eq", stellarAddressNotEq); + _addToQueryList(queryOptions, "stellarAddress_gt", stellarAddressGt); + _addToQueryList(queryOptions, "stellarAddress_gte", stellarAddressGte); + _addToQueryList(queryOptions, "stellarAddress_lt", stellarAddressLt); + _addToQueryList(queryOptions, "stellarAddress_lte", stellarAddressLte); + _addToQueryList(queryOptions, "stellarAddress_in", stellarAddressIn); + _addToQueryList(queryOptions, "stellarAddress_not_in", stellarAddressNotIn); + _addToQueryList( + queryOptions, "stellarAddress_contains", stellarAddressContains); + _addToQueryList( + queryOptions, "stellarAddress_not_contains", stellarAddressNotContains); + _addToQueryList(queryOptions, "stellarAddress_containsInsensitive", + stellarAddressContainsInsensitive); + _addToQueryList(queryOptions, "stellarAddress_not_containsInsensitive", + stellarAddressNotContainsInsensitive); + _addToQueryList( + queryOptions, "stellarAddress_startsWith", stellarAddressStartsWith); + _addToQueryList(queryOptions, "stellarAddress_not_startsWith", + stellarAddressNotStartsWith); + _addToQueryList( + queryOptions, "stellarAddress_endsWith", stellarAddressEndsWith); + _addToQueryList( + queryOptions, "stellarAddress_not_endsWith", stellarAddressNotEndsWith); + _addToQueryList(queryOptions, "dedicatedFarm_isNull", dedicatedFarmIsNull); + _addToQueryList(queryOptions, "dedicatedFarm_eq", dedicatedFarmEq); + _addToQueryList(queryOptions, "dedicatedFarm_not_eq", dedicatedFarmNotEq); + + String queryString = ''; + if (queryOptions.isNotEmpty) { + queryString += 'where: {${queryOptions.join(', ')} }'; + } + + if (after != null) { + if (queryString.isNotEmpty) { + queryString += ','; + } + queryString += 'after: "$after"'; + } + + if (first != null) { + if (queryString.isNotEmpty) { + queryString += ','; + } + queryString += 'first: $first'; + } + + if (queryString.isNotEmpty) { + queryString += ', '; + } + queryString += 'orderBy: ${orderBy.toString().split('.').last}'; + queryString = '($queryString)'; + return queryString; + } +} + +@reflector +class FarmsConnectionInfo { + int? totalCount; + PageInfo? pageInfo; + List? edges; + + FarmsConnectionInfo({ + this.totalCount, + this.pageInfo, + this.edges, + }); + + factory FarmsConnectionInfo.fromJson(Map json) { + return FarmsConnectionInfo( + totalCount: json['totalCount'] ?? 0, + pageInfo: + json['pageInfo'] != null ? PageInfo.fromJson(json['pageInfo']) : null, + edges: json['edges'] != null + ? (json['edges'] as List).map((e) => EdgesInfo.fromJson(e)).toList() + : null, + ); + } + + @override + String toString() { + return generateToString(this); + } +} diff --git a/packages/graphql_client/lib/models/interfaces.dart b/packages/graphql_client/lib/models/interfaces.dart new file mode 100644 index 00000000..0a4f5e61 --- /dev/null +++ b/packages/graphql_client/lib/models/interfaces.dart @@ -0,0 +1,325 @@ +part of '../models.dart'; + +@reflector +class Interfaces { + String? id; + Node? node; + String? name; + String? mac; + String? ips; + + Interfaces({ + this.id, + this.node, + this.name, + this.mac, + this.ips, + }); + + factory Interfaces.fromJson(Map json) { + return Interfaces( + id: json['id'] ?? "", + node: json['node'] != null + ? Node.fromJson(json['node'] as Map) + : null, + name: json['name'] ?? "", + mac: json['mac'] ?? "", + ips: json['ips'] ?? "", + ); + } + + @override + String toString() { + return generateToString(this); + } +} + +@reflector +class InterfacesReturnOptions { + bool id; + NodesReturnOptions? node; + bool name; + bool mac; + bool ips; + + InterfacesReturnOptions({ + this.id = false, + this.node, + this.name = false, + this.mac = false, + this.ips = false, + }); + + @override + String toString() { + String returnOptions = ""; + returnOptions = _addToReturnList(returnOptions, "id", id); + returnOptions = _addToReturnList(returnOptions, "name", name); + returnOptions = _addToReturnList(returnOptions, "mac", mac); + returnOptions = _addToReturnList(returnOptions, "ips", ips); + returnOptions = _addToReturnList(returnOptions, "node {", node != null); + returnOptions = + _addToReturnList(returnOptions, node.toString(), node != null); + returnOptions = _addToReturnList(returnOptions, "} ", node != null); + return returnOptions; + } +} + +class InterfaceWhereOptions { + //ids + bool? idIsNull; + String? idEq; + String? idNotEq; + String? idGt; + String? idGte; + String? idLt; + String? idLte; + List? idIn; + List? idNotIn; + String? idContains; + String? idNotContains; + String? idContainsInsensitive; + String? idNotContainsInsensitive; + String? idStartsWith; + String? idNotStartsWith; + String? idEndsWith; + String? idNotEndsWith; + + //node + bool? nodeIsNull; + NodesQueryWhereOptions? node; + + //name + bool? nameIsNull; + String? nameEq; + String? nameNotEq; + String? nameGt; + String? nameGte; + String? nameLt; + String? nameLte; + List? nameIn; + List? nameNotIn; + String? nameContains; + String? nameNotContains; + String? nameContainsInsensitive; + String? nameNotContainsInsensitive; + String? nameStartsWith; + String? nameNotStartsWith; + String? nameEndsWith; + String? nameNotEndsWith; + + //mac + bool? macIsNull; + String? macEq; + String? macNotEq; + String? macGt; + String? macGte; + String? macLt; + String? macLte; + List? macIn; + List? macNotIn; + String? macContains; + String? macNotContains; + String? macContainsInsensitive; + String? macNotContainsInsensitive; + String? macStartsWith; + String? macNotStartsWith; + String? macEndsWith; + String? macNotEndsWith; + + //ips + bool? ipsIsNull; + String? ipsEq; + String? ipsNotEq; + String? ipsGt; + String? ipsGte; + String? ipsLt; + String? ipsLte; + List? ipsIn; + List? ipsNotIn; + String? ipsContains; + String? ipsNotContains; + String? ipsContainsInsensitive; + String? ipsNotContainsInsensitive; + String? ipsStartsWith; + String? ipsNotStartsWith; + String? ipsEndsWith; + String? ipsNotEndsWith; + + InterfaceWhereOptions({ + //id + this.idIsNull, + this.idEq, + this.idNotEq, + this.idGt, + this.idGte, + this.idLt, + this.idLte, + this.idIn, + this.idNotIn, + this.idContains, + this.idNotContains, + this.idContainsInsensitive, + this.idNotContainsInsensitive, + this.idStartsWith, + this.idNotStartsWith, + this.idEndsWith, + this.idNotEndsWith, + + //node + this.nodeIsNull, + this.node, + + //name + this.nameIsNull, + this.nameEq, + this.nameNotEq, + this.nameGt, + this.nameGte, + this.nameLt, + this.nameLte, + this.nameIn, + this.nameNotIn, + this.nameContains, + this.nameNotContains, + this.nameContainsInsensitive, + this.nameNotContainsInsensitive, + this.nameStartsWith, + this.nameNotStartsWith, + this.nameEndsWith, + this.nameNotEndsWith, + + //mac + this.macIsNull, + this.macEq, + this.macNotEq, + this.macGt, + this.macGte, + this.macLt, + this.macLte, + this.macIn, + this.macNotIn, + this.macContains, + this.macNotContains, + this.macContainsInsensitive, + this.macNotContainsInsensitive, + this.macStartsWith, + this.macNotStartsWith, + this.macEndsWith, + this.macNotEndsWith, + + //ips + this.ipsIsNull, + this.ipsEq, + this.ipsNotEq, + this.ipsGt, + this.ipsGte, + this.ipsLt, + this.ipsLte, + this.ipsIn, + this.ipsNotIn, + this.ipsContains, + this.ipsNotContains, + this.ipsContainsInsensitive, + this.ipsNotContainsInsensitive, + this.ipsStartsWith, + this.ipsNotStartsWith, + this.ipsEndsWith, + this.ipsNotEndsWith, + }); + + @override + String toString() { + List queryOptions = []; + + //id + _addToQueryList(queryOptions, "id_isNull", idIsNull); + _addToQueryList(queryOptions, "id_eq", idEq); + _addToQueryList(queryOptions, "id_not_eq", idNotEq); + _addToQueryList(queryOptions, "id_gt", idGt); + _addToQueryList(queryOptions, "id_gte", idGte); + _addToQueryList(queryOptions, "id_lt", idLt); + _addToQueryList(queryOptions, "id_lte", idLte); + _addToQueryList(queryOptions, "id_in", idIn); + _addToQueryList(queryOptions, "id_not_in", idNotIn); + _addToQueryList(queryOptions, "id_contains", idContains); + _addToQueryList(queryOptions, "id_not_contains", idNotContains); + _addToQueryList( + queryOptions, "id_containsInsensitive", idContainsInsensitive); + _addToQueryList( + queryOptions, "id_not_containsInsensitive", idNotContainsInsensitive); + _addToQueryList(queryOptions, "id_startsWith", idStartsWith); + _addToQueryList(queryOptions, "id_not_startsWith", idNotStartsWith); + _addToQueryList(queryOptions, "id_endsWith", idEndsWith); + _addToQueryList(queryOptions, "id_not_endsWith", idNotEndsWith); + + //node + _addToQueryList(queryOptions, "node_isNull", nodeIsNull); + if (node != null) queryOptions.add('node: {${node.toString()}}'); + + //name + _addToQueryList(queryOptions, "name_isNull", nameIsNull); + _addToQueryList(queryOptions, "name_eq", nameEq); + _addToQueryList(queryOptions, "name_not_eq", nameNotEq); + _addToQueryList(queryOptions, "name_gt", nameGt); + _addToQueryList(queryOptions, "name_gte", nameGte); + _addToQueryList(queryOptions, "name_lt", nameLt); + _addToQueryList(queryOptions, "name_lte", nameLte); + _addToQueryList(queryOptions, "name_in", nameIn); + _addToQueryList(queryOptions, "name_not_in", nameNotIn); + _addToQueryList(queryOptions, "name_contains", nameContains); + _addToQueryList(queryOptions, "name_not_contains", nameNotContains); + _addToQueryList( + queryOptions, "name_containsInsensitive", nameContainsInsensitive); + _addToQueryList(queryOptions, "name_not_containsInsensitive", + nameNotContainsInsensitive); + _addToQueryList(queryOptions, "name_startsWith", nameStartsWith); + _addToQueryList(queryOptions, "name_not_startsWith", nameNotStartsWith); + _addToQueryList(queryOptions, "name_endsWith", nameEndsWith); + _addToQueryList(queryOptions, "name_not_endsWith", nameNotEndsWith); + + //mac + _addToQueryList(queryOptions, "mac_isNull", macIsNull); + _addToQueryList(queryOptions, "mac_eq", macEq); + _addToQueryList(queryOptions, "mac_not_eq", macNotEq); + _addToQueryList(queryOptions, "mac_gt", macGt); + _addToQueryList(queryOptions, "mac_gte", macGte); + _addToQueryList(queryOptions, "mac_lt", macLt); + _addToQueryList(queryOptions, "mac_lte", macLte); + _addToQueryList(queryOptions, "mac_in", macIn); + _addToQueryList(queryOptions, "mac_not_in", macNotIn); + _addToQueryList(queryOptions, "mac_contains", macContains); + _addToQueryList(queryOptions, "mac_not_contains", macNotContains); + _addToQueryList( + queryOptions, "mac_containsInsensitive", macContainsInsensitive); + _addToQueryList( + queryOptions, "mac_not_containsInsensitive", macNotContainsInsensitive); + _addToQueryList(queryOptions, "mac_startsWith", macStartsWith); + _addToQueryList(queryOptions, "mac_not_startsWith", macNotStartsWith); + _addToQueryList(queryOptions, "mac_endsWith", macEndsWith); + _addToQueryList(queryOptions, "mac_not_endsWith", macNotEndsWith); + + //ips + _addToQueryList(queryOptions, "ips_isNull", ipsIsNull); + _addToQueryList(queryOptions, "ips_eq", ipsEq); + _addToQueryList(queryOptions, "ips_not_eq", ipsNotEq); + _addToQueryList(queryOptions, "ips_gt", ipsGt); + _addToQueryList(queryOptions, "ips_gte", ipsGte); + _addToQueryList(queryOptions, "ips_lt", ipsLt); + _addToQueryList(queryOptions, "ips_lte", ipsLte); + _addToQueryList(queryOptions, "ips_in", ipsIn); + _addToQueryList(queryOptions, "ips_not_in", ipsNotIn); + _addToQueryList(queryOptions, "ips_contains", ipsContains); + _addToQueryList(queryOptions, "ips_not_contains", ipsNotContains); + _addToQueryList( + queryOptions, "ips_containsInsensitive", ipsContainsInsensitive); + _addToQueryList( + queryOptions, "ips_not_containsInsensitive", ipsNotContainsInsensitive); + _addToQueryList(queryOptions, "ips_startsWith", ipsStartsWith); + _addToQueryList(queryOptions, "ips_not_startsWith", ipsNotStartsWith); + _addToQueryList(queryOptions, "ips_endsWith", ipsEndsWith); + _addToQueryList(queryOptions, "ips_not_endsWith", ipsNotEndsWith); + + return queryOptions.isNotEmpty ? queryOptions.join(', ') : " "; + } +} diff --git a/packages/graphql_client/lib/models/location.dart b/packages/graphql_client/lib/models/location.dart new file mode 100644 index 00000000..68117053 --- /dev/null +++ b/packages/graphql_client/lib/models/location.dart @@ -0,0 +1,232 @@ +part of '../models.dart'; + +@reflector +class LocationReturnOptions { + bool id; + bool longitude; + bool latitude; + + LocationReturnOptions({ + this.id = false, + this.longitude = false, + this.latitude = false, + }); + @override + String toString() { + return generateToString(this); + } +} + +@reflector +class Location { + String? id; + String? longitude; + String? latitude; + + Location({ + this.id, + this.longitude, + this.latitude, + }); + + factory Location.fromJson(Map json) { + return fromJson(json); + } + + @override + String toString() { + return generateToString(this); + } +} + +class LocationWhereOptions { + //id + bool? idIsNull; + String? idEq; + String? idNotEq; + String? idGt; + String? idGte; + String? idLt; + String? idLte; + List? idIn; + List? idNotIn; + String? idContains; + String? idNotContains; + String? idContainsInsensitive; + String? idNotContainsInsensitive; + String? idStartsWith; + String? idNotStartsWith; + String? idEndsWith; + String? idNotEndsWith; + + //longitude + bool? longitudeIsNull; + String? longitudeEq; + String? longitudeNotEq; + String? longitudeGt; + String? longitudeGte; + String? longitudeLt; + String? longitudeLte; + List? longitudeIn; + List? longitudeNotIn; + String? longitudeContains; + String? longitudeNotContains; + String? longitudeContainsInsensitive; + String? longitudeNotContainsInsensitive; + String? longitudeStartsWith; + String? longitudeNotStartsWith; + String? longitudeEndsWith; + String? longitudeNotEndsWith; + + //latitude + bool? latitudeIsNull; + String? latitudeEq; + String? latitudeNotEq; + String? latitudeGt; + String? latitudeGte; + String? latitudeLt; + String? latitudeLte; + List? latitudeIn; + List? latitudeNotIn; + String? latitudeContains; + String? latitudeNotContains; + String? latitudeContainsInsensitive; + String? latitudeNotContainsInsensitive; + String? latitudeStartsWith; + String? latitudeNotStartsWith; + String? latitudeEndsWith; + String? latitudeNotEndsWith; + + LocationWhereOptions({ + //id + this.idIsNull, + this.idEq, + this.idNotEq, + this.idGt, + this.idGte, + this.idLt, + this.idLte, + this.idIn, + this.idNotIn, + this.idContains, + this.idNotContains, + this.idContainsInsensitive, + this.idNotContainsInsensitive, + this.idStartsWith, + this.idNotStartsWith, + this.idEndsWith, + this.idNotEndsWith, + + //longitude + this.longitudeIsNull, + this.longitudeEq, + this.longitudeNotEq, + this.longitudeGt, + this.longitudeGte, + this.longitudeLt, + this.longitudeLte, + this.longitudeIn, + this.longitudeNotIn, + this.longitudeContains, + this.longitudeNotContains, + this.longitudeContainsInsensitive, + this.longitudeNotContainsInsensitive, + this.longitudeStartsWith, + this.longitudeNotStartsWith, + this.longitudeEndsWith, + this.longitudeNotEndsWith, + + //latitude + this.latitudeIsNull, + this.latitudeEq, + this.latitudeNotEq, + this.latitudeGt, + this.latitudeGte, + this.latitudeLt, + this.latitudeLte, + this.latitudeIn, + this.latitudeNotIn, + this.latitudeContains, + this.latitudeNotContains, + this.latitudeContainsInsensitive, + this.latitudeNotContainsInsensitive, + this.latitudeStartsWith, + this.latitudeNotStartsWith, + this.latitudeEndsWith, + this.latitudeNotEndsWith, + }); + + @override + String toString() { + List queryOptions = []; + + //id + _addToQueryList(queryOptions, "id_isNull", idIsNull); + _addToQueryList(queryOptions, "id_eq", idEq); + _addToQueryList(queryOptions, "id_not_eq", idNotEq); + _addToQueryList(queryOptions, "id_gt", idGt); + _addToQueryList(queryOptions, "id_gte", idGte); + _addToQueryList(queryOptions, "id_lt", idLt); + _addToQueryList(queryOptions, "id_lte", idLte); + _addToQueryList(queryOptions, "id_in", idIn); + _addToQueryList(queryOptions, "id_not_in", idNotIn); + _addToQueryList(queryOptions, "id_contains", idContains); + _addToQueryList(queryOptions, "id_not_contains", idNotContains); + _addToQueryList( + queryOptions, "id_containsInsensitive", idContainsInsensitive); + _addToQueryList( + queryOptions, "id_not_containsInsensitive", idNotContainsInsensitive); + _addToQueryList(queryOptions, "id_startsWith", idStartsWith); + _addToQueryList(queryOptions, "id_not_startsWith", idNotStartsWith); + _addToQueryList(queryOptions, "id_endsWith", idEndsWith); + _addToQueryList(queryOptions, "id_not_endsWith", idNotEndsWith); + + //longitude + _addToQueryList(queryOptions, "longitude_isNull", longitudeIsNull); + _addToQueryList(queryOptions, "longitude_eq", longitudeEq); + _addToQueryList(queryOptions, "longitude_not_eq", longitudeNotEq); + _addToQueryList(queryOptions, "longitude_gt", longitudeGt); + _addToQueryList(queryOptions, "longitude_gte", longitudeGte); + _addToQueryList(queryOptions, "longitude_lt", longitudeLt); + _addToQueryList(queryOptions, "longitude_lte", longitudeLte); + _addToQueryList(queryOptions, "longitude_in", longitudeIn); + _addToQueryList(queryOptions, "longitude_not_in", longitudeNotIn); + _addToQueryList(queryOptions, "longitude_contains", longitudeContains); + _addToQueryList( + queryOptions, "longitude_not_contains", longitudeNotContains); + _addToQueryList(queryOptions, "longitude_containsInsensitive", + longitudeContainsInsensitive); + _addToQueryList(queryOptions, "longitude_not_containsInsensitive", + longitudeNotContainsInsensitive); + _addToQueryList(queryOptions, "longitude_startsWith", longitudeStartsWith); + _addToQueryList( + queryOptions, "longitude_not_startsWith", longitudeNotStartsWith); + _addToQueryList(queryOptions, "longitude_endsWith", longitudeEndsWith); + _addToQueryList( + queryOptions, "longitude_not_endsWith", longitudeNotEndsWith); + + //latitude + _addToQueryList(queryOptions, "latitude_isNull", latitudeIsNull); + _addToQueryList(queryOptions, "latitude_eq", latitudeEq); + _addToQueryList(queryOptions, "latitude_not_eq", latitudeNotEq); + _addToQueryList(queryOptions, "latitude_gt", latitudeGt); + _addToQueryList(queryOptions, "latitude_gte", latitudeGte); + _addToQueryList(queryOptions, "latitude_lt", latitudeLt); + _addToQueryList(queryOptions, "latitude_lte", latitudeLte); + _addToQueryList(queryOptions, "latitude_in", latitudeIn); + _addToQueryList(queryOptions, "latitude_not_in", latitudeNotIn); + _addToQueryList(queryOptions, "latitude_contains", latitudeContains); + _addToQueryList(queryOptions, "latitude_not_contains", latitudeNotContains); + _addToQueryList(queryOptions, "latitude_containsInsensitive", + latitudeContainsInsensitive); + _addToQueryList(queryOptions, "latitude_not_containsInsensitive", + latitudeNotContainsInsensitive); + _addToQueryList(queryOptions, "latitude_startsWith", latitudeStartsWith); + _addToQueryList( + queryOptions, "latitude_not_startsWith", latitudeNotStartsWith); + _addToQueryList(queryOptions, "latitude_endsWith", latitudeEndsWith); + _addToQueryList(queryOptions, "latitude_not_endsWith", latitudeNotEndsWith); + + return queryOptions.isNotEmpty ? queryOptions.join(', ') : " "; + } +} diff --git a/packages/graphql_client/lib/models/node.dart b/packages/graphql_client/lib/models/node.dart new file mode 100644 index 00000000..5d7a48fd --- /dev/null +++ b/packages/graphql_client/lib/models/node.dart @@ -0,0 +1,103 @@ +part of '../models.dart'; + +@reflector +class NodeInfo { + String? id; + String? certification; + bool? dedicatedFarm; + int? farmID; + int? gridVersion; + String? name; + int? pricingPolicyID; + String? stellarAddress; + int? twinID; + List? publicIPs; + + NodeInfo({ + this.id, + this.certification, + this.dedicatedFarm, + this.farmID, + this.gridVersion, + this.name, + this.pricingPolicyID, + this.stellarAddress, + this.twinID, + this.publicIPs, + }); + + @override + String toString() { + return generateToString(this); + } + + factory NodeInfo.fromJson(Map json) { + return NodeInfo( + id: json['id'] ?? '', + certification: json['certification'] ?? '', + dedicatedFarm: json['dedicatedFarm'] ?? false, + farmID: json['farmID'] ?? 0, + gridVersion: json['gridVersion'] ?? 0, + name: json['name'] ?? '', + pricingPolicyID: json['pricingPolicyID'] ?? 0, + stellarAddress: json['stellarAddress'] ?? '', + twinID: json['twinID'] ?? 0, + publicIPs: json['publicIPs'] != null + ? (json['publicIPs'] as List) + .map((item) => PublicIpsInfo.fromJson(item)) + .toList() + : null, + ); + } +} + +@reflector +class NodeReturnOptions { + bool id; + bool certification; + bool dedicatedFarm; + bool farmID; + bool gridVersion; + bool name; + bool pricingPolicyID; + bool stellarAddress; + bool twinID; + PublicIpsReturnOptions? publicIPs; + + NodeReturnOptions({ + this.id = false, + this.certification = false, + this.dedicatedFarm = false, + this.farmID = false, + this.gridVersion = false, + this.name = false, + this.pricingPolicyID = false, + this.stellarAddress = false, + this.twinID = false, + this.publicIPs, + }); + + @override + String toString() { + String returnOptions = ""; + returnOptions = _addToReturnList(returnOptions, "id", id); + returnOptions = + _addToReturnList(returnOptions, "certification", certification); + returnOptions = + _addToReturnList(returnOptions, "dedicatedFarm", dedicatedFarm); + returnOptions = _addToReturnList(returnOptions, "farmID", farmID); + returnOptions = _addToReturnList(returnOptions, "gridVersion", gridVersion); + returnOptions = _addToReturnList(returnOptions, "name", name); + returnOptions = + _addToReturnList(returnOptions, "pricingPolicyID", pricingPolicyID); + returnOptions = + _addToReturnList(returnOptions, "stellarAddress", stellarAddress); + returnOptions = _addToReturnList(returnOptions, "twinID", twinID); + returnOptions = + _addToReturnList(returnOptions, "publicIPs {", publicIPs != null); + returnOptions = _addToReturnList( + returnOptions, publicIPs.toString(), publicIPs != null); + returnOptions = _addToReturnList(returnOptions, "}", publicIPs != null); + return returnOptions; + } +} diff --git a/packages/graphql_client/lib/models/nodes.dart b/packages/graphql_client/lib/models/nodes.dart new file mode 100644 index 00000000..11badeb2 --- /dev/null +++ b/packages/graphql_client/lib/models/nodes.dart @@ -0,0 +1,1682 @@ +// ignore_for_file: constant_identifier_names + +part of '../models.dart'; + +enum NodeCertification { + Diy, + Certified; + + @override + String toString() { + return name; + } +} + +NodeCertification certificationFromJson(String jsonString) { + switch (jsonString) { + case 'Certified': + return NodeCertification.Certified; + case 'Diy': + default: + return NodeCertification.Diy; + } +} + +enum NodesOrderByOptions { + none, + id_ASC, + id_DESC, + gridVersion_ASC, + gridVersion_DESC, + nodeID_ASC, + nodeID_DESC, + farmID_ASC, + farmID_DESC, + twinID_ASC, + twinID_DESC, + location_id_ASC, + location_id_DESC, + location_longitude_ASC, + location_longitude_DESC, + location_latitude_ASC, + location_latitude_DESC, + country_ASC, + country_DESC, + city_ASC, + city_DESC, + publicConfig_id_ASC, + publicConfig_id_DESC, + publicConfig_ipv4_ASC, + publicConfig_ipv4_DESC, + publicConfig_ipv6_ASC, + publicConfig_ipv6_DESC, + publicConfig_gw4_ASC, + publicConfig_gw4_DESC, + publicConfig_gw6_ASC, + publicConfig_gw6_DESC, + publicConfig_domain_ASC, + publicConfig_domain_DESC, + resourcesTotal_id_ASC, + resourcesTotal_id_DESC, + resourcesTotal_hru_ASC, + resourcesTotal_hru_DESC, + resourcesTotal_sru_ASC, + resourcesTotal_sru_DESC, + resourcesTotal_cru_ASC, + resourcesTotal_cru_DESC, + resourcesTotal_mru_ASC, + resourcesTotal_mru_DESC, + uptime_ASC, + uptime_DESC, + created_ASC, + created_DESC, + farmingPolicyId_ASC, + farmingPolicyId_DESC, + certification_ASC, + certification_DESC, + secure_ASC, + secure_DESC, + virtualized_ASC, + virtualized_DESC, + serialNumber_ASC, + serialNumber_DESC, + createdAt_ASC, + createdAt_DESC, + updatedAt_ASC, + updatedAt_DESC, + connectionPrice_ASC, + connectionPrice_DESC, + power_state_ASC, + power_state_DESC, + power_target_ASC, + power_target_DESC, + dedicated_ASC, + dedicated_DESC, + extraFee_ASC, + extraFee_DESC; + + @override + String toString() { + return name; + } +} + +class NodesQueryWhereOptions { + // ids + bool? idIsNull; + String? idEq; + String? idNotEq; + String? idGt; + String? idGte; + String? idLt; + String? idLte; + List? idIn; + List? idNotIn; + String? idContains; + String? idNotContains; + String? idContainsInsensitive; + String? idNotContainsInsensitive; + String? idStartsWith; + String? idNotStartsWith; + String? idEndsWith; + String? idNotEndsWith; + + // grid + bool? gridVersionIsNull; + int? gridVersionEq; + int? gridVersionNotEq; + int? gridVersionGt; + int? gridVersionGte; + int? gridVersionLt; + int? gridVersionLte; + List? gridVersionIn; + List? gridVersionNotIn; + + // nodeID + bool? nodeIDIsNull; + int? nodeIDEq; + int? nodeIDNotEq; + int? nodeIDGt; + int? nodeIDGte; + int? nodeIDLt; + int? nodeIDLte; + List? nodeIDIn; + List? nodeIDNotIn; + + // farmID + bool? farmIDIsNull; + int? farmIDEq; + int? farmIDNotEq; + int? farmIDGt; + int? farmIDGte; + int? farmIDLt; + int? farmIDLte; + List? farmIDIn; + List? farmIDNotIn; + + // twins + bool? twinIDIsNull; + int? twinIDEq; + int? twinIDNotEq; + int? twinIDGt; + int? twinIDGte; + int? twinIDLt; + int? twinIDLte; + List? twinIDIn; + List? twinIDNotIn; + + // location + bool? locationIsNull; + LocationWhereOptions? location; + + // country + bool? countryIsNull; + String? countryEq; + String? countryNotEq; + String? countryGt; + String? countryGte; + String? countryLt; + String? countryLte; + List? countryIn; + List? countryNotIn; + String? countryContains; + String? countryNotContains; + String? countryContainsInsensitive; + String? countryNotContainsInsensitive; + String? countryStartsWith; + String? countryNotStartsWith; + String? countryEndsWith; + String? countryNotEndsWith; + + // city + bool? cityIsNull; + String? cityEq; + String? cityNotEq; + String? cityGt; + String? cityGte; + String? cityLt; + String? cityLte; + List? cityIn; + List? cityNotIn; + String? cityContains; + String? cityNotContains; + String? cityContainsInsensitive; + String? cityNotContainsInsensitive; + String? cityStartsWith; + String? cityNotStartsWith; + String? cityEndsWith; + String? cityNotEndsWith; + + // publicConfig + bool? publicConfigIsNull; + PublicConfigWhereOptions? publicConfig; + + // resourcesTotal + bool? resourcesTotalIsNull; + NodeResourcesWhereOptions? resourcesTotal; + + // uptime + bool? uptimeIsNull; + BigInt? uptimeEq; + BigInt? uptimeNotEq; + BigInt? uptimeGt; + BigInt? uptimeGte; + BigInt? uptimeLt; + BigInt? uptimeLte; + List? uptimeIn; + List? uptimeNotIn; + + // created + bool? createdIsNull; + int? createdEq; + int? createdNotEq; + int? createdGt; + int? createdGte; + int? createdLt; + int? createdLte; + List? createdIn; + List? createdNotIn; + + // farmingPolicyId + bool? farmingPolicyIdIsNull; + int? farmingPolicyIdEq; + int? farmingPolicyIdNotEq; + int? farmingPolicyIdGt; + int? farmingPolicyIdGte; + int? farmingPolicyIdLt; + int? farmingPolicyIdLte; + List? farmingPolicyIdIn; + List? farmingPolicyIdNotIn; + + // interfaces + InterfaceWhereOptions? interfacesEvery; + InterfaceWhereOptions? interfacesSome; + InterfaceWhereOptions? interfacesNone; + + // certification + bool? certificationIsNull; + NodeCertification? certificationEq; + NodeCertification? certificationNotEq; + List? certificationIn; + List? certificationNotIn; + + // secure + bool? secureIsNull; + bool? secureEq; + bool? secureNotEq; + + // virtualized + bool? virtualizedIsNull; + bool? virtualizedEq; + bool? virtualizedNotEq; + + // serialNumber + bool? serialNumberIsNull; + String? serialNumberEq; + String? serialNumberNotEq; + String? serialNumberGt; + String? serialNumberGte; + String? serialNumberLt; + String? serialNumberLte; + List? serialNumberIn; + List? serialNumberNotIn; + String? serialNumberContains; + String? serialNumberNotContains; + String? serialNumberContainsInsensitive; + String? serialNumberNotContainsInsensitive; + String? serialNumberStartsWith; + String? serialNumberNotStartsWith; + String? serialNumberEndsWith; + String? serialNumberNotEndsWith; + + // createdAt + bool? createdAtIsNull; + BigInt? createdAtEq; + BigInt? createdAtNotEq; + BigInt? createdAtGt; + BigInt? createdAtGte; + BigInt? createdAtLt; + BigInt? createdAtLte; + List? createdAtIn; + List? createdAtNotIn; + + // updatedAt + bool? updatedAtIsNull; + BigInt? updatedAtEq; + BigInt? updatedAtNotEq; + BigInt? updatedAtGt; + BigInt? updatedAtGte; + BigInt? updatedAtLt; + BigInt? updatedAtLte; + List? updatedAtIn; + List? updatedAtNotIn; + + // connectionPrice + bool? connectionPriceIsNull; + int? connectionPriceEq; + int? connectionPriceNotEq; + int? connectionPriceGt; + int? connectionPriceGte; + int? connectionPriceLt; + int? connectionPriceLte; + List? connectionPriceIn; + List? connectionPriceNotIn; + + // power + bool? powerIsNull; + PowerWhereOptions? power; + + // dedicated + bool? dedicatedIsNull; + bool? dedicatedEq; + bool? dedicatedNotEq; + + // extraFee + bool? extraFeeIsNull; + BigInt? extraFeeEq; + BigInt? extraFeeNotEq; + BigInt? extraFeeGt; + BigInt? extraFeeGte; + BigInt? extraFeeLt; + BigInt? extraFeeLte; + List? extraFeeIn; + List? extraFeeNotIn; + + NodesQueryWhereOptions({ + // ids + this.idIsNull, + this.idEq, + this.idNotEq, + this.idGt, + this.idGte, + this.idLt, + this.idLte, + this.idIn, + this.idNotIn, + this.idContains, + this.idNotContains, + this.idContainsInsensitive, + this.idNotContainsInsensitive, + this.idStartsWith, + this.idNotStartsWith, + this.idEndsWith, + this.idNotEndsWith, + + // grid + this.gridVersionIsNull, + this.gridVersionEq, + this.gridVersionNotEq, + this.gridVersionGt, + this.gridVersionGte, + this.gridVersionLt, + this.gridVersionLte, + this.gridVersionIn, + this.gridVersionNotIn, + + // nodeID + this.nodeIDIsNull, + this.nodeIDEq, + this.nodeIDNotEq, + this.nodeIDGt, + this.nodeIDGte, + this.nodeIDLt, + this.nodeIDLte, + this.nodeIDIn, + this.nodeIDNotIn, + + // farmID + this.farmIDIsNull, + this.farmIDEq, + this.farmIDNotEq, + this.farmIDGt, + this.farmIDGte, + this.farmIDLt, + this.farmIDLte, + this.farmIDIn, + this.farmIDNotIn, + + // twins + this.twinIDIsNull, + this.twinIDEq, + this.twinIDNotEq, + this.twinIDGt, + this.twinIDGte, + this.twinIDLt, + this.twinIDLte, + this.twinIDIn, + this.twinIDNotIn, + + // location + this.locationIsNull, + this.location, + + // country + this.countryIsNull, + this.countryEq, + this.countryNotEq, + this.countryGt, + this.countryGte, + this.countryLt, + this.countryLte, + this.countryIn, + this.countryNotIn, + this.countryContains, + this.countryNotContains, + this.countryContainsInsensitive, + this.countryNotContainsInsensitive, + this.countryStartsWith, + this.countryNotStartsWith, + this.countryEndsWith, + this.countryNotEndsWith, + + // city + this.cityIsNull, + this.cityEq, + this.cityNotEq, + this.cityGt, + this.cityGte, + this.cityLt, + this.cityLte, + this.cityIn, + this.cityNotIn, + this.cityContains, + this.cityNotContains, + this.cityContainsInsensitive, + this.cityNotContainsInsensitive, + this.cityStartsWith, + this.cityNotStartsWith, + this.cityEndsWith, + this.cityNotEndsWith, + + // publicConfig + this.publicConfigIsNull, + this.publicConfig, + + // resourcesTotal + this.resourcesTotalIsNull, + this.resourcesTotal, + + // uptime + this.uptimeIsNull, + this.uptimeEq, + this.uptimeNotEq, + this.uptimeGt, + this.uptimeGte, + this.uptimeLt, + this.uptimeLte, + this.uptimeIn, + this.uptimeNotIn, + + // created + this.createdIsNull, + this.createdEq, + this.createdNotEq, + this.createdGt, + this.createdGte, + this.createdLt, + this.createdLte, + this.createdIn, + this.createdNotIn, + + // farmingPolicyId + this.farmingPolicyIdIsNull, + this.farmingPolicyIdEq, + this.farmingPolicyIdNotEq, + this.farmingPolicyIdGt, + this.farmingPolicyIdGte, + this.farmingPolicyIdLt, + this.farmingPolicyIdLte, + this.farmingPolicyIdIn, + this.farmingPolicyIdNotIn, + + // interfaces + this.interfacesEvery, + this.interfacesSome, + this.interfacesNone, + + // certification + this.certificationIsNull, + this.certificationEq, + this.certificationNotEq, + this.certificationIn, + this.certificationNotIn, + + // secure + this.secureIsNull, + this.secureEq, + this.secureNotEq, + + // virtualized + this.virtualizedIsNull, + this.virtualizedEq, + this.virtualizedNotEq, + + // serialNumber + this.serialNumberIsNull, + this.serialNumberEq, + this.serialNumberNotEq, + this.serialNumberGt, + this.serialNumberGte, + this.serialNumberLt, + this.serialNumberLte, + this.serialNumberIn, + this.serialNumberNotIn, + this.serialNumberContains, + this.serialNumberNotContains, + this.serialNumberContainsInsensitive, + this.serialNumberNotContainsInsensitive, + this.serialNumberStartsWith, + this.serialNumberNotStartsWith, + this.serialNumberEndsWith, + this.serialNumberNotEndsWith, + + // createdAt + this.createdAtIsNull, + this.createdAtEq, + this.createdAtNotEq, + this.createdAtGt, + this.createdAtGte, + this.createdAtLt, + this.createdAtLte, + this.createdAtIn, + this.createdAtNotIn, + + // updatedAt + this.updatedAtIsNull, + this.updatedAtEq, + this.updatedAtNotEq, + this.updatedAtGt, + this.updatedAtGte, + this.updatedAtLt, + this.updatedAtLte, + this.updatedAtIn, + this.updatedAtNotIn, + + // connectionPrice + this.connectionPriceIsNull, + this.connectionPriceEq, + this.connectionPriceNotEq, + this.connectionPriceGt, + this.connectionPriceGte, + this.connectionPriceLt, + this.connectionPriceLte, + this.connectionPriceIn, + this.connectionPriceNotIn, + + // power + this.powerIsNull, + this.power, + + // dedicated + this.dedicatedIsNull, + this.dedicatedEq, + this.dedicatedNotEq, + + // extraFee + this.extraFeeIsNull, + this.extraFeeEq, + this.extraFeeNotEq, + this.extraFeeGt, + this.extraFeeGte, + this.extraFeeLt, + this.extraFeeLte, + this.extraFeeIn, + this.extraFeeNotIn, + }); + + @override + String toString() { + List queryOptions = []; + + // ids + _addToQueryList(queryOptions, "id_isNull", idIsNull); + _addToQueryList(queryOptions, "id_eq", idEq); + _addToQueryList(queryOptions, "id_not_eq", idNotEq); + _addToQueryList(queryOptions, "id_gt", idGt); + _addToQueryList(queryOptions, "id_gte", idGte); + _addToQueryList(queryOptions, "id_lt", idLt); + _addToQueryList(queryOptions, "id_lte", idLte); + _addToQueryList(queryOptions, "id_in", idIn); + _addToQueryList(queryOptions, "id_not_in", idNotIn); + _addToQueryList(queryOptions, "id_contains", idContains); + _addToQueryList(queryOptions, "id_not_contains", idNotContains); + _addToQueryList( + queryOptions, "id_containsInsensitive", idContainsInsensitive); + _addToQueryList( + queryOptions, "id_not_containsInsensitive", idNotContainsInsensitive); + _addToQueryList(queryOptions, "id_startsWith", idStartsWith); + _addToQueryList(queryOptions, "id_not_startsWith", idNotStartsWith); + _addToQueryList(queryOptions, "id_endsWith", idEndsWith); + _addToQueryList(queryOptions, "id_not_endsWith", idNotEndsWith); + + // grid + _addToQueryList(queryOptions, "gridVersion_isNull", gridVersionIsNull); + _addToQueryList(queryOptions, "gridVersion_eq", gridVersionEq); + _addToQueryList(queryOptions, "gridVersion_not_eq", gridVersionNotEq); + _addToQueryList(queryOptions, "gridVersion_gt", gridVersionGt); + _addToQueryList(queryOptions, "gridVersion_gte", gridVersionGte); + _addToQueryList(queryOptions, "gridVersion_lt", gridVersionLt); + _addToQueryList(queryOptions, "gridVersion_lte", gridVersionLte); + _addToQueryList(queryOptions, "gridVersion_in", gridVersionIn); + _addToQueryList(queryOptions, "gridVersion_not_in", gridVersionNotIn); + + // nodeID + _addToQueryList(queryOptions, "nodeID_isNull", nodeIDIsNull); + _addToQueryList(queryOptions, "nodeID_eq", nodeIDEq); + _addToQueryList(queryOptions, "nodeID_not_eq", nodeIDNotEq); + _addToQueryList(queryOptions, "nodeID_gt", nodeIDGt); + _addToQueryList(queryOptions, "nodeID_gte", nodeIDGte); + _addToQueryList(queryOptions, "nodeID_lt", nodeIDLt); + _addToQueryList(queryOptions, "nodeID_lte", nodeIDLte); + _addToQueryList(queryOptions, "nodeID_in", nodeIDIn); + _addToQueryList(queryOptions, "nodeID_not_in", nodeIDNotIn); + + // farmID + _addToQueryList(queryOptions, "farmID_isNull", farmIDIsNull); + _addToQueryList(queryOptions, "farmID_eq", farmIDEq); + _addToQueryList(queryOptions, "farmID_not_eq", farmIDNotEq); + _addToQueryList(queryOptions, "farmID_gt", farmIDGt); + _addToQueryList(queryOptions, "farmID_gte", farmIDGte); + _addToQueryList(queryOptions, "farmID_lt", farmIDLt); + _addToQueryList(queryOptions, "farmID_lte", farmIDLte); + _addToQueryList(queryOptions, "farmID_in", farmIDIn); + _addToQueryList(queryOptions, "farmID_not_in", farmIDNotIn); + + // twins + _addToQueryList(queryOptions, "twinID_isNull", twinIDIsNull); + _addToQueryList(queryOptions, "twinID_eq", twinIDEq); + _addToQueryList(queryOptions, "twinID_not_eq", twinIDNotEq); + _addToQueryList(queryOptions, "twinID_gt", twinIDGt); + _addToQueryList(queryOptions, "twinID_gte", twinIDGte); + _addToQueryList(queryOptions, "twinID_lt", twinIDLt); + _addToQueryList(queryOptions, "twinID_lte", twinIDLte); + _addToQueryList(queryOptions, "twinID_in", twinIDIn); + _addToQueryList(queryOptions, "twinID_not_in", twinIDNotIn); + + // location + _addToQueryList(queryOptions, "location_isNull", locationIsNull); + if (location != null) { + queryOptions.add('location: {${location.toString()}}'); + } + + // country + _addToQueryList(queryOptions, "country_isNull", countryIsNull); + _addToQueryList(queryOptions, "country_eq", countryEq); + _addToQueryList(queryOptions, "country_not_eq", countryNotEq); + _addToQueryList(queryOptions, "country_gt", countryGt); + _addToQueryList(queryOptions, "country_gte", countryGte); + _addToQueryList(queryOptions, "country_lt", countryLt); + _addToQueryList(queryOptions, "country_lte", countryLte); + _addToQueryList(queryOptions, "country_in", countryIn); + _addToQueryList(queryOptions, "country_not_in", countryNotIn); + _addToQueryList(queryOptions, "country_contains", countryContains); + _addToQueryList(queryOptions, "country_not_contains", countryNotContains); + _addToQueryList(queryOptions, "country_containsInsensitive", + countryContainsInsensitive); + _addToQueryList(queryOptions, "country_not_containsInsensitive", + countryNotContainsInsensitive); + _addToQueryList(queryOptions, "country_startsWith", countryStartsWith); + _addToQueryList( + queryOptions, "country_not_startsWith", countryNotStartsWith); + _addToQueryList(queryOptions, "country_endsWith", countryEndsWith); + _addToQueryList(queryOptions, "country_not_endsWith", countryNotEndsWith); + + // city + _addToQueryList(queryOptions, "city_isNull", cityIsNull); + _addToQueryList(queryOptions, "city_eq", cityEq); + _addToQueryList(queryOptions, "city_not_eq", cityNotEq); + _addToQueryList(queryOptions, "city_gt", cityGt); + _addToQueryList(queryOptions, "city_gte", cityGte); + _addToQueryList(queryOptions, "city_lt", cityLt); + _addToQueryList(queryOptions, "city_lte", cityLte); + _addToQueryList(queryOptions, "city_in", cityIn); + _addToQueryList(queryOptions, "city_not_in", cityNotIn); + _addToQueryList(queryOptions, "city_contains", cityContains); + _addToQueryList(queryOptions, "city_not_contains", cityNotContains); + _addToQueryList( + queryOptions, "city_containsInsensitive", cityContainsInsensitive); + _addToQueryList(queryOptions, "city_not_containsInsensitive", + cityNotContainsInsensitive); + _addToQueryList(queryOptions, "city_startsWith", cityStartsWith); + _addToQueryList(queryOptions, "city_not_startsWith", cityNotStartsWith); + _addToQueryList(queryOptions, "city_endsWith", cityEndsWith); + _addToQueryList(queryOptions, "city_not_endsWith", cityNotEndsWith); + + // publicConfig + _addToQueryList(queryOptions, "publicConfig_isNull", publicConfigIsNull); + if (publicConfig != null) { + queryOptions.add('publicConfig: {${publicConfig.toString()}}'); + } + + // resourcesTotal + _addToQueryList( + queryOptions, "resourcesTotal_isNull", resourcesTotalIsNull); + if (resourcesTotal != null) { + queryOptions.add('resourcesTotal: {${resourcesTotal.toString()}}'); + } + + // uptime + _addToQueryList(queryOptions, "uptime_isNull", uptimeIsNull); + _addToQueryList(queryOptions, "uptime_eq", uptimeEq); + _addToQueryList(queryOptions, "uptime_not_eq", uptimeNotEq); + _addToQueryList(queryOptions, "uptime_gt", uptimeGt); + _addToQueryList(queryOptions, "uptime_gte", uptimeGte); + _addToQueryList(queryOptions, "uptime_lt", uptimeLt); + _addToQueryList(queryOptions, "uptime_lte", uptimeLte); + _addToQueryList(queryOptions, "uptime_in", uptimeIn); + _addToQueryList(queryOptions, "uptime_not_in", uptimeNotIn); + + // created + _addToQueryList(queryOptions, "created_isNull", createdIsNull); + _addToQueryList(queryOptions, "created_eq", createdEq); + _addToQueryList(queryOptions, "created_not_eq", createdNotEq); + _addToQueryList(queryOptions, "created_gt", createdGt); + _addToQueryList(queryOptions, "created_gte", createdGte); + _addToQueryList(queryOptions, "created_lt", createdLt); + _addToQueryList(queryOptions, "created_lte", createdLte); + _addToQueryList(queryOptions, "created_in", createdIn); + _addToQueryList(queryOptions, "created_not_in", createdNotIn); + + // farmingPolicyId + _addToQueryList( + queryOptions, "farmingPolicyId_isNull", farmingPolicyIdIsNull); + _addToQueryList(queryOptions, "farmingPolicyId_eq", farmingPolicyIdEq); + _addToQueryList( + queryOptions, "farmingPolicyId_not_eq", farmingPolicyIdNotEq); + _addToQueryList(queryOptions, "farmingPolicyId_gt", farmingPolicyIdGt); + _addToQueryList(queryOptions, "farmingPolicyId_gte", farmingPolicyIdGte); + _addToQueryList(queryOptions, "farmingPolicyId_lt", farmingPolicyIdLt); + _addToQueryList(queryOptions, "farmingPolicyId_lte", farmingPolicyIdLte); + _addToQueryList(queryOptions, "farmingPolicyId_in", farmingPolicyIdIn); + _addToQueryList( + queryOptions, "farmingPolicyId_not_in", farmingPolicyIdNotIn); + + // interfaces + if (interfacesEvery != null) { + queryOptions.add('interfaces_every: {${interfacesEvery.toString()}}'); + } + if (interfacesSome != null) { + queryOptions.add('interfaces_some: {${interfacesSome.toString()}}'); + } + if (interfacesNone != null) { + queryOptions.add('interfaces_none: {${interfacesNone.toString()}}'); + } + + // certification + _addToQueryList(queryOptions, "certification_isNull", certificationIsNull); + _addToQueryList(queryOptions, "certification_eq", certificationEq); + _addToQueryList(queryOptions, "certification_not_eq", certificationNotEq); + _addToQueryList(queryOptions, "certification_in", certificationIn); + _addToQueryList(queryOptions, "certification_not_in", certificationNotIn); + + // secure + _addToQueryList(queryOptions, "secure_isNull", secureIsNull); + _addToQueryList(queryOptions, "secure_eq", secureEq); + _addToQueryList(queryOptions, "secure_not_eq", secureNotEq); + + // virtualized + _addToQueryList(queryOptions, "virtualized_isNull", virtualizedIsNull); + _addToQueryList(queryOptions, "virtualized_eq", virtualizedEq); + _addToQueryList(queryOptions, "virtualized_not_eq", virtualizedNotEq); + + // serialNumber + _addToQueryList(queryOptions, "serialNumber_isNull", serialNumberIsNull); + _addToQueryList(queryOptions, "serialNumber_eq", serialNumberEq); + _addToQueryList(queryOptions, "serialNumber_not_eq", serialNumberNotEq); + _addToQueryList(queryOptions, "serialNumber_gt", serialNumberGt); + _addToQueryList(queryOptions, "serialNumber_gte", serialNumberGte); + _addToQueryList(queryOptions, "serialNumber_lt", serialNumberLt); + _addToQueryList(queryOptions, "serialNumber_lte", serialNumberLte); + _addToQueryList(queryOptions, "serialNumber_in", serialNumberIn); + _addToQueryList(queryOptions, "serialNumber_not_in", serialNumberNotIn); + _addToQueryList( + queryOptions, "serialNumber_contains", serialNumberContains); + _addToQueryList( + queryOptions, "serialNumber_not_contains", serialNumberNotContains); + _addToQueryList(queryOptions, "serialNumber_containsInsensitive", + serialNumberContainsInsensitive); + _addToQueryList(queryOptions, "serialNumber_not_containsInsensitive", + serialNumberNotContainsInsensitive); + _addToQueryList( + queryOptions, "serialNumber_startsWith", serialNumberStartsWith); + _addToQueryList( + queryOptions, "serialNumber_not_startsWith", serialNumberNotStartsWith); + _addToQueryList( + queryOptions, "serialNumber_endsWith", serialNumberEndsWith); + _addToQueryList( + queryOptions, "serialNumber_not_endsWith", serialNumberNotEndsWith); + + // createdAt + _addToQueryList(queryOptions, "createdAt_isNull", createdAtIsNull); + _addToQueryList(queryOptions, "createdAt_eq", createdAtEq); + _addToQueryList(queryOptions, "createdAt_not_eq", createdAtNotEq); + _addToQueryList(queryOptions, "createdAt_gt", createdAtGt); + _addToQueryList(queryOptions, "createdAt_gte", createdAtGte); + _addToQueryList(queryOptions, "createdAt_lt", createdAtLt); + _addToQueryList(queryOptions, "createdAt_lte", createdAtLte); + _addToQueryList(queryOptions, "createdAt_in", createdAtIn); + _addToQueryList(queryOptions, "createdAt_not_in", createdAtNotIn); + + // updatedAt + _addToQueryList(queryOptions, "updatedAt_isNull", updatedAtIsNull); + _addToQueryList(queryOptions, "updatedAt_eq", updatedAtEq); + _addToQueryList(queryOptions, "updatedAt_not_eq", updatedAtNotEq); + _addToQueryList(queryOptions, "updatedAt_gt", updatedAtGt); + _addToQueryList(queryOptions, "updatedAt_gte", updatedAtGte); + _addToQueryList(queryOptions, "updatedAt_lt", updatedAtLt); + _addToQueryList(queryOptions, "updatedAt_lte", updatedAtLte); + _addToQueryList(queryOptions, "updatedAt_in", updatedAtIn); + _addToQueryList(queryOptions, "updatedAt_not_in", updatedAtNotIn); + + // connectionPrice + _addToQueryList( + queryOptions, "connectionPrice_isNull", connectionPriceIsNull); + _addToQueryList(queryOptions, "connectionPrice_eq", connectionPriceEq); + _addToQueryList( + queryOptions, "connectionPrice_not_eq", connectionPriceNotEq); + _addToQueryList(queryOptions, "connectionPrice_gt", connectionPriceGt); + _addToQueryList(queryOptions, "connectionPrice_gte", connectionPriceGte); + _addToQueryList(queryOptions, "connectionPrice_lt", connectionPriceLt); + _addToQueryList(queryOptions, "connectionPrice_lte", connectionPriceLte); + _addToQueryList(queryOptions, "connectionPrice_in", connectionPriceIn); + _addToQueryList( + queryOptions, "connectionPrice_not_in", connectionPriceNotIn); + + // power + _addToQueryList(queryOptions, "power_isNull", powerIsNull); + if (power != null) queryOptions.add('power: {${power.toString()}}'); + + // dedicated + _addToQueryList(queryOptions, "dedicated_isNull", dedicatedIsNull); + _addToQueryList(queryOptions, "dedicated_eq", dedicatedEq); + _addToQueryList(queryOptions, "dedicated_not_eq", dedicatedNotEq); + + // extraFee + _addToQueryList(queryOptions, "extraFee_isNull", extraFeeIsNull); + _addToQueryList(queryOptions, "extraFee_eq", extraFeeEq); + _addToQueryList(queryOptions, "extraFee_not_eq", extraFeeNotEq); + _addToQueryList(queryOptions, "extraFee_gt", extraFeeGt); + _addToQueryList(queryOptions, "extraFee_gte", extraFeeGte); + _addToQueryList(queryOptions, "extraFee_lt", extraFeeLt); + _addToQueryList(queryOptions, "extraFee_lte", extraFeeLte); + _addToQueryList(queryOptions, "extraFee_in", extraFeeIn); + _addToQueryList(queryOptions, "extraFee_not_in", extraFeeNotIn); + + return queryOptions.isNotEmpty ? queryOptions.join(', ') : " "; + } +} + +class NodesQueryOptions { + NodesOrderByOptions orderby; + int? limit; + int? offset; + NodesQueryWhereOptions? whereOptions; + + NodesQueryOptions({ + this.orderby = NodesOrderByOptions.none, + this.limit, + this.offset, + this.whereOptions, + }); + @override + String toString() { + String? order = + orderby == NodesOrderByOptions.none ? null : orderby.toString(); + if ((whereOptions != null && whereOptions.toString() == " ") && + order == null && + limit == null && + offset == null) return ""; + List queryString = []; + if (whereOptions != null && whereOptions.toString() != " ") { + queryString.add("where: {${whereOptions.toString()}}"); + } + if (order != null) queryString.add("orderBy: $order"); + if (limit != null) queryString.add("limit: $limit"); + if (offset != null) queryString.add("offset: $offset"); + return queryString.isNotEmpty ? "(${queryString.join(', ')})" : ""; + } +} + +@reflector +class NodesReturnOptions { + bool id; + bool gridVersion; + bool nodeID; + bool farmID; + bool twinID; + LocationReturnOptions? location; + bool country; + bool city; + PublicConfigReturnOptions? publicConfig; + NodeResourcesTotalReturnOptions? resourcesTotal; + bool uptime; + bool created; + bool farmingPolicyId; + InterfacesReturnOptions? interfaces; + bool certification; + bool secure; + bool virtualized; + bool serialNumber; + bool createdAt; + bool updatedAt; + bool connectionPrice; + NodePowerReturnOptions? power; + bool dedicated; + bool extraFee; + + NodesReturnOptions({ + this.id = false, + this.gridVersion = false, + this.nodeID = false, + this.farmID = false, + this.twinID = false, + this.location, + this.country = false, + this.city = false, + this.publicConfig, + this.resourcesTotal, + this.uptime = false, + this.created = false, + this.farmingPolicyId = false, + this.interfaces, + this.certification = false, + this.secure = false, + this.virtualized = false, + this.serialNumber = false, + this.createdAt = false, + this.updatedAt = false, + this.connectionPrice = false, + this.power, + this.dedicated = false, + this.extraFee = false, + }); + + @override + String toString() { + String returnOptions = ""; + returnOptions = _addToReturnList(returnOptions, "id", id); + returnOptions = _addToReturnList(returnOptions, "gridVersion", gridVersion); + returnOptions = _addToReturnList(returnOptions, "nodeID", nodeID); + returnOptions = _addToReturnList(returnOptions, "farmID", farmID); + returnOptions = _addToReturnList(returnOptions, "twinID", twinID); + if (location != null && location.toString() != "") { + returnOptions += "location { \n ${location.toString()} } \n"; + } + returnOptions = _addToReturnList(returnOptions, "country", country); + returnOptions = _addToReturnList(returnOptions, "city", city); + if (publicConfig != null && publicConfig.toString() != "") { + returnOptions += "publicConfig { \n ${publicConfig.toString()} } \n"; + } + if (resourcesTotal != null && resourcesTotal.toString() != "") { + returnOptions += "resourcesTotal { \n ${resourcesTotal.toString()} } \n"; + } + returnOptions = _addToReturnList(returnOptions, "uptime", uptime); + returnOptions = _addToReturnList(returnOptions, "created", created); + returnOptions = + _addToReturnList(returnOptions, "farmingPolicyId", farmingPolicyId); + if (interfaces != null && interfaces.toString() != "") { + returnOptions += "interfaces { \n ${interfaces.toString()} } \n"; + } + returnOptions = + _addToReturnList(returnOptions, "certification", certification); + returnOptions = _addToReturnList(returnOptions, "secure", secure); + returnOptions = _addToReturnList(returnOptions, "virtualized", virtualized); + returnOptions = + _addToReturnList(returnOptions, "serialNumber", serialNumber); + returnOptions = _addToReturnList(returnOptions, "createdAt", createdAt); + returnOptions = _addToReturnList(returnOptions, "updatedAt", updatedAt); + returnOptions = + _addToReturnList(returnOptions, "connectionPrice", connectionPrice); + if (power != null) returnOptions += power.toString(); + returnOptions = _addToReturnList(returnOptions, "dedicated", dedicated); + returnOptions = _addToReturnList(returnOptions, "extraFee", extraFee); + return returnOptions; + } +} + +@reflector +class Node { + String? id; + int? gridVersion; + int? nodeID; + int? farmID; + int? twinID; + Location? location; + String? country; + String? city; + PublicConfig? publicConfig; + NodeResourcesTotal? resourcesTotal; + BigInt? uptime; + int? created; + int? farmingPolicyId; + List? interfaces; + NodeCertification? certification; + bool? secure; + bool? virtualized; + String? serialNumber; + BigInt? createdAt; + BigInt? updatedAt; + int? connectionPrice; + NodePower? power; + bool? dedicated; + BigInt? extraFee; + + Node({ + this.id, + this.gridVersion, + this.nodeID, + this.farmID, + this.twinID, + this.location, + this.country, + this.city, + this.publicConfig, + this.resourcesTotal, + this.uptime, + this.created, + this.farmingPolicyId, + this.interfaces, + this.certification, + this.secure, + this.virtualized, + this.serialNumber, + this.createdAt, + this.updatedAt, + this.connectionPrice, + this.power, + this.dedicated, + this.extraFee, + }); + + factory Node.fromJson(Map json) { + return Node( + id: json['id'] ?? "", + gridVersion: json['gridVersion'] ?? 0, + nodeID: json['nodeID'] ?? 0, + farmID: json['farmID'] ?? 0, + twinID: json['twinID'] ?? 0, + location: json['location'] != null + ? Location.fromJson(json['location'] as Map) + : null, + country: json['country'] ?? "", + city: json['city'] ?? "", + publicConfig: json['publicConfig'] != null + ? PublicConfig.fromJson(json['publicConfig'] as Map) + : null, + resourcesTotal: json['resourcesTotal'] != null + ? NodeResourcesTotal.fromJson( + json['resourcesTotal'] as Map) + : null, + uptime: BigInt.parse(json['uptime'] ?? '0'), + created: json['created'] ?? 0, + farmingPolicyId: json['farmingPolicyId'] ?? 0, + interfaces: json['interfaces'] != null + ? (json['interfaces'] as List) + .map((i) => Interfaces.fromJson(i as Map)) + .toList() + : null, + certification: json['certification'] != null + ? certificationFromJson(json['certification']) + : null, + secure: json['secure'] ?? false, + virtualized: json['virtualized'] ?? false, + serialNumber: json['serialNumber'] ?? "", + createdAt: BigInt.parse(json['createdAt'] ?? '0'), + updatedAt: BigInt.parse(json['updatedAt'] ?? '0'), + connectionPrice: json['connectionPrice'] ?? 0, + power: json['power'] != null + ? NodePower.fromJson(json['power'] as Map) + : null, + dedicated: json['dedicated'] ?? false, + extraFee: BigInt.parse(json['extraFee'] ?? '0'), + ); + } + + @override + String toString() { + return generateToString(this); + } +} + +class NodeEdgeInfo { + String? cursor; + Node? node; + + NodeEdgeInfo({ + this.cursor, + this.node, + }); + + factory NodeEdgeInfo.fromJson(Map json) { + return NodeEdgeInfo( + cursor: json['cursor'] ?? '', + node: json['node'] != null ? Node.fromJson(json['node']) : null, + ); + } + + @override + String toString() { + return generateToString(this); + } +} + +@reflector +class NodeConnectionsInfo { + List? edges; + PageInfo? pageInfo; + int? totalCount; + + NodeConnectionsInfo({ + this.edges, + this.pageInfo, + this.totalCount, + }); + + factory NodeConnectionsInfo.fromJson(Map json) { + return NodeConnectionsInfo( + edges: json['edges'] != null + ? (json['edges'] as List) + .map((i) => NodeEdgeInfo.fromJson(i as Map)) + .toList() + : null, + pageInfo: json['pageInfo'] != null + ? PageInfo.fromJson(json['pageInfo'] as Map) + : null, + totalCount: json['totalCount'] ?? 0, + ); + } + + @override + String toString() { + return generateToString(this); + } +} + +class NodesConnectionsQueryOptions { + NodesOrderByOptions orderby; + int? first; + int? after; + NodesQueryWhereOptions? whereOptions; + + NodesConnectionsQueryOptions({ + this.orderby = NodesOrderByOptions.id_ASC, + this.first, + this.after, + this.whereOptions, + }); + @override + String toString() { + return generateToString(this); + } +} + +@reflector +class NodeEdgeReturnOptions { + bool cursor; + NodesReturnOptions? node; + + NodeEdgeReturnOptions({ + this.cursor = false, + this.node, + }); + + @override + String toString() { + return generateToString(this); + } +} + +@reflector +class NodesConnectionsReturnOptions { + NodeEdgeReturnOptions? edges; + PageInfoReturnOptions? pageInfo; + bool totalCount; + + NodesConnectionsReturnOptions({ + this.edges, + this.pageInfo, + this.totalCount = false, + }); + + @override + String toString() { + return generateToString(this); + } +} + +enum NodeResourcesTotalOrderByOptions { + none, + id_ASC, + id_DESC, + node_id_ASC, + node_id_DESC, + node_gridVersion_ASC, + node_gridVersion_DESC, + node_nodeID_ASC, + node_nodeID_DESC, + node_farmID_ASC, + node_farmID_DESC, + node_twinID_ASC, + node_twinID_DESC, + node_country_ASC, + node_country_DESC, + node_city_ASC, + node_city_DESC, + node_uptime_ASC, + node_uptime_DESC, + node_created_ASC, + node_created_DESC, + node_farmingPolicyId_ASC, + node_farmingPolicyId_DESC, + node_certification_ASC, + node_certification_DESC, + node_secure_ASC, + node_secure_DESC, + node_virtualized_ASC, + node_virtualized_DESC, + node_serialNumber_ASC, + node_serialNumber_DESC, + node_createdAt_ASC, + node_createdAt_DESC, + node_updatedAt_ASC, + node_updatedAt_DESC, + node_connectionPrice_ASC, + node_connectionPrice_DESC, + node_dedicated_ASC, + node_dedicated_DESC, + node_extraFee_ASC, + node_extraFee_DESC, + hru_ASC, + hru_DESC, + sru_ASC, + sru_DESC, + cru_ASC, + cru_DESC, + mru_ASC, + mru_DESC; + + @override + String toString() { + return name; + } +} + +@reflector +class NodeResourcesTotalReturnOptions { + bool id; + bool cru; + bool hru; + bool mru; + bool sru; + NodesReturnOptions? node; + + NodeResourcesTotalReturnOptions({ + this.id = false, + this.cru = false, + this.hru = false, + this.mru = false, + this.sru = false, + this.node, + }); + @override + String toString() { + return generateToString(this); + } +} + +@reflector +class NodeResourcesTotal { + String? id; + Node? node; + BigInt? hru; + BigInt? sru; + BigInt? cru; + BigInt? mru; + + NodeResourcesTotal({ + this.id, + this.node, + this.hru, + this.sru, + this.cru, + this.mru, + }); + + factory NodeResourcesTotal.fromJson(Map json) { + return NodeResourcesTotal( + id: json['id'] ?? "", + node: json['node'] != null + ? Node.fromJson(json['node'] as Map) + : null, + hru: BigInt.parse(json['hru'] ?? '0'), + sru: BigInt.parse(json['sru'] ?? '0'), + cru: BigInt.parse(json['cru'] ?? '0'), + mru: BigInt.parse(json['mru'] ?? '0'), + ); + } + + @override + String toString() { + return generateToString(this); + } +} + +class NodeResourcesWhereOptions { + //id + bool? idIsNull; + String? idEq; + String? idNotEq; + String? idGt; + String? idGte; + String? idLt; + String? idLte; + List? idIn; + List? idNotIn; + String? idContains; + String? idNotContains; + String? idContainsInsensitive; + String? idNotContainsInsensitive; + String? idStartsWith; + String? idNotStartsWith; + String? idEndsWith; + String? idNotEndsWith; + + //node + bool? nodeIsNull; + NodesQueryWhereOptions? node; + + //hru + bool? hruIsNull; + BigInt? hruEq; + BigInt? hruNotEq; + BigInt? hruGt; + BigInt? hruGte; + BigInt? hruLt; + BigInt? hruLte; + List? hruIn; + List? hruNotIn; + + //sru + bool? sruIsNull; + BigInt? sruEq; + BigInt? sruNotEq; + BigInt? sruGt; + BigInt? sruGte; + BigInt? sruLt; + BigInt? sruLte; + List? sruIn; + List? sruNotIn; + + //cru + bool? cruIsNull; + BigInt? cruEq; + BigInt? cruNotEq; + BigInt? cruGt; + BigInt? cruGte; + BigInt? cruLt; + BigInt? cruLte; + List? cruIn; + List? cruNotIn; + + //mru + bool? mruIsNull; + BigInt? mruEq; + BigInt? mruNotEq; + BigInt? mruGt; + BigInt? mruGte; + BigInt? mruLt; + BigInt? mruLte; + List? mruIn; + List? mruNotIn; + + NodeResourcesWhereOptions({ + //id + this.idIsNull, + this.idEq, + this.idNotEq, + this.idGt, + this.idGte, + this.idLt, + this.idLte, + this.idIn, + this.idNotIn, + this.idContains, + this.idNotContains, + this.idContainsInsensitive, + this.idNotContainsInsensitive, + this.idStartsWith, + this.idNotStartsWith, + this.idEndsWith, + this.idNotEndsWith, + + //node + this.nodeIsNull, + this.node, + + //hru + this.hruIsNull, + this.hruEq, + this.hruNotEq, + this.hruGt, + this.hruGte, + this.hruLt, + this.hruLte, + this.hruIn, + this.hruNotIn, + + //sru + this.sruIsNull, + this.sruEq, + this.sruNotEq, + this.sruGt, + this.sruGte, + this.sruLt, + this.sruLte, + this.sruIn, + this.sruNotIn, + + //cru + this.cruIsNull, + this.cruEq, + this.cruNotEq, + this.cruGt, + this.cruGte, + this.cruLt, + this.cruLte, + this.cruIn, + this.cruNotIn, + + //mru + this.mruIsNull, + this.mruEq, + this.mruNotEq, + this.mruGt, + this.mruGte, + this.mruLt, + this.mruLte, + this.mruIn, + this.mruNotIn, + }); + + @override + String toString() { + List queryOptions = []; + //id + _addToQueryList(queryOptions, "id_isNull", idIsNull); + _addToQueryList(queryOptions, "id_eq", idEq); + _addToQueryList(queryOptions, "id_not_eq", idNotEq); + _addToQueryList(queryOptions, "id_gt", idGt); + _addToQueryList(queryOptions, "id_gte", idGte); + _addToQueryList(queryOptions, "id_lt", idLt); + _addToQueryList(queryOptions, "id_lte", idLte); + _addToQueryList(queryOptions, "id_in", idIn); + _addToQueryList(queryOptions, "id_not_in", idNotIn); + _addToQueryList(queryOptions, "id_contains", idContains); + _addToQueryList(queryOptions, "id_not_contains", idNotContains); + _addToQueryList( + queryOptions, "id_containsInsensitive", idContainsInsensitive); + _addToQueryList( + queryOptions, "id_not_containsInsensitive", idNotContainsInsensitive); + _addToQueryList(queryOptions, "id_startsWith", idStartsWith); + _addToQueryList(queryOptions, "id_not_startsWith", idNotStartsWith); + _addToQueryList(queryOptions, "id_endsWith", idEndsWith); + _addToQueryList(queryOptions, "id_not_endsWith", idNotEndsWith); + + //node + _addToQueryList(queryOptions, "node_isNull", nodeIsNull); + if (node != null) queryOptions.add('node: {${node.toString()}}'); + + //hru + _addToQueryList(queryOptions, "hru_isNull", hruIsNull); + _addToQueryList(queryOptions, "hru_eq", hruEq); + _addToQueryList(queryOptions, "hru_not_eq", hruNotEq); + _addToQueryList(queryOptions, "hru_gt", hruGt); + _addToQueryList(queryOptions, "hru_gte", hruGte); + _addToQueryList(queryOptions, "hru_lt", hruLt); + _addToQueryList(queryOptions, "hru_lte", hruLte); + _addToQueryList(queryOptions, "hru_in", hruIn); + _addToQueryList(queryOptions, "hru_not_in", hruNotIn); + //sru + _addToQueryList(queryOptions, "sru_isNull", sruIsNull); + _addToQueryList(queryOptions, "sru_eq", sruEq); + _addToQueryList(queryOptions, "sru_not_eq", sruNotEq); + _addToQueryList(queryOptions, "sru_gt", sruGt); + _addToQueryList(queryOptions, "sru_gte", sruGte); + _addToQueryList(queryOptions, "sru_lt", sruLt); + _addToQueryList(queryOptions, "sru_lte", sruLte); + _addToQueryList(queryOptions, "sru_in", sruIn); + _addToQueryList(queryOptions, "sru_not_in", sruNotIn); + + //cru + _addToQueryList(queryOptions, "cru_isNull", cruIsNull); + _addToQueryList(queryOptions, "cru_eq", cruEq); + _addToQueryList(queryOptions, "cru_not_eq", cruNotEq); + _addToQueryList(queryOptions, "cru_gt", cruGt); + _addToQueryList(queryOptions, "cru_gte", cruGte); + _addToQueryList(queryOptions, "cru_lt", cruLt); + _addToQueryList(queryOptions, "cru_lte", cruLte); + _addToQueryList(queryOptions, "cru_in", cruIn); + _addToQueryList(queryOptions, "cru_not_in", cruNotIn); + + //mru + _addToQueryList(queryOptions, "mru_isNull", mruIsNull); + _addToQueryList(queryOptions, "mru_eq", mruEq); + _addToQueryList(queryOptions, "mru_not_eq", mruNotEq); + _addToQueryList(queryOptions, "mru_gt", mruGt); + _addToQueryList(queryOptions, "mru_gte", mruGte); + _addToQueryList(queryOptions, "mru_lt", mruLt); + _addToQueryList(queryOptions, "mru_lte", mruLte); + _addToQueryList(queryOptions, "mru_in", mruIn); + _addToQueryList(queryOptions, "mru_not_in", mruNotIn); + + return queryOptions.isNotEmpty ? queryOptions.join(', ') : " "; + } +} + +class NodeResourcesTotalQueryOptions { + NodeResourcesTotalOrderByOptions orderby; + int? limit; + int? offset; + NodeResourcesWhereOptions? whereOptions; + + NodeResourcesTotalQueryOptions({ + this.orderby = NodeResourcesTotalOrderByOptions.none, + this.limit, + this.offset, + this.whereOptions, + }); + @override + String toString() { + String? order = orderby == NodeResourcesTotalOrderByOptions.none + ? null + : orderby.toString(); + if ((whereOptions != null && whereOptions.toString() == " ") && + order == null && + limit == null && + offset == null) return ""; + List queryString = []; + if (whereOptions != null && whereOptions.toString() != " ") { + queryString.add("where: {${whereOptions.toString()}}"); + } + if (order != null) queryString.add("orderBy: $order"); + if (limit != null) queryString.add("limit: $limit"); + if (offset != null) queryString.add("offset: $offset"); + return queryString.isEmpty ? "" : "(${queryString.join(', ')})"; + } +} + +class NodeResourcesTotalEdgeInfo { + String? cursor; + NodeResourcesTotal? node; + + NodeResourcesTotalEdgeInfo({ + this.cursor, + this.node, + }); + + factory NodeResourcesTotalEdgeInfo.fromJson(Map json) { + return NodeResourcesTotalEdgeInfo( + cursor: json['cursor'] ?? '', + node: json['node'] != null + ? NodeResourcesTotal.fromJson(json['node'] as Map) + : null, + ); + } + + @override + String toString() { + return generateToString(this); + } +} + +class NodeResourcesTotalsConnectionInfo { + List? edges; + PageInfo? pageInfo; + int? totalCount; + + NodeResourcesTotalsConnectionInfo({ + this.edges, + this.pageInfo, + this.totalCount, + }); + + factory NodeResourcesTotalsConnectionInfo.fromJson( + Map json) { + return NodeResourcesTotalsConnectionInfo( + edges: json['edges'] != null + ? (json['edges'] as List) + .map((i) => NodeResourcesTotalEdgeInfo.fromJson( + i as Map)) + .toList() + : null, + pageInfo: json['pageInfo'] != null + ? PageInfo.fromJson(json['pageInfo'] as Map) + : null, + totalCount: json['totalCount'] ?? 0, + ); + } + + @override + String toString() { + return generateToString(this); + } +} + +class NodeResourcesTotalsConnectionQueryOptions { + NodeResourcesTotalOrderByOptions orderby; + int? first; + int? after; + NodesQueryWhereOptions? whereOptions; + + NodeResourcesTotalsConnectionQueryOptions({ + this.orderby = NodeResourcesTotalOrderByOptions.id_ASC, + this.first, + this.after, + this.whereOptions, + }); + @override + String toString() { + List queryString = []; + if (whereOptions != null && whereOptions.toString() != " ") { + queryString.add("where: {${whereOptions.toString()}}"); + } + queryString.add("orderBy: $orderby"); + if (first != null) queryString.add("first: $first"); + if (after != null) queryString.add('after: "$after"'); + return queryString.isNotEmpty ? "(${queryString.join(', ')})" : ""; + } +} + +@reflector +class NodeResourcesTotalEdgeReturnOptions { + bool cursor; + NodeResourcesTotalReturnOptions? node; + + NodeResourcesTotalEdgeReturnOptions({ + this.cursor = false, + this.node, + }); + + @override + String toString() { + return generateToString(this); + } +} + +@reflector +class NodeResourcesTotalsConnectionReturnOptions { + NodeResourcesTotalEdgeReturnOptions? edges; + PageInfoReturnOptions? pageInfo; + bool totalCount; + + NodeResourcesTotalsConnectionReturnOptions({ + this.edges, + this.pageInfo, + this.totalCount = false, + }); + + @override + String toString() { + return generateToString(this); + } +} diff --git a/packages/graphql_client/lib/models/page_info.dart b/packages/graphql_client/lib/models/page_info.dart new file mode 100644 index 00000000..81d80a52 --- /dev/null +++ b/packages/graphql_client/lib/models/page_info.dart @@ -0,0 +1,54 @@ +part of '../models.dart'; + +@reflector +class PageInfo { + String? startCursor; + String? endCursor; + bool? hasNextPage; + bool? hasPreviousPage; + + PageInfo({ + this.startCursor, + this.endCursor, + this.hasNextPage, + this.hasPreviousPage, + }); + + factory PageInfo.fromJson(Map json) { + return fromJson(json); + } + + @override + String toString() { + return generateToString(this); + } +} + +@reflector +class PageInfoReturnOptions { + bool endCursor; + bool hasNextPage; + bool hasPreviousPage; + bool startCursor; + + PageInfoReturnOptions({ + this.endCursor = false, + this.hasNextPage = false, + this.hasPreviousPage = false, + this.startCursor = false, + }); + + @override + String toString() { + String returnOptions = ""; + returnOptions = _addToReturnList(returnOptions, "endCursor", endCursor); + returnOptions = _addToReturnList(returnOptions, "hasNextPage", hasNextPage); + returnOptions = + _addToReturnList(returnOptions, "hasPreviousPage", hasPreviousPage); + returnOptions = _addToReturnList(returnOptions, "startCursor", startCursor); + if (returnOptions != "") { + returnOptions = "pageInfo { \n $returnOptions } \n"; + } + return returnOptions; + } +} diff --git a/packages/graphql_client/lib/models/power.dart b/packages/graphql_client/lib/models/power.dart new file mode 100644 index 00000000..397d8ef2 --- /dev/null +++ b/packages/graphql_client/lib/models/power.dart @@ -0,0 +1,137 @@ +// ignore_for_file: constant_identifier_names + +part of '../models.dart'; + +enum PowerState { + Up, + Down; + + @override + String toString() { + return name; + } +} + +enum Power { + Up, + Down; + + @override + String toString() { + return name; + } +} + +Power powerFromJson(String jsonString) { + switch (jsonString) { + case 'Up': + return Power.Up; + case 'Down': + default: + return Power.Down; + } +} + +PowerState powerStateFromJson(String jsonString) { + switch (jsonString) { + case 'Up': + return PowerState.Up; + case 'Down': + default: + return PowerState.Down; + } +} + +@reflector +class NodePowerReturnOptions { + bool state; + bool target; + + NodePowerReturnOptions({ + this.state = false, + this.target = false, + }); + @override + String toString() { + String returnOptions = ""; + returnOptions = _addToReturnList(returnOptions, "state", state); + returnOptions = _addToReturnList(returnOptions, "target", target); + if (returnOptions != "") returnOptions = "power { \n $returnOptions } \n"; + return returnOptions; + } +} + +@reflector +class NodePower { + PowerState? state; + Power? target; + + NodePower({ + this.state, + this.target, + }); + + factory NodePower.fromJson(Map json) { + return NodePower( + state: json['state'] != null ? powerStateFromJson(json['state']) : null, + target: json['target'] != null ? powerFromJson(json['target']) : null, + ); + } + + @override + String toString() { + return generateToString(this); + } +} + +class PowerWhereOptions { + //state + bool? stateIsNull; + PowerState? stateEq; + PowerState? stateNotEq; + List? stateIn; + List? stateNotIn; + + //target + bool? targetIsNull; + Power? targetEq; + Power? targetNotEq; + List? targetIn; + List? targetNotIn; + + PowerWhereOptions({ + //state + this.stateIsNull, + this.stateEq, + this.stateNotEq, + this.stateIn, + this.stateNotIn, + + //target + this.targetIsNull, + this.targetEq, + this.targetNotEq, + this.targetIn, + this.targetNotIn, + }); + + @override + String toString() { + List queryOptions = []; + //state + _addToQueryList(queryOptions, "state_isNull", stateIsNull); + _addToQueryList(queryOptions, "state_eq", stateEq); + _addToQueryList(queryOptions, "state_not_eq", stateNotEq); + _addToQueryList(queryOptions, "state_in", stateIn); + _addToQueryList(queryOptions, "state_not_in", stateNotIn); + + //target + _addToQueryList(queryOptions, "target_isNull", targetIsNull); + _addToQueryList(queryOptions, "target_eq", targetEq); + _addToQueryList(queryOptions, "target_not_eq", targetNotEq); + _addToQueryList(queryOptions, "target_in", targetIn); + _addToQueryList(queryOptions, "target_not_in", targetNotIn); + + return queryOptions.isNotEmpty ? queryOptions.join(', ') : " "; + } +} diff --git a/packages/graphql_client/lib/models/public_config.dart b/packages/graphql_client/lib/models/public_config.dart new file mode 100644 index 00000000..1c2bc5fd --- /dev/null +++ b/packages/graphql_client/lib/models/public_config.dart @@ -0,0 +1,444 @@ +part of '../models.dart'; + +@reflector +class PublicConfigReturnOptions { + bool id; + NodesReturnOptions? node; + bool ipv4; + bool ipv6; + bool gw4; + bool gw6; + bool domain; + + PublicConfigReturnOptions({ + this.id = false, + this.node, + this.ipv4 = false, + this.ipv6 = false, + this.gw4 = false, + this.gw6 = false, + this.domain = false, + }); + @override + String toString() { + String returnOptions = ""; + returnOptions = _addToReturnList(returnOptions, "id", id); + returnOptions = _addToReturnList(returnOptions, "ipv4", ipv4); + returnOptions = _addToReturnList(returnOptions, "ipv6", ipv6); + returnOptions = _addToReturnList(returnOptions, "gw4", gw4); + returnOptions = _addToReturnList(returnOptions, "gw6", gw6); + returnOptions = _addToReturnList(returnOptions, "domain", domain); + returnOptions = _addToReturnList(returnOptions, "node {", node != null); + returnOptions = + _addToReturnList(returnOptions, node.toString(), node != null); + returnOptions = _addToReturnList(returnOptions, "} ", node != null); + return returnOptions; + } +} + +@reflector +class PublicConfig { + String? id; + Node? node; + String? ipv4; + String? ipv6; + String? gw4; + String? gw6; + String? domain; + + PublicConfig({ + this.id, + this.node, + this.ipv4, + this.ipv6, + this.gw4, + this.gw6, + this.domain, + }); + + factory PublicConfig.fromJson(Map json) { + return fromJson(json); + } + + @override + String toString() { + return generateToString(this); + } +} + +class PublicConfigWhereOptions { + //ids + bool? idIsNull; + String? idEq; + String? idNotEq; + String? idGt; + String? idGte; + String? idLt; + String? idLte; + List? idIn; + List? idNotIn; + String? idContains; + String? idNotContains; + String? idContainsInsensitive; + String? idNotContainsInsensitive; + String? idStartsWith; + String? idNotStartsWith; + String? idEndsWith; + String? idNotEndsWith; + + //node + bool? nodeIsNull; + NodesQueryWhereOptions? node; + + //ipv4 + bool? ipv4IsNull; + String? ipv4Eq; + String? ipv4NotEq; + String? ipv4Gt; + String? ipv4Gte; + String? ipv4Lt; + String? ipv4Lte; + List? ipv4In; + List? ipv4NotIn; + String? ipv4Contains; + String? ipv4NotContains; + String? ipv4ContainsInsensitive; + String? ipv4NotContainsInsensitive; + String? ipv4StartsWith; + String? ipv4NotStartsWith; + String? ipv4EndsWith; + String? ipv4NotEndsWith; + + //ipv6 + bool? ipv6IsNull; + String? ipv6Eq; + String? ipv6NotEq; + String? ipv6Gt; + String? ipv6Gte; + String? ipv6Lt; + String? ipv6Lte; + List? ipv6In; + List? ipv6NotIn; + String? ipv6Contains; + String? ipv6NotContains; + String? ipv6ContainsInsensitive; + String? ipv6NotContainsInsensitive; + String? ipv6StartsWith; + String? ipv6NotStartsWith; + String? ipv6EndsWith; + String? ipv6NotEndsWith; + + //gw4 + bool? gw4IsNull; + String? gw4Eq; + String? gw4NotEq; + String? gw4Gt; + String? gw4Gte; + String? gw4Lt; + String? gw4Lte; + List? gw4In; + List? gw4NotIn; + String? gw4Contains; + String? gw4NotContains; + String? gw4ContainsInsensitive; + String? gw4NotContainsInsensitive; + String? gw4StartsWith; + String? gw4NotStartsWith; + String? gw4EndsWith; + String? gw4NotEndsWith; + + //gw6 + bool? gw6IsNull; + String? gw6Eq; + String? gw6NotEq; + String? gw6Gt; + String? gw6Gte; + String? gw6Lt; + String? gw6Lte; + List? gw6In; + List? gw6NotIn; + String? gw6Contains; + String? gw6NotContains; + String? gw6ContainsInsensitive; + String? gw6NotContainsInsensitive; + String? gw6StartsWith; + String? gw6NotStartsWith; + String? gw6EndsWith; + String? gw6NotEndsWith; + + //domain + bool? domainIsNull; + String? domainEq; + String? domainNotEq; + String? domainGt; + String? domainGte; + String? domainLt; + String? domainLte; + List? domainIn; + List? domainNotIn; + String? domainContains; + String? domainNotContains; + String? domainContainsInsensitive; + String? domainNotContainsInsensitive; + String? domainStartsWith; + String? domainNotStartsWith; + String? domainEndsWith; + String? domainNotEndsWith; + + PublicConfigWhereOptions({ + //ids + this.idIsNull, + this.idEq, + this.idNotEq, + this.idGt, + this.idGte, + this.idLt, + this.idLte, + this.idIn, + this.idNotIn, + this.idContains, + this.idNotContains, + this.idContainsInsensitive, + this.idNotContainsInsensitive, + this.idStartsWith, + this.idNotStartsWith, + this.idEndsWith, + this.idNotEndsWith, + + //node + this.nodeIsNull, + this.node, + + //ipv4 + this.ipv4IsNull, + this.ipv4Eq, + this.ipv4NotEq, + this.ipv4Gt, + this.ipv4Gte, + this.ipv4Lt, + this.ipv4Lte, + this.ipv4In, + this.ipv4NotIn, + this.ipv4Contains, + this.ipv4NotContains, + this.ipv4ContainsInsensitive, + this.ipv4NotContainsInsensitive, + this.ipv4StartsWith, + this.ipv4NotStartsWith, + this.ipv4EndsWith, + this.ipv4NotEndsWith, + + //ipv6 + this.ipv6IsNull, + this.ipv6Eq, + this.ipv6NotEq, + this.ipv6Gt, + this.ipv6Gte, + this.ipv6Lt, + this.ipv6Lte, + this.ipv6In, + this.ipv6NotIn, + this.ipv6Contains, + this.ipv6NotContains, + this.ipv6ContainsInsensitive, + this.ipv6NotContainsInsensitive, + this.ipv6StartsWith, + this.ipv6NotStartsWith, + this.ipv6EndsWith, + this.ipv6NotEndsWith, + + //gw4 + this.gw4IsNull, + this.gw4Eq, + this.gw4NotEq, + this.gw4Gt, + this.gw4Gte, + this.gw4Lt, + this.gw4Lte, + this.gw4In, + this.gw4NotIn, + this.gw4Contains, + this.gw4NotContains, + this.gw4ContainsInsensitive, + this.gw4NotContainsInsensitive, + this.gw4StartsWith, + this.gw4NotStartsWith, + this.gw4EndsWith, + this.gw4NotEndsWith, + + //gw6 + this.gw6IsNull, + this.gw6Eq, + this.gw6NotEq, + this.gw6Gt, + this.gw6Gte, + this.gw6Lt, + this.gw6Lte, + this.gw6In, + this.gw6NotIn, + this.gw6Contains, + this.gw6NotContains, + this.gw6ContainsInsensitive, + this.gw6NotContainsInsensitive, + this.gw6StartsWith, + this.gw6NotStartsWith, + this.gw6EndsWith, + this.gw6NotEndsWith, + + //domain + this.domainIsNull, + this.domainEq, + this.domainNotEq, + this.domainGt, + this.domainGte, + this.domainLt, + this.domainLte, + this.domainIn, + this.domainNotIn, + this.domainContains, + this.domainNotContains, + this.domainContainsInsensitive, + this.domainNotContainsInsensitive, + this.domainStartsWith, + this.domainNotStartsWith, + this.domainEndsWith, + this.domainNotEndsWith, + }); + + @override + String toString() { + List queryOptions = []; + + // id + _addToQueryList(queryOptions, "id_isNull", idIsNull); + _addToQueryList(queryOptions, "id_eq", idEq); + _addToQueryList(queryOptions, "id_not_eq", idNotEq); + _addToQueryList(queryOptions, "id_gt", idGt); + _addToQueryList(queryOptions, "id_gte", idGte); + _addToQueryList(queryOptions, "id_lt", idLt); + _addToQueryList(queryOptions, "id_lte", idLte); + _addToQueryList(queryOptions, "id_in", idIn); + _addToQueryList(queryOptions, "id_not_in", idNotIn); + _addToQueryList(queryOptions, "id_contains", idContains); + _addToQueryList(queryOptions, "id_not_contains", idNotContains); + _addToQueryList( + queryOptions, "id_containsInsensitive", idContainsInsensitive); + _addToQueryList( + queryOptions, "id_not_containsInsensitive", idNotContainsInsensitive); + _addToQueryList(queryOptions, "id_startsWith", idStartsWith); + _addToQueryList(queryOptions, "id_not_startsWith", idNotStartsWith); + _addToQueryList(queryOptions, "id_endsWith", idEndsWith); + _addToQueryList(queryOptions, "id_not_endsWith", idNotEndsWith); + + //node + _addToQueryList(queryOptions, "node_isNull", nodeIsNull); + if (node != null) queryOptions.add('node: {${node.toString()}}'); + + //ipv4 + _addToQueryList(queryOptions, "ipv4_isNull", ipv4IsNull); + _addToQueryList(queryOptions, "ipv4_eq", ipv4Eq); + _addToQueryList(queryOptions, "ipv4_not_eq", ipv4NotEq); + _addToQueryList(queryOptions, "ipv4_gt", ipv4Gt); + _addToQueryList(queryOptions, "ipv4_gte", ipv4Gte); + _addToQueryList(queryOptions, "ipv4_lt", ipv4Lt); + _addToQueryList(queryOptions, "ipv4_lte", ipv4Lte); + _addToQueryList(queryOptions, "ipv4_in", ipv4In); + _addToQueryList(queryOptions, "ipv4_not_in", ipv4NotIn); + _addToQueryList(queryOptions, "ipv4_contains", ipv4Contains); + _addToQueryList(queryOptions, "ipv4_not_contains", ipv4NotContains); + _addToQueryList( + queryOptions, "ipv4_containsInsensitive", ipv4ContainsInsensitive); + _addToQueryList(queryOptions, "ipv4_not_containsInsensitive", + ipv4NotContainsInsensitive); + _addToQueryList(queryOptions, "ipv4_startsWith", ipv4StartsWith); + _addToQueryList(queryOptions, "ipv4_not_startsWith", ipv4NotStartsWith); + _addToQueryList(queryOptions, "ipv4_endsWith", ipv4EndsWith); + _addToQueryList(queryOptions, "ipv4_not_endsWith", ipv4NotEndsWith); + + //ipv6 + _addToQueryList(queryOptions, "ipv6_isNull", ipv6IsNull); + _addToQueryList(queryOptions, "ipv6_eq", ipv6Eq); + _addToQueryList(queryOptions, "ipv6_not_eq", ipv6NotEq); + _addToQueryList(queryOptions, "ipv6_gt", ipv6Gt); + _addToQueryList(queryOptions, "ipv6_gte", ipv6Gte); + _addToQueryList(queryOptions, "ipv6_lt", ipv6Lt); + _addToQueryList(queryOptions, "ipv6_lte", ipv6Lte); + _addToQueryList(queryOptions, "ipv6_in", ipv6In); + _addToQueryList(queryOptions, "ipv6_not_in", ipv6NotIn); + _addToQueryList(queryOptions, "ipv6_contains", ipv6Contains); + _addToQueryList(queryOptions, "ipv6_not_contains", ipv6NotContains); + _addToQueryList( + queryOptions, "ipv6_containsInsensitive", ipv6ContainsInsensitive); + _addToQueryList(queryOptions, "ipv6_not_containsInsensitive", + ipv6NotContainsInsensitive); + _addToQueryList(queryOptions, "ipv6_startsWith", ipv6StartsWith); + _addToQueryList(queryOptions, "ipv6_not_startsWith", ipv6NotStartsWith); + _addToQueryList(queryOptions, "ipv6_endsWith", ipv6EndsWith); + _addToQueryList(queryOptions, "ipv6_not_endsWith", ipv6NotEndsWith); + + //gw4 + _addToQueryList(queryOptions, "gw4_isNull", gw4IsNull); + _addToQueryList(queryOptions, "gw4_eq", gw4Eq); + _addToQueryList(queryOptions, "gw4_not_eq", gw4NotEq); + _addToQueryList(queryOptions, "gw4_gt", gw4Gt); + _addToQueryList(queryOptions, "gw4_gte", gw4Gte); + _addToQueryList(queryOptions, "gw4_lt", gw4Lt); + _addToQueryList(queryOptions, "gw4_lte", gw4Lte); + _addToQueryList(queryOptions, "gw4_in", gw4In); + _addToQueryList(queryOptions, "gw4_not_in", gw4NotIn); + _addToQueryList(queryOptions, "gw4_contains", gw4Contains); + _addToQueryList(queryOptions, "gw4_not_contains", gw4NotContains); + _addToQueryList( + queryOptions, "gw4_containsInsensitive", gw4ContainsInsensitive); + _addToQueryList( + queryOptions, "gw4_not_containsInsensitive", gw4NotContainsInsensitive); + _addToQueryList(queryOptions, "gw4_startsWith", gw4StartsWith); + _addToQueryList(queryOptions, "gw4_not_startsWith", gw4NotStartsWith); + _addToQueryList(queryOptions, "gw4_endsWith", gw4EndsWith); + _addToQueryList(queryOptions, "gw4_not_endsWith", gw4NotEndsWith); + + //gw6 + _addToQueryList(queryOptions, "gw6_isNull", gw6IsNull); + _addToQueryList(queryOptions, "gw6_eq", gw6Eq); + _addToQueryList(queryOptions, "gw6_not_eq", gw6NotEq); + _addToQueryList(queryOptions, "gw6_gt", gw6Gt); + _addToQueryList(queryOptions, "gw6_gte", gw6Gte); + _addToQueryList(queryOptions, "gw6_lt", gw6Lt); + _addToQueryList(queryOptions, "gw6_lte", gw6Lte); + _addToQueryList(queryOptions, "gw6_in", gw6In); + _addToQueryList(queryOptions, "gw6_not_in", gw6NotIn); + _addToQueryList(queryOptions, "gw6_contains", gw6Contains); + _addToQueryList(queryOptions, "gw6_not_contains", gw6NotContains); + _addToQueryList( + queryOptions, "gw6_containsInsensitive", gw6ContainsInsensitive); + _addToQueryList( + queryOptions, "gw6_not_containsInsensitive", gw6NotContainsInsensitive); + _addToQueryList(queryOptions, "gw6_startsWith", gw6StartsWith); + _addToQueryList(queryOptions, "gw6_not_startsWith", gw6NotStartsWith); + _addToQueryList(queryOptions, "gw6_endsWith", gw6EndsWith); + _addToQueryList(queryOptions, "gw6_not_endsWith", gw6NotEndsWith); + + //domain + _addToQueryList(queryOptions, "domain_isNull", domainIsNull); + _addToQueryList(queryOptions, "domain_eq", domainEq); + _addToQueryList(queryOptions, "domain_not_eq", domainNotEq); + _addToQueryList(queryOptions, "domain_gt", domainGt); + _addToQueryList(queryOptions, "domain_gte", domainGte); + _addToQueryList(queryOptions, "domain_lt", domainLt); + _addToQueryList(queryOptions, "domain_lte", domainLte); + _addToQueryList(queryOptions, "domain_in", domainIn); + _addToQueryList(queryOptions, "domain_not_in", domainNotIn); + _addToQueryList(queryOptions, "domain_contains", domainContains); + _addToQueryList(queryOptions, "domain_not_contains", domainNotContains); + _addToQueryList( + queryOptions, "domain_containsInsensitive", domainContainsInsensitive); + _addToQueryList(queryOptions, "domain_not_containsInsensitive", + domainNotContainsInsensitive); + _addToQueryList(queryOptions, "domain_startsWith", domainStartsWith); + _addToQueryList(queryOptions, "domain_not_startsWith", domainNotStartsWith); + _addToQueryList(queryOptions, "domain_endsWith", domainEndsWith); + _addToQueryList(queryOptions, "domain_not_endsWith", domainNotEndsWith); + + return queryOptions.isNotEmpty ? queryOptions.join(', ') : " "; + } +} diff --git a/packages/graphql_client/lib/models/public_ips.dart b/packages/graphql_client/lib/models/public_ips.dart new file mode 100644 index 00000000..6fc76d03 --- /dev/null +++ b/packages/graphql_client/lib/models/public_ips.dart @@ -0,0 +1,47 @@ +part of '../models.dart'; + +@reflector +class PublicIpsInfo { + String? id; + String? contractId; + String? ip; + String? gateway; + + PublicIpsInfo({ + this.id, + this.contractId, + this.ip, + this.gateway, + }); + + factory PublicIpsInfo.fromJson(Map json) { + return fromJson(json); + } + + @override + String toString() { + return generateToString(this); + } +} + +@reflector +class PublicIpsReturnOptions { + bool contractId; + bool ip; + bool gateway; + bool id; + + PublicIpsReturnOptions({ + this.id = false, + this.contractId = false, + this.ip = false, + this.gateway = false, + }); + + @override + String toString() { + return generateToString(this); + } +} + +class PublicIpsQueryOptions {} diff --git a/packages/graphql_client/lib/models/reflector.dart b/packages/graphql_client/lib/models/reflector.dart new file mode 100644 index 00000000..be55ec4d --- /dev/null +++ b/packages/graphql_client/lib/models/reflector.dart @@ -0,0 +1,18 @@ +import 'package:reflectable/reflectable.dart'; + +class Reflector extends Reflectable { + const Reflector() + : super( + invokingCapability, + declarationsCapability, + typeCapability, + reflectedTypeCapability, + newInstanceCapability, + subtypeQuantifyCapability, + typeRelationsCapability, + superclassQuantifyCapability, + instanceInvokeCapability, + ); +} + +const reflector = Reflector(); diff --git a/packages/graphql_client/lib/models/twins.dart b/packages/graphql_client/lib/models/twins.dart new file mode 100644 index 00000000..642c4e0e --- /dev/null +++ b/packages/graphql_client/lib/models/twins.dart @@ -0,0 +1,559 @@ +// ignore_for_file: constant_identifier_names + +part of '../models.dart'; + +enum TwinOrderByOptions { + none, + id_ASC, + id_DESC, + gridVersion_ASC, + gridVersion_DESC, + twinID_ASC, + twinID_DESC, + accountID_ASC, + accountID_DESC, + relay_ASC, + relay_DESC, + publicKey_ASC, + publicKey_DESC; + + @override + String toString() { + return name; + } +} + +@reflector +class TwinQueryWhereOptions { + //ids options + bool? idIsNull; + String? idEq; + String? idNotEq; + String? idGt; + String? idGte; + String? idLt; + String? idLte; + List? idIn; + List? idNotIn; + String? idContains; + String? idNotContains; + String? idContainsInsensitive; + String? idNotContainsInsensitive; + String? idStartsWith; + String? idNotStartsWith; + String? idEndsWith; + String? idNotEndsWith; + + //grid options + bool? gridVersionisNull; + int? gridVersionEq; + int? gridVersionNotEq; + int? gridVersionGt; + int? gridVersionGte; + int? gridVersionLt; + int? gridVersionLte; + List? gridVersionIn; + List? gridVersionNotIn; + + //twins options + bool? twinIDIsNull; + int? twinIDEq; + int? twinIDNotEq; + int? twinIDGt; + int? twinIDGte; + int? twinIDLt; + int? twinIDLte; + List? twinIDIn; + List? twinIDNotIn; + + //account options + bool? accountIDIsNull; + String? accountIDEq; + String? accountIDNotEq; + String? accountIDGt; + String? accountIDGte; + String? accountIDLt; + String? accountIDLte; + List? accountIDIn; + List? accountIDNotIn; + String? accountIDContains; + String? accountIDNotContains; + String? accountIDContainsInsensitive; + String? accountIDNotContainsInsensitive; + String? accountIDStartsWith; + String? accountIDNotStartsWith; + String? accountIDEndsWith; + String? accountIDNotEndsWith; + + //relay + bool? relayIsNull; + String? relayEq; + String? relayNotEq; + String? relayGt; + String? relayGte; + String? relayLt; + String? relayLte; + List? relayIn; + List? relayNotIn; + String? relayContains; + String? relayNotContains; + String? relayContainsInsensitive; + String? relayNotContainsInsensitive; + String? relayStartsWith; + String? relayNotStartsWith; + String? relayEndsWith; + String? relayNotEndsWith; + + //public keys + bool? publicKeyIsNull; + String? publicKeyEq; + String? publicKeyNotEq; + String? publicKeyGt; + String? publicKeyGte; + String? publicKeyLt; + String? publicKeyLte; + List? publicKeyIn; + List? publicKeyNotIn; + String? publicKeyContains; + String? publicKeyNotContains; + String? publicKeyContainsInsensitive; + String? publicKeyNotContainsInsensitive; + String? publicKeyStartsWith; + String? publicKeyNotStartsWith; + String? publicKeyEndsWith; + String? publicKeyNotEndsWith; + + TwinQueryWhereOptions({ + //ids + this.idIsNull, + this.idEq, + this.idNotEq, + this.idGt, + this.idGte, + this.idLt, + this.idLte, + this.idIn, + this.idNotIn, + this.idContains, + this.idNotContains, + this.idContainsInsensitive, + this.idNotContainsInsensitive, + this.idStartsWith, + this.idNotStartsWith, + this.idEndsWith, + this.idNotEndsWith, + + //grid + this.gridVersionisNull, + this.gridVersionEq, + this.gridVersionNotEq, + this.gridVersionGt, + this.gridVersionGte, + this.gridVersionLt, + this.gridVersionLte, + this.gridVersionIn, + this.gridVersionNotIn, + + //twins + this.twinIDIsNull, + this.twinIDEq, + this.twinIDNotEq, + this.twinIDGt, + this.twinIDGte, + this.twinIDLt, + this.twinIDLte, + this.twinIDIn, + this.twinIDNotIn, + + //account + this.accountIDIsNull, + this.accountIDEq, + this.accountIDNotEq, + this.accountIDGt, + this.accountIDGte, + this.accountIDLt, + this.accountIDLte, + this.accountIDIn, + this.accountIDNotIn, + this.accountIDContains, + this.accountIDNotContains, + this.accountIDContainsInsensitive, + this.accountIDNotContainsInsensitive, + this.accountIDStartsWith, + this.accountIDNotStartsWith, + this.accountIDEndsWith, + this.accountIDNotEndsWith, + + //relay + this.relayIsNull, + this.relayEq, + this.relayNotEq, + this.relayGt, + this.relayGte, + this.relayLt, + this.relayLte, + this.relayIn, + this.relayNotIn, + this.relayContains, + this.relayNotContains, + this.relayContainsInsensitive, + this.relayNotContainsInsensitive, + this.relayStartsWith, + this.relayNotStartsWith, + this.relayEndsWith, + this.relayNotEndsWith, + + // public Key + this.publicKeyIsNull, + this.publicKeyEq, + this.publicKeyNotEq, + this.publicKeyGt, + this.publicKeyGte, + this.publicKeyLt, + this.publicKeyLte, + this.publicKeyIn, + this.publicKeyNotIn, + this.publicKeyContains, + this.publicKeyNotContains, + this.publicKeyContainsInsensitive, + this.publicKeyNotContainsInsensitive, + this.publicKeyStartsWith, + this.publicKeyNotStartsWith, + this.publicKeyEndsWith, + this.publicKeyNotEndsWith, + }); + + @override + String toString() { + List queryOptions = []; + //ids + _addToQueryList(queryOptions, "id_isNull", idIsNull); + _addToQueryList(queryOptions, "id_eq", idEq); + _addToQueryList(queryOptions, "id_not_eq", idNotEq); + _addToQueryList(queryOptions, "id_gt", idGt); + _addToQueryList(queryOptions, "id_gte", idGte); + _addToQueryList(queryOptions, "id_lt", idLt); + _addToQueryList(queryOptions, "id_lte", idLte); + _addToQueryList(queryOptions, "id_in", idIn); + _addToQueryList(queryOptions, "id_not_in", idNotIn); + _addToQueryList(queryOptions, "id_contains", idContains); + _addToQueryList(queryOptions, "id_not_contains", idNotContains); + _addToQueryList( + queryOptions, "id_containsInsensitive", idContainsInsensitive); + _addToQueryList( + queryOptions, "id_not_containsInsensitive", idNotContainsInsensitive); + _addToQueryList(queryOptions, "id_startsWith", idStartsWith); + _addToQueryList(queryOptions, "id_not_startsWith", idNotStartsWith); + _addToQueryList(queryOptions, "id_endsWith", idEndsWith); + _addToQueryList(queryOptions, "id_not_endsWith", idNotEndsWith); + + //grid + _addToQueryList(queryOptions, "gridVersion_isNull", gridVersionisNull); + _addToQueryList(queryOptions, "gridVersion_eq", gridVersionEq); + _addToQueryList(queryOptions, "gridVersion_not_eq", gridVersionNotEq); + _addToQueryList(queryOptions, "gridVersion_gt", gridVersionGt); + _addToQueryList(queryOptions, "gridVersion_gte", gridVersionGte); + _addToQueryList(queryOptions, "gridVersion_lt", gridVersionLt); + _addToQueryList(queryOptions, "gridVersion_lte", gridVersionLte); + _addToQueryList(queryOptions, "gridVersion_in", gridVersionIn); + _addToQueryList(queryOptions, "gridVersion_not_in", gridVersionNotIn); + + //twins + _addToQueryList(queryOptions, "twinID_isNull", twinIDIsNull); + _addToQueryList(queryOptions, "twinID_eq", twinIDEq); + _addToQueryList(queryOptions, "twinID_not_eq", twinIDNotEq); + _addToQueryList(queryOptions, "twinID_gt", twinIDGt); + _addToQueryList(queryOptions, "twinID_gte", twinIDGte); + _addToQueryList(queryOptions, "twinID_lt", twinIDLt); + _addToQueryList(queryOptions, "twinID_lte", twinIDLte); + _addToQueryList(queryOptions, "twinID_in", twinIDIn); + _addToQueryList(queryOptions, "twinID_not_in", twinIDNotIn); + + //accounts + _addToQueryList(queryOptions, "accountID_isNull", accountIDIsNull); + _addToQueryList(queryOptions, "accountID_eq", accountIDEq); + _addToQueryList(queryOptions, "accountID_not_eq", accountIDNotEq); + _addToQueryList(queryOptions, "accountID_gt", accountIDGt); + _addToQueryList(queryOptions, "accountID_gte", accountIDGte); + _addToQueryList(queryOptions, "accountID_lt", accountIDLt); + _addToQueryList(queryOptions, "accountID_lte", accountIDLte); + _addToQueryList(queryOptions, "accountID_in", accountIDIn); + _addToQueryList(queryOptions, "accountID_not_in", accountIDNotIn); + _addToQueryList(queryOptions, "accountID_contains", accountIDContains); + _addToQueryList( + queryOptions, "accountID_not_contains", accountIDNotContains); + _addToQueryList(queryOptions, "accountID_containsInsensitive", + accountIDContainsInsensitive); + _addToQueryList(queryOptions, "accountID_not_containsInsensitive", + accountIDNotContainsInsensitive); + _addToQueryList(queryOptions, "accountID_startsWith", accountIDStartsWith); + _addToQueryList( + queryOptions, "accountID_not_startsWith", accountIDNotStartsWith); + _addToQueryList(queryOptions, "accountID_endsWith", accountIDEndsWith); + _addToQueryList( + queryOptions, "accountID_not_endsWith", accountIDNotEndsWith); + + //relay + _addToQueryList(queryOptions, "relay_isNull", relayIsNull); + _addToQueryList(queryOptions, "relay_eq", relayEq); + _addToQueryList(queryOptions, "relay_not_eq", relayNotEq); + _addToQueryList(queryOptions, "relay_gt", relayGt); + _addToQueryList(queryOptions, "relay_gte", relayGte); + _addToQueryList(queryOptions, "relay_lt", relayLt); + _addToQueryList(queryOptions, "relay_lte", relayLte); + _addToQueryList(queryOptions, "relay_in", relayIn); + _addToQueryList(queryOptions, "relay_not_in", relayNotIn); + _addToQueryList(queryOptions, "relay_contains", relayContains); + _addToQueryList(queryOptions, "relay_not_contains", relayNotContains); + _addToQueryList( + queryOptions, "relay_containsInsensitive", relayContainsInsensitive); + _addToQueryList(queryOptions, "relay_not_containsInsensitive", + relayNotContainsInsensitive); + _addToQueryList(queryOptions, "relay_startsWith", relayStartsWith); + _addToQueryList(queryOptions, "relay_not_startsWith", relayNotStartsWith); + _addToQueryList(queryOptions, "relay_endsWith", relayEndsWith); + _addToQueryList(queryOptions, "relay_not_endsWith", relayNotEndsWith); + + // public key + _addToQueryList(queryOptions, "publicKey_isNull", publicKeyIsNull); + _addToQueryList(queryOptions, "publicKey_eq", publicKeyEq); + _addToQueryList(queryOptions, "publicKey_not_eq", publicKeyNotEq); + _addToQueryList(queryOptions, "publicKey_gt", publicKeyGt); + _addToQueryList(queryOptions, "publicKey_gte", publicKeyGte); + _addToQueryList(queryOptions, "publicKey_lt", publicKeyLt); + _addToQueryList(queryOptions, "publicKey_lte", publicKeyLte); + _addToQueryList(queryOptions, "publicKey_in", publicKeyIn); + _addToQueryList(queryOptions, "publicKey_not_in", publicKeyNotIn); + _addToQueryList(queryOptions, "publicKey_contains", publicKeyContains); + _addToQueryList( + queryOptions, "publicKey_not_contains", publicKeyNotContains); + _addToQueryList(queryOptions, "publicKey_containsInsensitive", + publicKeyContainsInsensitive); + _addToQueryList(queryOptions, "publicKey_not_containsInsensitive", + publicKeyNotContainsInsensitive); + _addToQueryList(queryOptions, "publicKey_startsWith", publicKeyStartsWith); + _addToQueryList( + queryOptions, "publicKey_not_startsWith", publicKeyNotStartsWith); + _addToQueryList(queryOptions, "publicKey_endsWith", publicKeyEndsWith); + _addToQueryList( + queryOptions, "publicKey_not_endsWith", publicKeyNotEndsWith); + + return queryOptions.isNotEmpty ? queryOptions.join(', ') : " "; + } +} + +class TwinQueryOptions { + TwinOrderByOptions? orderby; + int? limit; + int? offset; + TwinQueryWhereOptions? whereOptions; + + TwinQueryOptions({ + this.orderby, + this.limit, + this.offset, + this.whereOptions, + }); + @override + String toString() { + if ((whereOptions == null || whereOptions.toString() == " ") && + orderby == null && + limit == null && + offset == null) return ""; + List queryString = []; + if (whereOptions != null && whereOptions.toString() != " ") { + queryString.add("where: {${whereOptions.toString()}}"); + } + if (orderby != null) queryString.add("orderBy: $orderby"); + if (limit != null) queryString.add("limit: $limit"); + if (offset != null) queryString.add("offset: $offset"); + return queryString.isEmpty ? "" : "(${queryString.join(', ')})"; + } +} + +class TwinConnectionsQueryOptions { + TwinOrderByOptions orderby; + int? first; + int? after; + TwinQueryWhereOptions? whereOptions; + + TwinConnectionsQueryOptions({ + this.orderby = TwinOrderByOptions.id_ASC, + this.first, + this.after, + this.whereOptions, + }); + @override + String toString() { + List queryString = []; + if (whereOptions != null && whereOptions.toString() != " ") { + queryString.add("where: {${whereOptions.toString()}}"); + } + queryString.add("orderBy: $orderby"); + if (first != null) queryString.add("first: $first"); + if (after != null) queryString.add('after: "$after"'); + return queryString.isEmpty ? "" : "(${queryString.join(', ')})"; + } +} + +@reflector +class TwinReturnOptions { + bool id; + bool accountID; + bool gridVersion; + bool publicKey; + bool relay; + bool twinID; + + TwinReturnOptions({ + this.id = false, + this.accountID = false, + this.gridVersion = false, + this.publicKey = false, + this.relay = false, + this.twinID = false, + }); + + @override + String toString() { + String returnOptions = ""; + returnOptions = _addToReturnList(returnOptions, "id", id); + returnOptions = _addToReturnList(returnOptions, "accountID", accountID); + returnOptions = _addToReturnList(returnOptions, "gridVersion", gridVersion); + returnOptions = _addToReturnList(returnOptions, "publicKey", publicKey); + returnOptions = _addToReturnList(returnOptions, "relay", relay); + returnOptions = _addToReturnList(returnOptions, "twinID", twinID); + return returnOptions; + } +} + +@reflector +class TwinConnectionsEdgeReturnOptions { + bool cursor; + TwinReturnOptions? node; + + TwinConnectionsEdgeReturnOptions({ + this.cursor = false, + this.node, + }); + + @override + String toString() { + String returnOptions = ""; + returnOptions = _addToReturnList(returnOptions, "cursor", cursor); + returnOptions = _addToReturnList(returnOptions, "node {", node != null); + returnOptions = + _addToReturnList(returnOptions, node.toString(), node != null); + returnOptions = _addToReturnList(returnOptions, "} ", node != null); + if (returnOptions != "") returnOptions = "edges { \n $returnOptions } \n"; + return returnOptions; + } +} + +@reflector +class TwinConnectionsReturnOptions { + TwinConnectionsEdgeReturnOptions? edges; + PageInfoReturnOptions? pageInfo; + bool totalCount; + + TwinConnectionsReturnOptions({ + this.edges, + this.pageInfo, + this.totalCount = false, + }); + + @override + String toString() { + String returnOptions = ""; + if (edges != null) returnOptions += edges.toString(); + if (pageInfo != null) returnOptions += pageInfo.toString(); + returnOptions = _addToReturnList(returnOptions, "totalCount", totalCount); + return returnOptions; + } +} + +@reflector +class TwinInfo { + String? id; + String? accountID; + int? gridVersion; + String? publicKey; + String? relay; + int? twinID; + + TwinInfo({ + this.id, + this.accountID, + this.gridVersion, + this.publicKey, + this.relay, + this.twinID, + }); + + factory TwinInfo.fromJson(Map json) { + return fromJson(json); + } + + @override + String toString() { + return generateToString(this); + } +} + +@reflector +class TwinConnectionsEdgeInfo { + String? cursor; + TwinInfo? node; + + TwinConnectionsEdgeInfo({ + this.cursor, + this.node, + }); + + factory TwinConnectionsEdgeInfo.fromJson(Map json) { + return TwinConnectionsEdgeInfo( + cursor: json['cursor'] ?? '', + node: json['node'] != null + ? TwinInfo.fromJson(json['node'] as Map) + : null, + ); + } + + @override + String toString() { + return generateToString(this); + } +} + +@reflector +class TwinConnectionsInfo { + List? edges; + PageInfo? pageInfo; + int? totalCount; + + TwinConnectionsInfo({ + this.edges, + this.pageInfo, + this.totalCount, + }); + + factory TwinConnectionsInfo.fromJson(Map json) { + return TwinConnectionsInfo( + edges: json['edges'] != null + ? (json['edges'] as List) + .map((i) => + TwinConnectionsEdgeInfo.fromJson(i as Map)) + .toList() + : null, + pageInfo: json['pageInfo'] != null + ? PageInfo.fromJson(json['pageInfo'] as Map) + : null, + totalCount: json['totalCount'] ?? 0, + ); + } + + @override + String toString() { + return generateToString(this); + } +} diff --git a/packages/graphql_client/lib/src/client.dart b/packages/graphql_client/lib/src/client.dart new file mode 100644 index 00000000..bfe77b2f --- /dev/null +++ b/packages/graphql_client/lib/src/client.dart @@ -0,0 +1,50 @@ +part of '../graphql_client.dart'; + +class GraphQLClient { + final String url; + late final TFContracts contracts; + late final TFFarms farms; + late final TFTwins twins; + late final TFNodes nodes; + + GraphQLClient(this.url) { + contracts = TFContracts(this); + farms = TFFarms(this); + twins = TFTwins(this); + nodes = TFNodes(this); + } + + Future getItemTotalCount(String itemName, [String options = ""]) async { + final queryOptions = options.isNotEmpty ? options : ""; + final countBody = + 'query { items: ${itemName}Connection$queryOptions { count: totalCount } }'; + final response = await http.post( + Uri.parse(url), + headers: {'Content-Type': 'application/json'}, + body: json.encode({'query': countBody}), + ); + + if (response.statusCode == 200) { + final data = json.decode(response.body); + return data['data']['items']['count'] as int; + } else { + throw Exception('Failed to fetch data: ${response.statusCode}'); + } + } + + Future> query(String body, + {Map variables = const {}}) async { + final response = await http.post( + Uri.parse(url), + headers: {'Content-Type': 'application/json'}, + body: json.encode({'query': body, 'variables': variables}), + ); + + if (response.statusCode == 200) { + return json.decode(response.body); + } else { + print("ERROR: ${response.body}"); + throw Exception('Failed to fetch data: ${response.statusCode}'); + } + } +} diff --git a/packages/graphql_client/lib/src/contracts.dart b/packages/graphql_client/lib/src/contracts.dart new file mode 100644 index 00000000..675b0ecb --- /dev/null +++ b/packages/graphql_client/lib/src/contracts.dart @@ -0,0 +1,219 @@ +import 'package:graphql_client/graphql_client.dart'; +import 'package:graphql_client/models.dart'; + +class TFContracts { + final GraphQLClient gqlClient; + + TFContracts(this.gqlClient); + + Future> listNameContracts( + NameContractQueryOptions? queryOptions, + NameContractReturnOptions? returnOptions) async { + final queryString = queryOptions?.toString() ?? ""; + final String returnString; + + if (returnOptions == null || areAllBooleansFalse(returnOptions)) { + returnString = ''' + id + gridVersion + contractID + twinID + state + createdAt + solutionProviderID + name + '''; + } else { + returnString = returnOptions.toString(); + } + + final body = ''' + query getNameContracts { + nameContracts $queryString { + $returnString + } + }'''; + + final response = await gqlClient.query(body); + + if (response['data'] == null) { + throw Exception("Data returned is null"); + } + if (response['data']['nameContracts'] == null) { + throw Exception("NameContracts returned is null"); + } + final nameContractsDataList = + response['data']['nameContracts'] as List; + if (nameContractsDataList.any((item) => item is! Map)) { + throw Exception( + 'Invalid data format: Expected a list of maps: $response'); + } + + List nameContracts = nameContractsDataList.map((data) { + return NameContract.fromJson(data); + }).toList(); + + return nameContracts; + } + + Future> listRentContracts( + RentContractQueryOptions? queryOptions, + RentContractReturnOptions? returnOptions) async { + final queryString = queryOptions?.toString() ?? ""; + final String returnString; + + if (returnOptions == null || areAllBooleansFalse(returnOptions)) { + returnString = ''' + id + gridVersion + contractID + twinID + state + createdAt + solutionProviderID + nodeID + '''; + } else { + returnString = returnOptions.toString(); + } + + final body = ''' + query getRentContracts { + rentContracts $queryString { + $returnString + } + }'''; + + final response = await gqlClient.query(body); + + if (response['data'] == null) { + throw Exception("Data returned is null"); + } + if (response['data']['rentContracts'] == null) { + throw Exception("RentContracts returned is null"); + } + final rentContractsDataList = + response['data']['rentContracts'] as List; + if (rentContractsDataList.any((item) => item is! Map)) { + throw Exception( + 'Invalid data format: Expected a list of maps: $response'); + } + + List rentContracts = rentContractsDataList.map((data) { + return RentContract.fromJson(data); + }).toList(); + + return rentContracts; + } + + Future> listNodeContracts( + NodeContractQueryOptions? queryOptions, + NodeContractReturnOptions? returnOptions) async { + final queryString = queryOptions?.toString() ?? ""; + final String returnString; + + if (returnOptions == null || areAllBooleansFalse(returnOptions)) { + returnString = ''' + id + gridVersion + contractID + twinID + state + createdAt + nodeID + numberOfPublicIPs + solutionProviderID + deploymentData + deploymentHash + resourcesUsed { + cru + hru + id + mru + sru + } + '''; + } else { + returnString = returnOptions.toString(); + } + + final body = ''' + query getNodeContracts { + nodeContracts $queryString { + $returnString + } + }'''; + + final response = await gqlClient.query(body); + + if (response['data'] == null) { + throw Exception("Data returned is null"); + } + if (response['data']['nodeContracts'] == null) { + throw Exception("NodeContracts returned is null"); + } + final nodeContractsDataList = + response['data']['nodeContracts'] as List; + if (nodeContractsDataList.any((item) => item is! Map)) { + throw Exception( + 'Invalid data format: Expected a list of maps: $response'); + } + + List nodeContracts = nodeContractsDataList.map((data) { + return NodeContract.fromJson(data); + }).toList(); + + return nodeContracts; + } + + Future> listContractConsumption(BigInt contractId, + ContractBillReportsReturnOptions? returnOptions) async { + final String returnString; + + if (returnOptions == null || areAllBooleansFalse(returnOptions)) { + returnString = ''' + contractID + amountBilled + discountReceived + timestamp + id + '''; + } else { + returnString = returnOptions.toString(); + } + + final body = ''' + query getConsumptionforNameContracts { + contractBillReports(where : {contractID_eq: $contractId}){ + $returnString + } + } + + '''; + + final response = await gqlClient.query(body); + + if (response['data'] == null) { + throw Exception("Data returned is null"); + } + + if (response['data']['contractBillReports'] == null) { + throw Exception("contractBillReports returned is null"); + } + + final contractBillReportsDataList = + response['data']['contractBillReports'] as List; + if (contractBillReportsDataList + .any((item) => item is! Map)) { + throw Exception( + 'Invalid data format: Expected a list of maps: $response'); + } + + List contractBillReports = + contractBillReportsDataList.map((data) { + return ContractBillReports.fromJson(data); + }).toList(); + + return contractBillReports; + } +} diff --git a/packages/graphql_client/lib/src/farms.dart b/packages/graphql_client/lib/src/farms.dart new file mode 100644 index 00000000..6f8f1c82 --- /dev/null +++ b/packages/graphql_client/lib/src/farms.dart @@ -0,0 +1,127 @@ +import 'package:graphql_client/graphql_client.dart'; +import '../models.dart'; + +class TFFarms { + final GraphQLClient gqlClient; + + TFFarms(this.gqlClient); + + Future> list(FarmsQueryOptions? queryOptions, + FarmsReturnOptions? returnOptions) async { + final queryString = queryOptions?.toString() ?? ""; + final String returnString; + if (returnOptions == null || areAllBooleansFalse(returnOptions)) { + returnString = ''' + certification + dedicatedFarm + farmID + gridVersion + id + name + pricingPolicyID + publicIPs { + contractId + gateway + id + ip + } + stellarAddress + twinID +'''; + } else { + returnString = returnOptions.toString(); + } + + final body = ''' + query Farms{ + farms $queryString { + $returnString + } + }'''; + + final response = await gqlClient.query(body); + if (response['data'] == null) { + throw Exception("Data returned is null"); + } + if (response['data']['farms'] == null) { + throw Exception("Farms returned is null"); + } + final farmsDataList = response['data']['farms'] as List; + if (farmsDataList.any((item) => item is! Map)) { + throw Exception( + 'Invalid data format: Expected a list of maps: $response'); + } + List farms = + (response['data']['farms'] as List).map((farmsData) { + return FarmInfo.fromJson(farmsData as Map); + }).toList(); + return farms; + } + + //sorts by id_ASC by default + //return total count by default + Future Connection( + FarmsConnectionQueryOptions? queryOptions, + FarmsConnectionReturnOptions? returnOptions) async { + final queryString = queryOptions?.toString() ?? "(orderBy: id_ASC)"; + final String returnString; + if (returnOptions == null || areAllBooleansFalse(returnOptions)) { + returnString = ''' +totalCount + edges { + node { + publicIPs { + contractId + gateway + id + ip + } + certification + dedicatedFarm + farmID + gridVersion + id + name + pricingPolicyID + stellarAddress + twinID + } + cursor + } + pageInfo { + endCursor + hasNextPage + hasPreviousPage + startCursor + } +'''; + } else { + returnString = returnOptions.toString(); + } + + final body = ''' + query FarmsConnection{ + farmsConnection $queryString { + $returnString + } + }'''; + + final response = await gqlClient.query(body); + + if (response['data'] == null) { + throw Exception("Data returned is null"); + } + if (response['data']['farmsConnection'] == null) { + throw Exception("FarmsConnection returned is null"); + } + + final farmsConnectionData = response['data']['farmsConnection']; + + if (farmsConnectionData is! Map) { + throw Exception('Invalid data format: Expected a map: $response'); + } + + final farmsConnection = FarmsConnectionInfo.fromJson(farmsConnectionData); + return farmsConnection; + } +} diff --git a/packages/graphql_client/lib/src/nodes.dart b/packages/graphql_client/lib/src/nodes.dart new file mode 100644 index 00000000..6ec60b86 --- /dev/null +++ b/packages/graphql_client/lib/src/nodes.dart @@ -0,0 +1,287 @@ +import '../graphql_client.dart'; +import '../models.dart'; + +class TFNodes { + final GraphQLClient gqlClient; + + TFNodes(this.gqlClient); + + static const nodeReturnOptions = ''' +certification + city + id + gridVersion + farmingPolicyId + farmID + dedicated + createdAt + extraFee + created + country + connectionPrice + nodeID + secure + serialNumber + twinID + updatedAt + uptime + virtualized + resourcesTotal { + cru + hru + id + mru + sru + } + publicConfig { + domain + gw4 + gw6 + ipv4 + id + ipv6 + } + power { + state + target + } + location { + id + latitude + longitude + }'''; + + static const nodeResourcesNodeReturnOptions = ''' + node { + certification + city + connectionPrice + country + created + createdAt + dedicated + extraFee + farmID + farmingPolicyId + gridVersion + id + nodeID + secure + serialNumber + twinID + updatedAt + uptime + virtualized + publicConfig { + domain + gw4 + gw6 + id + ipv4 + ipv6 + } + power { + state + target + } + location { + id + latitude + longitude + } + interfaces { + ips + id + mac + name + } + } +'''; + + Future> list(NodesReturnOptions? returnOptions, + NodesQueryOptions? queryOptions) async { + final queryString = queryOptions?.toString() ?? ""; + final String returnString; + if (returnOptions == null || areAllBooleansFalse(returnOptions)) { + returnString = nodeReturnOptions; + } else { + returnString = returnOptions.toString(); + } + final body = ''' +query Nodes { + nodes $queryString { + $returnString + } +}'''; + final response = await gqlClient.query(body); + + if (response['data'] == null) { + throw Exception('Missing "data" field in response: $response'); + } + if (response['data']['nodes'] == null) { + throw Exception( + 'Missing "nodes" field in response data: ${response['data']}'); + } + if (response['data']['nodes'] is! List) { + throw Exception( + 'Invalid data format: Expected a list in "nodes" field, got ${response['data']['nodes'].runtimeType}'); + } + List nodes = + (response['data']['nodes'] as List).map((nodesData) { + return Node.fromJson(nodesData as Map); + }).toList(); + return nodes; + } + + Future Connection( + NodesConnectionsReturnOptions? returnOptions, + NodesConnectionsQueryOptions? queryOptions) async { + queryOptions ??= NodesConnectionsQueryOptions(); + final queryString = queryOptions.toString(); + final String returnString; + if (returnOptions == null || areAllBooleansFalse(returnOptions)) { + returnString = ''' + pageInfo { + endCursor + hasNextPage + hasPreviousPage + startCursor + } + totalCount + edges { + cursor + node { + $nodeReturnOptions + } + } + +'''; + } else { + returnString = returnOptions.toString(); + } + final body = ''' +query Nodes { + nodesConnection $queryString { + $returnString + } +}'''; + final response = await gqlClient.query(body); + if (response['data'] == null) { + throw Exception('Missing "data" field in response: $response'); + } + if (response['data']['nodesConnection'] == null) { + throw Exception( + 'Missing "nodesConnection" field in response data: ${response['data']}'); + } + if (response['data']['nodesConnection'] is! Map) { + throw Exception( + 'Invalid data format: Expected a list of maps in "nodesConnection" field, got ${response['data']['nodesConnection'].runtimeType}'); + } + + NodeConnectionsInfo nodesConnection = NodeConnectionsInfo.fromJson( + response['data']['nodesConnection'] as Map); + return nodesConnection; + } + + Future> nodeResourcesTotal( + NodeResourcesTotalReturnOptions? returnOptions, + NodeResourcesTotalQueryOptions? queryOptions) async { + final queryString = queryOptions?.toString() ?? ""; + final String returnString; + if (returnOptions == null || areAllBooleansFalse(returnOptions)) { + returnString = ''' + cru + hru + id + mru + sru + $nodeResourcesNodeReturnOptions +'''; + } else { + returnString = returnOptions.toString(); + } + final body = ''' +query nodeResourcesTotals { + nodeResourcesTotals $queryString { + $returnString + } +}'''; + final response = await gqlClient.query(body); + if (response['data'] == null) { + throw Exception('Missing "data" field in response: $response'); + } + if (response['data']['nodeResourcesTotals'] == null) { + throw Exception( + 'Missing "nodeResourcesTotals" field in response data: ${response['data']}'); + } + if (response['data']['nodeResourcesTotals'] is! List) { + throw Exception( + 'Invalid data format: Expected a list in "nodeResourcesTotals" field, got ${response['data']['nodeResourcesTotals'].runtimeType}'); + } + List nodeResourcesTotals = + (response['data']['nodeResourcesTotals'] as List) + .map((nodeResourcesTotalsData) { + return NodeResourcesTotal.fromJson( + nodeResourcesTotalsData as Map); + }).toList(); + return nodeResourcesTotals; + } + + Future nodeResourcesTotalConnection( + NodeResourcesTotalsConnectionReturnOptions? returnOptions, + NodeResourcesTotalsConnectionQueryOptions? queryOptions) async { + queryOptions ??= NodeResourcesTotalsConnectionQueryOptions(); + final queryString = queryOptions.toString(); + final String returnString; + if (returnOptions == null || areAllBooleansFalse(returnOptions)) { + returnString = ''' + edges { + cursor + node { + cru + hru + mru + id + sru + $nodeResourcesNodeReturnOptions + } + } + totalCount + pageInfo { + endCursor + hasNextPage + hasPreviousPage + startCursor + } +'''; + } else { + returnString = returnOptions.toString(); + } + + final body = ''' +query Nodes { + nodeResourcesTotalsConnection $queryString { + $returnString + } +}'''; + final response = await gqlClient.query(body); + + if (response['data'] == null) { + throw Exception('Missing "data" field in response: $response'); + } + if (response['data']['nodeResourcesTotalsConnection'] == null) { + throw Exception( + 'Missing "nodeResourcesTotalsConnection" field in response data: ${response['data']}'); + } + if (response['data']['nodeResourcesTotalsConnection'] + is! Map) { + throw Exception( + 'Invalid data format: Expected a list of maps in "nodeResourcesTotalsConnection" field, got ${response['data']['nodeResourcesTotalsConnection'].runtimeType}'); + } + NodeResourcesTotalsConnectionInfo nodeResourcesTotalsConnection = + NodeResourcesTotalsConnectionInfo.fromJson(response['data'] + ['nodeResourcesTotalsConnection'] as Map); + + return nodeResourcesTotalsConnection; + } +} diff --git a/packages/graphql_client/lib/src/query_builder.dart b/packages/graphql_client/lib/src/query_builder.dart new file mode 100644 index 00000000..6bfa5312 --- /dev/null +++ b/packages/graphql_client/lib/src/query_builder.dart @@ -0,0 +1,123 @@ +part of '../models.dart'; + +void _addToQueryList(List list, String key, dynamic value) { + switch (value.runtimeType) { + case const (String): + list.add('$key: "$value"'); + break; + case const (List): + final formattedList = + (value as List).map((item) => '"$item"').join(', '); + list.add('$key: [$formattedList]'); + break; + default: + if (value != null) { + list.add('$key: $value'); + } + break; + } +} + +String _addToReturnList(String returnOptions, String key, bool value) { + if (value != false) { + returnOptions += key; + returnOptions += '\n'; + } + return returnOptions; +} + +bool areAllBooleansFalse(Object object) { + var instanceMirror = reflector.reflect(object); + var classMirror = instanceMirror.type; + + for (var declaration in classMirror.declarations.values) { + if (declaration is VariableMirror) { + var value = instanceMirror.invokeGetter(declaration.simpleName); + if (declaration.reflectedType == bool) { + if (value == true) { + return false; + } + } else if (value != null && reflector.canReflect(value)) { + if (!areAllBooleansFalse(value)) { + return false; + } + } + } + } + + return true; +} + +T fromJson(Map json) { + ClassMirror classMirror = reflector.reflectType(T) as ClassMirror; + + Map namedParams = {}; + + void populateNamedParams(ClassMirror cm) { + cm.declarations.forEach((symbol, declaration) { + if (declaration is VariableMirror && !declaration.isStatic) { + String fieldName = declaration.simpleName.toString(); + if (json.containsKey(fieldName)) { + var fieldValue = json[fieldName]; + + if (declaration.reflectedType == double && fieldValue is int) { + fieldValue = fieldValue.toDouble(); + } + + namedParams[Symbol(symbol)] = fieldValue; + } else { + namedParams[Symbol(symbol)] = + _getDefaultValue(declaration.reflectedType); + } + } + }); + + if (cm.superclass != null && cm.superclass!.reflectedType != Object) { + populateNamedParams(cm.superclass as ClassMirror); + } + } + + populateNamedParams(classMirror); + + T instance = classMirror.newInstance('', [], namedParams) as T; + return instance; +} + +dynamic _getDefaultValue(Type type) { + if (type == int) return 0; + if (type == double) return 0.0; + if (type == String) return ''; + if (type == bool) return false; + if (type == List) return []; + + return null; +} + +String generateToString(Object obj) { + InstanceMirror instanceMirror = reflector.reflect(obj); + ClassMirror classMirror = instanceMirror.type; + + List collectFields(ClassMirror cm) { + List fields = []; + + cm.declarations.forEach((symbol, declaration) { + if (declaration is VariableMirror && !declaration.isStatic) { + String fieldName = declaration.simpleName.toString(); + final fieldValue = instanceMirror.invokeGetter(declaration.simpleName); + + fields.add('$fieldName: $fieldValue'); + } + }); + + if (cm.superclass != null && cm.superclass!.reflectedType != Object) { + fields.addAll(collectFields(cm.superclass as ClassMirror)); + } + + return fields; + } + + String className = classMirror.simpleName; + List fields = collectFields(classMirror); + + return '$className{${fields.join(', ')}}'; +} diff --git a/packages/graphql_client/lib/src/twins.dart b/packages/graphql_client/lib/src/twins.dart new file mode 100644 index 00000000..c7953b77 --- /dev/null +++ b/packages/graphql_client/lib/src/twins.dart @@ -0,0 +1,102 @@ +import '../graphql_client.dart'; +import '../models.dart'; + +class TFTwins { + final GraphQLClient gqlClient; + + TFTwins(this.gqlClient); + + Future> list( + TwinReturnOptions? returnOptions, TwinQueryOptions? queryOptions) async { + final queryString = queryOptions?.toString() ?? ""; + final String returnString; + if (returnOptions == null || areAllBooleansFalse(returnOptions)) { + returnString = ''' + accountID + gridVersion + id + publicKey + relay + twinID +'''; + } else { + returnString = returnOptions.toString(); + } + final body = ''' +query Twins { + twins $queryString { + $returnString + } +}'''; + final response = await gqlClient.query(body); + + if (response['data'] == null) { + throw Exception('Missing "data" field in response: $response'); + } + if (response['data']['twins'] == null) { + throw Exception( + 'Missing "twins" field in response data: ${response['data']}'); + } + if (response['data']['twins'] is! List) { + throw Exception( + 'Invalid data format: Expected a list in "twins" field, got ${response['data']['twins'].runtimeType}'); + } + List twins = + (response['data']['twins'] as List).map((twinsData) { + return TwinInfo.fromJson(twinsData as Map); + }).toList(); + return twins; + } + + Future twinsConnections( + TwinConnectionsReturnOptions? returnOptions, + TwinConnectionsQueryOptions? queryOptions) async { + final queryString = queryOptions?.toString() ?? ""; + final String returnString; + if (returnOptions == null || areAllBooleansFalse(returnOptions)) { + returnString = ''' + totalCount + pageInfo { + startCursor + hasPreviousPage + hasNextPage + endCursor + } + edges { + cursor + node { + accountID + gridVersion + id + publicKey + relay + twinID + } + } +'''; + } else { + returnString = returnOptions.toString(); + } + final body = ''' +query Twins { + twinsConnection $queryString { + $returnString + } +}'''; + final response = await gqlClient.query(body); + if (response['data'] == null) { + throw Exception('Missing "data" field in response: $response'); + } + if (response['data']['twinsConnection'] == null) { + throw Exception( + 'Missing "twinsConnection" field in response data: ${response['data']}'); + } + if (response['data']['twinsConnection'] is! Map) { + throw Exception( + 'Invalid data format: Expected a Map for "twinsConnection" field, got ${response['data']['twinsConnection'].runtimeType}'); + } + TwinConnectionsInfo twinsConnection = TwinConnectionsInfo.fromJson( + response['data']['twinsConnection'] as Map); + return twinsConnection; + } +} diff --git a/packages/graphql_client/pubspec.lock b/packages/graphql_client/pubspec.lock new file mode 100644 index 00000000..f1163632 --- /dev/null +++ b/packages/graphql_client/pubspec.lock @@ -0,0 +1,533 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + _fe_analyzer_shared: + dependency: transitive + description: + name: _fe_analyzer_shared + sha256: "0b2f2bd91ba804e53a61d757b986f89f1f9eaed5b11e4b2f5a2468d86d6c9fc7" + url: "https://pub.dev" + source: hosted + version: "67.0.0" + analyzer: + dependency: transitive + description: + name: analyzer + sha256: "37577842a27e4338429a1cbc32679d508836510b056f1eedf0c8d20e39c1383d" + url: "https://pub.dev" + source: hosted + version: "6.4.1" + args: + dependency: transitive + description: + name: args + sha256: "7cf60b9f0cc88203c5a190b4cd62a99feea42759a7fa695010eb5de1c0b2252a" + url: "https://pub.dev" + source: hosted + version: "2.5.0" + async: + dependency: transitive + description: + name: async + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" + url: "https://pub.dev" + source: hosted + version: "2.11.0" + boolean_selector: + dependency: transitive + description: + name: boolean_selector + sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" + url: "https://pub.dev" + source: hosted + version: "2.1.1" + build: + dependency: transitive + description: + name: build + sha256: "80184af8b6cb3e5c1c4ec6d8544d27711700bc3e6d2efad04238c7b5290889f0" + url: "https://pub.dev" + source: hosted + version: "2.4.1" + build_config: + dependency: transitive + description: + name: build_config + sha256: bf80fcfb46a29945b423bd9aad884590fb1dc69b330a4d4700cac476af1708d1 + url: "https://pub.dev" + source: hosted + version: "1.1.1" + build_daemon: + dependency: transitive + description: + name: build_daemon + sha256: "0343061a33da9c5810b2d6cee51945127d8f4c060b7fbdd9d54917f0a3feaaa1" + url: "https://pub.dev" + source: hosted + version: "4.0.1" + build_resolvers: + dependency: transitive + description: + name: build_resolvers + sha256: "339086358431fa15d7eca8b6a36e5d783728cf025e559b834f4609a1fcfb7b0a" + url: "https://pub.dev" + source: hosted + version: "2.4.2" + build_runner: + dependency: transitive + description: + name: build_runner + sha256: "3ac61a79bfb6f6cc11f693591063a7f19a7af628dc52f141743edac5c16e8c22" + url: "https://pub.dev" + source: hosted + version: "2.4.9" + build_runner_core: + dependency: transitive + description: + name: build_runner_core + sha256: "4ae8ffe5ac758da294ecf1802f2aff01558d8b1b00616aa7538ea9a8a5d50799" + url: "https://pub.dev" + source: hosted + version: "7.3.0" + built_collection: + dependency: transitive + description: + name: built_collection + sha256: "376e3dd27b51ea877c28d525560790aee2e6fbb5f20e2f85d5081027d94e2100" + url: "https://pub.dev" + source: hosted + version: "5.1.1" + built_value: + dependency: transitive + description: + name: built_value + sha256: c7913a9737ee4007efedaffc968c049fd0f3d0e49109e778edc10de9426005cb + url: "https://pub.dev" + source: hosted + version: "8.9.2" + checked_yaml: + dependency: transitive + description: + name: checked_yaml + sha256: feb6bed21949061731a7a75fc5d2aa727cf160b91af9a3e464c5e3a32e28b5ff + url: "https://pub.dev" + source: hosted + version: "2.0.3" + code_builder: + dependency: transitive + description: + name: code_builder + sha256: f692079e25e7869c14132d39f223f8eec9830eb76131925143b2129c4bb01b37 + url: "https://pub.dev" + source: hosted + version: "4.10.0" + collection: + dependency: transitive + description: + name: collection + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a + url: "https://pub.dev" + source: hosted + version: "1.18.0" + convert: + dependency: transitive + description: + name: convert + sha256: "0f08b14755d163f6e2134cb58222dd25ea2a2ee8a195e53983d57c075324d592" + url: "https://pub.dev" + source: hosted + version: "3.1.1" + coverage: + dependency: transitive + description: + name: coverage + sha256: "3945034e86ea203af7a056d98e98e42a5518fff200d6e8e6647e1886b07e936e" + url: "https://pub.dev" + source: hosted + version: "1.8.0" + crypto: + dependency: transitive + description: + name: crypto + sha256: ff625774173754681d66daaf4a448684fb04b78f902da9cb3d308c19cc5e8bab + url: "https://pub.dev" + source: hosted + version: "3.0.3" + dart_style: + dependency: transitive + description: + name: dart_style + sha256: "99e066ce75c89d6b29903d788a7bb9369cf754f7b24bf70bf4b6d6d6b26853b9" + url: "https://pub.dev" + source: hosted + version: "2.3.6" + file: + dependency: transitive + description: + name: file + sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c" + url: "https://pub.dev" + source: hosted + version: "7.0.0" + fixnum: + dependency: transitive + description: + name: fixnum + sha256: "25517a4deb0c03aa0f32fd12db525856438902d9c16536311e76cdc57b31d7d1" + url: "https://pub.dev" + source: hosted + version: "1.1.0" + frontend_server_client: + dependency: transitive + description: + name: frontend_server_client + sha256: f64a0333a82f30b0cca061bc3d143813a486dc086b574bfb233b7c1372427694 + url: "https://pub.dev" + source: hosted + version: "4.0.0" + glob: + dependency: transitive + description: + name: glob + sha256: "0e7014b3b7d4dac1ca4d6114f82bf1782ee86745b9b42a92c9289c23d8a0ab63" + url: "https://pub.dev" + source: hosted + version: "2.1.2" + graphs: + dependency: transitive + description: + name: graphs + sha256: aedc5a15e78fc65a6e23bcd927f24c64dd995062bcd1ca6eda65a3cff92a4d19 + url: "https://pub.dev" + source: hosted + version: "2.3.1" + http: + dependency: "direct main" + description: + name: http + sha256: a2bbf9d017fcced29139daa8ed2bba4ece450ab222871df93ca9eec6f80c34ba + url: "https://pub.dev" + source: hosted + version: "1.2.0" + http_multi_server: + dependency: transitive + description: + name: http_multi_server + sha256: "97486f20f9c2f7be8f514851703d0119c3596d14ea63227af6f7a481ef2b2f8b" + url: "https://pub.dev" + source: hosted + version: "3.2.1" + http_parser: + dependency: transitive + description: + name: http_parser + sha256: "2aa08ce0341cc9b354a498388e30986515406668dbcc4f7c950c3e715496693b" + url: "https://pub.dev" + source: hosted + version: "4.0.2" + io: + dependency: transitive + description: + name: io + sha256: "2ec25704aba361659e10e3e5f5d672068d332fc8ac516421d483a11e5cbd061e" + url: "https://pub.dev" + source: hosted + version: "1.0.4" + js: + dependency: transitive + description: + name: js + sha256: c1b2e9b5ea78c45e1a0788d29606ba27dc5f71f019f32ca5140f61ef071838cf + url: "https://pub.dev" + source: hosted + version: "0.7.1" + json_annotation: + dependency: transitive + description: + name: json_annotation + sha256: "1ce844379ca14835a50d2f019a3099f419082cfdd231cd86a142af94dd5c6bb1" + url: "https://pub.dev" + source: hosted + version: "4.9.0" + lints: + dependency: "direct dev" + description: + name: lints + sha256: cbf8d4b858bb0134ef3ef87841abdf8d63bfc255c266b7bf6b39daa1085c4290 + url: "https://pub.dev" + source: hosted + version: "3.0.0" + logging: + dependency: transitive + description: + name: logging + sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340" + url: "https://pub.dev" + source: hosted + version: "1.2.0" + matcher: + dependency: transitive + description: + name: matcher + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb + url: "https://pub.dev" + source: hosted + version: "0.12.16+1" + meta: + dependency: transitive + description: + name: meta + sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7 + url: "https://pub.dev" + source: hosted + version: "1.15.0" + mime: + dependency: transitive + description: + name: mime + sha256: "2e123074287cc9fd6c09de8336dae606d1ddb88d9ac47358826db698c176a1f2" + url: "https://pub.dev" + source: hosted + version: "1.0.5" + node_preamble: + dependency: transitive + description: + name: node_preamble + sha256: "6e7eac89047ab8a8d26cf16127b5ed26de65209847630400f9aefd7cd5c730db" + url: "https://pub.dev" + source: hosted + version: "2.0.2" + package_config: + dependency: transitive + description: + name: package_config + sha256: "1c5b77ccc91e4823a5af61ee74e6b972db1ef98c2ff5a18d3161c982a55448bd" + url: "https://pub.dev" + source: hosted + version: "2.1.0" + path: + dependency: transitive + description: + name: path + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" + url: "https://pub.dev" + source: hosted + version: "1.9.0" + pool: + dependency: transitive + description: + name: pool + sha256: "20fe868b6314b322ea036ba325e6fc0711a22948856475e2c2b6306e8ab39c2a" + url: "https://pub.dev" + source: hosted + version: "1.5.1" + pub_semver: + dependency: transitive + description: + name: pub_semver + sha256: "40d3ab1bbd474c4c2328c91e3a7df8c6dd629b79ece4c4bd04bee496a224fb0c" + url: "https://pub.dev" + source: hosted + version: "2.1.4" + pubspec_parse: + dependency: transitive + description: + name: pubspec_parse + sha256: c799b721d79eb6ee6fa56f00c04b472dcd44a30d258fac2174a6ec57302678f8 + url: "https://pub.dev" + source: hosted + version: "1.3.0" + reflectable: + dependency: "direct main" + description: + name: reflectable + sha256: cdc1a278a2e9769abafaf9ba54ce1fd3432b2a38360e14b87ea6344f715340de + url: "https://pub.dev" + source: hosted + version: "4.0.6" + shelf: + dependency: transitive + description: + name: shelf + sha256: ad29c505aee705f41a4d8963641f91ac4cee3c8fad5947e033390a7bd8180fa4 + url: "https://pub.dev" + source: hosted + version: "1.4.1" + shelf_packages_handler: + dependency: transitive + description: + name: shelf_packages_handler + sha256: "89f967eca29607c933ba9571d838be31d67f53f6e4ee15147d5dc2934fee1b1e" + url: "https://pub.dev" + source: hosted + version: "3.0.2" + shelf_static: + dependency: transitive + description: + name: shelf_static + sha256: a41d3f53c4adf0f57480578c1d61d90342cd617de7fc8077b1304643c2d85c1e + url: "https://pub.dev" + source: hosted + version: "1.1.2" + shelf_web_socket: + dependency: transitive + description: + name: shelf_web_socket + sha256: "9ca081be41c60190ebcb4766b2486a7d50261db7bd0f5d9615f2d653637a84c1" + url: "https://pub.dev" + source: hosted + version: "1.0.4" + source_map_stack_trace: + dependency: transitive + description: + name: source_map_stack_trace + sha256: "84cf769ad83aa6bb61e0aa5a18e53aea683395f196a6f39c4c881fb90ed4f7ae" + url: "https://pub.dev" + source: hosted + version: "2.1.1" + source_maps: + dependency: transitive + description: + name: source_maps + sha256: "708b3f6b97248e5781f493b765c3337db11c5d2c81c3094f10904bfa8004c703" + url: "https://pub.dev" + source: hosted + version: "0.10.12" + source_span: + dependency: transitive + description: + name: source_span + sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" + url: "https://pub.dev" + source: hosted + version: "1.10.0" + stack_trace: + dependency: transitive + description: + name: stack_trace + sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" + url: "https://pub.dev" + source: hosted + version: "1.11.1" + stream_channel: + dependency: transitive + description: + name: stream_channel + sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 + url: "https://pub.dev" + source: hosted + version: "2.1.2" + stream_transform: + dependency: transitive + description: + name: stream_transform + sha256: "14a00e794c7c11aa145a170587321aedce29769c08d7f58b1d141da75e3b1c6f" + url: "https://pub.dev" + source: hosted + version: "2.1.0" + string_scanner: + dependency: transitive + description: + name: string_scanner + sha256: "688af5ed3402a4bde5b3a6c15fd768dbf2621a614950b17f04626c431ab3c4c3" + url: "https://pub.dev" + source: hosted + version: "1.3.0" + term_glyph: + dependency: transitive + description: + name: term_glyph + sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 + url: "https://pub.dev" + source: hosted + version: "1.2.1" + test: + dependency: "direct dev" + description: + name: test + sha256: "7ee44229615f8f642b68120165ae4c2a75fe77ae2065b1e55ae4711f6cf0899e" + url: "https://pub.dev" + source: hosted + version: "1.25.7" + test_api: + dependency: transitive + description: + name: test_api + sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb" + url: "https://pub.dev" + source: hosted + version: "0.7.2" + test_core: + dependency: transitive + description: + name: test_core + sha256: "55ea5a652e38a1dfb32943a7973f3681a60f872f8c3a05a14664ad54ef9c6696" + url: "https://pub.dev" + source: hosted + version: "0.6.4" + timing: + dependency: transitive + description: + name: timing + sha256: "70a3b636575d4163c477e6de42f247a23b315ae20e86442bebe32d3cabf61c32" + url: "https://pub.dev" + source: hosted + version: "1.0.1" + typed_data: + dependency: transitive + description: + name: typed_data + sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c + url: "https://pub.dev" + source: hosted + version: "1.3.2" + vm_service: + dependency: transitive + description: + name: vm_service + sha256: a2662fb1f114f4296cf3f5a50786a2d888268d7776cf681aa17d660ffa23b246 + url: "https://pub.dev" + source: hosted + version: "14.0.0" + watcher: + dependency: transitive + description: + name: watcher + sha256: "3d2ad6751b3c16cf07c7fca317a1413b3f26530319181b37e3b9039b84fc01d8" + url: "https://pub.dev" + source: hosted + version: "1.1.0" + web: + dependency: transitive + description: + name: web + sha256: "4188706108906f002b3a293509234588823c8c979dc83304e229ff400c996b05" + url: "https://pub.dev" + source: hosted + version: "0.4.2" + web_socket_channel: + dependency: transitive + description: + name: web_socket_channel + sha256: "939ab60734a4f8fa95feacb55804fa278de28bdeef38e616dc08e44a84adea23" + url: "https://pub.dev" + source: hosted + version: "2.4.3" + webkit_inspection_protocol: + dependency: transitive + description: + name: webkit_inspection_protocol + sha256: "87d3f2333bb240704cd3f1c6b5b7acd8a10e7f0bc28c28dcf14e782014f4a572" + url: "https://pub.dev" + source: hosted + version: "1.2.1" + yaml: + dependency: transitive + description: + name: yaml + sha256: "75769501ea3489fca56601ff33454fe45507ea3bfb014161abc3b43ae25989d5" + url: "https://pub.dev" + source: hosted + version: "3.1.2" +sdks: + dart: ">=3.2.3 <4.0.0" diff --git a/packages/graphql_client/pubspec.yaml b/packages/graphql_client/pubspec.yaml new file mode 100644 index 00000000..1274c327 --- /dev/null +++ b/packages/graphql_client/pubspec.yaml @@ -0,0 +1,20 @@ +name: graphql_client +description: A sample command-line application. +version: 0.1.0 +# repository: https://github.com/my_org/my_repo + +environment: + sdk: ^3.2.3 + +# Add regular dependencies here. +dependencies: + http: ^1.2.0 + reflectable: '>=4.0.6 <4.0.9' + # path: ^1.8.0 + +dev_dependencies: + lints: ^3.0.0 + test: ^1.24.0 + +scripts: + test: --coverage=coverage \ No newline at end of file diff --git a/packages/gridproxy_client/README.md b/packages/gridproxy_client/README.md new file mode 100644 index 00000000..529888e9 --- /dev/null +++ b/packages/gridproxy_client/README.md @@ -0,0 +1,32 @@ +# Gridproxy Client + +This is a dart client to communicate with GridProxy based on the network. + +## Install Dependencies + +```bash +dart pub get +``` + +## Generate Reflectable code + +```bash +dart run build_runner build +``` + +## Usage + +- Ensure that initializeReflectable() is called at the beginning of your main + +- Example usage: + +```dart + import 'gridproxy_client.reflectable.dart'; + + initializeReflectable(); + + GridProxyClient client = GridProxyClient('https://gridproxy.dev.grid.tf'); + final farms = + await client.farms.list(ListFarmsQueryParameters(page: 1, size: 20)); + print(farms); +``` diff --git a/packages/gridproxy_client/bin/gridproxy_client.dart b/packages/gridproxy_client/bin/gridproxy_client.dart new file mode 100644 index 00000000..38e8cffd --- /dev/null +++ b/packages/gridproxy_client/bin/gridproxy_client.dart @@ -0,0 +1,11 @@ +import 'package:gridproxy_client/gridproxy_client.dart'; +// import 'gridproxy_client.reflectable.dart'; + +void main() async { + // initializeReflectable(); + + GridProxyClient client = GridProxyClient('https://gridproxy.dev.grid.tf/'); + + final res = await client.nodes.getNodeStatistics(nodeID: 161); + print(res); +} diff --git a/packages/gridproxy_client/build.yaml b/packages/gridproxy_client/build.yaml new file mode 100644 index 00000000..37cd324b --- /dev/null +++ b/packages/gridproxy_client/build.yaml @@ -0,0 +1,7 @@ +targets: + $default: + builders: + gridproxy_client: + generate_for: + - lib/**/*.dart + diff --git a/packages/gridproxy_client/lib/gridproxy_client.dart b/packages/gridproxy_client/lib/gridproxy_client.dart new file mode 100644 index 00000000..892f5c9d --- /dev/null +++ b/packages/gridproxy_client/lib/gridproxy_client.dart @@ -0,0 +1,11 @@ +library client; + +import 'dart:convert'; +import 'package:gridproxy_client/src/nodes.dart'; +import 'package:gridproxy_client/src/contracts.dart'; +import 'package:gridproxy_client/src/farms.dart'; +import 'package:gridproxy_client/src/stats.dart'; +import 'package:gridproxy_client/src/twins.dart'; +import 'package:http/http.dart' as http; + +part 'src/client.dart'; diff --git a/packages/gridproxy_client/lib/models/contracts.dart b/packages/gridproxy_client/lib/models/contracts.dart new file mode 100644 index 00000000..9e8e5d09 --- /dev/null +++ b/packages/gridproxy_client/lib/models/contracts.dart @@ -0,0 +1,287 @@ +import 'package:gridproxy_client/models/reflector.dart'; +import 'package:gridproxy_client/models/sort_order.dart'; +import 'package:gridproxy_client/src/query_builder.dart'; + +@reflector +class Contract {} + +@reflector +class NameContract extends Contract { + String name; + + NameContract({ + required this.name, + }); + + factory NameContract.fromJson(Map json) { + return fromJson(json); + } + + Map toJson() { + return toMap(this); + } + + @override + String toString() { + return toJson().toString(); + } +} + +@reflector +class NodeContract extends Contract { + int nodeId; + String deployment_data; + String deployment_hash; + int number_of_public_ips; + String farm_name; + int farm_id; + + NodeContract({ + required this.nodeId, + required this.deployment_data, + required this.deployment_hash, + required this.number_of_public_ips, + required this.farm_name, + required this.farm_id, + }); + + factory NodeContract.fromJson(Map json) { + return fromJson(json); + } + + Map toJson() { + return toMap(this); + } + + @override + String toString() { + return toJson().toString(); + } +} + +@reflector +class RentContract extends Contract { + int nodeId; + String farm_name; + int farm_id; + + RentContract( + {required this.nodeId, required this.farm_name, required this.farm_id}); + + factory RentContract.fromJson(Map json) { + return fromJson(json); + } + + Map toJson() { + return toMap(this); + } + + @override + String toString() { + return toJson().toString(); + } +} + +@reflector +class ContractInfo { + int contract_id; + int created_at; + Contract? details; + String state; + int twin_id; + String type; + + ContractInfo({ + required this.contract_id, + required this.created_at, + required this.details, + required this.state, + required this.twin_id, + required this.type, + }); + + factory ContractInfo.fromJson(Map json) { + final jsonType = json['type']; + final type = ContractTypes.fromString(jsonType); + + Contract? details; + if (json['details'] != null) { + final detailsJson = json['details']; + switch (type) { + case ContractTypes.name: + details = NameContract.fromJson(detailsJson); + break; + case ContractTypes.node: + details = NodeContract.fromJson(detailsJson); + break; + case ContractTypes.rent: + details = RentContract.fromJson(detailsJson); + break; + default: + print("Unhandled type: $type"); + } + } + + return ContractInfo( + contract_id: json['contract_id'] ?? 0, + created_at: json['created_at'] ?? 0, + details: details, + state: json['state'] ?? '', + twin_id: json['twin_id'] ?? 0, + type: json['type'] ?? '', + ); + } + + Map toJson() { + return toMap(this); + } + + @override + String toString() { + return toJson().toString(); + } +} + +enum ContractSortBy { + twin_id, + contract_id, + type, + state, + created_at; + + @override + String toString() { + return name; + } +} + +enum ContractTypes { + node, + name, + rent; + + static ContractTypes fromString(String type) { + switch (type) { + case 'node': + return ContractTypes.node; + case 'name': + return ContractTypes.name; + case 'rent': + return ContractTypes.rent; + default: + throw ArgumentError('Unknown contract type: $type'); + } + } + + @override + String toString() { + return this.name; + } +} + +enum ContractState { + Created, + GracePeriod, + Deleted; + + @override + String toString() { + return name; + } +} + +@reflector +class ContractInfoQueryParams { + int? page; + int? size; + bool? retCount; + bool? randomize; + ContractSortBy? sort_by; + sortOrder? sort_order; + int? contract_id; + int? twin_id; + int? node_id; + String? name; + ContractTypes? type; + ContractState? state; + String? deployment_data; + String? deployment_hash; + int? number_of_public_ips; + + ContractInfoQueryParams({ + this.page, + this.size, + this.retCount, + this.randomize, + this.sort_by, + this.sort_order, + this.contract_id, + this.twin_id, + this.node_id, + this.name, + this.type, + this.state, + this.deployment_data, + this.deployment_hash, + this.number_of_public_ips, + }); + + Map toJson() { + return toMap(this); + } + + @override + String toString() { + return toJson().toString(); + } +} + +@reflector +class ContractBills { + int amountBilled; + int contract_id; + String discountReceived; + int timestamp; + + ContractBills({ + required this.amountBilled, + required this.contract_id, + required this.discountReceived, + required this.timestamp, + }); + + factory ContractBills.fromJson(Map json) { + return fromJson(json); + } + + Map toJson() { + return toMap(this); + } + + @override + String toString() { + return toJson().toString(); + } +} + +@reflector +class ContractBillQueryParams { + int? page; + int? size; + bool? retCount; + + ContractBillQueryParams({ + this.page, + this.size, + this.retCount, + }); + + Map toJson() { + return toMap(this); + } + + @override + String toString() { + return toJson().toString(); + } +} diff --git a/packages/gridproxy_client/lib/models/farms.dart b/packages/gridproxy_client/lib/models/farms.dart new file mode 100644 index 00000000..8650b1cd --- /dev/null +++ b/packages/gridproxy_client/lib/models/farms.dart @@ -0,0 +1,149 @@ +import 'package:gridproxy_client/models/reflector.dart'; +import 'package:gridproxy_client/models/sort_order.dart'; +import 'package:gridproxy_client/src/query_builder.dart'; + +@reflector +class ListFarmsQueryParameters { + int? page; + int? size; + bool? ret_count; + bool? randomize; + String? sort_by; + sortOrder? sort_order; + int? free_ips; + int? total_ips; + int? pricing_policy_id; + int? farm_id; + int? twin_id; + String? name; + String? name_contains; + String? certification_type; + bool? dedicated; + String? stellar_address; + int? node_free_mru; + int? node_free_hru; + int? node_free_sru; + int? node_total_cru; + String? node_status; + int? node_rented_by; + int? node_available_for; + bool? node_has_gpu; + bool? node_has_ipv6; + bool? node_certified; + String? country; + String? region; + + ListFarmsQueryParameters({ + this.page, + this.size, + this.ret_count, + this.randomize, + this.sort_by, + this.sort_order, + this.free_ips, + this.total_ips, + this.pricing_policy_id, + this.farm_id, + this.twin_id, + this.name, + this.name_contains, + this.certification_type, + this.dedicated, + this.stellar_address, + this.node_free_mru, + this.node_free_hru, + this.node_free_sru, + this.node_total_cru, + this.node_status, + this.node_rented_by, + this.node_available_for, + this.node_has_gpu, + this.node_has_ipv6, + this.node_certified, + this.country, + this.region, + }); + + Map toJson() { + return toMap(this); + } +} + +@reflector +class Farm { + String certificationType; + bool dedicated; + int farmID; + String name; + int pricingPolicyId; + List publicIps; + String stellarAddress; + int twinId; + + Farm({ + required this.certificationType, + required this.dedicated, + required this.farmID, + required this.name, + required this.pricingPolicyId, + required this.publicIps, + required this.stellarAddress, + required this.twinId, + }); + + factory Farm.fromJson(Map json) { + return Farm( + certificationType: json['certificationType'], + dedicated: json['dedicated'], + farmID: json['farmId'], + name: json['name'], + pricingPolicyId: json['pricingPolicyId'], + publicIps: json['publicIps'] != null + ? (json['publicIps'] as List) + .map((i) => PublicIp.fromJson(i)) + .toList() + : [], + stellarAddress: json['stellarAddress'], + twinId: json['twinId'], + ); + } + + Map toJson() { + return toMap(this); + } + + @override + String toString() { + return toJson().toString(); + } +} + +@reflector +class PublicIp { + int contract_id; + String farm_id; + String gateway; + String id; + String ip; + + PublicIp({ + required this.contract_id, + required this.farm_id, + required this.gateway, + required this.id, + required this.ip, + }); + + factory PublicIp.fromJson(Map json) { + return fromJson(json); + } + + Map toJson() { + return toMap(this); + } + + @override + String toString() { + return toJson().toString(); + } +} diff --git a/packages/gridproxy_client/lib/models/nodes.dart b/packages/gridproxy_client/lib/models/nodes.dart new file mode 100644 index 00000000..ea00687e --- /dev/null +++ b/packages/gridproxy_client/lib/models/nodes.dart @@ -0,0 +1,603 @@ +import 'package:gridproxy_client/models/reflector.dart'; +import 'package:gridproxy_client/models/sort_order.dart'; +import 'package:gridproxy_client/src/query_builder.dart'; + +class GetNodeStatusOptions { + int nodeID; + + GetNodeStatusOptions({ + required this.nodeID, + }); +} + +@reflector +class ListNodesQueryParamaters { + int? page; + int? size; + bool? ret_count; + bool? randomize; + String? sort_by; + sortOrder? sort_order; + String? balance; + int? free_mru; + int? free_hru; + int? free_sru; + int? total_mru; + int? total_cru; + int? total_sru; + int? total_hru; + int? free_ips; + String? status; + bool? healthy; + bool? has_ipv6; + String? city; + String? country; + String? region; + String? farm_name; + bool? ipv4; + bool? ipv6; + bool? domain; + bool? dedicated; + bool? in_dedicated_farm; + bool? rentable; + bool? rented; + int? rented_by; + int? available_for; + String? farm_ids; + String? certification_type; + bool? has_gpu; + String? gpu_device_id; + String? gpu_device_name; + String? gpu_vendor_id; + String? gpu_vendor_name; + bool? gpu_available; + int? owned_by; + String? price_min; + String? price_max; + + ListNodesQueryParamaters({ + this.page, + this.size, + this.ret_count, + this.randomize, + this.sort_by, + this.sort_order, + this.balance, + this.free_mru, + this.free_hru, + this.free_sru, + this.total_mru, + this.total_cru, + this.total_sru, + this.total_hru, + this.free_ips, + this.status, + this.healthy, + this.has_ipv6, + this.city, + this.country, + this.region, + this.farm_name, + this.ipv4, + this.ipv6, + this.domain, + this.dedicated, + this.in_dedicated_farm, + this.rentable, + this.rented, + this.rented_by, + this.available_for, + this.farm_ids, + this.certification_type, + this.has_gpu, + this.gpu_device_id, + this.gpu_device_name, + this.gpu_vendor_id, + this.gpu_vendor_name, + this.gpu_available, + this.owned_by, + this.price_min, + this.price_max, + }); + + Map toJson() { + return toMap(this); + } +} + +@reflector +class Node { + String certificationType; + String city; + String country; + int created; + bool dedicated; + Dmi? dmi; + int extraFee; + int farmId; + String farmName; + int farmingPolicyId; + int gridVersion; + bool healthy; + String id; + bool inDedicatedFarm; + Location? location; + int nodeId; + int num_gpu; + Power? power; + double priceUsd; + PublicConfig? publicConfig; + int rentContractId; + bool rentable; + bool rented; + int rentedByTwinId; + String serialNumber; + Speed? speed; + String status; + Resources? total_resources; + int twinId; + int updatedAt; + int uptime; + Resources? used_resources; + + Node({ + required this.certificationType, + required this.city, + required this.country, + required this.created, + required this.dedicated, + this.dmi, + required this.extraFee, + required this.farmId, + required this.farmName, + required this.farmingPolicyId, + required this.gridVersion, + required this.healthy, + required this.id, + required this.inDedicatedFarm, + this.location, + required this.nodeId, + required this.num_gpu, + this.power, + required this.priceUsd, + this.publicConfig, + required this.rentContractId, + required this.rentable, + required this.rented, + required this.rentedByTwinId, + required this.serialNumber, + this.speed, + required this.status, + this.total_resources, + required this.twinId, + required this.updatedAt, + required this.uptime, + this.used_resources, + }); + + factory Node.fromJson(Map json) { + final capacity = json['capacity']; + return Node( + certificationType: json['certificationType'] ?? '', + city: json['city'] ?? '', + country: json['country'] ?? '', + created: json['created'] ?? 0, + dedicated: json['dedicated'] ?? false, + dmi: json['dmi'] != null ? Dmi.fromJson(json['dmi']) : null, + extraFee: json['extraFee'] ?? 0, + farmId: json['farmId'] ?? 0, + farmName: json['farmName'] ?? '', + farmingPolicyId: json['farmingPolicyId'] ?? 0, + gridVersion: json['gridVersion'] ?? 0, + healthy: json['healthy'] ?? false, + id: json['id'] ?? '', + inDedicatedFarm: json['inDedicatedFarm'] ?? false, + location: + json['location'] != null ? Location.fromJson(json['location']) : null, + nodeId: json['nodeId'] ?? 0, + num_gpu: json['num_gpu'] ?? 0, + power: json['power'] != null ? Power.fromJson(json['power']) : null, + priceUsd: json['price_usd'].toDouble() ?? 0, + publicConfig: json['publicConfig'] != null + ? PublicConfig.fromJson(json['publicConfig']) + : null, + rentContractId: json['rentContractId'] ?? 0, + rentable: json['rentable'] ?? false, + rented: json['rented'] ?? false, + rentedByTwinId: json['rentedByTwinId'] ?? 0, + serialNumber: json['serialNumber'] ?? '', + speed: json['speed'] != null ? Speed.fromJson(json['speed']) : null, + status: json['status'] ?? '', + twinId: json['twinId'] ?? 0, + updatedAt: json['updatedAt'] ?? 0, + uptime: json['uptime'] ?? 0, + used_resources: capacity != null && capacity['used_resources'] != null + ? Resources.fromJson(capacity['used_resources']) + : json['used_resources'] != null + ? Resources.fromJson(json['used_resources']) + : null, + total_resources: capacity != null && capacity['total_resources'] != null + ? Resources.fromJson(capacity['total_resources']) + : json['total_resources'] != null + ? Resources.fromJson(json['total_resources']) + : null, + ); + } + Map toJson() { + return toMap(this); + } + + @override + String toString() { + return toJson().toString(); + } +} + +@reflector +class Dmi { + Baseboard? baseboard; + Bios? bios; + List? memory; + int node_twin_id; + List? processor; + + Dmi({ + this.baseboard, + this.bios, + this.memory, + required this.node_twin_id, + this.processor, + }); + + factory Dmi.fromJson(Map json) { + return Dmi( + baseboard: json['baseboard'] != null + ? Baseboard.fromJson(json['baseboard']) + : null, + bios: json['bios'] != null ? Bios.fromJson(json['bios']) : null, + memory: json['memory'] != null + ? (json['memory'] as List).map((i) => Memory.fromJson(i)).toList() + : [], + node_twin_id: json['node_twin_id'] ?? 0, + processor: json['processor'] != null + ? (json['processor'] as List) + .map((i) => Processor.fromJson(i)) + .toList() + : [], + ); + } + + Map toJson() { + return toMap(this); + } + + @override + String toString() { + return toJson().toString(); + } +} + +@reflector +class Bios { + String vendor; + String version; + + Bios({ + required this.vendor, + required this.version, + }); + + factory Bios.fromJson(Map json) { + return fromJson(json); + } + + Map toJson() { + return toMap(this); + } + + @override + String toString() { + return toJson().toString(); + } +} + +@reflector +class Memory { + String manufacturer; + String type; + + Memory({ + required this.manufacturer, + required this.type, + }); + + factory Memory.fromJson(Map json) { + return fromJson(json); + } + + Map toJson() { + return toMap(this); + } + + @override + String toString() { + return toJson().toString(); + } +} + +@reflector +class Processor { + String thread_count; + String version; + + Processor({ + required this.thread_count, + required this.version, + }); + + factory Processor.fromJson(Map json) { + return fromJson(json); + } + + Map toJson() { + return toMap(this); + } + + @override + String toString() { + return toJson().toString(); + } +} + +@reflector +class Location { + String city; + String country; + double latitude; + double longitude; + + Location({ + required this.city, + required this.country, + required this.latitude, + required this.longitude, + }); + + factory Location.fromJson(Map json) { + return fromJson(json); + } + + Map toJson() { + return toMap(this); + } + + @override + String toString() { + return toJson().toString(); + } +} + +@reflector +class Power { + String state; + String target; + + Power({ + required this.state, + required this.target, + }); + + factory Power.fromJson(Map json) { + return fromJson(json); + } + + Map toJson() { + return toMap(this); + } + + @override + String toString() { + return toJson().toString(); + } +} + +@reflector +class PublicConfig { + String domain; + String gw4; + String gw6; + String ipv4; + String ipv6; + + PublicConfig({ + required this.domain, + required this.gw4, + required this.gw6, + required this.ipv4, + required this.ipv6, + }); + + factory PublicConfig.fromJson(Map json) { + return fromJson(json); + } + Map toJson() { + return toMap(this); + } + + @override + String toString() { + return toJson().toString(); + } +} + +@reflector +class Speed { + double download; + int node_twin_id; + double upload; + + Speed({ + required this.download, + required this.node_twin_id, + required this.upload, + }); + + factory Speed.fromJson(Map json) { + return fromJson(json); + } + + Map toJson() { + return toMap(this); + } + + @override + String toString() { + return toJson().toString(); + } +} + +@reflector +class Baseboard { + String manufacturer; + String product_name; + + Baseboard({ + required this.manufacturer, + required this.product_name, + }); + + factory Baseboard.fromJson(Map json) { + return fromJson(json); + } + + Map toJson() { + return toMap(this); + } + + @override + String toString() { + return toJson().toString(); + } +} + +@reflector +class Resources { + int cru; + int hru; + int mru; + int sru; + int ipv4u; + + Resources({ + required this.cru, + required this.hru, + required this.mru, + required this.sru, + required this.ipv4u, + }); + + factory Resources.fromJson(Map json) { + return fromJson(json); + } + + Map toJson() { + return toMap(this); + } + + @override + String toString() { + return toJson().toString(); + } +} + +@reflector +class NodeGPUInfo { + int contract; + String device; + String id; + int node_twin_id; + int updated_at; + String vendor; + + NodeGPUInfo({ + required this.contract, + required this.device, + required this.id, + required this.node_twin_id, + required this.updated_at, + required this.vendor, + }); + + factory NodeGPUInfo.fromJson(Map json) { + return fromJson(json); + } + + Map toJson() { + return toMap(this); + } + + @override + String toString() { + return toJson().toString(); + } +} + +@reflector +class NodeStatistics { + Resources? system; + Resources? total; + Resources? used; + NodeUsers? users; + + NodeStatistics({ + this.system, + this.total, + this.used, + this.users, + }); + + factory NodeStatistics.fromJson(Map json) { + return NodeStatistics( + system: + json['system'] != null ? Resources.fromJson(json['system']) : null, + total: json['total'] != null ? Resources.fromJson(json['total']) : null, + used: json['used'] != null ? Resources.fromJson(json['used']) : null, + users: json['users'] != null ? NodeUsers.fromJson(json['users']) : null, + ); + } + + Map toJson() { + return toMap(this); + } + + @override + String toString() { + return toJson().toString(); + } +} + +@reflector +class NodeUsers { + int deployments; + int lastDeploymentTimestamp; + int workloads; + + NodeUsers({ + required this.deployments, + required this.lastDeploymentTimestamp, + required this.workloads, + }); + + factory NodeUsers.fromJson(Map json) { + return fromJson(json); + } + + Map toJson() { + return toMap(this); + } + + @override + String toString() { + return toJson().toString(); + } +} diff --git a/packages/gridproxy_client/lib/models/reflector.dart b/packages/gridproxy_client/lib/models/reflector.dart new file mode 100644 index 00000000..d24ef6a8 --- /dev/null +++ b/packages/gridproxy_client/lib/models/reflector.dart @@ -0,0 +1,14 @@ +import 'package:reflectable/reflectable.dart'; + +class Reflector extends Reflectable { + const Reflector() + : super( + invokingCapability, + declarationsCapability, + typeCapability, + reflectedTypeCapability, + newInstanceCapability, + ); +} + +const reflector = Reflector(); diff --git a/packages/gridproxy_client/lib/models/sort_order.dart b/packages/gridproxy_client/lib/models/sort_order.dart new file mode 100644 index 00000000..42cc4f2a --- /dev/null +++ b/packages/gridproxy_client/lib/models/sort_order.dart @@ -0,0 +1,9 @@ +enum sortOrder { + asc, + desc; + + @override + String toString() { + return name; + } +} diff --git a/packages/gridproxy_client/lib/models/stats.dart b/packages/gridproxy_client/lib/models/stats.dart new file mode 100644 index 00000000..5274ef0d --- /dev/null +++ b/packages/gridproxy_client/lib/models/stats.dart @@ -0,0 +1,78 @@ +import 'package:gridproxy_client/models/reflector.dart'; +import 'package:gridproxy_client/src/query_builder.dart'; + +@reflector +class StatsInfo { + int accessNodes; + int contracts; + int countries; + int dedicatedNodes; + int farms; + int gateways; + int gpus; + int nodes; + Map nodesDistribution; + int publicIps; + int totalCru; + int totalHru; + int totalMru; + int totalSru; + int twins; + int workloads_number; + + StatsInfo({ + required this.accessNodes, + required this.contracts, + required this.countries, + required this.dedicatedNodes, + required this.farms, + required this.gateways, + required this.gpus, + required this.nodes, + required this.nodesDistribution, + required this.publicIps, + required this.totalCru, + required this.totalHru, + required this.totalMru, + required this.totalSru, + required this.twins, + required this.workloads_number, + }); + + factory StatsInfo.fromJson(Map json) { + return fromJson(json); + } + + Map toJson() { + return toMap(this); + } + + @override + String toString() { + return toJson().toString(); + } +} + +enum NodeStatus { + up, + down, + standby; + + @override + String toString() { + return name; + } +} + +@reflector +class StatsQueryParams { + NodeStatus? status; + + StatsQueryParams({ + this.status, + }); + + Map toJson() { + return toMap(this); + } +} diff --git a/packages/gridproxy_client/lib/models/twins.dart b/packages/gridproxy_client/lib/models/twins.dart new file mode 100644 index 00000000..bca1c5c9 --- /dev/null +++ b/packages/gridproxy_client/lib/models/twins.dart @@ -0,0 +1,100 @@ +// ignore_for_file: constant_identifier_names + +import 'package:gridproxy_client/models/reflector.dart'; +import 'package:gridproxy_client/models/sort_order.dart'; +import 'package:gridproxy_client/src/query_builder.dart'; + +enum TwinSortBy { + relay, + public_key, + account_id, + twin_id; + + @override + String toString() { + return name; + } +} + +@reflector +class TwinsQueryParams { + int? page; + int? size; + bool? ret_count; + bool? randomize; + TwinSortBy? sort_by; + sortOrder? sort_order; + int? twin_id; + String? account_id; + String? relay; + String? public_key; + + TwinsQueryParams({ + this.page, + this.size, + this.ret_count, + this.randomize, + this.sort_by, + this.sort_order, + this.twin_id, + this.account_id, + this.relay, + this.public_key, + }); + + Map toJson() { + return toMap(this); + } +} + +@reflector +class TwinsInfo { + String accountId; + String publicKey; + String relay; + int twinId; + + TwinsInfo({ + required this.accountId, + required this.publicKey, + required this.relay, + required this.twinId, + }); + + factory TwinsInfo.fromJson(Map json) { + return fromJson(json); + } + + Map toJson() { + return toMap(this); + } + + @override + String toString() { + return toJson().toString(); + } +} + +@reflector +class TwinConsumption { + double last_hour_consumption; + double overall_consumption; + + TwinConsumption({ + required this.last_hour_consumption, + required this.overall_consumption, + }); + + factory TwinConsumption.fromJson(Map json) { + return fromJson(json); + } + + Map toJson() { + return toMap(this); + } + + @override + String toString() { + return toJson().toString(); + } +} diff --git a/packages/gridproxy_client/lib/src/client.dart b/packages/gridproxy_client/lib/src/client.dart new file mode 100644 index 00000000..e148a197 --- /dev/null +++ b/packages/gridproxy_client/lib/src/client.dart @@ -0,0 +1,47 @@ +part of '../gridproxy_client.dart'; + +class GridProxyClient { + final String baseUrl; + late final Nodes nodes; + late final Contracts contracts; + late final Farms farms; + late final Stats stats; + late final Twins twins; + + GridProxyClient(this.baseUrl) { + nodes = Nodes(this); + contracts = Contracts(this); + farms = Farms(this); + stats = Stats(this); + twins = Twins(this); + } + + Future getRequest( + String path, Map? queryParameters) async { + try { + final convertedQueryParameters = queryParameters + ?.map((key, value) => MapEntry(key, value?.toString() ?? '')); + + final uri = Uri.parse(baseUrl); + final scheme = uri.scheme; + final host = uri.host; + + final requestUri = convertedQueryParameters != null && + convertedQueryParameters.isNotEmpty + ? (scheme == 'https' + ? Uri.https(host, path, convertedQueryParameters) + : Uri.http(host, path, convertedQueryParameters)) + : (scheme == 'https' ? Uri.https(host, path) : Uri.http(host, path)); + final response = await http.get(requestUri); + + if (response.statusCode == 200) { + final jsonData = json.decode(response.body); + return jsonData; + } else { + throw Exception('Failed to load data got: ${response.body}'); + } + } catch (e) { + throw Exception('Error: $e'); + } + } +} diff --git a/packages/gridproxy_client/lib/src/contracts.dart b/packages/gridproxy_client/lib/src/contracts.dart new file mode 100644 index 00000000..b04d8023 --- /dev/null +++ b/packages/gridproxy_client/lib/src/contracts.dart @@ -0,0 +1,37 @@ +import 'package:gridproxy_client/gridproxy_client.dart'; +import 'package:gridproxy_client/models/contracts.dart'; + +class Contracts { + final GridProxyClient client; + + Contracts(this.client); + + Future> list( + ContractInfoQueryParams queryParameters) async { + final response = + await client.getRequest('/contracts', queryParameters.toJson()); + List contracts = + (response as List).map((contractsData) { + return ContractInfo.fromJson(contractsData as Map); + }).toList(); + return contracts; + } + + Future getById({required int contractId}) async { + final response = await client.getRequest('/contracts/$contractId', null); + ContractInfo contract = + ContractInfo.fromJson(response as Map); + return contract; + } + + Future> getBills( + int contractId, ContractBillQueryParams queryParameters) async { + final response = await client.getRequest( + '/contracts/$contractId/bills', queryParameters.toJson()); + List contractsBills = + (response as List).map((contractsData) { + return ContractBills.fromJson(contractsData as Map); + }).toList(); + return contractsBills; + } +} diff --git a/packages/gridproxy_client/lib/src/farms.dart b/packages/gridproxy_client/lib/src/farms.dart new file mode 100644 index 00000000..c0527086 --- /dev/null +++ b/packages/gridproxy_client/lib/src/farms.dart @@ -0,0 +1,14 @@ +import 'package:gridproxy_client/gridproxy_client.dart'; +import 'package:gridproxy_client/models/farms.dart'; + +class Farms { + final GridProxyClient client; + + Farms(this.client); + + Future> list(ListFarmsQueryParameters? queryParams) async { + final farms = await client.getRequest('/farms', queryParams?.toJson()) + as List; + return farms.map((farm) => Farm.fromJson(farm)).toList(); + } +} diff --git a/packages/gridproxy_client/lib/src/nodes.dart b/packages/gridproxy_client/lib/src/nodes.dart new file mode 100644 index 00000000..df96a7f3 --- /dev/null +++ b/packages/gridproxy_client/lib/src/nodes.dart @@ -0,0 +1,31 @@ +import 'package:gridproxy_client/gridproxy_client.dart'; +import 'package:gridproxy_client/models/nodes.dart'; + +class Nodes { + final GridProxyClient client; + + Nodes(this.client); + + Future> list(ListNodesQueryParamaters? queryParams) async { + final nodes = await client.getRequest('/nodes', queryParams?.toJson()) + as List; + return nodes.map((node) => Node.fromJson(node)).toList(); + } + + Future getById({required int nodeID}) async { + final node = await client.getRequest('/nodes/$nodeID', null); + return Node.fromJson(node); + } + + Future> listNodeGPUs({required int nodeID}) async { + final nodeGPUs = + await client.getRequest('/nodes/$nodeID/gpu', null) as List; + return nodeGPUs.map((gpu) => NodeGPUInfo.fromJson(gpu)).toList(); + } + + Future getNodeStatistics({required int nodeID}) async { + final nodeStatistics = + await client.getRequest('/nodes/$nodeID/statistics', null); + return NodeStatistics.fromJson(nodeStatistics); + } +} diff --git a/packages/gridproxy_client/lib/src/query_builder.dart b/packages/gridproxy_client/lib/src/query_builder.dart new file mode 100644 index 00000000..96192b99 --- /dev/null +++ b/packages/gridproxy_client/lib/src/query_builder.dart @@ -0,0 +1,54 @@ +import 'package:gridproxy_client/models/reflector.dart'; +import 'package:reflectable/reflectable.dart'; + +Map toMap(Object object) { + final instanceMirror = reflector.reflect(object); + final classMirror = instanceMirror.type; + + final map = {}; + for (var declaration in classMirror.declarations.values) { + if (declaration is VariableMirror && !declaration.isStatic) { + final fieldName = declaration.simpleName.toString(); + final fieldValue = instanceMirror.invokeGetter(declaration.simpleName); + if (fieldValue != null) { + map[fieldName] = fieldValue; + } + } + } + return map; +} + +T fromJson(Map json) { + ClassMirror classMirror = reflector.reflectType(T) as ClassMirror; + + Map namedParams = {}; + + classMirror.declarations.forEach((symbol, declaration) { + if (declaration is VariableMirror && !declaration.isStatic) { + final fieldName = declaration.simpleName.toString(); + + var fieldValue = json.containsKey(fieldName) + ? json[fieldName] + : _getDefaultValue(declaration.reflectedType); + + if (declaration.reflectedType == double && fieldValue is int) { + fieldValue = fieldValue.toDouble(); + } + + namedParams[Symbol(symbol)] = fieldValue; + } + }); + + T instance = classMirror.newInstance('', [], namedParams) as T; + return instance; +} + +dynamic _getDefaultValue(Type type) { + if (type == int) return 0; + if (type == double) return 0.0; + if (type == String) return ''; + if (type == bool) return false; + if (type == List) return []; + + return null; +} diff --git a/packages/gridproxy_client/lib/src/stats.dart b/packages/gridproxy_client/lib/src/stats.dart new file mode 100644 index 00000000..d62bf739 --- /dev/null +++ b/packages/gridproxy_client/lib/src/stats.dart @@ -0,0 +1,14 @@ +import 'package:gridproxy_client/gridproxy_client.dart'; +import 'package:gridproxy_client/models/stats.dart'; + +class Stats { + final GridProxyClient client; + + Stats(this.client); + + Future get(StatsQueryParams options) async { + final response = await client.getRequest('stats', options.toJson()); + StatsInfo stat = StatsInfo.fromJson(response as Map); + return stat; + } +} diff --git a/packages/gridproxy_client/lib/src/twins.dart b/packages/gridproxy_client/lib/src/twins.dart new file mode 100644 index 00000000..6b005324 --- /dev/null +++ b/packages/gridproxy_client/lib/src/twins.dart @@ -0,0 +1,24 @@ +import 'package:gridproxy_client/gridproxy_client.dart'; +import 'package:gridproxy_client/models/twins.dart'; + +class Twins { + final GridProxyClient client; + + Twins(this.client); + + Future> list(TwinsQueryParams queryParameters) async { + final response = + await client.getRequest('/twins', queryParameters.toJson()); + List twins = (response as List).map((contractsData) { + return TwinsInfo.fromJson(contractsData as Map); + }).toList(); + return twins; + } + + Future getConsumption({required int twinID}) async { + final response = await client.getRequest('twins/$twinID/consumption', null); + TwinConsumption twinConsumption = + TwinConsumption.fromJson(response as Map); + return twinConsumption; + } +} diff --git a/packages/gridproxy_client/pubspec.lock b/packages/gridproxy_client/pubspec.lock new file mode 100644 index 00000000..97eff76f --- /dev/null +++ b/packages/gridproxy_client/pubspec.lock @@ -0,0 +1,533 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + _fe_analyzer_shared: + dependency: transitive + description: + name: _fe_analyzer_shared + sha256: "0b2f2bd91ba804e53a61d757b986f89f1f9eaed5b11e4b2f5a2468d86d6c9fc7" + url: "https://pub.dev" + source: hosted + version: "67.0.0" + analyzer: + dependency: transitive + description: + name: analyzer + sha256: "37577842a27e4338429a1cbc32679d508836510b056f1eedf0c8d20e39c1383d" + url: "https://pub.dev" + source: hosted + version: "6.4.1" + args: + dependency: transitive + description: + name: args + sha256: "7cf60b9f0cc88203c5a190b4cd62a99feea42759a7fa695010eb5de1c0b2252a" + url: "https://pub.dev" + source: hosted + version: "2.5.0" + async: + dependency: transitive + description: + name: async + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" + url: "https://pub.dev" + source: hosted + version: "2.11.0" + boolean_selector: + dependency: transitive + description: + name: boolean_selector + sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" + url: "https://pub.dev" + source: hosted + version: "2.1.1" + build: + dependency: transitive + description: + name: build + sha256: "80184af8b6cb3e5c1c4ec6d8544d27711700bc3e6d2efad04238c7b5290889f0" + url: "https://pub.dev" + source: hosted + version: "2.4.1" + build_config: + dependency: transitive + description: + name: build_config + sha256: bf80fcfb46a29945b423bd9aad884590fb1dc69b330a4d4700cac476af1708d1 + url: "https://pub.dev" + source: hosted + version: "1.1.1" + build_daemon: + dependency: transitive + description: + name: build_daemon + sha256: "0343061a33da9c5810b2d6cee51945127d8f4c060b7fbdd9d54917f0a3feaaa1" + url: "https://pub.dev" + source: hosted + version: "4.0.1" + build_resolvers: + dependency: transitive + description: + name: build_resolvers + sha256: "339086358431fa15d7eca8b6a36e5d783728cf025e559b834f4609a1fcfb7b0a" + url: "https://pub.dev" + source: hosted + version: "2.4.2" + build_runner: + dependency: transitive + description: + name: build_runner + sha256: "3ac61a79bfb6f6cc11f693591063a7f19a7af628dc52f141743edac5c16e8c22" + url: "https://pub.dev" + source: hosted + version: "2.4.9" + build_runner_core: + dependency: transitive + description: + name: build_runner_core + sha256: "4ae8ffe5ac758da294ecf1802f2aff01558d8b1b00616aa7538ea9a8a5d50799" + url: "https://pub.dev" + source: hosted + version: "7.3.0" + built_collection: + dependency: transitive + description: + name: built_collection + sha256: "376e3dd27b51ea877c28d525560790aee2e6fbb5f20e2f85d5081027d94e2100" + url: "https://pub.dev" + source: hosted + version: "5.1.1" + built_value: + dependency: transitive + description: + name: built_value + sha256: c7913a9737ee4007efedaffc968c049fd0f3d0e49109e778edc10de9426005cb + url: "https://pub.dev" + source: hosted + version: "8.9.2" + checked_yaml: + dependency: transitive + description: + name: checked_yaml + sha256: feb6bed21949061731a7a75fc5d2aa727cf160b91af9a3e464c5e3a32e28b5ff + url: "https://pub.dev" + source: hosted + version: "2.0.3" + code_builder: + dependency: transitive + description: + name: code_builder + sha256: f692079e25e7869c14132d39f223f8eec9830eb76131925143b2129c4bb01b37 + url: "https://pub.dev" + source: hosted + version: "4.10.0" + collection: + dependency: transitive + description: + name: collection + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a + url: "https://pub.dev" + source: hosted + version: "1.18.0" + convert: + dependency: transitive + description: + name: convert + sha256: "0f08b14755d163f6e2134cb58222dd25ea2a2ee8a195e53983d57c075324d592" + url: "https://pub.dev" + source: hosted + version: "3.1.1" + coverage: + dependency: transitive + description: + name: coverage + sha256: "3945034e86ea203af7a056d98e98e42a5518fff200d6e8e6647e1886b07e936e" + url: "https://pub.dev" + source: hosted + version: "1.8.0" + crypto: + dependency: transitive + description: + name: crypto + sha256: ff625774173754681d66daaf4a448684fb04b78f902da9cb3d308c19cc5e8bab + url: "https://pub.dev" + source: hosted + version: "3.0.3" + dart_style: + dependency: transitive + description: + name: dart_style + sha256: "99e066ce75c89d6b29903d788a7bb9369cf754f7b24bf70bf4b6d6d6b26853b9" + url: "https://pub.dev" + source: hosted + version: "2.3.6" + file: + dependency: transitive + description: + name: file + sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c" + url: "https://pub.dev" + source: hosted + version: "7.0.0" + fixnum: + dependency: transitive + description: + name: fixnum + sha256: "25517a4deb0c03aa0f32fd12db525856438902d9c16536311e76cdc57b31d7d1" + url: "https://pub.dev" + source: hosted + version: "1.1.0" + frontend_server_client: + dependency: transitive + description: + name: frontend_server_client + sha256: f64a0333a82f30b0cca061bc3d143813a486dc086b574bfb233b7c1372427694 + url: "https://pub.dev" + source: hosted + version: "4.0.0" + glob: + dependency: transitive + description: + name: glob + sha256: "0e7014b3b7d4dac1ca4d6114f82bf1782ee86745b9b42a92c9289c23d8a0ab63" + url: "https://pub.dev" + source: hosted + version: "2.1.2" + graphs: + dependency: transitive + description: + name: graphs + sha256: aedc5a15e78fc65a6e23bcd927f24c64dd995062bcd1ca6eda65a3cff92a4d19 + url: "https://pub.dev" + source: hosted + version: "2.3.1" + http: + dependency: "direct main" + description: + name: http + sha256: a2bbf9d017fcced29139daa8ed2bba4ece450ab222871df93ca9eec6f80c34ba + url: "https://pub.dev" + source: hosted + version: "1.2.0" + http_multi_server: + dependency: transitive + description: + name: http_multi_server + sha256: "97486f20f9c2f7be8f514851703d0119c3596d14ea63227af6f7a481ef2b2f8b" + url: "https://pub.dev" + source: hosted + version: "3.2.1" + http_parser: + dependency: transitive + description: + name: http_parser + sha256: "2aa08ce0341cc9b354a498388e30986515406668dbcc4f7c950c3e715496693b" + url: "https://pub.dev" + source: hosted + version: "4.0.2" + io: + dependency: transitive + description: + name: io + sha256: "2ec25704aba361659e10e3e5f5d672068d332fc8ac516421d483a11e5cbd061e" + url: "https://pub.dev" + source: hosted + version: "1.0.4" + js: + dependency: transitive + description: + name: js + sha256: c1b2e9b5ea78c45e1a0788d29606ba27dc5f71f019f32ca5140f61ef071838cf + url: "https://pub.dev" + source: hosted + version: "0.7.1" + json_annotation: + dependency: transitive + description: + name: json_annotation + sha256: "1ce844379ca14835a50d2f019a3099f419082cfdd231cd86a142af94dd5c6bb1" + url: "https://pub.dev" + source: hosted + version: "4.9.0" + lints: + dependency: "direct dev" + description: + name: lints + sha256: cbf8d4b858bb0134ef3ef87841abdf8d63bfc255c266b7bf6b39daa1085c4290 + url: "https://pub.dev" + source: hosted + version: "3.0.0" + logging: + dependency: transitive + description: + name: logging + sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340" + url: "https://pub.dev" + source: hosted + version: "1.2.0" + matcher: + dependency: transitive + description: + name: matcher + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb + url: "https://pub.dev" + source: hosted + version: "0.12.16+1" + meta: + dependency: transitive + description: + name: meta + sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7 + url: "https://pub.dev" + source: hosted + version: "1.15.0" + mime: + dependency: transitive + description: + name: mime + sha256: "801fd0b26f14a4a58ccb09d5892c3fbdeff209594300a542492cf13fba9d247a" + url: "https://pub.dev" + source: hosted + version: "1.0.6" + node_preamble: + dependency: transitive + description: + name: node_preamble + sha256: "6e7eac89047ab8a8d26cf16127b5ed26de65209847630400f9aefd7cd5c730db" + url: "https://pub.dev" + source: hosted + version: "2.0.2" + package_config: + dependency: transitive + description: + name: package_config + sha256: "1c5b77ccc91e4823a5af61ee74e6b972db1ef98c2ff5a18d3161c982a55448bd" + url: "https://pub.dev" + source: hosted + version: "2.1.0" + path: + dependency: transitive + description: + name: path + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" + url: "https://pub.dev" + source: hosted + version: "1.9.0" + pool: + dependency: transitive + description: + name: pool + sha256: "20fe868b6314b322ea036ba325e6fc0711a22948856475e2c2b6306e8ab39c2a" + url: "https://pub.dev" + source: hosted + version: "1.5.1" + pub_semver: + dependency: transitive + description: + name: pub_semver + sha256: "40d3ab1bbd474c4c2328c91e3a7df8c6dd629b79ece4c4bd04bee496a224fb0c" + url: "https://pub.dev" + source: hosted + version: "2.1.4" + pubspec_parse: + dependency: transitive + description: + name: pubspec_parse + sha256: c799b721d79eb6ee6fa56f00c04b472dcd44a30d258fac2174a6ec57302678f8 + url: "https://pub.dev" + source: hosted + version: "1.3.0" + reflectable: + dependency: "direct main" + description: + name: reflectable + sha256: cdc1a278a2e9769abafaf9ba54ce1fd3432b2a38360e14b87ea6344f715340de + url: "https://pub.dev" + source: hosted + version: "4.0.6" + shelf: + dependency: transitive + description: + name: shelf + sha256: ad29c505aee705f41a4d8963641f91ac4cee3c8fad5947e033390a7bd8180fa4 + url: "https://pub.dev" + source: hosted + version: "1.4.1" + shelf_packages_handler: + dependency: transitive + description: + name: shelf_packages_handler + sha256: "89f967eca29607c933ba9571d838be31d67f53f6e4ee15147d5dc2934fee1b1e" + url: "https://pub.dev" + source: hosted + version: "3.0.2" + shelf_static: + dependency: transitive + description: + name: shelf_static + sha256: a41d3f53c4adf0f57480578c1d61d90342cd617de7fc8077b1304643c2d85c1e + url: "https://pub.dev" + source: hosted + version: "1.1.2" + shelf_web_socket: + dependency: transitive + description: + name: shelf_web_socket + sha256: "9ca081be41c60190ebcb4766b2486a7d50261db7bd0f5d9615f2d653637a84c1" + url: "https://pub.dev" + source: hosted + version: "1.0.4" + source_map_stack_trace: + dependency: transitive + description: + name: source_map_stack_trace + sha256: "84cf769ad83aa6bb61e0aa5a18e53aea683395f196a6f39c4c881fb90ed4f7ae" + url: "https://pub.dev" + source: hosted + version: "2.1.1" + source_maps: + dependency: transitive + description: + name: source_maps + sha256: "708b3f6b97248e5781f493b765c3337db11c5d2c81c3094f10904bfa8004c703" + url: "https://pub.dev" + source: hosted + version: "0.10.12" + source_span: + dependency: transitive + description: + name: source_span + sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" + url: "https://pub.dev" + source: hosted + version: "1.10.0" + stack_trace: + dependency: transitive + description: + name: stack_trace + sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" + url: "https://pub.dev" + source: hosted + version: "1.11.1" + stream_channel: + dependency: transitive + description: + name: stream_channel + sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 + url: "https://pub.dev" + source: hosted + version: "2.1.2" + stream_transform: + dependency: transitive + description: + name: stream_transform + sha256: "14a00e794c7c11aa145a170587321aedce29769c08d7f58b1d141da75e3b1c6f" + url: "https://pub.dev" + source: hosted + version: "2.1.0" + string_scanner: + dependency: transitive + description: + name: string_scanner + sha256: "688af5ed3402a4bde5b3a6c15fd768dbf2621a614950b17f04626c431ab3c4c3" + url: "https://pub.dev" + source: hosted + version: "1.3.0" + term_glyph: + dependency: transitive + description: + name: term_glyph + sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 + url: "https://pub.dev" + source: hosted + version: "1.2.1" + test: + dependency: "direct dev" + description: + name: test + sha256: "7ee44229615f8f642b68120165ae4c2a75fe77ae2065b1e55ae4711f6cf0899e" + url: "https://pub.dev" + source: hosted + version: "1.25.7" + test_api: + dependency: transitive + description: + name: test_api + sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb" + url: "https://pub.dev" + source: hosted + version: "0.7.2" + test_core: + dependency: transitive + description: + name: test_core + sha256: "55ea5a652e38a1dfb32943a7973f3681a60f872f8c3a05a14664ad54ef9c6696" + url: "https://pub.dev" + source: hosted + version: "0.6.4" + timing: + dependency: transitive + description: + name: timing + sha256: "70a3b636575d4163c477e6de42f247a23b315ae20e86442bebe32d3cabf61c32" + url: "https://pub.dev" + source: hosted + version: "1.0.1" + typed_data: + dependency: transitive + description: + name: typed_data + sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c + url: "https://pub.dev" + source: hosted + version: "1.3.2" + vm_service: + dependency: transitive + description: + name: vm_service + sha256: a2662fb1f114f4296cf3f5a50786a2d888268d7776cf681aa17d660ffa23b246 + url: "https://pub.dev" + source: hosted + version: "14.0.0" + watcher: + dependency: transitive + description: + name: watcher + sha256: "3d2ad6751b3c16cf07c7fca317a1413b3f26530319181b37e3b9039b84fc01d8" + url: "https://pub.dev" + source: hosted + version: "1.1.0" + web: + dependency: transitive + description: + name: web + sha256: "4188706108906f002b3a293509234588823c8c979dc83304e229ff400c996b05" + url: "https://pub.dev" + source: hosted + version: "0.4.2" + web_socket_channel: + dependency: transitive + description: + name: web_socket_channel + sha256: "939ab60734a4f8fa95feacb55804fa278de28bdeef38e616dc08e44a84adea23" + url: "https://pub.dev" + source: hosted + version: "2.4.3" + webkit_inspection_protocol: + dependency: transitive + description: + name: webkit_inspection_protocol + sha256: "87d3f2333bb240704cd3f1c6b5b7acd8a10e7f0bc28c28dcf14e782014f4a572" + url: "https://pub.dev" + source: hosted + version: "1.2.1" + yaml: + dependency: transitive + description: + name: yaml + sha256: "75769501ea3489fca56601ff33454fe45507ea3bfb014161abc3b43ae25989d5" + url: "https://pub.dev" + source: hosted + version: "3.1.2" +sdks: + dart: ">=3.2.3 <4.0.0" diff --git a/packages/gridproxy_client/pubspec.yaml b/packages/gridproxy_client/pubspec.yaml new file mode 100644 index 00000000..3b8e76ad --- /dev/null +++ b/packages/gridproxy_client/pubspec.yaml @@ -0,0 +1,18 @@ +name: gridproxy_client +description: A sample command-line application. +version: 1.0.0 +# repository: https://github.com/my_org/my_repo + +environment: + sdk: ^3.2.3 + +dependencies: + http: ^1.2.0 + reflectable: '>=4.0.6 <4.0.9' + +dev_dependencies: + lints: ^3.0.0 + test: ^1.24.0 + +scripts: + test: --coverage=coverage \ No newline at end of file diff --git a/packages/stellar_client/lib/models/balance.dart b/packages/stellar_client/lib/models/balance.dart index 1a493610..6d9a1b35 100644 --- a/packages/stellar_client/lib/models/balance.dart +++ b/packages/stellar_client/lib/models/balance.dart @@ -11,7 +11,7 @@ class BalanceData implements BalanceInfo { BalanceData({required this.assetCode, required this.balance}); - @override + @override String toString() { return 'BalanceData(assetCode: $assetCode, balance: $balance)'; } diff --git a/packages/stellar_client/lib/models/transaction.dart b/packages/stellar_client/lib/models/transaction.dart new file mode 100644 index 00000000..b148df6f --- /dev/null +++ b/packages/stellar_client/lib/models/transaction.dart @@ -0,0 +1,31 @@ +enum TransactionType { Create, Payment, Receive } + +class ITransaction {} + +class PaymentTransaction extends ITransaction { + PaymentTransaction({ + required this.hash, + required this.from, + required this.to, + required this.asset, + required this.amount, + required this.memo, + required this.status, + required this.date, + required this.type, + }); + final String hash; + final String from; + final String to; + final String asset; + final String amount; + final String memo; + final bool status; + final String date; + final TransactionType type; + + @override + String toString() { + return 'ITransaction(hash: $hash, from: $from, to: $to, asset: $asset, amount: $amount, memo: $memo, status: $status, date: $date)'; + } +} diff --git a/packages/stellar_client/lib/src/client.dart b/packages/stellar_client/lib/src/client.dart index b17e9b25..46a70f48 100644 --- a/packages/stellar_client/lib/src/client.dart +++ b/packages/stellar_client/lib/src/client.dart @@ -22,7 +22,13 @@ class Client { return Client(network, keyPair.secretSeed); } - static Future createFromMnemonic( + factory Client.fromSecretSeedHex(NetworkType network, String secretSeedHex) { + final seed = Uint8List.fromList(hex.decode(secretSeedHex)); + final keyPair = KeyPair.fromSecretSeedList(seed); + return Client(network, keyPair.secretSeed); + } + + static Future fromMnemonic( NetworkType network, String mnemonic) async { Wallet wallet = await Wallet.from(mnemonic); final keyPair = await wallet.getKeyPair(); @@ -286,9 +292,19 @@ class Client { required String currency, String? memoText, required bool funded}) async { + // check if I have enough balance + final accountBalances = await this.getBalance(); + accountBalances.firstWhere( + (b) => + b.assetCode == currency && + double.parse(b.balance) > double.parse(amount), orElse: () { + if (accountBalances.contains(currency)) { + throw Exception('Balance is not enough.'); + } + throw Exception('Balance with asset code ${currency} not found.'); + }); // check that receiver account exists final receiver = await _sdk.accounts.account(accountId); - // check that asset exists var specificBalance = receiver.balances.firstWhere( (balance) => balance.assetCode == currency, @@ -337,6 +353,7 @@ class Client { destinationAddress: destinationAddress, amount: amount, currency: currency, + memoText: memoText, funded: true); fundedTransaction!.sign(_keyPair, _stellarNetwork); @@ -350,7 +367,8 @@ class Client { Uri.parse( '${_serviceUrls[_network.toString()]}/transactionfunding_service/fund_transaction'), headers: {'Content-Type': 'application/json'}, - body: jsonEncode({'transaction': fundedTransaction.toEnvelopeXdrBase64()}), + body: jsonEncode( + {'transaction': fundedTransaction.toEnvelopeXdrBase64()}), ); print(response.body); @@ -359,35 +377,34 @@ class Client { } } - Future>> getTransactions( - {String? assetCodeFilter}) async { + Future> getTransactions({String? assetCodeFilter}) async { Page payments = await _sdk.payments .forAccount(accountId) .order(RequestBuilderOrder.DESC) .execute(); - List> transactionDetails = []; + List transactionDetails = []; if (payments.records != null && payments.records!.isNotEmpty) { for (OperationResponse response in payments.records!) { if (response is PaymentOperationResponse) { + final memoText = await this + .getMemoText(response.links?.transaction?.toJson()["href"]); String assetCode = response.assetCode ?? 'XLM'; if (assetCodeFilter == null || assetCode == assetCodeFilter) { - var details = _handlePaymentOperationResponse(response); - transactionDetails.add({'type': 'Payment', 'details': details}); - } - } else if (response is CreateAccountOperationResponse) { - if (assetCodeFilter == null) { - var details = _handleCreateAccountOperationResponse(response); - transactionDetails - .add({'type': 'CreateAccount', 'details': details}); - } - } else if (response is PathPaymentStrictReceiveOperationResponse) { - String assetCode = response.assetCode ?? 'XLM'; - if (assetCodeFilter == null || assetCode == assetCodeFilter) { - var details = - _handlePathPaymentStrictReceiveOperationResponse(response); - transactionDetails - .add({'type': 'PathPaymentStrictReceive', 'details': details}); + final details = PaymentTransaction( + hash: response.transactionHash!, + from: response.from!.accountId, + to: response.to!.accountId, + asset: response.assetCode.toString(), + amount: response.amount!, + type: response.to!.accountId == this.accountId + ? TransactionType.Receive + : TransactionType.Payment, + status: response.transactionSuccessful!, + date: DateTime.parse(response.createdAt!).toLocal().toString(), + memo: memoText); + + transactionDetails.add(details); } } else { print("Unhandled operation type: ${response.runtimeType}"); @@ -399,38 +416,6 @@ class Client { return transactionDetails; } - PathPaymentStrictReceiveOperationDetails - _handlePathPaymentStrictReceiveOperationResponse( - PathPaymentStrictReceiveOperationResponse response) { - return PathPaymentStrictReceiveOperationDetails( - from: response.from!, - to: response.to!, - sourceAmount: double.parse(response.sourceAmount!), - sourceAssetCode: response.sourceAssetCode ?? 'XLM', - destinationAmount: double.parse(response.amount!), - destinationAssetCode: response.assetCode!, - ); - } - - PaymentOperationDetails _handlePaymentOperationResponse( - PaymentOperationResponse response) { - return PaymentOperationDetails( - from: response.from!.accountId, - to: response.to!.accountId, - amount: double.parse(response.amount!), - assetCode: response.assetCode ?? 'XLM', - isSuccessful: response.transactionSuccessful!, - ); - } - - CreateAccountOperationDetails _handleCreateAccountOperationResponse( - CreateAccountOperationResponse response) { - return CreateAccountOperationDetails( - account: response.account!, - startingBalance: double.parse(response.startingBalance!), - ); - } - Future> getBalance() async { List balancesList = []; AccountResponse account = await _sdk.accounts.account(accountId); @@ -480,4 +465,18 @@ class Client { throw Exception('Could not create vestingAccount due to $error'); } } + + Future getMemoText(String url) async { + try { + final response = await http.get( + Uri.parse(url), + headers: {'Content-Type': 'application/json'}, + ); + final body = jsonDecode(response.body); + final memoText = body['memo'] ?? ""; + return memoText; + } catch (e) { + throw Exception("Couldn't get memo text due to ${e}"); + } + } } diff --git a/packages/stellar_client/lib/stellar_client.dart b/packages/stellar_client/lib/stellar_client.dart index 90b686d1..ab471557 100644 --- a/packages/stellar_client/lib/stellar_client.dart +++ b/packages/stellar_client/lib/stellar_client.dart @@ -6,10 +6,11 @@ import 'dart:typed_data'; import 'package:stellar_client/models/balance.dart'; import 'package:stellar_client/models/currency.dart' as currency; import 'package:stellar_client/models/transaction_data.dart'; -import 'package:stellar_client/models/transactions.dart'; import 'package:stellar_client/models/vesting_account.dart'; +import 'package:stellar_client/models/transaction.dart'; import 'package:stellar_flutter_sdk/stellar_flutter_sdk.dart'; import 'package:http/http.dart' as http; +import 'package:convert/convert.dart'; part 'src/client.dart'; part 'src/network_types.dart'; diff --git a/packages/stellar_client/pubspec.lock b/packages/stellar_client/pubspec.lock index c3375831..47e2d397 100644 --- a/packages/stellar_client/pubspec.lock +++ b/packages/stellar_client/pubspec.lock @@ -210,18 +210,18 @@ packages: dependency: transitive description: name: material_color_utilities - sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41" + sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec url: "https://pub.dev" source: hosted - version: "0.5.0" + version: "0.11.1" meta: dependency: transitive description: name: meta - sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e + sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7 url: "https://pub.dev" source: hosted - version: "1.10.0" + version: "1.15.0" mime: dependency: transitive description: @@ -508,4 +508,4 @@ packages: source: hosted version: "3.1.2" sdks: - dart: ">=3.2.3 <4.0.0" + dart: ">=3.3.0-0 <4.0.0" diff --git a/packages/stellar_client/pubspec.yaml b/packages/stellar_client/pubspec.yaml index 677ed89c..a6a04c1f 100644 --- a/packages/stellar_client/pubspec.yaml +++ b/packages/stellar_client/pubspec.yaml @@ -13,3 +13,6 @@ dependencies: dev_dependencies: lints: ^3.0.0 test: ^1.24.0 + +scripts: + test: --coverage=coverage diff --git a/packages/tfchain_client/lib/src/client.dart b/packages/tfchain_client/lib/src/client.dart index 331428b5..38726b33 100644 --- a/packages/tfchain_client/lib/src/client.dart +++ b/packages/tfchain_client/lib/src/client.dart @@ -1,6 +1,7 @@ part of '../tfchain_client.dart'; class QueryClient { + static Map connections = {}; final String url; late Provider? provider; late polkadot.Dev api; @@ -69,8 +70,18 @@ class QueryClient { Future connect() async { _checkInputs(); - provider = Provider.fromUri(Uri.parse(url)); - api = polkadot.Dev(provider!); + if (connections.containsKey(url)) { + provider = connections[url]["provider"]; + api = connections[url]["api"]; + if (!provider!.isConnected()) { + api.connect(); + } + } else { + provider = Provider.fromUri(Uri.parse(url)); + api = polkadot.Dev(provider!); + final map = {"provider": provider, "api": api}; + connections[url] = map; + } } Future disconnect() async { @@ -84,7 +95,7 @@ class Client extends QueryClient { final String mnemonicOrSecretSeed; late String address; final String _keypairType; - late final KeyPair? keypair; + late KeyPair? keypair; KVStore? _kvStore; Signer.KPType? _type; TermsAndConditions? _termsAndConditions; diff --git a/packages/tfchain_client/lib/src/utils.dart b/packages/tfchain_client/lib/src/utils.dart index 20135f2a..81d6a208 100644 --- a/packages/tfchain_client/lib/src/utils.dart +++ b/packages/tfchain_client/lib/src/utils.dart @@ -2,7 +2,7 @@ import 'dart:typed_data'; import 'package:convert/convert.dart'; bool isValidSeed(String seed) { - final RegExp hexRegex = RegExp(r'0[xX][0-9a-fA-F]+'); + final RegExp hexRegex = RegExp(r'(0[xX])?[0-9a-fA-F]+'); return hexRegex.hasMatch(seed); } diff --git a/packages/tfchain_client/pubspec.yaml b/packages/tfchain_client/pubspec.yaml index c1a2012e..7d83524f 100644 --- a/packages/tfchain_client/pubspec.yaml +++ b/packages/tfchain_client/pubspec.yaml @@ -33,3 +33,6 @@ polkadart: # qa: wss://tfchain.qa.grid.tf/ws # test: wss://tfchain.test.grid.tf/ws # main: wss://tfchain.grid.tf/ws + +scripts: + test: --coverage=coverage \ No newline at end of file diff --git a/packages/tfchain_client/test/client_test.dart b/packages/tfchain_client/test/client_test.dart index 0f04083a..4e0979e8 100644 --- a/packages/tfchain_client/test/client_test.dart +++ b/packages/tfchain_client/test/client_test.dart @@ -65,6 +65,5 @@ void main() { await setupManager.client.disconnect(); expect(false, setupManager.client.provider!.isConnected()); }); - }); }