@helios-lang/contract-utils 0.2.82 → 0.3.1

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 (68) hide show
  1. package/package.json +7 -7
  2. package/src/cast/Cast.js +149 -140
  3. package/src/cast/UserFunc.js +39 -50
  4. package/src/cast/index.js +2 -29
  5. package/src/codegen/LoadedScriptsWriter.js +55 -55
  6. package/src/codegen/TypeSchema.js +6 -14
  7. package/src/codegen/index.js +1 -14
  8. package/src/compiler/CompilerLib.js +1 -80
  9. package/src/compiler/CompilerLib_v0_16.js +15 -15
  10. package/src/compiler/CompilerLib_v0_17.js +26 -24
  11. package/src/compiler/index.js +0 -5
  12. package/src/compiler/ops.js +5 -7
  13. package/src/context/CacheEntry.js +86 -64
  14. package/src/context/ContractContextBuilder.js +37 -57
  15. package/src/context/ContractContextCache.js +8 -9
  16. package/src/context/DagCompiler.js +25 -21
  17. package/src/context/index.js +1 -7
  18. package/src/context/set-fs-build-cache.js +1 -0
  19. package/src/hl2ts.js +3 -6
  20. package/src/index.js +356 -9
  21. package/types/cast/Cast.d.ts +17 -103
  22. package/types/cast/Cast.d.ts.map +1 -1
  23. package/types/cast/UserFunc.d.ts +11 -94
  24. package/types/cast/UserFunc.d.ts.map +1 -1
  25. package/types/cast/index.d.ts +2 -9
  26. package/types/cast/index.d.ts.map +1 -1
  27. package/types/codegen/LoadedScriptsWriter.d.ts +8 -83
  28. package/types/codegen/LoadedScriptsWriter.d.ts.map +1 -1
  29. package/types/codegen/TypeCheckedValidator.d.ts +1 -1
  30. package/types/codegen/TypeCheckedValidator.d.ts.map +1 -1
  31. package/types/codegen/TypeSchema.d.ts +1 -1
  32. package/types/codegen/TypeSchema.d.ts.map +1 -1
  33. package/types/codegen/index.d.ts +1 -7
  34. package/types/codegen/index.d.ts.map +1 -1
  35. package/types/compiler/CompilerLib.d.ts +3 -138
  36. package/types/compiler/CompilerLib.d.ts.map +1 -1
  37. package/types/compiler/CompilerLib_v0_16.d.ts +8 -118
  38. package/types/compiler/CompilerLib_v0_16.d.ts.map +1 -1
  39. package/types/compiler/CompilerLib_v0_17.d.ts +14 -54
  40. package/types/compiler/CompilerLib_v0_17.d.ts.map +1 -1
  41. package/types/compiler/index.d.ts +0 -2
  42. package/types/compiler/index.d.ts.map +1 -1
  43. package/types/compiler/ops.d.ts +2 -2
  44. package/types/compiler/ops.d.ts.map +1 -1
  45. package/types/context/CacheEntry.d.ts +9 -22
  46. package/types/context/CacheEntry.d.ts.map +1 -1
  47. package/types/context/ContractContext.d.ts +8 -8
  48. package/types/context/ContractContext.d.ts.map +1 -1
  49. package/types/context/ContractContextBuilder.d.ts +5 -100
  50. package/types/context/ContractContextBuilder.d.ts.map +1 -1
  51. package/types/context/ContractContextCache.d.ts +11 -12
  52. package/types/context/ContractContextCache.d.ts.map +1 -1
  53. package/types/context/DagCompiler.d.ts +12 -16
  54. package/types/context/DagCompiler.d.ts.map +1 -1
  55. package/types/context/index.d.ts +1 -6
  56. package/types/context/index.d.ts.map +1 -1
  57. package/types/context/set-fs-build-cache.d.ts.map +1 -1
  58. package/types/hl2ts.d.ts +0 -3
  59. package/types/hl2ts.d.ts.map +1 -1
  60. package/types/index.d.ts +285 -9
  61. package/types/index.d.ts.map +1 -1
  62. package/src/cast/PermissiveType.js +0 -18
  63. package/src/cast/StrictType.js +0 -18
  64. package/src/codegen/LoadedModule.js +0 -23
  65. package/src/codegen/LoadedValidator.js +0 -52
  66. package/src/codegen/TypeCheckedModule.js +0 -31
  67. package/src/codegen/TypeCheckedValidator.js +0 -15
  68. package/src/context/ContractContext.js +0 -130
@@ -1,21 +1,19 @@
1
1
  import { bytesToHex } from "@helios-lang/codec-utils"
2
2
  import {
3
- MintingPolicyHash,
4
- ScriptHash,
5
- StakingValidatorHash,
6
- ValidatorHash
3
+ makeMintingPolicyHash,
4
+ makeStakingValidatorHash,
5
+ makeValidatorHash
7
6
  } from "@helios-lang/ledger"
8
- import { None, expectSome, isSome } from "@helios-lang/type-utils"
7
+ import {
8
+ expectDefined as expectSome,
9
+ isDefined as isSome
10
+ } from "@helios-lang/type-utils"
9
11
  import { restoreUplcProgram } from "@helios-lang/uplc"
10
12
  import { configureCast } from "../cast/index.js"
11
13
 
12
14
  /**
13
- * @typedef {import("@helios-lang/uplc").UplcData} UplcData
14
- * @typedef {import("@helios-lang/uplc").UplcProgram} UplcProgram
15
- * @typedef {import("../cast/index.js").CastConfig} CastConfig
16
- * @typedef {import("../codegen/LoadedValidator.js").LoadedValidator} LoadedValidator
17
- * @typedef {import("../compiler/index.js").CompilerLib} CompilerLib
18
- * @typedef {import("./ContractContext.js").AnyContractValidatorContext} AnyContractValidatorContext
15
+ * @import { UplcData, UplcProgram, UplcProgramV2 } from "@helios-lang/uplc"
16
+ * @import { AnyContractValidatorContext, CastConfig, CompilerLib, LoadedValidator} from "../index.js"
19
17
  */
20
18
 
21
19
  /**
@@ -79,10 +77,10 @@ export class DagCompiler {
79
77
  * @param {LoadedValidator[]} validators
80
78
  * @param {Record<string, UplcData>} parameters
81
79
  * @param {boolean} isTestnet
82
- * @param {Option<{[name: string]: string}>} expectedHashes
80
+ * @param {{[name: string]: string} | undefined} expectedHashes
83
81
  * @returns {DagCompilerOutput}
84
82
  */
85
- build(validators, parameters, isTestnet, expectedHashes = None) {
83
+ build(validators, parameters, isTestnet, expectedHashes = undefined) {
86
84
  const hashTypes = this.getHashTypes(validators)
87
85
  const validatorIndices = this.getValidatorIndices(validators)
88
86
 
@@ -169,7 +167,12 @@ export class DagCompiler {
169
167
  this.cachedValidators[validator.$name]
170
168
  )
171
169
  const optimizedHashHex = optimizedHash.toHex()
172
- const optimizedProgram = optimizedHash.context.program
170
+
171
+ /**
172
+ * @type {UplcProgramV2}
173
+ */
174
+ const optimizedProgram = /** @type {any} */ (optimizedHash.context)
175
+ .program
173
176
 
174
177
  // unoptimized compilation (so traces are untouched)
175
178
  const {
@@ -281,21 +284,22 @@ export class DagCompiler {
281
284
 
282
285
  switch (validator.$purpose) {
283
286
  case "spending":
284
- this.cachedValidators[name] = new ValidatorHash(hash, {
287
+ this.cachedValidators[name] = makeValidatorHash(hash, {
285
288
  program,
286
289
  redeemer,
287
290
  datum: configureCast(validator.$Datum, this.config)
288
291
  })
289
292
  break
290
293
  case "mixed":
291
- this.cachedValidators[name] = new ScriptHash(hash, {
294
+ throw new Error("not yet implemented")
295
+ /*this.cachedValidators[name] = new ScriptHash(hash, {
292
296
  program,
293
297
  redeemer,
294
298
  datum: configureCast(validator.$Datum, this.config)
295
- })
299
+ })*/
296
300
  break
297
301
  case "minting":
298
- this.cachedValidators[name] = new MintingPolicyHash(hash, {
302
+ this.cachedValidators[name] = makeMintingPolicyHash(hash, {
299
303
  program,
300
304
  redeemer
301
305
  })
@@ -303,7 +307,7 @@ export class DagCompiler {
303
307
  case "certifying":
304
308
  case "rewarding":
305
309
  case "staking":
306
- this.cachedValidators[name] = new StakingValidatorHash(hash, {
310
+ this.cachedValidators[name] = makeStakingValidatorHash(hash, {
307
311
  program,
308
312
  redeemer
309
313
  })
@@ -385,7 +389,7 @@ export class DagCompiler {
385
389
  * If any $currentScriptIndex is missing, None is returned
386
390
  * @private
387
391
  * @param {LoadedValidator[]} validators
388
- * @returns {Option<Record<string, number>>}
392
+ * @returns {Record<string, number> | undefined}
389
393
  */
390
394
  getValidatorIndices(validators) {
391
395
  /**
@@ -397,7 +401,7 @@ export class DagCompiler {
397
401
  if (isSome(v.$currentScriptIndex)) {
398
402
  res[v.$name] = v.$currentScriptIndex
399
403
  } else {
400
- return None
404
+ return undefined
401
405
  }
402
406
  }
403
407
 
@@ -1,8 +1,2 @@
1
- export { ContractContextBuilder } from "./ContractContextBuilder.js"
1
+ export { makeContractContextBuilder } from "./ContractContextBuilder.js"
2
2
  export { contractContextCache } from "./ContractContextCache.js"
3
-
4
- /**
5
- * @template {{[name: string]: import("../codegen/index.js").LoadedValidator}} Vs
6
- * @template {{[name: string]: import("../codegen/index.js").LoadedModule}} Ms
7
- * @typedef {import("./ContractContext.js").ContractContext<Vs, Ms>} ContractContext
8
- */
@@ -4,6 +4,7 @@ import * as path from "node:path"
4
4
  import { contractContextCache } from "./ContractContextCache.js"
5
5
 
6
6
  /**
7
+ * @import { JsonSafe } from "@helios-lang/type-utils"
7
8
  * @typedef {import("./ContractContextCache.js").ExplicitCache} ExplicitCache
8
9
  */
9
10
 
package/src/hl2ts.js CHANGED
@@ -9,15 +9,12 @@ import {
9
9
  } from "node:fs"
10
10
  import { dirname, join, resolve } from "node:path"
11
11
  import { Cli, EnumOpt, StringOpt } from "@helios-lang/cli-utils"
12
- import { None } from "@helios-lang/type-utils"
13
- import { LoadedScriptsWriter } from "./codegen/index.js"
12
+ import { makeLoadedScriptsWriter } from "./codegen/index.js"
14
13
  import { loadCompilerLib } from "./compiler/index.js"
15
14
  import { typeCheckFiles } from "./compiler/ops.js"
16
15
 
17
16
  /**
18
- * @typedef {import("./compiler/CompilerLib.js").CompilerLib} CompilerLib
19
- * @typedef {import("./compiler/CompilerLib.js").TypeCheckedModule} ModuleDetails
20
- * @typedef {import("./compiler/CompilerLib.js").TypeCheckedValidator} ValidatorDetails
17
+ * @import { CompilerLib, TypeCheckedModule, TypeCheckedValidator } from "./index.js"
21
18
  */
22
19
 
23
20
  /**
@@ -90,7 +87,7 @@ async function mainInternal(_args, { outDir, format }) {
90
87
  resolve(join(dirname(current), rel))
91
88
  )
92
89
 
93
- const [js, dts, ts] = LoadedScriptsWriter.new()
90
+ const [js, dts, ts] = makeLoadedScriptsWriter()
94
91
  .writeModules(modules)
95
92
  .writeValidators(validators)
96
93
  .finalize()
package/src/index.js CHANGED
@@ -1,24 +1,371 @@
1
- export * from "./cast/index.js"
1
+ export { makeCast, makeUserFunc } from "./cast/index.js"
2
2
  export {
3
- ContractContextBuilder,
3
+ makeContractContextBuilder,
4
4
  contractContextCache
5
5
  } from "./context/index.js"
6
6
  export { typeCheckFiles, typeCheckScripts } from "./compiler/ops.js"
7
- export { LoadedScriptsWriter } from "./codegen/LoadedScriptsWriter.js"
7
+ export { makeLoadedScriptsWriter } from "./codegen/index.js"
8
8
  export { loadCompilerLib } from "./compiler/ops.js"
9
9
 
10
+ export { genTypes } from "./codegen/TypeSchema.js"
10
11
  /**
11
- * @typedef {import("./codegen/index.js").LoadedValidator} LoadedValidator
12
- * @typedef {import("./codegen/index.js").LoadedModule} LoadedModule
12
+ * @import { MintingContext, MintingPolicyHash, ScriptHash, SpendingContext, StakingContext, StakingValidatorHash, ValidatorHash } from "@helios-lang/ledger"
13
+ * @import { TypeSchema } from "@helios-lang/type-utils"
14
+ * @import { CekResult, PlutusVersion, UplcData, UplcLogger, UplcProgram, UplcSourceMapJsonSafe } from "@helios-lang/uplc"
13
15
  */
14
16
 
15
17
  /**
16
- * @template {{[name: string]: import("./codegen/index.js").LoadedValidator}} Vs
17
- * @template {{[name: string]: import("./codegen/index.js").LoadedModule}} Ms
18
- * @typedef {import("./context/index.js").ContractContext<Vs, Ms>} ContractContext
18
+ * `returns` is optional to accomodate main functions that return undefined
19
+ * @typedef {{
20
+ * name: string
21
+ * requiresScriptContext: boolean
22
+ * requiresCurrentScript: boolean
23
+ * arguments: {
24
+ * name: string
25
+ * type: TypeSchema
26
+ * isOptional: boolean
27
+ * }[]
28
+ * returns?: TypeSchema
29
+ * }} TypeCheckedUserFunc
30
+ */
31
+
32
+ /**
33
+ * @typedef {{
34
+ * name: string
35
+ * purpose: string
36
+ * sourceCode: string
37
+ * moduleDepedencies: string[]
38
+ * types: Record<string, TypeSchema>
39
+ * functions?: Record<string, TypeCheckedUserFunc>
40
+ * }} TypeCheckedModule
41
+ */
42
+
43
+ /**
44
+ * @typedef {TypeCheckedModule & {
45
+ * hashDependencies: string[]
46
+ * currentScriptIndex?: number
47
+ * Redeemer: TypeSchema
48
+ * Datum?: TypeSchema
49
+ * }} TypeCheckedValidator
50
+ */
51
+
52
+ /**
53
+ * @typedef {any} ScriptHashType
54
+ */
55
+
56
+ /**
57
+ * if `debug` is true, the ir is included in the user functions where possible
58
+ * @typedef {{
59
+ * allValidatorHashTypes: Record<string, ScriptHashType>
60
+ * allValidatorIndices?: Record<string, number>
61
+ * hashDependencies: Record<string, string>
62
+ * dependsOnOwnHash?: boolean
63
+ * ownHash?: string
64
+ * parameters?: Record<string, UplcData>
65
+ * isTestnet: boolean
66
+ * optimize: boolean
67
+ * debug?: boolean
68
+ * excludeUserFuncs?: Set<string>
69
+ * onCompileUserFunc?: (props: {
70
+ * name: string
71
+ * cborHex: string
72
+ * plutusVersion: PlutusVersion
73
+ * ir?: string
74
+ * sourceMap?: UplcSourceMapJsonSafe
75
+ * alt?: {
76
+ * cborHex: string
77
+ * ir?: string
78
+ * sourceMap?: UplcSourceMapJsonSafe
79
+ * }
80
+ * }) => void
81
+ * }} CompileOptions
82
+ */
83
+
84
+ /**
85
+ * @typedef {{
86
+ * cborHex: string
87
+ * plutusVersion: PlutusVersion
88
+ * ir?: string
89
+ * sourceMap?: import("@helios-lang/uplc").UplcSourceMapJsonSafe
90
+ * }} CompileOutput
91
+ */
92
+
93
+ /**
94
+ * @typedef {{
95
+ * modules: {[name: string]: TypeCheckedModule}
96
+ * validators: {[name: string]: TypeCheckedValidator}
97
+ * }} TypeCheckOutput
98
+ */
99
+
100
+ /**
101
+ * @typedef {{
102
+ * name: string
103
+ * purpose: string
104
+ * sourceCode: string
105
+ * }} SourceDetails
106
+ */
107
+
108
+ /**
109
+ * @typedef {{
110
+ * version: string
111
+ * getScriptHashType: (purpose: string) => ScriptHashType
112
+ * typeCheck: (validators: string[], modules: string[]) => ({
113
+ * modules: {[name: string]: TypeCheckedModule},
114
+ * validators: {[name: string]: TypeCheckedValidator}
115
+ * })
116
+ * compile: (main: string, modules: string[], options: CompileOptions) => CompileOutput
117
+ * }} CompilerLib
118
+ */
119
+
120
+ /**
121
+ * @typedef {Record<string, string[]>} DagDependencies
122
+ */
123
+
124
+ /**
125
+ * @typedef {{
126
+ * isMainnet: boolean
127
+ * }} CastConfig
128
+ */
129
+
130
+ /**
131
+ * @template TStrict
132
+ * @template TPermissive
133
+ * @typedef {object} Cast
134
+ * @prop {"Cast"} kind
135
+ * @prop {TypeSchema} schema
136
+ * @prop {CastConfig} config
137
+ * @prop {(data: UplcData, dataPath?: string) => TStrict} fromUplcData
138
+ *
139
+ * @prop {(x: TPermissive, dataPath?: string) => UplcData} toUplcData
140
+ * converts javascript object to UPLC data, according to the schema.
141
+ * The optional `dataPath` parameter can provide a contextual cue for the
142
+ * data-conversion process, and will be displayed as part of any error messages
143
+ * thrown during the data transformation
144
+ */
145
+
146
+ /**
147
+ * @template TStrict
148
+ * @template TPermissive
149
+ * @typedef {(config: CastConfig) => Cast<TStrict, TPermissive>} ConfigurableCast
150
+ */
151
+
152
+ /**
153
+ * StrictType and PermissiveType work for both Cast and ConfigurableCast
154
+ * @template TStrict
155
+ * @template TPermissive
156
+ * @typedef {Cast<TStrict, TPermissive> | ConfigurableCast<TStrict, TPermissive>} CastLike
157
+ */
158
+
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
+ /**
173
+ * TODO: add logOptions here as well (which can be overridden by logOptions passed directly to eval(), evalUnsafe() and profile())?
174
+ * `returns` is optional to accomodate main functions that return void
175
+ * @typedef {{
176
+ * name: string
177
+ * requiresScriptContext: boolean
178
+ * requiresCurrentScript: boolean
179
+ * arguments: {
180
+ * name: string
181
+ * type: TypeSchema
182
+ * isOptional: boolean
183
+ * }[]
184
+ * returns?: TypeSchema
185
+ * validatorIndices?: Record<string, number>
186
+ * castConfig: CastConfig
187
+ * }} UserFuncProps
188
+ */
189
+
190
+ /**
191
+ * @template ArgsT
192
+ * @typedef {{[K in keyof ArgsT]: K extends "$currentScript" ? string : UplcData}} UnsafeArgsT
193
+ */
194
+
195
+ /**
196
+ * @template {{[argName: string]: any}} ArgsT
197
+ * @template RetT
198
+ * @typedef {object} UserFunc
199
+ * @prop {UplcProgram} uplc
200
+ * @prop {string} name
201
+ * @prop {(namedArgs: ArgsT, logOptions?: UplcLogger | undefined) => RetT} eval
202
+ * @prop {(namedArgs: UnsafeArgsT<ArgsT>, logOptions?: UplcLogger | undefined) => RetT extends void ? void : UplcData} evalUnsafe
203
+ * @prop {(namedArgs: UnsafeArgsT<ArgsT>, logOptions?: UplcLogger | undefined) => CekResult} profile
204
+ */
205
+
206
+ /**
207
+ * @typedef {{
208
+ * $name: string
209
+ * $purpose: "module"
210
+ * $sourceCode: string
211
+ * $dependencies: ReadonlyArray<LoadedModule>
212
+ * $types: {[name: string]: CastLike<any, any>}
213
+ * $functions: {[name: string]: (uplc: UplcProgram, config: CastConfig) => UserFunc<any, any>}
214
+ * }} LoadedModule
215
+ */
216
+
217
+ /**
218
+ * * Note: `$hashDependencies` doesn't contain the indirect dependencies! It must be kept to a minimum in order to inform in which order the validators must be compiled
219
+ * @typedef {{
220
+ * $name: string
221
+ * $sourceCode: string
222
+ * $dependencies: ReadonlyArray<LoadedModule>
223
+ * $hashDependencies: ReadonlyArray<LoadedValidator>
224
+ * $currentScriptIndex?: number
225
+ * $dependsOnOwnHash: boolean
226
+ * $types: {[name: string]: CastLike<any, any>}
227
+ * $functions: {[name: string]: (uplc: UplcProgram, config: CastConfig) => UserFunc<any, any>}
228
+ * $Redeemer: CastLike<any, any>
229
+ * } & (
230
+ * {
231
+ * $purpose: "spending" | "mixed"
232
+ * $Datum: CastLike<any, any>
233
+ * } | {
234
+ * $purpose: "minting" | "certifying" | "rewarding" | "staking"
235
+ * }
236
+ * )} LoadedValidator
237
+ */
238
+
239
+ /**
240
+ * @template {{$name: string}} N
241
+ * @typedef {{
242
+ * [name in N["$name"]]: Extract<N, {"$name": name}>
243
+ * }} NamedDependencyToObject
244
+ */
245
+
246
+ /**
247
+ * @template {ReadonlyArray<{$name: string}>} N
248
+ * @typedef {NamedDependencyToObject<N extends ReadonlyArray<infer M> ? M : never>} NamedDependenciesToObject
249
+ */
250
+
251
+ /**
252
+ * @template {LoadedValidator} V
253
+ * @typedef {NamedDependenciesToObject<V["$dependencies"]>} ExtractDependencies
254
+ */
255
+
256
+ /**
257
+ * @template {CastLike<any, any>} C
258
+ * @typedef {C extends CastLike<any, infer TPermissive> ? TPermissive : never} PermissiveType
259
+ */
260
+
261
+ /**
262
+ * @template {CastLike<any, any>} C
263
+ * @typedef {C extends CastLike<infer TStrict, any> ? TStrict : never} StrictType
264
+ */
265
+
266
+ /**
267
+ * @typedef {(
268
+ * ValidatorHash<SpendingContext<any, any, any, any>> |
269
+ * MintingPolicyHash<MintingContext<any, any>> |
270
+ * StakingValidatorHash<StakingContext<any, any>> |
271
+ * ScriptHash
272
+ * )} AnyContractValidatorContext
19
273
  */
20
274
 
21
275
  /**
22
276
  * @template {LoadedValidator} V
23
- * @typedef {import("./codegen/index.js").ExtractDependencies<V>} ExtractDependencies
277
+ * @typedef {V extends {"$purpose": "spending", "$Datum": CastLike<any, any>, "$Redeemer": CastLike<any, any>} ? {
278
+ * $hash: ValidatorHash<
279
+ * SpendingContext<
280
+ * StrictType<V["$Datum"]>,
281
+ * PermissiveType<V["$Datum"]>,
282
+ * StrictType<V["$Redeemer"]>,
283
+ * PermissiveType<V["$Redeemer"]>
284
+ * >
285
+ * >
286
+ * } & ContractTypesContext<V["$types"]> & ContractUserFuncsContext<V["$functions"]> :
287
+ * V extends {"$purpose": "minting", "$Redeemer": CastLike<any, any>} ? {
288
+ * $hash: MintingPolicyHash<
289
+ * MintingContext<
290
+ * StrictType<V["$Redeemer"]>,
291
+ * PermissiveType<V["$Redeemer"]>
292
+ * >
293
+ * >
294
+ * } & ContractTypesContext<V["$types"]> & ContractUserFuncsContext<V["$functions"]> :
295
+ * V extends {"$purpose": ("certifying" | "rewarding" | "staking"), "$Redeemer": CastLike<any, any>} ? {
296
+ * $hash: StakingValidatorHash<
297
+ * StakingContext<
298
+ * StrictType<V["$Redeemer"]>,
299
+ * PermissiveType<V["$Redeemer"]>
300
+ * >
301
+ * >
302
+ * } & ContractTypesContext<V["$types"]> & ContractUserFuncsContext<V["$functions"]> :
303
+ * V extends {"$purpose": "mixed", "$Datum": CastLike<any, any>, "$Redeemer": CastLike<any, any>} ? {
304
+ * $hash: ScriptHash<
305
+ * SpendingContext<
306
+ * StrictType<V["$Datum"]>,
307
+ * PermissiveType<V["$Datum"]>,
308
+ * StrictType<V["$Redeemer"]>,
309
+ * PermissiveType<V["$Redeemer"]>
310
+ * >
311
+ * >
312
+ * } & ContractTypesContext<V["$types"]> & ContractUserFuncsContext<V["$functions"]> :
313
+ * never
314
+ * } ContractValidatorContexts
315
+ */
316
+
317
+ /**
318
+ * @template {LoadedModule} V
319
+ * @typedef {ContractTypesContext<V["$types"]> & ContractUserFuncsContext<V["$functions"]>} ContractModuleContexts
320
+ */
321
+
322
+ /**
323
+ * @template {{[typeName: string]: CastLike<any, any>}} T
324
+ * @typedef {{
325
+ * [K in keyof T]: Cast<StrictType<T[K]>, PermissiveType<T[K]>>
326
+ * }} ContractTypesContext
327
+ */
328
+
329
+ /**
330
+ * @template {{[funcName: string]: (uplc: UplcProgram, config: CastConfig) => UserFunc<any, any>}} T
331
+ * @typedef {{
332
+ * [K in keyof T]: ReturnType<T[K]>
333
+ * }} ContractUserFuncsContext
334
+ */
335
+
336
+ /**
337
+ * @template {{[name: string]: LoadedValidator}} Vs
338
+ * @template {{[name: string]: LoadedModule}} Ms
339
+ * @typedef {{
340
+ * [K in keyof Vs]: ContractValidatorContexts<Vs[K]>
341
+ * } & {
342
+ * [K in keyof Ms]: ContractModuleContexts<Ms[K]>
343
+ * }} ContractContext
344
+ */
345
+
346
+ /**
347
+ * if `debug` is true, the ir is included where possible
348
+ * @typedef {{
349
+ * isMainnet: boolean
350
+ * expectedHashes?: {[name: string]: string}
351
+ * parameters?: Record<string, UplcData>
352
+ * dumpHashes?: boolean
353
+ * debug?: boolean
354
+ * }} ContractContextBuilderProps
355
+ */
356
+
357
+ /**
358
+ * @typedef {object} LoadedScriptsWriter
359
+ * @prop {(modules: Record<string, TypeCheckedModule>) => LoadedScriptsWriter} writeModules
360
+ * @prop {(validators: Record<string, TypeCheckedValidator>) => LoadedScriptsWriter} writeValidators
361
+ * @prop {() => [string, string, string]} finalize
362
+ */
363
+
364
+ /**
365
+ * @template {{[name: string]: LoadedValidator}} Vs
366
+ * @template {{[name: string]: LoadedModule}} Ms
367
+ * @typedef {object} ContractContextBuilder
368
+ * @prop {<V extends LoadedValidator>(validator: V) => ContractContextBuilder<Vs & {[K in V["$name"]]: V}, Ms & ExtractDependencies<V>>} with
369
+ * @prop {<M extends LoadedModule>(m: M) => ContractContextBuilder<Vs, Ms & {[K in M["$name"]]: M}>} withModule
370
+ * @prop {(props: ContractContextBuilderProps) => ContractContext<Vs, Ms>} build
24
371
  */
@@ -1,113 +1,27 @@
1
1
  /**
2
- * @template TStrict
3
- * @template TPermissive
4
- * @param {CastLike<TStrict, TPermissive>} cast
5
- * @param {CastConfig} config
6
- * @returns {Cast<TStrict, TPermissive>}
7
- */
8
- export function configureCast<TStrict, TPermissive>(cast: CastLike<TStrict, TPermissive>, config: CastConfig): Cast<TStrict, TPermissive>;
9
- /**
10
- * @typedef {import("@helios-lang/uplc").UplcData} UplcData
11
- * @typedef {import("../codegen/index.js").TypeSchema} TypeSchema
12
- */
13
- /**
14
- * @typedef {{
15
- * isMainnet: boolean
16
- * }} CastConfig
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"
17
6
  */
18
7
  /**
19
8
  * @template TStrict
20
- * @template TPermissive
21
- * @typedef {(config: CastConfig) => Cast<TStrict, TPermissive>} ConfigurableCast
9
+ * @template TPermissive=TStrict
10
+ * @param {TypeSchema} schema
11
+ * @param {CastConfig} config
12
+ * @returns {Cast<TStrict, TPermissive>}
22
13
  */
14
+ export function makeCast<TStrict, TPermissive>(schema: TypeSchema, config: CastConfig): Cast<TStrict, TPermissive>;
23
15
  /**
24
- * StrictType and PermissiveType work for both Cast and ConfigurableCast
25
16
  * @template TStrict
26
17
  * @template TPermissive
27
- * @typedef {Cast<TStrict, TPermissive> | ConfigurableCast<TStrict, TPermissive>} CastLike
28
- */
29
- /**
30
- * @typedef {Object} SchemaToUplcContext
31
- * @property {Record<string, TypeSchema>} defs - symbol table permitting recursive schema references
32
- * @property {string} dataPath - provides developer-facing cues for any parsing errors, showing the deep field path of any error
33
- */
34
- /**
35
- * @typedef {Object} UplcToSchemaContext
36
- * @property {Record<string, TypeSchema>} defs - symbol table permitting recursive schema references
37
- * @property {string} dataPath - provides developer-facing cues for any parsing errors, showing the deep field path of any error
38
- * @property {CastConfig} config - has isMainnet indicator
39
- */
40
- /**
41
- * @template TStrict
42
- * @template TPermissive=TStrict
43
- */
44
- export class Cast<TStrict, TPermissive> {
45
- /**
46
- * @param {TypeSchema} schema
47
- * @param {CastConfig} config
48
- */
49
- constructor(schema: TypeSchema, config: CastConfig);
50
- /**
51
- * @readonly
52
- * @type {TypeSchema}
53
- */
54
- readonly schema: TypeSchema;
55
- /**
56
- * @readonly
57
- * @type {CastConfig}
58
- */
59
- readonly config: CastConfig;
60
- /**
61
- * @param {UplcData} data
62
- * @param {string} [dataPath] - can be used to indicate the kind or context of data-decoding
63
- * @returns {TStrict}
64
- */
65
- fromUplcData(data: UplcData, dataPath?: string | undefined): TStrict;
66
- /**
67
- * converts javascript object to UPLC data, according to the schema.
68
- * @remarks
69
- * The optional `dataPath` parameter can provide a contextual cue for the
70
- * data-conversion process, and will be displayed as part of any error messages
71
- * thrown during the data transformation
72
- *
73
- * @param {TPermissive} x
74
- * @param {string} dataPath
75
- * @returns {UplcData}
76
- */
77
- toUplcData(x: TPermissive, dataPath?: string): UplcData;
78
- }
79
- export type UplcData = import("@helios-lang/uplc").UplcData;
80
- export type TypeSchema = import("../codegen/index.js").TypeSchema;
81
- export type CastConfig = {
82
- isMainnet: boolean;
83
- };
84
- export type ConfigurableCast<TStrict, TPermissive> = (config: CastConfig) => Cast<TStrict, TPermissive>;
85
- /**
86
- * StrictType and PermissiveType work for both Cast and ConfigurableCast
18
+ * @param {CastLike<TStrict, TPermissive>} cast
19
+ * @param {CastConfig} config
20
+ * @returns {Cast<TStrict, TPermissive>}
87
21
  */
88
- export type CastLike<TStrict, TPermissive> = Cast<TStrict, TPermissive> | ConfigurableCast<TStrict, TPermissive>;
89
- export type SchemaToUplcContext = {
90
- /**
91
- * - symbol table permitting recursive schema references
92
- */
93
- defs: Record<string, TypeSchema>;
94
- /**
95
- * - provides developer-facing cues for any parsing errors, showing the deep field path of any error
96
- */
97
- dataPath: string;
98
- };
99
- export type UplcToSchemaContext = {
100
- /**
101
- * - symbol table permitting recursive schema references
102
- */
103
- defs: Record<string, TypeSchema>;
104
- /**
105
- * - provides developer-facing cues for any parsing errors, showing the deep field path of any error
106
- */
107
- dataPath: string;
108
- /**
109
- * - has isMainnet indicator
110
- */
111
- config: CastConfig;
112
- };
22
+ export function configureCast<TStrict, TPermissive>(cast: CastLike<TStrict, TPermissive>, config: CastConfig): Cast<TStrict, TPermissive>;
23
+ import type { TypeSchema } from "@helios-lang/type-utils";
24
+ import type { CastConfig } from "../index.js";
25
+ import type { Cast } from "../index.js";
26
+ import type { CastLike } from "../index.js";
113
27
  //# sourceMappingURL=Cast.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Cast.d.ts","sourceRoot":"","sources":["../../src/cast/Cast.js"],"names":[],"mappings":"AA0uBA;;;;;;GAMG;AACH,8BANa,OAAO,EACP,WAAW,QACb,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,UAC9B,UAAU,GACR,IAAI,CAAC,OAAO,EAAE,WAAW,CAAC,CAQtC;AAltBD;;;GAGG;AAEH;;;;GAIG;AAEH;;;;GAIG;AAEH;;;;;GAKG;AAEH;;;;GAIG;AAEH;;;;;GAKG;AAEH;;;GAGG;AACH,kBAHa,OAAO,EACP,WAAW;IAepB;;;OAGG;IACH,oBAHW,UAAU,UACV,UAAU,EAKpB;IAnBD;;;OAGG;IACH,iBAFU,UAAU,CAEd;IAEN;;;OAGG;IACH,iBAFU,UAAU,CAEd;IAWN;;;;OAIG;IACH,mBAJW,QAAQ,kCAEN,OAAO,CAQnB;IAED;;;;;;;;;;OAUG;IACH,cAJW,WAAW,aACX,MAAM,GACJ,QAAQ,CASpB;CACJ;uBA9FY,OAAO,mBAAmB,EAAE,QAAQ;yBACpC,OAAO,qBAAqB,EAAE,UAAU;yBAIxC;IACR,SAAS,EAAE,OAAO,CAAA;CACnB;6BAIS,OAAO,EACP,WAAW,IACX,CAAC,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC,OAAO,EAAE,WAAW,CAAC;;;;qBAKlD,OAAO,EACP,WAAW,IACX,IAAI,CAAC,OAAO,EAAE,WAAW,CAAC,GAAG,gBAAgB,CAAC,OAAO,EAAE,WAAW,CAAC;;;;;UAKlE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC;;;;cAC1B,MAAM;;;;;;UAKN,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC;;;;cAC1B,MAAM;;;;YACN,UAAU"}
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"}