-
Notifications
You must be signed in to change notification settings - Fork 15
Description
Here is the wit file
package mypackage:plugin
/// An example world for the component to target.
world plugin {
export widget-name: func() -> result<string, string>
export widget-code: func() -> result<string, string>
export request: func(key: string, config: string) -> result<string, string>
}
Below is the fully generated file. However everywhere where there is a FuncType, e.g.
const FuncType([], [('', ResultType(StringType(), StringType()))]),
You get the following error:
The element type 'String' can't be assigned to the list type '(String, ValType)'.
// FILE GENERATED FROM WIT
// ignore: lines_longer_than_80_chars
// ignore_for_file: require_trailing_commas, unnecessary_raw_strings, unnecessary_non_null_assertion, unused_element, avoid_returning_null_for_void
import 'dart:async';
// ignore: unused_import
import 'dart:typed_data';
import 'package:wasm_wit_component/wasm_wit_component.dart';
class PluginWorldImports {
const PluginWorldImports();
}
/// An example world for the component to target.
class PluginWorld {
final PluginWorldImports imports;
final WasmLibrary library;
PluginWorld({
required this.imports,
required this.library,
}) : _widgetName = library.getComponentFunction(
'widget-name',
const FuncType([], [('', ResultType(StringType(), StringType()))]),
)!,
_widgetCode = library.getComponentFunction(
'widget-code',
const FuncType([], [('', ResultType(StringType(), StringType()))]),
)!,
_request = library.getComponentFunction(
'request',
const FuncType([
('key', StringType()),
('config', StringType())
], [
('', ResultType(StringType(), StringType()))
]),
)!;
static Future init(
WasmInstanceBuilder builder, {
required PluginWorldImports imports,
}) async {
late final WasmLibrary library;
WasmLibrary getLib() => library;
final instance = await builder.build();
library = WasmLibrary(instance,
componentId: 'mypackage:plugin/plugin',
int64Type: Int64TypeConfig.bigInt);
return PluginWorld(imports: imports, library: library);
}
static final _zoneKey = Object();
late final _zoneValues = {_zoneKey: this};
static PluginWorld? currentZoneWorld() =>
Zone.current[_zoneKey] as PluginWorld?;
T withContext(T Function() fn) => runZoned(fn, zoneValues: _zoneValues);
final ListValue Function(ListValue) _widgetName;
Result<String, String> widgetName() {
final results = _widgetName([]);
final result = results[0];
return withContext(() => Result.fromJson(
result,
(ok) => ok is String ? ok : (ok! as ParsedString).value,
(error) => error is String ? error : (error! as ParsedString).value));
}
final ListValue Function(ListValue) _widgetCode;
Result<String, String> widgetCode() {
final results = _widgetCode([]);
final result = results[0];
return withContext(() => Result.fromJson(
result,
(ok) => ok is String ? ok : (ok! as ParsedString).value,
(error) => error is String ? error : (error! as ParsedString).value));
}
final ListValue Function(ListValue) _request;
Result<String, String> request({
required String key,
required String config,
}) {
final results = _request([key, config]);
final result = results[0];
return withContext(() => Result.fromJson(
result,
(ok) => ok is String ? ok : (ok! as ParsedString).value,
(error) => error is String ? error : (error! as ParsedString).value));
}
}