@helios-lang/contract-utils 0.3.4 → 0.3.6

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 +315 -160
  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 +123 -0
  17. package/src/context/index.js +1 -0
  18. package/src/hl2ts.js +0 -4
  19. package/src/index.js +38 -21
  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 +77 -3
  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 +34 -28
  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
@@ -122,8 +131,10 @@ export { genTypes } from "./codegen/TypeSchema.js"
122
131
  */
123
132
 
124
133
  /**
134
+ * `unwrapSingleFieldEnumVariants` defaults to false. If true, the following enum variant data structure is used: `{VariantName: SingleFieldData}`, instead of the more verbose `{VariantName: {SingleFieldName: SingleFieldData}}`
125
135
  * @typedef {{
126
136
  * isMainnet: boolean
137
+ * unwrapSingleFieldEnumVariants?: boolean
127
138
  * }} CastConfig
128
139
  */
129
140
 
@@ -156,19 +167,6 @@ export { genTypes } from "./codegen/TypeSchema.js"
156
167
  * @typedef {Cast<TStrict, TPermissive> | ConfigurableCast<TStrict, TPermissive>} CastLike
157
168
  */
158
169
 
159
- /**
160
- * @typedef {Object} SchemaToUplcContext
161
- * @prop {Record<string, TypeSchema>} defs - symbol table permitting recursive schema references
162
- * @prop {string} dataPath - provides developer-facing cues for any parsing errors, showing the deep field path of any error
163
- */
164
-
165
- /**
166
- * @typedef {Object} UplcToSchemaContext
167
- * @prop {Record<string, TypeSchema>} defs - symbol table permitting recursive schema references
168
- * @prop {string} dataPath - provides developer-facing cues for any parsing errors, showing the deep field path of any error
169
- * @prop {CastConfig} config - has isMainnet indicator
170
- */
171
-
172
170
  /**
173
171
  * TODO: add logOptions here as well (which can be overridden by logOptions passed directly to eval(), evalUnsafe() and profile())?
174
172
  * `returns` is optional to accomodate main functions that return void
@@ -198,6 +196,7 @@ export { genTypes } from "./codegen/TypeSchema.js"
198
196
  * @typedef {object} UserFunc
199
197
  * @prop {UplcProgram} uplc
200
198
  * @prop {string} name
199
+ * @prop {UserFuncProps} props
201
200
  * @prop {(namedArgs: ArgsT, logOptions?: UplcLogger | undefined) => RetT} eval
202
201
  * @prop {(namedArgs: UnsafeArgsT<ArgsT>, logOptions?: UplcLogger | undefined) => RetT extends void ? void : UplcData} evalUnsafe
203
202
  * @prop {(namedArgs: UnsafeArgsT<ArgsT>, logOptions?: UplcLogger | undefined) => CekResult} profile
@@ -273,7 +272,7 @@ export { genTypes } from "./codegen/TypeSchema.js"
273
272
  */
274
273
 
275
274
  /**
276
- * @template {LoadedValidator} V
275
+ * @template {LoadedValidator} [V=LoadedValidator]
277
276
  * @typedef {V extends {"$purpose": "spending", "$Datum": CastLike<any, any>, "$Redeemer": CastLike<any, any>} ? {
278
277
  * $hash: ValidatorHash<
279
278
  * SpendingContext<
@@ -310,32 +309,34 @@ export { genTypes } from "./codegen/TypeSchema.js"
310
309
  * >
311
310
  * >
312
311
  * } & ContractTypesContext<V["$types"]> & ContractUserFuncsContext<V["$functions"]> :
313
- * never
312
+ * {
313
+ * $hash: ScriptHash<any>
314
+ * } & ContractTypesContext & ContractUserFuncsContext
314
315
  * } ContractValidatorContexts
315
316
  */
316
317
 
317
318
  /**
318
- * @template {LoadedModule} V
319
+ * @template {LoadedModule} [V=LoadedModule]
319
320
  * @typedef {ContractTypesContext<V["$types"]> & ContractUserFuncsContext<V["$functions"]>} ContractModuleContexts
320
321
  */
321
322
 
322
323
  /**
323
- * @template {{[typeName: string]: CastLike<any, any>}} T
324
+ * @template {{[typeName: string]: CastLike<any, any>}} [T={[typeName: string]: CastLike<any, any>}]
324
325
  * @typedef {{
325
326
  * [K in keyof T]: Cast<StrictType<T[K]>, PermissiveType<T[K]>>
326
327
  * }} ContractTypesContext
327
328
  */
328
329
 
329
330
  /**
330
- * @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>}]
331
332
  * @typedef {{
332
333
  * [K in keyof T]: ReturnType<T[K]>
333
334
  * }} ContractUserFuncsContext
334
335
  */
335
336
 
336
337
  /**
337
- * @template {{[name: string]: LoadedValidator}} Vs
338
- * @template {{[name: string]: LoadedModule}} Ms
338
+ * @template {{[name: string]: LoadedValidator}} [Vs={[name: string]: LoadedValidator}]
339
+ * @template {{[name: string]: LoadedModule}} [Ms={[name: string]: LoadedModule}]
339
340
  * @typedef {{
340
341
  * [K in keyof Vs]: ContractValidatorContexts<Vs[K]>
341
342
  * } & {
@@ -369,3 +370,19 @@ export { genTypes } from "./codegen/TypeSchema.js"
369
370
  * @prop {<M extends LoadedModule>(m: M) => ContractContextBuilder<Vs, Ms & {[K in M["$name"]]: M}>} withModule
370
371
  * @prop {(props: ContractContextBuilderProps) => ContractContext<Vs, Ms>} build
371
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"}
@@ -1,8 +1,21 @@
1
1
  /**
2
2
  * @import { TxInput, TxOutput } from "@helios-lang/ledger"
3
- * @import { TypeSchema } from "@helios-lang/type-utils"
4
- * @import { UplcData } from "@helios-lang/uplc"
5
- * @import { Cast, CastConfig, CastLike, SchemaToUplcContext, UplcToSchemaContext } from "../index.js"
3
+ * @import { EnumTypeSchema, TypeSchema } from "@helios-lang/type-utils"
4
+ * @import { ConstrData, UplcData } from "@helios-lang/uplc"
5
+ * @import { Cast, CastConfig, CastLike } from "../index.js"
6
+ */
7
+ /**
8
+ * @typedef {Object} SchemaToUplcContext
9
+ * @prop {Record<string, TypeSchema>} defs - symbol table permitting recursive schema references
10
+ * @prop {string} dataPath - provides developer-facing cues for any parsing errors, showing the deep field path of any error
11
+ * @prop {boolean} unwrapSingleFieldEnumVariants - defaults to false. If true, assumes the following input objects for enum variants: `{VariantName: SingleFieldData}`, instead of the more verbose `{VariantName: {SingleFieldName: SingleFieldData}}`
12
+ */
13
+ /**
14
+ * @typedef {Object} UplcToSchemaContext
15
+ * @prop {Record<string, TypeSchema>} defs - symbol table permitting recursive schema references
16
+ * @prop {string} dataPath - provides developer-facing cues for any parsing errors, showing the deep field path of any error
17
+ * @prop {boolean} unwrapSingleFieldEnumVariants - defaults to false. If true, the following enum variant outputs are created: `{VariantName: SingleFieldData}`, instead of the more verbose `{VariantName: {SingleFieldName: SingleFieldData}}`
18
+ * @prop {boolean} isMainnet
6
19
  */
7
20
  /**
8
21
  * @template TStrict
@@ -12,6 +25,36 @@
12
25
  * @returns {Cast<TStrict, TPermissive>}
13
26
  */
14
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;
15
58
  /**
16
59
  * @template TStrict
17
60
  * @template TPermissive
@@ -20,8 +63,39 @@ export function makeCast<TStrict, TPermissive>(schema: TypeSchema, config: CastC
20
63
  * @returns {Cast<TStrict, TPermissive>}
21
64
  */
22
65
  export function configureCast<TStrict, TPermissive>(cast: CastLike<TStrict, TPermissive>, config: CastConfig): Cast<TStrict, TPermissive>;
66
+ export type SchemaToUplcContext = {
67
+ /**
68
+ * - symbol table permitting recursive schema references
69
+ */
70
+ defs: Record<string, TypeSchema>;
71
+ /**
72
+ * - provides developer-facing cues for any parsing errors, showing the deep field path of any error
73
+ */
74
+ dataPath: string;
75
+ /**
76
+ * - defaults to false. If true, assumes the following input objects for enum variants: `{VariantName: SingleFieldData}`, instead of the more verbose `{VariantName: {SingleFieldName: SingleFieldData}}`
77
+ */
78
+ unwrapSingleFieldEnumVariants: boolean;
79
+ };
80
+ export type UplcToSchemaContext = {
81
+ /**
82
+ * - symbol table permitting recursive schema references
83
+ */
84
+ defs: Record<string, TypeSchema>;
85
+ /**
86
+ * - provides developer-facing cues for any parsing errors, showing the deep field path of any error
87
+ */
88
+ dataPath: string;
89
+ /**
90
+ * - defaults to false. If true, the following enum variant outputs are created: `{VariantName: SingleFieldData}`, instead of the more verbose `{VariantName: {SingleFieldName: SingleFieldData}}`
91
+ */
92
+ unwrapSingleFieldEnumVariants: boolean;
93
+ isMainnet: boolean;
94
+ };
23
95
  import type { TypeSchema } from "@helios-lang/type-utils";
24
96
  import type { CastConfig } from "../index.js";
25
97
  import type { Cast } from "../index.js";
98
+ import type { UplcData } from "@helios-lang/uplc";
26
99
  import type { CastLike } from "../index.js";
100
+ import type { TypeSchema as TypeSchema_1 } from "@helios-lang/type-utils";
27
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;;;;;;GAMG;AACH,yBANa,OAAO,EACP,WAAW,UACb,UAAU,UACV,UAAU,GACR,KAAK,OAAO,EAAE,WAAW,CAAC,CAItC;AA6qBD;;;;;;GAMG;AACH,8BANa,OAAO,EACP,WAAW,QACb,SAAS,OAAO,EAAE,WAAW,CAAC,UAC9B,UAAU,GACR,KAAK,OAAO,EAAE,WAAW,CAAC,CAQtC;gCAxsB8B,yBAAyB;gCAEiC,aAAa;0BAAb,aAAa;8BAAb,aAAa"}
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"}