@helios-lang/contract-utils 0.2.54 → 0.2.55
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +43 -44
- package/src/cast/UserFunc.js +15 -7
- package/src/codegen/LoadedScriptsWriter.js +1 -1
- package/src/codegen/TypeCheckedModule.js +2 -1
- package/types/cast/UserFunc.d.ts +8 -4
- package/types/cast/UserFunc.d.ts.map +1 -1
- package/types/codegen/TypeCheckedModule.d.ts +4 -1
- package/types/codegen/TypeCheckedModule.d.ts.map +1 -1
package/package.json
CHANGED
|
@@ -1,45 +1,44 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
2
|
+
"name": "@helios-lang/contract-utils",
|
|
3
|
+
"version": "0.2.55",
|
|
4
|
+
"description": "Convenience and type-safety utilities for using Helios validators from within Typescript",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"types": "types/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"bin": {
|
|
9
|
+
"hl2ts": "src/hl2ts.js"
|
|
10
|
+
},
|
|
11
|
+
"author": "Christian Schmitz",
|
|
12
|
+
"license": "BSD-3-Clause",
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"@types/node": "^20.11.24",
|
|
15
|
+
"prettier": "^3.1.0",
|
|
16
|
+
"typescript": "^5.3.2"
|
|
17
|
+
},
|
|
18
|
+
"prettier": {
|
|
19
|
+
"trailingComma": "none",
|
|
20
|
+
"tabWidth": 4,
|
|
21
|
+
"semi": false,
|
|
22
|
+
"singleQuote": false
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"@helios-lang/compiler": "*"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@helios-lang/cli-utils": "^0.1.6",
|
|
29
|
+
"@helios-lang/codec-utils": "^0.1.34",
|
|
30
|
+
"@helios-lang/compiler-utils": "^0.1.25",
|
|
31
|
+
"@helios-lang/ledger": "^0.4.10",
|
|
32
|
+
"@helios-lang/type-utils": "^0.1.21",
|
|
33
|
+
"@helios-lang/uplc": "^0.3.5"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "pnpm run prettify && pnpm run build:types && pnpm run test:suite",
|
|
37
|
+
"build:types": "tsc -p jsconfig.json --noEmit false --emitDeclarationOnly",
|
|
38
|
+
"prettify": "prettier . --write",
|
|
39
|
+
"test": "pnpm run test:pretty && pnpm run test:types && pnpm run test:suite",
|
|
40
|
+
"test:pretty": "prettier . --check",
|
|
41
|
+
"test:suite": "node --test",
|
|
42
|
+
"test:types": "pnpm run build:types"
|
|
43
|
+
}
|
|
44
|
+
}
|
package/src/cast/UserFunc.js
CHANGED
|
@@ -13,6 +13,7 @@ import { Cast } from "./Cast.js"
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
+
* `returns` is optional to accomodate main functions that return void
|
|
16
17
|
* @typedef {{
|
|
17
18
|
* name: string
|
|
18
19
|
* requiresScriptContext: boolean
|
|
@@ -23,7 +24,7 @@ import { Cast } from "./Cast.js"
|
|
|
23
24
|
* isOptional: boolean
|
|
24
25
|
* isIgnored?: boolean
|
|
25
26
|
* }[]
|
|
26
|
-
* returns
|
|
27
|
+
* returns?: TypeSchema
|
|
27
28
|
* validatorIndices?: Record<string, number>
|
|
28
29
|
* castConfig: CastConfig
|
|
29
30
|
* }} UserFuncProps
|
|
@@ -103,14 +104,19 @@ export class UserFunc {
|
|
|
103
104
|
/** @type {UnsafeArgsT<ArgsT>} */ (unsafeNamedArgs)
|
|
104
105
|
)
|
|
105
106
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
107
|
+
if (this.props.returns) {
|
|
108
|
+
return new Cast(
|
|
109
|
+
this.props.returns,
|
|
110
|
+
this.props.castConfig
|
|
111
|
+
).fromUplcData(expectSome(/** @type {any} */ (result)))
|
|
112
|
+
} else {
|
|
113
|
+
return /** @type {any} */ (undefined)
|
|
114
|
+
}
|
|
109
115
|
}
|
|
110
116
|
|
|
111
117
|
/**
|
|
112
118
|
* @param {UnsafeArgsT<ArgsT>} namedArgs
|
|
113
|
-
* @returns {UplcData}
|
|
119
|
+
* @returns {RetT extends void ? void : UplcData}
|
|
114
120
|
*/
|
|
115
121
|
evalUnsafe(namedArgs) {
|
|
116
122
|
const result = this.profile(namedArgs).result
|
|
@@ -118,9 +124,11 @@ export class UserFunc {
|
|
|
118
124
|
if (isLeft(result)) {
|
|
119
125
|
throw new Error(result.left.error)
|
|
120
126
|
} else if (!isString(result.right) && result.right.kind == "data") {
|
|
121
|
-
return result.right.value
|
|
122
|
-
} else {
|
|
127
|
+
return /** @type {any} */ (result.right.value)
|
|
128
|
+
} else if (this.props.returns) {
|
|
123
129
|
throw new Error(`${result.right.toString()} isn't a UplcDataValue`)
|
|
130
|
+
} else {
|
|
131
|
+
return /** @type {any} */ (undefined)
|
|
124
132
|
}
|
|
125
133
|
}
|
|
126
134
|
|
|
@@ -5,6 +5,7 @@ export {}
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
+
* `returns` is optional to accomodate main functions that return undefined
|
|
8
9
|
* @typedef {{
|
|
9
10
|
* name: string
|
|
10
11
|
* requiresScriptContext: boolean
|
|
@@ -15,7 +16,7 @@ export {}
|
|
|
15
16
|
* isOptional: boolean
|
|
16
17
|
* isIgnored?: boolean
|
|
17
18
|
* }[]
|
|
18
|
-
* returns
|
|
19
|
+
* returns?: TypeSchema
|
|
19
20
|
* }} TypeCheckedUserFunc
|
|
20
21
|
*/
|
|
21
22
|
|
package/types/cast/UserFunc.d.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* @typedef {import("./Cast.js").CastConfig} CastConfig
|
|
8
8
|
*/
|
|
9
9
|
/**
|
|
10
|
+
* `returns` is optional to accomodate main functions that return void
|
|
10
11
|
* @typedef {{
|
|
11
12
|
* name: string
|
|
12
13
|
* requiresScriptContext: boolean
|
|
@@ -17,7 +18,7 @@
|
|
|
17
18
|
* isOptional: boolean
|
|
18
19
|
* isIgnored?: boolean
|
|
19
20
|
* }[]
|
|
20
|
-
* returns
|
|
21
|
+
* returns?: TypeSchema
|
|
21
22
|
* validatorIndices?: Record<string, number>
|
|
22
23
|
* castConfig: CastConfig
|
|
23
24
|
* }} UserFuncProps
|
|
@@ -60,9 +61,9 @@ export class UserFunc<ArgsT extends {
|
|
|
60
61
|
eval(namedArgs: ArgsT): RetT;
|
|
61
62
|
/**
|
|
62
63
|
* @param {UnsafeArgsT<ArgsT>} namedArgs
|
|
63
|
-
* @returns {UplcData}
|
|
64
|
+
* @returns {RetT extends void ? void : UplcData}
|
|
64
65
|
*/
|
|
65
|
-
evalUnsafe(namedArgs: UnsafeArgsT<ArgsT>): UplcData;
|
|
66
|
+
evalUnsafe(namedArgs: UnsafeArgsT<ArgsT>): RetT extends void ? void : UplcData;
|
|
66
67
|
/**
|
|
67
68
|
* @param {UnsafeArgsT<ArgsT>} namedArgs
|
|
68
69
|
* @returns {CekResult}
|
|
@@ -75,6 +76,9 @@ export type UplcData = import("@helios-lang/uplc").UplcData;
|
|
|
75
76
|
export type UplcProgram = import("@helios-lang/uplc").UplcProgram;
|
|
76
77
|
export type UplcValue = import("@helios-lang/uplc").UplcValue;
|
|
77
78
|
export type CastConfig = import("./Cast.js").CastConfig;
|
|
79
|
+
/**
|
|
80
|
+
* `returns` is optional to accomodate main functions that return void
|
|
81
|
+
*/
|
|
78
82
|
export type UserFuncProps = {
|
|
79
83
|
name: string;
|
|
80
84
|
requiresScriptContext: boolean;
|
|
@@ -85,7 +89,7 @@ export type UserFuncProps = {
|
|
|
85
89
|
isOptional: boolean;
|
|
86
90
|
isIgnored?: boolean;
|
|
87
91
|
}[];
|
|
88
|
-
returns
|
|
92
|
+
returns?: TypeSchema;
|
|
89
93
|
validatorIndices?: Record<string, number>;
|
|
90
94
|
castConfig: CastConfig;
|
|
91
95
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UserFunc.d.ts","sourceRoot":"","sources":["../../src/cast/UserFunc.js"],"names":[],"mappings":"AAKA;;;;;;;GAOG;AAEH
|
|
1
|
+
{"version":3,"file":"UserFunc.d.ts","sourceRoot":"","sources":["../../src/cast/UserFunc.js"],"names":[],"mappings":"AAKA;;;;;;;GAOG;AAEH;;;;;;;;;;;;;;;;GAgBG;AAEH;;;GAGG;AAEH;;;GAGG;AACH,sBAHwC,KAAK,SAAhC;IAAE,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,EAC1B,IAAI;IAgBb;;;OAGG;IACH,kBAHW,WAAW,SACX,aAAa,EAKvB;IApBD;;;OAGG;IACH,eAFU,WAAW,CAEjB;IAEJ;;;;OAIG;IACH,uBAAK;IAWL;;OAEG;IACH,mBAEC;IAED;;;OAGG;IACH,gBAHW,KAAK,GACH,IAAI,CAyChB;IAED;;;OAGG;IACH,sBAHW,WAAW,CAAC,KAAK,CAAC,GAChB,IAAI,SAAS,IAAI,GAAG,IAAI,GAAG,QAAQ,CAc/C;IAED;;;OAGG;IACH,mBAHW,WAAW,CAAC,KAAK,CAAC,GAChB,SAAS,CAyGrB;CACJ;yBA5OY,OAAO,yBAAyB,EAAE,UAAU;wBAC5C,OAAO,mBAAmB,EAAE,SAAS;uBACrC,OAAO,mBAAmB,EAAE,QAAQ;0BACpC,OAAO,mBAAmB,EAAE,WAAW;wBACvC,OAAO,mBAAmB,EAAE,SAAS;yBACrC,OAAO,WAAW,EAAE,UAAU;;;;4BAK9B;IACZ,IAAQ,EAAE,MAAM,CAAA;IAChB,qBAAyB,EAAE,OAAO,CAAA;IAClC,qBAAyB,EAAE,OAAO,CAAA;IAClC,SAAa,EAAE;QACf,IAAU,EAAE,MAAM,CAAA;QAClB,IAAU,EAAE,UAAU,CAAA;QACtB,UAAgB,EAAE,OAAO,CAAA;QACzB,SAAe,CAAC,EAAE,OAAO,CAAA;KACpB,EAAE,CAAA;IACP,OAAW,CAAC,EAAE,UAAU,CAAA;IACxB,gBAAoB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC7C,UAAc,EAAE,UAAU,CAAA;CACvB;wBAIS,KAAK,IACL,GAAE,CAAgB,IAAX,MAAM,KAAK,GAAG,CAAC,SAAS,gBAAgB,GAAG,MAAM,GAAG,QAAQ,GAAC"}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export type TypeSchema = import("./TypeSchema.js").TypeSchema;
|
|
2
|
+
/**
|
|
3
|
+
* `returns` is optional to accomodate main functions that return undefined
|
|
4
|
+
*/
|
|
2
5
|
export type TypeCheckedUserFunc = {
|
|
3
6
|
name: string;
|
|
4
7
|
requiresScriptContext: boolean;
|
|
@@ -9,7 +12,7 @@ export type TypeCheckedUserFunc = {
|
|
|
9
12
|
isOptional: boolean;
|
|
10
13
|
isIgnored?: boolean;
|
|
11
14
|
}[];
|
|
12
|
-
returns
|
|
15
|
+
returns?: TypeSchema;
|
|
13
16
|
};
|
|
14
17
|
export type TypeCheckedModule = {
|
|
15
18
|
name: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypeCheckedModule.d.ts","sourceRoot":"","sources":["../../src/codegen/TypeCheckedModule.js"],"names":[],"mappings":"yBAGa,OAAO,iBAAiB,EAAE,UAAU;
|
|
1
|
+
{"version":3,"file":"TypeCheckedModule.d.ts","sourceRoot":"","sources":["../../src/codegen/TypeCheckedModule.js"],"names":[],"mappings":"yBAGa,OAAO,iBAAiB,EAAE,UAAU;;;;kCAKpC;IACZ,IAAQ,EAAE,MAAM,CAAA;IAChB,qBAAyB,EAAE,OAAO,CAAA;IAClC,qBAAyB,EAAE,OAAO,CAAA;IAClC,SAAa,EAAE;QACf,IAAU,EAAE,MAAM,CAAA;QAClB,IAAU,EAAE,UAAU,CAAA;QACtB,UAAgB,EAAE,OAAO,CAAA;QACzB,SAAe,CAAC,EAAE,OAAO,CAAA;KACpB,EAAE,CAAA;IACP,OAAW,CAAC,EAAE,UAAU,CAAA;CACrB;gCAIS;IACZ,IAAQ,EAAE,MAAM,CAAA;IAChB,OAAW,EAAE,MAAM,CAAA;IACnB,UAAc,EAAE,MAAM,CAAA;IACtB,iBAAqB,EAAE,MAAM,EAAE,CAAA;IAC/B,KAAS,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;IACrC,SAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAA;CAChD"}
|