@helios-lang/contract-utils 0.2.81 → 0.3.0

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 (66) hide show
  1. package/package.json +7 -7
  2. package/src/cast/Cast.js +149 -140
  3. package/src/cast/UserFunc.js +43 -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 +14 -14
  10. package/src/compiler/CompilerLib_v0_17.js +25 -23
  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 +5 -7
  16. package/src/context/DagCompiler.js +24 -20
  17. package/src/context/index.js +1 -7
  18. package/src/hl2ts.js +3 -6
  19. package/src/index.js +355 -9
  20. package/types/cast/Cast.d.ts +17 -103
  21. package/types/cast/Cast.d.ts.map +1 -1
  22. package/types/cast/UserFunc.d.ts +11 -94
  23. package/types/cast/UserFunc.d.ts.map +1 -1
  24. package/types/cast/index.d.ts +2 -9
  25. package/types/cast/index.d.ts.map +1 -1
  26. package/types/codegen/LoadedScriptsWriter.d.ts +8 -83
  27. package/types/codegen/LoadedScriptsWriter.d.ts.map +1 -1
  28. package/types/codegen/TypeCheckedValidator.d.ts +1 -1
  29. package/types/codegen/TypeCheckedValidator.d.ts.map +1 -1
  30. package/types/codegen/TypeSchema.d.ts +1 -1
  31. package/types/codegen/TypeSchema.d.ts.map +1 -1
  32. package/types/codegen/index.d.ts +1 -7
  33. package/types/codegen/index.d.ts.map +1 -1
  34. package/types/compiler/CompilerLib.d.ts +3 -138
  35. package/types/compiler/CompilerLib.d.ts.map +1 -1
  36. package/types/compiler/CompilerLib_v0_16.d.ts +8 -118
  37. package/types/compiler/CompilerLib_v0_16.d.ts.map +1 -1
  38. package/types/compiler/CompilerLib_v0_17.d.ts +12 -52
  39. package/types/compiler/CompilerLib_v0_17.d.ts.map +1 -1
  40. package/types/compiler/index.d.ts +0 -2
  41. package/types/compiler/index.d.ts.map +1 -1
  42. package/types/compiler/ops.d.ts +2 -2
  43. package/types/compiler/ops.d.ts.map +1 -1
  44. package/types/context/CacheEntry.d.ts +9 -22
  45. package/types/context/CacheEntry.d.ts.map +1 -1
  46. package/types/context/ContractContext.d.ts +8 -8
  47. package/types/context/ContractContext.d.ts.map +1 -1
  48. package/types/context/ContractContextBuilder.d.ts +5 -100
  49. package/types/context/ContractContextBuilder.d.ts.map +1 -1
  50. package/types/context/ContractContextCache.d.ts +5 -8
  51. package/types/context/ContractContextCache.d.ts.map +1 -1
  52. package/types/context/DagCompiler.d.ts +11 -15
  53. package/types/context/DagCompiler.d.ts.map +1 -1
  54. package/types/context/index.d.ts +1 -6
  55. package/types/context/index.d.ts.map +1 -1
  56. package/types/hl2ts.d.ts +0 -3
  57. package/types/hl2ts.d.ts.map +1 -1
  58. package/types/index.d.ts +284 -9
  59. package/types/index.d.ts.map +1 -1
  60. package/src/cast/PermissiveType.js +0 -18
  61. package/src/cast/StrictType.js +0 -18
  62. package/src/codegen/LoadedModule.js +0 -23
  63. package/src/codegen/LoadedValidator.js +0 -52
  64. package/src/codegen/TypeCheckedModule.js +0 -31
  65. package/src/codegen/TypeCheckedValidator.js +0 -15
  66. 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
  })
@@ -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
- */
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,370 @@
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
10
  /**
11
- * @typedef {import("./codegen/index.js").LoadedValidator} LoadedValidator
12
- * @typedef {import("./codegen/index.js").LoadedModule} LoadedModule
11
+ * @import { MintingContext, MintingPolicyHash, ScriptHash, SpendingContext, StakingContext, StakingValidatorHash, ValidatorHash } from "@helios-lang/ledger"
12
+ * @import { TypeSchema } from "@helios-lang/type-utils"
13
+ * @import { CekResult, PlutusVersion, UplcData, UplcLogger, UplcProgram, UplcSourceMapJsonSafe } from "@helios-lang/uplc"
13
14
  */
14
15
 
15
16
  /**
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
17
+ * `returns` is optional to accomodate main functions that return undefined
18
+ * @typedef {{
19
+ * name: string
20
+ * requiresScriptContext: boolean
21
+ * requiresCurrentScript: boolean
22
+ * arguments: {
23
+ * name: string
24
+ * type: TypeSchema
25
+ * isOptional: boolean
26
+ * }[]
27
+ * returns?: TypeSchema
28
+ * }} TypeCheckedUserFunc
29
+ */
30
+
31
+ /**
32
+ * @typedef {{
33
+ * name: string
34
+ * purpose: string
35
+ * sourceCode: string
36
+ * moduleDepedencies: string[]
37
+ * types: Record<string, TypeSchema>
38
+ * functions?: Record<string, TypeCheckedUserFunc>
39
+ * }} TypeCheckedModule
40
+ */
41
+
42
+ /**
43
+ * @typedef {TypeCheckedModule & {
44
+ * hashDependencies: string[]
45
+ * currentScriptIndex?: number
46
+ * Redeemer: TypeSchema
47
+ * Datum?: TypeSchema
48
+ * }} TypeCheckedValidator
49
+ */
50
+
51
+ /**
52
+ * @typedef {any} ScriptHashType
53
+ */
54
+
55
+ /**
56
+ * if `debug` is true, the ir is included in the user functions where possible
57
+ * @typedef {{
58
+ * allValidatorHashTypes: Record<string, ScriptHashType>
59
+ * allValidatorIndices?: Record<string, number>
60
+ * hashDependencies: Record<string, string>
61
+ * dependsOnOwnHash?: boolean
62
+ * ownHash?: string
63
+ * parameters?: Record<string, UplcData>
64
+ * isTestnet: boolean
65
+ * optimize: boolean
66
+ * debug?: boolean
67
+ * excludeUserFuncs?: Set<string>
68
+ * onCompileUserFunc?: (props: {
69
+ * name: string
70
+ * cborHex: string
71
+ * plutusVersion: PlutusVersion
72
+ * ir?: string
73
+ * sourceMap?: UplcSourceMapJsonSafe
74
+ * alt?: {
75
+ * cborHex: string
76
+ * ir?: string
77
+ * sourceMap?: UplcSourceMapJsonSafe
78
+ * }
79
+ * }) => void
80
+ * }} CompileOptions
81
+ */
82
+
83
+ /**
84
+ * @typedef {{
85
+ * cborHex: string
86
+ * plutusVersion: PlutusVersion
87
+ * ir?: string
88
+ * sourceMap?: import("@helios-lang/uplc").UplcSourceMapJsonSafe
89
+ * }} CompileOutput
90
+ */
91
+
92
+ /**
93
+ * @typedef {{
94
+ * modules: {[name: string]: TypeCheckedModule}
95
+ * validators: {[name: string]: TypeCheckedValidator}
96
+ * }} TypeCheckOutput
97
+ */
98
+
99
+ /**
100
+ * @typedef {{
101
+ * name: string
102
+ * purpose: string
103
+ * sourceCode: string
104
+ * }} SourceDetails
105
+ */
106
+
107
+ /**
108
+ * @typedef {{
109
+ * version: string
110
+ * getScriptHashType: (purpose: string) => ScriptHashType
111
+ * typeCheck: (validators: string[], modules: string[]) => ({
112
+ * modules: {[name: string]: TypeCheckedModule},
113
+ * validators: {[name: string]: TypeCheckedValidator}
114
+ * })
115
+ * compile: (main: string, modules: string[], options: CompileOptions) => CompileOutput
116
+ * }} CompilerLib
117
+ */
118
+
119
+ /**
120
+ * @typedef {Record<string, string[]>} DagDependencies
121
+ */
122
+
123
+ /**
124
+ * @typedef {{
125
+ * isMainnet: boolean
126
+ * }} CastConfig
127
+ */
128
+
129
+ /**
130
+ * @template TStrict
131
+ * @template TPermissive
132
+ * @typedef {object} Cast
133
+ * @prop {"Cast"} kind
134
+ * @prop {TypeSchema} schema
135
+ * @prop {CastConfig} config
136
+ * @prop {(data: UplcData, dataPath?: string) => TStrict} fromUplcData
137
+ *
138
+ * @prop {(x: TPermissive, dataPath?: string) => UplcData} toUplcData
139
+ * converts javascript object to UPLC data, according to the schema.
140
+ * The optional `dataPath` parameter can provide a contextual cue for the
141
+ * data-conversion process, and will be displayed as part of any error messages
142
+ * thrown during the data transformation
143
+ */
144
+
145
+ /**
146
+ * @template TStrict
147
+ * @template TPermissive
148
+ * @typedef {(config: CastConfig) => Cast<TStrict, TPermissive>} ConfigurableCast
149
+ */
150
+
151
+ /**
152
+ * StrictType and PermissiveType work for both Cast and ConfigurableCast
153
+ * @template TStrict
154
+ * @template TPermissive
155
+ * @typedef {Cast<TStrict, TPermissive> | ConfigurableCast<TStrict, TPermissive>} CastLike
156
+ */
157
+
158
+ /**
159
+ * @typedef {Object} SchemaToUplcContext
160
+ * @prop {Record<string, TypeSchema>} defs - symbol table permitting recursive schema references
161
+ * @prop {string} dataPath - provides developer-facing cues for any parsing errors, showing the deep field path of any error
162
+ */
163
+
164
+ /**
165
+ * @typedef {Object} UplcToSchemaContext
166
+ * @prop {Record<string, TypeSchema>} defs - symbol table permitting recursive schema references
167
+ * @prop {string} dataPath - provides developer-facing cues for any parsing errors, showing the deep field path of any error
168
+ * @prop {CastConfig} config - has isMainnet indicator
169
+ */
170
+
171
+ /**
172
+ * TODO: add logOptions here as well (which can be overridden by logOptions passed directly to eval(), evalUnsafe() and profile())?
173
+ * `returns` is optional to accomodate main functions that return void
174
+ * @typedef {{
175
+ * name: string
176
+ * requiresScriptContext: boolean
177
+ * requiresCurrentScript: boolean
178
+ * arguments: {
179
+ * name: string
180
+ * type: TypeSchema
181
+ * isOptional: boolean
182
+ * }[]
183
+ * returns?: TypeSchema
184
+ * validatorIndices?: Record<string, number>
185
+ * castConfig: CastConfig
186
+ * }} UserFuncProps
187
+ */
188
+
189
+ /**
190
+ * @template ArgsT
191
+ * @typedef {{[K in keyof ArgsT]: K extends "$currentScript" ? string : UplcData}} UnsafeArgsT
192
+ */
193
+
194
+ /**
195
+ * @template {{[argName: string]: any}} ArgsT
196
+ * @template RetT
197
+ * @typedef {object} UserFunc
198
+ * @prop {UplcProgram} uplc
199
+ * @prop {string} name
200
+ * @prop {(namedArgs: ArgsT, logOptions?: UplcLogger | undefined) => RetT} eval
201
+ * @prop {(namedArgs: UnsafeArgsT<ArgsT>, logOptions?: UplcLogger | undefined) => RetT extends void ? void : UplcData} evalUnsafe
202
+ * @prop {(namedArgs: UnsafeArgsT<ArgsT>, logOptions?: UplcLogger | undefined) => CekResult} profile
203
+ */
204
+
205
+ /**
206
+ * @typedef {{
207
+ * $name: string
208
+ * $purpose: "module"
209
+ * $sourceCode: string
210
+ * $dependencies: ReadonlyArray<LoadedModule>
211
+ * $types: {[name: string]: CastLike<any, any>}
212
+ * $functions: {[name: string]: (uplc: UplcProgram, config: CastConfig) => UserFunc<any, any>}
213
+ * }} LoadedModule
214
+ */
215
+
216
+ /**
217
+ * * 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
218
+ * @typedef {{
219
+ * $name: string
220
+ * $sourceCode: string
221
+ * $dependencies: ReadonlyArray<LoadedModule>
222
+ * $hashDependencies: ReadonlyArray<LoadedValidator>
223
+ * $currentScriptIndex?: number
224
+ * $dependsOnOwnHash: boolean
225
+ * $types: {[name: string]: CastLike<any, any>}
226
+ * $functions: {[name: string]: (uplc: UplcProgram, config: CastConfig) => UserFunc<any, any>}
227
+ * $Redeemer: CastLike<any, any>
228
+ * } & (
229
+ * {
230
+ * $purpose: "spending" | "mixed"
231
+ * $Datum: CastLike<any, any>
232
+ * } | {
233
+ * $purpose: "minting" | "certifying" | "rewarding" | "staking"
234
+ * }
235
+ * )} LoadedValidator
236
+ */
237
+
238
+ /**
239
+ * @template {{$name: string}} N
240
+ * @typedef {{
241
+ * [name in N["$name"]]: Extract<N, {"$name": name}>
242
+ * }} NamedDependencyToObject
243
+ */
244
+
245
+ /**
246
+ * @template {ReadonlyArray<{$name: string}>} N
247
+ * @typedef {NamedDependencyToObject<N extends ReadonlyArray<infer M> ? M : never>} NamedDependenciesToObject
248
+ */
249
+
250
+ /**
251
+ * @template {LoadedValidator} V
252
+ * @typedef {NamedDependenciesToObject<V["$dependencies"]>} ExtractDependencies
253
+ */
254
+
255
+ /**
256
+ * @template {CastLike<any, any>} C
257
+ * @typedef {C extends CastLike<any, infer TPermissive> ? TPermissive : never} PermissiveType
258
+ */
259
+
260
+ /**
261
+ * @template {CastLike<any, any>} C
262
+ * @typedef {C extends CastLike<infer TStrict, any> ? TStrict : never} StrictType
263
+ */
264
+
265
+ /**
266
+ * @typedef {(
267
+ * ValidatorHash<SpendingContext<any, any, any, any>> |
268
+ * MintingPolicyHash<MintingContext<any, any>> |
269
+ * StakingValidatorHash<StakingContext<any, any>> |
270
+ * ScriptHash
271
+ * )} AnyContractValidatorContext
19
272
  */
20
273
 
21
274
  /**
22
275
  * @template {LoadedValidator} V
23
- * @typedef {import("./codegen/index.js").ExtractDependencies<V>} ExtractDependencies
276
+ * @typedef {V extends {"$purpose": "spending", "$Datum": CastLike<any, any>, "$Redeemer": CastLike<any, any>} ? {
277
+ * $hash: ValidatorHash<
278
+ * SpendingContext<
279
+ * StrictType<V["$Datum"]>,
280
+ * PermissiveType<V["$Datum"]>,
281
+ * StrictType<V["$Redeemer"]>,
282
+ * PermissiveType<V["$Redeemer"]>
283
+ * >
284
+ * >
285
+ * } & ContractTypesContext<V["$types"]> & ContractUserFuncsContext<V["$functions"]> :
286
+ * V extends {"$purpose": "minting", "$Redeemer": CastLike<any, any>} ? {
287
+ * $hash: MintingPolicyHash<
288
+ * MintingContext<
289
+ * StrictType<V["$Redeemer"]>,
290
+ * PermissiveType<V["$Redeemer"]>
291
+ * >
292
+ * >
293
+ * } & ContractTypesContext<V["$types"]> & ContractUserFuncsContext<V["$functions"]> :
294
+ * V extends {"$purpose": ("certifying" | "rewarding" | "staking"), "$Redeemer": CastLike<any, any>} ? {
295
+ * $hash: StakingValidatorHash<
296
+ * StakingContext<
297
+ * StrictType<V["$Redeemer"]>,
298
+ * PermissiveType<V["$Redeemer"]>
299
+ * >
300
+ * >
301
+ * } & ContractTypesContext<V["$types"]> & ContractUserFuncsContext<V["$functions"]> :
302
+ * V extends {"$purpose": "mixed", "$Datum": CastLike<any, any>, "$Redeemer": CastLike<any, any>} ? {
303
+ * $hash: ScriptHash<
304
+ * SpendingContext<
305
+ * StrictType<V["$Datum"]>,
306
+ * PermissiveType<V["$Datum"]>,
307
+ * StrictType<V["$Redeemer"]>,
308
+ * PermissiveType<V["$Redeemer"]>
309
+ * >
310
+ * >
311
+ * } & ContractTypesContext<V["$types"]> & ContractUserFuncsContext<V["$functions"]> :
312
+ * never
313
+ * } ContractValidatorContexts
314
+ */
315
+
316
+ /**
317
+ * @template {LoadedModule} V
318
+ * @typedef {ContractTypesContext<V["$types"]> & ContractUserFuncsContext<V["$functions"]>} ContractModuleContexts
319
+ */
320
+
321
+ /**
322
+ * @template {{[typeName: string]: CastLike<any, any>}} T
323
+ * @typedef {{
324
+ * [K in keyof T]: Cast<StrictType<T[K]>, PermissiveType<T[K]>>
325
+ * }} ContractTypesContext
326
+ */
327
+
328
+ /**
329
+ * @template {{[funcName: string]: (uplc: UplcProgram, config: CastConfig) => UserFunc<any, any>}} T
330
+ * @typedef {{
331
+ * [K in keyof T]: ReturnType<T[K]>
332
+ * }} ContractUserFuncsContext
333
+ */
334
+
335
+ /**
336
+ * @template {{[name: string]: LoadedValidator}} Vs
337
+ * @template {{[name: string]: LoadedModule}} Ms
338
+ * @typedef {{
339
+ * [K in keyof Vs]: ContractValidatorContexts<Vs[K]>
340
+ * } & {
341
+ * [K in keyof Ms]: ContractModuleContexts<Ms[K]>
342
+ * }} ContractContext
343
+ */
344
+
345
+ /**
346
+ * if `debug` is true, the ir is included where possible
347
+ * @typedef {{
348
+ * isMainnet: boolean
349
+ * expectedHashes?: {[name: string]: string}
350
+ * parameters?: Record<string, UplcData>
351
+ * dumpHashes?: boolean
352
+ * debug?: boolean
353
+ * }} ContractContextBuilderProps
354
+ */
355
+
356
+ /**
357
+ * @typedef {object} LoadedScriptsWriter
358
+ * @prop {(modules: Record<string, TypeCheckedModule>) => LoadedScriptsWriter} writeModules
359
+ * @prop {(validators: Record<string, TypeCheckedValidator>) => LoadedScriptsWriter} writeValidators
360
+ * @prop {() => [string, string, string]} finalize
361
+ */
362
+
363
+ /**
364
+ * @template {{[name: string]: LoadedValidator}} Vs
365
+ * @template {{[name: string]: LoadedModule}} Ms
366
+ * @typedef {object} ContractContextBuilder
367
+ * @prop {<V extends LoadedValidator>(validator: V) => ContractContextBuilder<Vs & {[K in V["$name"]]: V}, Ms & ExtractDependencies<V>>} with
368
+ * @prop {<M extends LoadedModule>(m: M) => ContractContextBuilder<Vs, Ms & {[K in M["$name"]]: M}>} withModule
369
+ * @prop {(props: ContractContextBuilderProps) => ContractContext<Vs, Ms>} build
24
370
  */
@@ -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"}