Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add open api sync debug #31

Merged
merged 1 commit into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/eval/eval_service.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'package:dart_eval/dart_eval.dart';
import 'package:paas_dashboard_flutter/open/open_api_debug_sync_eval_help.dart';

class EvalService {
static void eval(String piece) {
var parser = Parse();
parser.define(EvalOpenApiSyncDebug.declaration);
final code = "void main() async {" + "\n" + "final openApiSyncDebug = OpenApiSyncDebug();\n" + piece + "\n" + "}";
final func = parser.parse(code);
func('main', []);
}
}
11 changes: 11 additions & 0 deletions lib/open/open_api_debug_sync.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class OpenApiSyncDebug {
final name = "open debug";

String helloWorld() {
return "helloWorld";
}

String echo(String str) {
return str;
}
}
99 changes: 99 additions & 0 deletions lib/open/open_api_debug_sync_eval_help.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// Create a library-local lexical scope so that all classes and functions within
// a library can always access each other. Inherit from the empty scope.
import 'package:dart_eval/dart_eval.dart';
import 'package:paas_dashboard_flutter/open/open_api_debug_sync.dart';

final openDebugType = EvalType('OpenApiSyncDebug', 'OpenApiSyncDebug',
'package:paas_dashboard_flutter/open/open_api_debug_sync.dart', [EvalType.objectType], true);

class EvalOpenApiSyncDebug extends OpenApiSyncDebug
with
ValueInterop<EvalOpenApiSyncDebug>,
EvalBridgeObjectMixin<EvalOpenApiSyncDebug>,
BridgeRectifier<EvalOpenApiSyncDebug> {
EvalOpenApiSyncDebug() : super();

static final BridgeInstantiator<EvalOpenApiSyncDebug> _evalInstantiator =
(String constructor, List<dynamic> pos, Map<String, dynamic> named) {
return EvalOpenApiSyncDebug();
};

static final declaration = DartBridgeDeclaration(
visibility: DeclarationVisibility.PUBLIC,
declarator: (ctx, lex, cur) =>
{'OpenApiSyncDebug': EvalField('OpenApiSyncDebug', cls = clsGen(lex), null, Getter(null))});

static final clsGen = (lexicalScope) => EvalBridgeClass(
[DartConstructorDeclaration('', [])], openDebugType, lexicalScope, OpenApiSyncDebug, _evalInstantiator);

static late EvalBridgeClass cls;

@override
EvalBridgeData evalBridgeData = EvalBridgeData(cls);

static EvalValue evalMakeWrapper(OpenApiSyncDebug? target) {
if (target == null) {
return EvalNull();
}
return EvalRealObject(target, cls: cls, fields: {
'name': EvalField(
'name',
null,
null,
Getter(EvalCallableImpl(
(lexical, inherited, generics, args, {target}) => EvalString(target?.realValue!.name!)))),
'helloWorld': EvalField(
'helloWorld',
EvalFunctionImpl(DartMethodBody(callable: (lex, s2, gen, params, {EvalValue? target}) {
return EvalRealObject<Future<String>>(target!.realValue!.helloWorld());
}), []),
null,
Getter(null)),
'echo': EvalField(
'echo',
EvalFunctionImpl(DartMethodBody(callable: (lex, s2, gen, params, {EvalValue? target}) {
return EvalRealObject<Future<String>>(target!.realValue!.helloWorld());
}), []),
null,
Getter(null)),
});
}

@override
String helloWorld() {
return bridgeCall("helloWorld", []);
}

@override
String echo(String args) {
return bridgeCall("echo", [EvalString(args)]);
}

@override
String get name {
final _f = evalBridgeTryGetField('name');
if (_f != null) return _f.evalReifyFull();
return super.name;
}

@override
EvalValue evalGetField(String name, {bool internalGet = false}) {
switch (name) {
case 'name':
final _f = evalBridgeTryGetField('name');
if (_f != null) return _f;
return EvalString(super.name);
case 'helloWorld':
return EvalFunctionImpl(DartMethodBody(callable: (lex, s2, gen, params, {EvalValue? target}) {
return EvalString(super.helloWorld());
}), []);
case 'echo':
return EvalFunctionImpl(DartMethodBody(callable: (lex, s2, gen, params, {EvalValue? target}) {
EvalString params0 = params[0].value as EvalString;
return EvalString(super.echo(params0.realValue!));
}), []);
default:
return super.evalGetField(name, internalGet: internalGet);
}
}
}
13 changes: 13 additions & 0 deletions lib/open/open_api_pulsar.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'package:paas_dashboard_flutter/api/pulsar/pulsar_partitioned_topic_api.dart';
import 'package:paas_dashboard_flutter/persistent/persistent.dart';

class PulsarService {
Future<int> partitionTopicNumber(String name, String tenant, String namespace) async {
var pulsarInstance = await Persistent.pulsarInstance(name);
if (pulsarInstance == null) {
throw ArgumentError("pulsar instance not exist");
}
var list = await PulsarPartitionedTopicApi.getTopics(pulsarInstance.host, pulsarInstance.port, tenant, namespace);
return list.length;
}
}
74 changes: 72 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
_fe_analyzer_shared:
dependency: transitive
description:
name: _fe_analyzer_shared
url: "https://pub.dartlang.org"
source: hosted
version: "22.0.0"
analyzer:
dependency: transitive
description:
name: analyzer
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.2"
async:
dependency: transitive
description:
Expand Down Expand Up @@ -50,6 +64,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.1"
cli_util:
dependency: transitive
description:
name: cli_util
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.5"
clipboard:
dependency: "direct main"
description:
Expand Down Expand Up @@ -92,6 +113,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.4"
dart_eval:
dependency: "direct main"
description:
name: dart_eval
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.4"
fake_async:
dependency: transitive
description:
Expand All @@ -106,6 +134,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.2"
file:
dependency: transitive
description:
name: file
url: "https://pub.dartlang.org"
source: hosted
version: "6.1.2"
fixnum:
dependency: transitive
description:
Expand All @@ -128,6 +163,13 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
glob:
dependency: transitive
description:
name: glob
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.2"
http:
dependency: "direct main"
description:
Expand Down Expand Up @@ -212,6 +254,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
package_config:
dependency: transitive
description:
name: package_config
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.2"
path:
dependency: "direct main"
description:
Expand Down Expand Up @@ -247,6 +296,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "6.0.2"
pub_semver:
dependency: transitive
description:
name: pub_semver
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
rational:
dependency: transitive
description:
Expand Down Expand Up @@ -286,7 +342,7 @@ packages:
name: sqflite
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
version: "2.0.2"
sqflite_common:
dependency: transitive
description:
Expand All @@ -307,7 +363,7 @@ packages:
name: sqlite3
url: "https://pub.dartlang.org"
source: hosted
version: "1.5.0"
version: "1.5.1"
stack_trace:
dependency: transitive
description:
Expand Down Expand Up @@ -385,6 +441,20 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.3"
watcher:
dependency: transitive
description:
name: watcher
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
yaml:
dependency: transitive
description:
name: yaml
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.0"
sdks:
dart: ">=2.15.0 <3.0.0"
flutter: ">=1.16.0"
17 changes: 9 additions & 8 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1

environment:
sdk: ">=2.12.0 <3.0.0"
sdk: ">=2.15.0 <3.0.0"

dependencies:
flutter:
Expand All @@ -27,15 +27,16 @@ dependencies:

# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
cupertino_icons: ^1.0.4
mongo_dart: ^0.7.4
mysql1: ^0.19.2
http: ^0.13.3
clipboard:
provider: ^6.0.1
sqflite:
sqflite_common_ffi:
path:
dart_eval: ^0.0.4
http: ^0.13.4
clipboard: ^0.1.3
provider: ^6.0.2
sqflite: ^2.0.2
sqflite_common_ffi: ^2.0.2
path: ^1.8.0
flutter_localizations:
sdk: flutter

Expand Down
8 changes: 8 additions & 0 deletions test/eval/eval_service_test_debug_sync_helloworld.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import 'package:paas_dashboard_flutter/eval/eval_service.dart';

void main() async {
EvalService.eval('''
print(openApiSyncDebug.helloWorld());
print(openApiSyncDebug.echo("Hi!"));
''');
}