createTypesqlParser function

Future<TypesqlParserWorld> createTypesqlParser({
  1. Future<WasmModule> loadModule()?,
  2. WorkersConfig? workersConfig,
})

Creates a TypesqlParserWorld with the given wasiConfig. It setsUp the dynamic library for wasm_run in native platforms and loads the typesql_parser WASM module from the file system or from the url pointing to 'lib/typesql_parser_wasm.wasm'.

If loadModule is provided, it will be used to load the WASM module. This can be useful if you want to provide a different configuration or implementation, or you are loading it from Flutter assets or from a different HTTP endpoint. By default, it will load the WASM module from the file system in lib/typesql_parser_wasm.wasm either reading it directly in native platforms or with a GET request for Dart web.

Implementation

Future<TypesqlParserWorld> createTypesqlParser({
  Future<WasmModule> Function()? loadModule,
  WorkersConfig? workersConfig,
}) async {
  await WasmRunLibrary.setUp(override: false);

  final WasmModule module;
  if (loadModule != null) {
    module = await loadModule();
  } else {
    final uri = await WasmFileUris.uriForPackage(
      package: 'typesql_parser',
      libPath: 'assets/typesql_parser_wasm.wasm',
      envVariable: 'TYPESQL_PARSER_WASM_PATH',
    );
    final uris = WasmFileUris(uri: uri);
    module = await uris.loadModule();
  }
  final builder = module.builder(
    workersConfig: workersConfig,
  );

  return TypesqlParserWorld.init(
    builder,
    imports: const TypesqlParserWorldImports(),
  );
}