UNPKG

@harmoniclabs/plu-ts-onchain

Version:

An embedded DSL for Cardano smart contracts creation coupled with a library for Cardano transactions, all in Typescript

29 lines (28 loc) 1.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.term_as = exports.punsafeConvertType = void 0; var addUtilityForType_1 = require("../std/UtilityTerms/addUtilityForType.js"); var isWellFormedType_1 = require("../../type_system/kinds/isWellFormedType.js"); var Term_1 = require("../../Term/index.js"); function punsafeConvertType(psome, toType) { if (!(0, isWellFormedType_1.isWellFormedType)(toType)) { throw new Error("`punsafeConvertType` called with invalid type"); } var converted = new Term_1.Term(toType, psome.toIR, Boolean(psome.isConstant) // isConstant ); Object.keys(psome).forEach(function (k) { var _a; // do not overwrite `type` and `toUPLC` properties if (k === "type" || k === "toUPLC" || k === "toIR") return; Object.defineProperty(converted, k, (_a = Object.getOwnPropertyDescriptor(psome, k)) !== null && _a !== void 0 ? _a : {}); }); return (0, addUtilityForType_1.addUtilityForType)(toType)(converted); } exports.punsafeConvertType = punsafeConvertType; function term_as(toType) { return punsafeConvertType(this, toType); } exports.term_as = term_as;