@helios-lang/contract-utils 0.3.5 → 0.3.7

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.
Files changed (56) hide show
  1. package/package.json +1 -1
  2. package/src/artifacts/Artifact.js +14 -0
  3. package/src/artifacts/ArtifactWriter.js +199 -0
  4. package/src/artifacts/ChildArtifactWriter.js +118 -0
  5. package/src/artifacts/FunctionArtifact.js +90 -0
  6. package/src/artifacts/ModuleArtifact.js +83 -0
  7. package/src/artifacts/RootArtifact.js +105 -0
  8. package/src/artifacts/TypeArtifact.js +104 -0
  9. package/src/artifacts/ValidatorArtifact.js +158 -0
  10. package/src/artifacts/index.js +1 -0
  11. package/src/artifacts/symbols.js +16 -0
  12. package/src/cast/Cast.js +45 -9
  13. package/src/cast/UserFunc.js +182 -131
  14. package/src/cast/index.js +12 -3
  15. package/src/codegen/LoadedScriptsWriter.js +35 -11
  16. package/src/codegen/TypeSchema.js +126 -0
  17. package/src/context/index.js +1 -0
  18. package/src/hl2ts.js +0 -4
  19. package/src/index.js +36 -8
  20. package/src/internal.js +12 -0
  21. package/types/artifacts/Artifact.d.ts +11 -0
  22. package/types/artifacts/Artifact.d.ts.map +1 -0
  23. package/types/artifacts/ArtifactWriter.d.ts +64 -0
  24. package/types/artifacts/ArtifactWriter.d.ts.map +1 -0
  25. package/types/artifacts/ChildArtifactWriter.d.ts +35 -0
  26. package/types/artifacts/ChildArtifactWriter.d.ts.map +1 -0
  27. package/types/artifacts/FunctionArtifact.d.ts +14 -0
  28. package/types/artifacts/FunctionArtifact.d.ts.map +1 -0
  29. package/types/artifacts/ModuleArtifact.d.ts +29 -0
  30. package/types/artifacts/ModuleArtifact.d.ts.map +1 -0
  31. package/types/artifacts/RootArtifact.d.ts +11 -0
  32. package/types/artifacts/RootArtifact.d.ts.map +1 -0
  33. package/types/artifacts/TypeArtifact.d.ts +17 -0
  34. package/types/artifacts/TypeArtifact.d.ts.map +1 -0
  35. package/types/artifacts/ValidatorArtifact.d.ts +17 -0
  36. package/types/artifacts/ValidatorArtifact.d.ts.map +1 -0
  37. package/types/artifacts/index.d.ts +2 -0
  38. package/types/artifacts/index.d.ts.map +1 -0
  39. package/types/artifacts/symbols.d.ts +8 -0
  40. package/types/artifacts/symbols.d.ts.map +1 -0
  41. package/types/cast/Cast.d.ts +31 -0
  42. package/types/cast/Cast.d.ts.map +1 -1
  43. package/types/cast/UserFunc.d.ts +39 -0
  44. package/types/cast/UserFunc.d.ts.map +1 -1
  45. package/types/cast/index.d.ts +2 -2
  46. package/types/codegen/LoadedScriptsWriter.d.ts +18 -0
  47. package/types/codegen/LoadedScriptsWriter.d.ts.map +1 -1
  48. package/types/codegen/TypeSchema.d.ts +5 -0
  49. package/types/codegen/TypeSchema.d.ts.map +1 -1
  50. package/types/context/writeContractContextArtifacts.d.ts +30 -0
  51. package/types/context/writeContractContextArtifacts.d.ts.map +1 -0
  52. package/types/hl2ts.d.ts.map +1 -1
  53. package/types/index.d.ts +30 -4
  54. package/types/index.d.ts.map +1 -1
  55. package/types/internal.d.ts +5 -0
  56. package/types/internal.d.ts.map +1 -0
package/src/index.js CHANGED
@@ -1,4 +1,13 @@
1
- export { makeCast, makeUserFunc } from "./cast/index.js"
1
+ export { writeContractContextArtifacts } from "./artifacts/index.js"
2
+ export {
3
+ convertFromUplcData,
4
+ convertToUplcData,
5
+ evalUserFunc,
6
+ evalUserFuncUnsafe,
7
+ makeCast,
8
+ makeUserFunc,
9
+ profileUserFunc
10
+ } from "./cast/index.js"
2
11
  export {
3
12
  makeContractContextBuilder,
4
13
  contractContextCache
@@ -187,6 +196,7 @@ export { genTypes } from "./codegen/TypeSchema.js"
187
196
  * @typedef {object} UserFunc
188
197
  * @prop {UplcProgram} uplc
189
198
  * @prop {string} name
199
+ * @prop {UserFuncProps} props
190
200
  * @prop {(namedArgs: ArgsT, logOptions?: UplcLogger | undefined) => RetT} eval
191
201
  * @prop {(namedArgs: UnsafeArgsT<ArgsT>, logOptions?: UplcLogger | undefined) => RetT extends void ? void : UplcData} evalUnsafe
192
202
  * @prop {(namedArgs: UnsafeArgsT<ArgsT>, logOptions?: UplcLogger | undefined) => CekResult} profile
@@ -262,7 +272,7 @@ export { genTypes } from "./codegen/TypeSchema.js"
262
272
  */
263
273
 
264
274
  /**
265
- * @template {LoadedValidator} V
275
+ * @template {LoadedValidator} [V=LoadedValidator]
266
276
  * @typedef {V extends {"$purpose": "spending", "$Datum": CastLike<any, any>, "$Redeemer": CastLike<any, any>} ? {
267
277
  * $hash: ValidatorHash<
268
278
  * SpendingContext<
@@ -299,32 +309,34 @@ export { genTypes } from "./codegen/TypeSchema.js"
299
309
  * >
300
310
  * >
301
311
  * } & ContractTypesContext<V["$types"]> & ContractUserFuncsContext<V["$functions"]> :
302
- * never
312
+ * {
313
+ * $hash: ScriptHash<any>
314
+ * } & ContractTypesContext & ContractUserFuncsContext
303
315
  * } ContractValidatorContexts
304
316
  */
305
317
 
306
318
  /**
307
- * @template {LoadedModule} V
319
+ * @template {LoadedModule} [V=LoadedModule]
308
320
  * @typedef {ContractTypesContext<V["$types"]> & ContractUserFuncsContext<V["$functions"]>} ContractModuleContexts
309
321
  */
310
322
 
311
323
  /**
312
- * @template {{[typeName: string]: CastLike<any, any>}} T
324
+ * @template {{[typeName: string]: CastLike<any, any>}} [T={[typeName: string]: CastLike<any, any>}]
313
325
  * @typedef {{
314
326
  * [K in keyof T]: Cast<StrictType<T[K]>, PermissiveType<T[K]>>
315
327
  * }} ContractTypesContext
316
328
  */
317
329
 
318
330
  /**
319
- * @template {{[funcName: string]: (uplc: UplcProgram, config: CastConfig) => UserFunc<any, any>}} T
331
+ * @template {{[funcName: string]: (uplc: UplcProgram, config: CastConfig) => UserFunc<any, any>}} [T={[funcName: string]: (uplc: UplcProgram, config: CastConfig) => UserFunc<any, any>}]
320
332
  * @typedef {{
321
333
  * [K in keyof T]: ReturnType<T[K]>
322
334
  * }} ContractUserFuncsContext
323
335
  */
324
336
 
325
337
  /**
326
- * @template {{[name: string]: LoadedValidator}} Vs
327
- * @template {{[name: string]: LoadedModule}} Ms
338
+ * @template {{[name: string]: LoadedValidator}} [Vs={[name: string]: LoadedValidator}]
339
+ * @template {{[name: string]: LoadedModule}} [Ms={[name: string]: LoadedModule}]
328
340
  * @typedef {{
329
341
  * [K in keyof Vs]: ContractValidatorContexts<Vs[K]>
330
342
  * } & {
@@ -358,3 +370,19 @@ export { genTypes } from "./codegen/TypeSchema.js"
358
370
  * @prop {<M extends LoadedModule>(m: M) => ContractContextBuilder<Vs, Ms & {[K in M["$name"]]: M}>} withModule
359
371
  * @prop {(props: ContractContextBuilderProps) => ContractContext<Vs, Ms>} build
360
372
  */
373
+
374
+ /**
375
+ * A subset of the Node FS interface, that can easily be implemented in other environments
376
+ * This type symbol shadows `FileSystem` from the FileSystem API
377
+ * @typedef {{
378
+ * mkdirSync(path: string, options?: {recursive: boolean}): void
379
+ * writeFileSync(path: string, content: string): void
380
+ * }} FileSystem
381
+ */
382
+
383
+ /**
384
+ * @typedef {{
385
+ * outDir: string
386
+ * fs: FileSystem
387
+ * }} WriteContractContextArtifactsOptions
388
+ */
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @import { AssertExtends } from "@helios-lang/type-utils"
3
+ * @import { FileSystem } from "./index.js"
4
+ */
5
+
6
+ /**
7
+ * @typedef {typeof import("node:fs")} NodeFileSystem
8
+ */
9
+
10
+ /**
11
+ * @typedef {AssertExtends<FileSystem, NodeFileSystem>} NodeFileSystemExtendsFileSystem
12
+ */
@@ -0,0 +1,11 @@
1
+ export type Artifact = {
2
+ dir: string;
3
+ fs: FileSystem;
4
+ isMainnet: boolean;
5
+ writeDeclLine: (line: string) => void;
6
+ writeDefLine: (line: string) => void;
7
+ writeAggregateExport: (name: string) => void;
8
+ save: () => void;
9
+ };
10
+ import type { FileSystem } from "../index.js";
11
+ //# sourceMappingURL=Artifact.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Artifact.d.ts","sourceRoot":"","sources":["../../src/artifacts/Artifact.js"],"names":[],"mappings":";SAMU,MAAM;QACN,UAAU;eACV,OAAO;mBACP,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI;kBACtB,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI;0BACtB,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI;UACtB,MAAM,IAAI;;gCAXW,aAAa"}
@@ -0,0 +1,64 @@
1
+ /**
2
+ * @import { StringWriter } from "@helios-lang/codec-utils"
3
+ * @import { FileSystem } from "../index.js"
4
+ */
5
+ export class ArtifactWriter {
6
+ /**
7
+ * @param {FileSystem} fs
8
+ * @param {string} dir
9
+ */
10
+ constructor(fs: FileSystem, dir: string);
11
+ /**
12
+ * @readonly
13
+ * @type {FileSystem}
14
+ */
15
+ readonly fs: FileSystem;
16
+ /**
17
+ * @readonly
18
+ * @type {string}
19
+ */
20
+ readonly dir: string;
21
+ /**
22
+ * @private
23
+ * @type {StringWriter}
24
+ */
25
+ private decl;
26
+ /**
27
+ * @private
28
+ * @type {StringWriter}
29
+ */
30
+ private def;
31
+ /**
32
+ * @private
33
+ * @type {[string, string, boolean][]}
34
+ */
35
+ private imports;
36
+ /**
37
+ * @param {string} name
38
+ * @param {string} from
39
+ * @param {boolean} [isType]
40
+ * @returns {ArtifactWriter}
41
+ */
42
+ addImport(name: string, from: string, isType?: boolean | undefined): ArtifactWriter;
43
+ /**
44
+ * @param {string} line
45
+ * @returns {ArtifactWriter}
46
+ */
47
+ writeDeclLine(line: string): ArtifactWriter;
48
+ /**
49
+ * @param {string} line
50
+ * @returns {ArtifactWriter}
51
+ */
52
+ writeDefLine(line: string): ArtifactWriter;
53
+ /**
54
+ * @param {string} name
55
+ * @returns {ArtifactWriter}
56
+ */
57
+ writeAggregateExport(name: string): ArtifactWriter;
58
+ /**
59
+ * Write the .d.ts and .js files to the FS
60
+ */
61
+ save(): void;
62
+ }
63
+ import type { FileSystem } from "../index.js";
64
+ //# sourceMappingURL=ArtifactWriter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ArtifactWriter.d.ts","sourceRoot":"","sources":["../../src/artifacts/ArtifactWriter.js"],"names":[],"mappings":"AAGA;;;GAGG;AAEH;IA+BI;;;OAGG;IACH,gBAHW,UAAU,OACV,MAAM,EAShB;IAzCD;;;OAGG;IACH,aAFU,UAAU,CAElB;IAEF;;;OAGG;IACH,cAFU,MAAM,CAEb;IAEH;;;OAGG;IACH,aAAI;IAEJ;;;OAGG;IACH,YAAG;IAEH;;;OAGG;IACH,gBAAO;IAeP;;;;;OAKG;IACH,gBALW,MAAM,QACN,MAAM,iCAEJ,cAAc,CAK1B;IAED;;;OAGG;IACH,oBAHW,MAAM,GACJ,cAAc,CAK1B;IAED;;;OAGG;IACH,mBAHW,MAAM,GACJ,cAAc,CAK1B;IAED;;;OAGG;IACH,2BAHW,MAAM,GACJ,cAAc,CAM1B;IAED;;OAEG;IACH,aA8DC;CACJ;gCAxJ8B,aAAa"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @import { UplcProgram } from "@helios-lang/uplc"
3
+ * @import { Artifact } from "./Artifact.js"
4
+ */
5
+ export class ChildArtifactWriter extends ArtifactWriter {
6
+ /**
7
+ * @param {Artifact} parent
8
+ * @param {string} name
9
+ */
10
+ constructor(parent: Artifact, name: string);
11
+ /**
12
+ * @readonly
13
+ * @type {Artifact}
14
+ */
15
+ readonly parent: Artifact;
16
+ /**
17
+ * @readonly
18
+ * @type {string}
19
+ */
20
+ readonly name: string;
21
+ /**
22
+ * @type {boolean}
23
+ */
24
+ get isMainnet(): boolean;
25
+ /**
26
+ * @param {string} name
27
+ * @param {UplcProgram} program
28
+ * @returns {ChildArtifactWriter}
29
+ */
30
+ writeProgram(name: string, program: UplcProgram): ChildArtifactWriter;
31
+ }
32
+ import { ArtifactWriter } from "./ArtifactWriter.js";
33
+ import type { Artifact } from "./Artifact.js";
34
+ import type { UplcProgram } from "@helios-lang/uplc";
35
+ //# sourceMappingURL=ChildArtifactWriter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChildArtifactWriter.d.ts","sourceRoot":"","sources":["../../src/artifacts/ChildArtifactWriter.js"],"names":[],"mappings":"AAIA;;;GAGG;AAEH;IAaI;;;OAGG;IACH,oBAHW,QAAQ,QACR,MAAM,EAOhB;IArBD;;;OAGG;IACH,iBAFU,QAAQ,CAEZ;IAEN;;;OAGG;IACH,eAFU,MAAM,CAEZ;IAaJ;;OAEG;IACH,yBAEC;IAED;;;;OAIG;IACH,mBAJW,MAAM,WACN,WAAW,GACT,mBAAmB,CAmC/B;CACJ;+BA7E8B,qBAAqB;8BAIvB,eAAe;iCADZ,mBAAmB"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @import { UserFuncProps } from "../index.js"
3
+ * @import { Artifact } from "./Artifact.js"
4
+ * @import { FunctionDetails } from "./symbols.js"
5
+ */
6
+ /**
7
+ * @param {Artifact} parent
8
+ * @param {string} name
9
+ * @param {FunctionDetails} details
10
+ */
11
+ export function writeFunctionArtifact(parent: Artifact, name: string, details: FunctionDetails): void;
12
+ import type { Artifact } from "./Artifact.js";
13
+ import type { FunctionDetails } from "./symbols.js";
14
+ //# sourceMappingURL=FunctionArtifact.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FunctionArtifact.d.ts","sourceRoot":"","sources":["../../src/artifacts/FunctionArtifact.js"],"names":[],"mappings":"AAOA;;;;GAIG;AAEH;;;;GAIG;AACH,8CAJW,QAAQ,QACR,MAAM,WACN,eAAe,QAezB;8BAtB4B,eAAe;qCACR,cAAc"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @import { FunctionDetails, ModuleSymbols, TypeDetails } from "./symbols.js"
3
+ */
4
+ /**
5
+ * Re-export Artifact to avoid issues with typescript private symbol errors
6
+ * @typedef {import("./Artifact.js").Artifact} Artifact
7
+ */
8
+ /**
9
+ * @param {Artifact} parent
10
+ * @param {string} name
11
+ * @param {ModuleSymbols} symbols
12
+ */
13
+ export function writeModuleArtifact(parent: Artifact, name: string, symbols: ModuleSymbols): void;
14
+ /**
15
+ * @implements {Artifact}
16
+ */
17
+ export class ModuleArtifact extends ChildArtifactWriter implements Artifact {
18
+ /**
19
+ * @param {ModuleSymbols} symbols
20
+ */
21
+ writeSymbols(symbols: ModuleSymbols): void;
22
+ }
23
+ /**
24
+ * Re-export Artifact to avoid issues with typescript private symbol errors
25
+ */
26
+ export type Artifact = import("./Artifact.js").Artifact;
27
+ import type { ModuleSymbols } from "./symbols.js";
28
+ import { ChildArtifactWriter } from "./ChildArtifactWriter.js";
29
+ //# sourceMappingURL=ModuleArtifact.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ModuleArtifact.d.ts","sourceRoot":"","sources":["../../src/artifacts/ModuleArtifact.js"],"names":[],"mappings":"AAKA;;GAEG;AAEH;;;GAGG;AAEH;;;;GAIG;AACH,4CAJW,QAAQ,QACR,MAAM,WACN,aAAa,QAUvB;AAED;;GAEG;AACH,mEAFgB,QAAQ;IAWpB;;OAEG;IACH,sBAFW,aAAa,QAuCvB;CACJ;;;;uBAvEY,OAAO,eAAe,EAAE,QAAQ;mCALmB,cAAc;oCAL1C,0BAA0B"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @import { ContractContext, ContractModuleContexts, ContractValidatorContexts, FileSystem, LoadedValidator, WriteContractContextArtifactsOptions } from "../index.js"
3
+ * @import { Artifact } from "./Artifact.js"
4
+ */
5
+ /**
6
+ * @param {any} context - TODO: make this typesafe (`ContractContext<any, any>` or `ContractContext` doesn't seem to work)
7
+ * @param {WriteContractContextArtifactsOptions} options - not optional, at least the fs and outDir must be specified
8
+ */
9
+ export function writeContractContextArtifacts(context: any, options: WriteContractContextArtifactsOptions): void;
10
+ import type { WriteContractContextArtifactsOptions } from "../index.js";
11
+ //# sourceMappingURL=RootArtifact.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RootArtifact.d.ts","sourceRoot":"","sources":["../../src/artifacts/RootArtifact.js"],"names":[],"mappings":"AAIA;;;GAGG;AAEH;;;GAGG;AACH,uDAHW,GAAG,WACH,oCAAoC,QA2B9C;0DAjCyJ,aAAa"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @import { TypeSchema } from "@helios-lang/type-utils"
3
+ * @import { Artifact } from "./Artifact.js"
4
+ * @import { FunctionDetails, TypeDetails } from "./symbols.js"
5
+ */
6
+ /**
7
+ *
8
+ * @param {Artifact} parent
9
+ * @param {string} name
10
+ * @param {TypeDetails} props
11
+ * @param {Record<string, FunctionDetails>} members
12
+ */
13
+ export function writeTypeArtifact(parent: Artifact, name: string, props: TypeDetails, members: Record<string, FunctionDetails>): void;
14
+ import type { Artifact } from "./Artifact.js";
15
+ import type { TypeDetails } from "./symbols.js";
16
+ import type { FunctionDetails } from "./symbols.js";
17
+ //# sourceMappingURL=TypeArtifact.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TypeArtifact.d.ts","sourceRoot":"","sources":["../../src/artifacts/TypeArtifact.js"],"names":[],"mappings":"AAIA;;;;GAIG;AAEH;;;;;;GAMG;AACH,0CALW,QAAQ,QACR,MAAM,SACN,WAAW,WACX,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,QAyBzC;8BAlC4B,eAAe;iCACK,cAAc;qCAAd,cAAc"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @import { MintingContext, ScriptHash, SpendingContext, StakingContext } from "@helios-lang/ledger"
3
+ * @import { Cast } from "../index.js"
4
+ * @import { Artifact } from "./Artifact.js"
5
+ * @import { ModuleSymbols } from "./symbols.js"
6
+ */
7
+ /**
8
+ * @param {Artifact} parent
9
+ * @param {string} name
10
+ * @param {ScriptHash} hash
11
+ * @param {ModuleSymbols} symbols
12
+ */
13
+ export function writeValidatorArtifact(parent: Artifact, name: string, hash: ScriptHash, symbols: ModuleSymbols): void;
14
+ import type { Artifact } from "./Artifact.js";
15
+ import type { ScriptHash } from "@helios-lang/ledger";
16
+ import type { ModuleSymbols } from "./symbols.js";
17
+ //# sourceMappingURL=ValidatorArtifact.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ValidatorArtifact.d.ts","sourceRoot":"","sources":["../../src/artifacts/ValidatorArtifact.js"],"names":[],"mappings":"AAGA;;;;;GAKG;AAEH;;;;;GAKG;AACH,+CALW,QAAQ,QACR,MAAM,QACN,UAAU,WACV,aAAa,QAYvB;8BApB4B,eAAe;gCAFoC,qBAAqB;mCAGnE,cAAc"}
@@ -0,0 +1,2 @@
1
+ export { writeContractContextArtifacts } from "./RootArtifact.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/artifacts/index.js"],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
1
+ export type FunctionDetails = UserFunc<any, any>;
2
+ export type TypeDetails = {
3
+ schema: TypeSchema;
4
+ };
5
+ export type ModuleSymbols = Record<string, FunctionDetails | TypeDetails>;
6
+ import type { UserFunc } from "../index.js";
7
+ import type { TypeSchema } from "@helios-lang/type-utils";
8
+ //# sourceMappingURL=symbols.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"symbols.d.ts","sourceRoot":"","sources":["../../src/artifacts/symbols.js"],"names":[],"mappings":"8BAMa,SAAS,GAAG,EAAE,GAAG,CAAC;0BAIlB;IAAC,MAAM,EAAE,UAAU,CAAA;CAAC;4BAIpB,MAAM,CAAC,MAAM,EAAE,eAAe,GAAG,WAAW,CAAC;8BAZvB,aAAa;gCADjB,yBAAyB"}
@@ -25,6 +25,36 @@
25
25
  * @returns {Cast<TStrict, TPermissive>}
26
26
  */
27
27
  export function makeCast<TStrict, TPermissive>(schema: TypeSchema, config: CastConfig): Cast<TStrict, TPermissive>;
28
+ /**
29
+ * @template T
30
+ * @param {TypeSchema} schema
31
+ * @param {UplcData} data
32
+ * @param {{
33
+ * isMainnet: boolean,
34
+ * dataPath?: string,
35
+ * unwrapSingleFieldEnumVariants?: boolean
36
+ * }} options
37
+ * @returns {T}
38
+ */
39
+ export function convertFromUplcData<T>(schema: TypeSchema, data: UplcData, options: {
40
+ isMainnet: boolean;
41
+ dataPath?: string;
42
+ unwrapSingleFieldEnumVariants?: boolean;
43
+ }): T;
44
+ /**
45
+ * @template T
46
+ * @param {TypeSchema} schema
47
+ * @param {T} x
48
+ * @param {{
49
+ * dataPath?: string,
50
+ * unwrapSingleFieldEnumVariants?: boolean
51
+ * }} [options]
52
+ * @returns {UplcData}
53
+ */
54
+ export function convertToUplcData<T>(schema: TypeSchema, x: T, options?: {
55
+ dataPath?: string;
56
+ unwrapSingleFieldEnumVariants?: boolean;
57
+ } | undefined): UplcData;
28
58
  /**
29
59
  * @template TStrict
30
60
  * @template TPermissive
@@ -65,6 +95,7 @@ export type UplcToSchemaContext = {
65
95
  import type { TypeSchema } from "@helios-lang/type-utils";
66
96
  import type { CastConfig } from "../index.js";
67
97
  import type { Cast } from "../index.js";
98
+ import type { UplcData } from "@helios-lang/uplc";
68
99
  import type { CastLike } from "../index.js";
69
100
  import type { TypeSchema as TypeSchema_1 } from "@helios-lang/type-utils";
70
101
  //# sourceMappingURL=Cast.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Cast.d.ts","sourceRoot":"","sources":["../../src/cast/Cast.js"],"names":[],"mappings":"AAsDA;;;;;GAKG;AAEH;;;;;GAKG;AAEH;;;;;;GAMG;AAEH;;;;;;GAMG;AACH,yBANa,OAAO,EACP,WAAW,UACb,UAAU,UACV,UAAU,GACR,KAAK,OAAO,EAAE,WAAW,CAAC,CAItC;AAqxBD;;;;;;GAMG;AACH,8BANa,OAAO,EACP,WAAW,QACb,SAAS,OAAO,EAAE,WAAW,CAAC,UAC9B,UAAU,GACR,KAAK,OAAO,EAAE,WAAW,CAAC,CAQtC;;;;;UAxzBS,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC;;;;cAC1B,MAAM;;;;mCACN,OAAO;;;;;;UAKP,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC;;;;cAC1B,MAAM;;;;mCACN,OAAO;eACP,OAAO;;gCAjB8B,yBAAyB;gCAEzB,aAAa;0BAAb,aAAa;8BAAb,aAAa;gDAFb,yBAAyB"}
1
+ {"version":3,"file":"Cast.d.ts","sourceRoot":"","sources":["../../src/cast/Cast.js"],"names":[],"mappings":"AAsDA;;;;;GAKG;AAEH;;;;;GAKG;AAEH;;;;;;GAMG;AAEH;;;;;;GAMG;AACH,yBANa,OAAO,EACP,WAAW,UACb,UAAU,UACV,UAAU,GACR,KAAK,OAAO,EAAE,WAAW,CAAC,CAItC;AAsED;;;;;;;;;;GAUG;AACH,oCAVa,CAAC,UACH,UAAU,QACV,QAAQ,WACR;IACN,SAAS,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,6BAA6B,CAAC,EAAE,OAAO,CAAA;CACxC,GACS,CAAC,CASb;AAED;;;;;;;;;GASG;AACH,kCATa,CAAC,UACH,UAAU,KACV,CAAC;eAEI,MAAM;oCACe,OAAO;gBAE/B,QAAQ,CAUpB;AA6sBD;;;;;;GAMG;AACH,8BANa,OAAO,EACP,WAAW,QACb,SAAS,OAAO,EAAE,WAAW,CAAC,UAC9B,UAAU,GACR,KAAK,OAAO,EAAE,WAAW,CAAC,CAQtC;;;;;UA51BS,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC;;;;cAC1B,MAAM;;;;mCACN,OAAO;;;;;;UAKP,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC;;;;cAC1B,MAAM;;;;mCACN,OAAO;eACP,OAAO;;gCAjB8B,yBAAyB;gCAEzB,aAAa;0BAAb,aAAa;8BADnB,mBAAmB;8BACb,aAAa;gDAFb,yBAAyB"}
@@ -13,7 +13,46 @@
13
13
  export function makeUserFunc<ArgsT extends {
14
14
  [argName: string]: any;
15
15
  }, RetT>(uplc: UplcProgram, props: UserFuncProps): UserFunc<ArgsT, RetT>;
16
+ /**
17
+ * @template {{[argName: string]: any}} ArgsT
18
+ * @template RetT
19
+ * @param {UplcProgram} program
20
+ * @param {UserFuncProps} props
21
+ * @param {ArgsT} namedArgs
22
+ * @param {UplcLogger | undefined} logOptions
23
+ * @returns {RetT}
24
+ */
25
+ export function evalUserFunc<ArgsT extends {
26
+ [argName: string]: any;
27
+ }, RetT>(program: UplcProgram, props: UserFuncProps, namedArgs: ArgsT, logOptions?: UplcLogger | undefined): RetT;
28
+ /**
29
+ * @template {{[argName: string]: any}} ArgsT
30
+ * @template RetT
31
+ * @param {UplcProgram} program
32
+ * @param {UserFuncProps} props
33
+ * @param {UnsafeArgsT<ArgsT>} namedArgs
34
+ * @param {UplcLogger | undefined} logOptions
35
+ * @returns {RetT extends void ? void : UplcData}
36
+ */
37
+ export function evalUserFuncUnsafe<ArgsT extends {
38
+ [argName: string]: any;
39
+ }, RetT>(program: UplcProgram, props: UserFuncProps, namedArgs: UnsafeArgsT<ArgsT>, logOptions?: UplcLogger | undefined): RetT extends void ? void : UplcData;
40
+ /**
41
+ * @template {{[argName: string]: any}} ArgsT
42
+ * @param {UplcProgram} program
43
+ * @param {UserFuncProps} props
44
+ * @param {UnsafeArgsT<ArgsT>} namedArgs
45
+ * @param {UplcLogger | undefined} logOptions - optional, passed to UplcProgram.eval if provided
46
+ * @returns {CekResult}
47
+ */
48
+ export function profileUserFunc<ArgsT extends {
49
+ [argName: string]: any;
50
+ }>(program: UplcProgram, props: UserFuncProps, namedArgs: UnsafeArgsT<ArgsT>, logOptions?: UplcLogger | undefined): CekResult;
16
51
  import type { UplcProgram } from "@helios-lang/uplc";
17
52
  import type { UserFuncProps } from "../index.js";
18
53
  import type { UserFunc } from "../index.js";
54
+ import type { UplcLogger } from "@helios-lang/uplc";
55
+ import type { UnsafeArgsT } from "../index.js";
56
+ import type { UplcData } from "@helios-lang/uplc";
57
+ import type { CekResult } from "@helios-lang/uplc";
19
58
  //# sourceMappingURL=UserFunc.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"UserFunc.d.ts","sourceRoot":"","sources":["../../src/cast/UserFunc.js"],"names":[],"mappings":"AASA;;;;GAIG;AAEH;;;;;;GAMG;AACH,6BANwC,KAAK,SAAhC;IAAE,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,EAC1B,IAAI,QACN,WAAW,SACX,aAAa,GACX,SAAS,KAAK,EAAE,IAAI,CAAC,CAIjC;iCAb2E,mBAAmB;mCACpB,aAAa;8BAAb,aAAa"}
1
+ {"version":3,"file":"UserFunc.d.ts","sourceRoot":"","sources":["../../src/cast/UserFunc.js"],"names":[],"mappings":"AASA;;;;GAIG;AAEH;;;;;;GAMG;AACH,6BANwC,KAAK,SAAhC;IAAE,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,EAC1B,IAAI,QACN,WAAW,SACX,aAAa,GACX,SAAS,KAAK,EAAE,IAAI,CAAC,CAIjC;AAgED;;;;;;;;GAQG;AACH,6BARwC,KAAK,SAAhC;IAAE,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,EAC1B,IAAI,WACN,WAAW,SACX,aAAa,aACb,KAAK,eACL,UAAU,GAAG,SAAS,GACpB,IAAI,CA8ChB;AAED;;;;;;;;GAQG;AACH,mCARwC,KAAK,SAAhC;IAAE,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,EAC1B,IAAI,WACN,WAAW,SACX,aAAa,aACb,YAAY,KAAK,CAAC,eAClB,UAAU,GAAG,SAAS,GACpB,IAAI,SAAS,IAAI,GAAG,IAAI,GAAG,QAAQ,CAmB/C;AAED;;;;;;;GAOG;AACH,gCAPwC,KAAK,SAAhC;IAAE,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,WAC5B,WAAW,SACX,aAAa,aACb,YAAY,KAAK,CAAC,eAClB,UAAU,GAAG,SAAS,GACpB,SAAS,CA6GrB;iCAnR2E,mBAAmB;mCACpB,aAAa;8BAAb,aAAa;gCADZ,mBAAmB;iCACpB,aAAa;8BADZ,mBAAmB;+BAAnB,mBAAmB"}
@@ -1,3 +1,3 @@
1
- export { makeUserFunc } from "./UserFunc.js";
2
- export { makeCast, configureCast } from "./Cast.js";
1
+ export { configureCast, convertFromUplcData, convertToUplcData, makeCast } from "./Cast.js";
2
+ export { evalUserFunc, evalUserFuncUnsafe, makeUserFunc, profileUserFunc } from "./UserFunc.js";
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -7,5 +7,23 @@
7
7
  * @returns {LoadedScriptsWriter}
8
8
  */
9
9
  export function makeLoadedScriptsWriter(): LoadedScriptsWriter;
10
+ /**
11
+ * @param {TypeCheckedUserFunc} props
12
+ * @param {boolean} unsafe
13
+ * @returns {string}
14
+ */
15
+ export function genUserFuncRetType(props: TypeCheckedUserFunc, unsafe?: boolean): string;
16
+ /**
17
+ * @param {TypeCheckedUserFunc} props
18
+ * @param {boolean} [unsafe]
19
+ * @returns {string}
20
+ */
21
+ export function genUserFuncArgsType(props: TypeCheckedUserFunc, unsafe?: boolean | undefined): string;
22
+ /**
23
+ * @param {TypeCheckedUserFunc} fn
24
+ * @returns {[string, string]}
25
+ */
26
+ export function genFuncType(fn: TypeCheckedUserFunc): [string, string];
10
27
  import type { LoadedScriptsWriter } from "../index.js";
28
+ import type { TypeCheckedUserFunc } from "../index.js";
11
29
  //# sourceMappingURL=LoadedScriptsWriter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"LoadedScriptsWriter.d.ts","sourceRoot":"","sources":["../../src/codegen/LoadedScriptsWriter.js"],"names":[],"mappings":"AAIA;;;GAGG;AAEH;;;GAGG;AACH,2CAFa,mBAAmB,CAI/B;yCATqG,aAAa"}
1
+ {"version":3,"file":"LoadedScriptsWriter.d.ts","sourceRoot":"","sources":["../../src/codegen/LoadedScriptsWriter.js"],"names":[],"mappings":"AAIA;;;GAGG;AAEH;;;GAGG;AACH,2CAFa,mBAAmB,CAI/B;AAsXD;;;;GAIG;AACH,0CAJW,mBAAmB,WACnB,OAAO,GACL,MAAM,CAUlB;AAED;;;;GAIG;AACH,2CAJW,mBAAmB,iCAEjB,MAAM,CAyBlB;AAED;;;GAGG;AACH,gCAHW,mBAAmB,GACjB,CAAC,MAAM,EAAE,MAAM,CAAC,CAI5B;yCAlbqG,aAAa;yCAAb,aAAa"}
@@ -4,5 +4,10 @@
4
4
  * @returns {[string, string]} - the first entry is the strict canonical type, the second is the permissive type
5
5
  */
6
6
  export function genTypes(schema: TypeSchema): [string, string];
7
+ /**
8
+ * @param {TypeSchema} schema
9
+ * @returns {Map<string, string>} - key=name, value=from
10
+ */
11
+ export function collectBuiltinTypes(schema: TypeSchema): Map<string, string>;
7
12
  import type { TypeSchema } from "@helios-lang/type-utils";
8
13
  //# sourceMappingURL=TypeSchema.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"TypeSchema.d.ts","sourceRoot":"","sources":["../../src/codegen/TypeSchema.js"],"names":[],"mappings":"AAMA;;;;GAIG;AAGH,iCALW,UAAU,GACR,CAAC,MAAM,EAAE,MAAM,CAAC,CA8J5B;gCAtK8B,yBAAyB"}
1
+ {"version":3,"file":"TypeSchema.d.ts","sourceRoot":"","sources":["../../src/codegen/TypeSchema.js"],"names":[],"mappings":"AAMA;;;;GAIG;AAGH,iCALW,UAAU,GACR,CAAC,MAAM,EAAE,MAAM,CAAC,CA8J5B;AAED;;;GAGG;AACH,4CAHW,UAAU,GACR,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAW/B;gCArL8B,yBAAyB"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @import { StringWriter } from "@helios-lang/codec-utils"
3
+ * @import { MintingPolicyHash, ScriptHash, StakingValidatorHash } from "@helios-lang/ledger"
4
+ * @import { UplcProgram } from "@helios-lang/uplc"
5
+ * @import { Cast, CastConfig, ContractContext, FileSystem, UserFunc, WriteContractContextArtifactsOptions } from "../index.js"
6
+ */
7
+ /**
8
+ * @typedef {(uplc: UplcProgram, config: CastConfig) => UserFunc<any, any>} FunctionDetails
9
+ */
10
+ /**
11
+ * @typedef {Cast<any, any>} TypeDetails
12
+ */
13
+ /**
14
+ * @typedef {Record<string, FunctionDetails | TypeDetails>} ModuleSymbols
15
+ */
16
+ /**
17
+ * @param {ContractContext<any, any>} context
18
+ * @param {WriteContractContextArtifactsOptions} options - not optional, at least the fs and outDir must be specified
19
+ */
20
+ export function writeContractContextArtifacts(context: ContractContext<any, any>, options: WriteContractContextArtifactsOptions): void;
21
+ export type FunctionDetails = (uplc: UplcProgram, config: CastConfig) => UserFunc<any, any>;
22
+ export type TypeDetails = Cast<any, any>;
23
+ export type ModuleSymbols = Record<string, FunctionDetails | TypeDetails>;
24
+ import type { ContractContext } from "../index.js";
25
+ import type { WriteContractContextArtifactsOptions } from "../index.js";
26
+ import type { UplcProgram } from "@helios-lang/uplc";
27
+ import type { CastConfig } from "../index.js";
28
+ import type { UserFunc } from "../index.js";
29
+ import type { Cast } from "../index.js";
30
+ //# sourceMappingURL=writeContractContextArtifacts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"writeContractContextArtifacts.d.ts","sourceRoot":"","sources":["../../src/context/writeContractContextArtifacts.js"],"names":[],"mappings":"AAEA;;;;;GAKG;AAEH;;GAEG;AAEH;;GAEG;AAEH;;GAEG;AAEH;;;GAGG;AACH,uDAHW,gBAAgB,GAAG,EAAE,GAAG,CAAC,WACzB,oCAAoC,QAqB9C;8BAlCY,CAAC,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,KAAK,SAAS,GAAG,EAAE,GAAG,CAAC;0BAI7D,KAAK,GAAG,EAAE,GAAG,CAAC;4BAId,MAAM,CAAC,MAAM,EAAE,eAAe,GAAG,WAAW,CAAC;qCAZwD,aAAa;0DAAb,aAAa;iCAD/F,mBAAmB;gCAC+D,aAAa;8BAAb,aAAa;0BAAb,aAAa"}
@@ -1 +1 @@
1
- {"version":3,"file":"hl2ts.d.ts","sourceRoot":"","sources":["../src/hl2ts.js"],"names":[],"mappings":";4BAoBa;IACR,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,UAAU,EAAE,MAAM,CAAA;CACnB;yBAIS,YAAY,GAAG,YAAY"}
1
+ {"version":3,"file":"hl2ts.d.ts","sourceRoot":"","sources":["../src/hl2ts.js"],"names":[],"mappings":";4BAgBa;IACR,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,UAAU,EAAE,MAAM,CAAA;CACnB;yBAIS,YAAY,GAAG,YAAY"}