Skip to content

Commit

Permalink
lets go
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornkihlberg committed Jan 26, 2024
1 parent a34dd8e commit 328e6ba
Showing 1 changed file with 30 additions and 5 deletions.
35 changes: 30 additions & 5 deletions packages/runtime/lifecycle/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ import {
mkFPTSRestClient,
mkRestClient,
} from "@marlowe.io/runtime-rest-client";
import { RuntimeLifecycle } from "./api.js";
import {
InvalidTypeError,
strictDynamicTypeCheck,
} from "@marlowe.io/adapter/io-ts";

export * as Browser from "./browser/index.js";

Expand All @@ -41,12 +46,32 @@ export interface RuntimeLifecycleOptions {

/**
* Creates an instance of RuntimeLifecycle.
* @param options
*/
export function mkRuntimeLifecycle(
options: RuntimeLifecycleOptions
): RuntimeLifecycle;
/**
* Creates an instance of RuntimeLifecycle.
* @param options
* @param strict Whether to perform runtime checking to provide helpful error messages. May have a slight negative performance impact. Default value is `true`.
*/
export function mkRuntimeLifecycle({
runtimeURL,
wallet,
}: RuntimeLifecycleOptions) {
export function mkRuntimeLifecycle(
options: RuntimeLifecycleOptions,
strict: boolean
): RuntimeLifecycle;
export function mkRuntimeLifecycle(
options: RuntimeLifecycleOptions,
strict: unknown = true
) {
if (!strictDynamicTypeCheck(strict)) {
throw new InvalidTypeError(
[],
`Invalid type for argument 'strict', expected boolean but got ${strict}`
);
}
const { runtimeURL, wallet } = options;
const deprecatedRestAPI = mkFPTSRestClient(runtimeURL);
const restClient = mkRestClient(runtimeURL);
const restClient = mkRestClient(runtimeURL, strict);
return Generic.mkRuntimeLifecycle(deprecatedRestAPI, restClient, wallet);
}

0 comments on commit 328e6ba

Please sign in to comment.