// Copyright Metatype OÜ, licensed under the Mozilla Public License Version 2.0.
// SPDX-License-Identifier: MPL-2.0
import "../_dnt.polyfills.js";
import * as t from "../types.js";
import { runtimes } from "../wit.js";
import { Runtime } from "./mod.js";
import { fx } from "../index.js";
export class WasmRuntime extends Runtime {
    /** create reflected wasm runtime */
    static reflected(modulePath) {
        return new WasmRuntimeReflected(modulePath);
    }
    /** create a wasm runtime using the wire protocol */
    static wire(modulePath) {
        return new WasmRuntimeWire(modulePath);
    }
}
class WasmRuntimeWire extends WasmRuntime {
    constructor(artifactPath) {
        super(runtimes.registerWasmWireRuntime({
            wasmArtifact: artifactPath,
        }));
    }
    handler(inp, out, { name, effect = fx.read(), }) {
        const matId = runtimes.fromWasmWireHandler({
            runtime: this._id,
            effect,
        }, {
            funcName: name,
        });
        return t.func(inp, out, {
            _id: matId,
            effect,
            funcName: name,
        });
    }
}
class WasmRuntimeReflected extends WasmRuntime {
    constructor(artifactPath) {
        super(runtimes.registerWasmReflectedRuntime({
            wasmArtifact: artifactPath,
        }));
    }
    export(inp, out, { name, effect = fx.read(), }) {
        const matId = runtimes.fromWasmReflectedFunc({
            runtime: this._id,
            effect,
        }, {
            funcName: name,
        });
        return t.func(inp, out, {
            _id: matId,
            effect,
            funcName: name,
        });
    }
}
