-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e627725
commit 187812e
Showing
7 changed files
with
224 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', []); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!")); | ||
'''); | ||
} |