@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,46 +1,39 @@
1
1
  import { bytesToHex } from "@helios-lang/codec-utils"
2
- import { expectSome, isLeft, isString, None } from "@helios-lang/type-utils"
3
- import { ConstrData, UplcDataValue, UplcRuntimeError } from "@helios-lang/uplc"
4
- import { Cast } from "./Cast.js"
2
+ import {
3
+ expectDefined as expectDefined,
4
+ isLeft,
5
+ isString
6
+ } from "@helios-lang/type-utils"
7
+ import {
8
+ makeConstrData,
9
+ makeUplcDataValue,
10
+ UplcRuntimeError
11
+ } from "@helios-lang/uplc"
12
+ import { makeCast } from "./Cast.js"
5
13
 
6
14
  /**
7
- * @typedef {import("@helios-lang/type-utils").TypeSchema} TypeSchema
8
- * @typedef {import("@helios-lang/uplc").CekResult} CekResult
9
- * @typedef {import("@helios-lang/uplc").UplcData} UplcData
10
- * @typedef {import("@helios-lang/uplc").UplcLoggingI} UplcLoggingI
11
- * @typedef {import("@helios-lang/uplc").UplcProgram} UplcProgram
12
- * @typedef {import("@helios-lang/uplc").UplcValue} UplcValue
13
- * @typedef {import("./Cast.js").CastConfig} CastConfig
15
+ * @import { TypeSchema } from "@helios-lang/type-utils"
16
+ * @import { CekResult, UplcData, UplcLogger, UplcProgram, UplcValue } from "@helios-lang/uplc"
17
+ * @import { Cast, CastConfig, UnsafeArgsT, UserFunc, UserFuncProps } from "../index.js"
14
18
  */
15
19
 
16
20
  /**
17
- * TODO: add logOptions here as well (which can be overridden by logOptions passed directly to eval(), evalUnsafe() and profile())?
18
- * `returns` is optional to accomodate main functions that return void
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
- * validatorIndices?: Record<string, number>
30
- * castConfig: CastConfig
31
- * }} UserFuncProps
32
- */
33
-
34
- /**
35
- * @template ArgsT
36
- * @typedef {{[K in keyof ArgsT]: K extends "$currentScript" ? string : UplcData}} UnsafeArgsT
21
+ * @template {{[argName: string]: any}} ArgsT
22
+ * @template RetT
23
+ * @param {UplcProgram} uplc
24
+ * @param {UserFuncProps} props
25
+ * @returns {UserFunc<ArgsT, RetT>}
37
26
  */
27
+ export function makeUserFunc(uplc, props) {
28
+ return new UserFuncImpl(uplc, props)
29
+ }
38
30
 
39
31
  /**
40
32
  * @template {{[argName: string]: any}} ArgsT
41
33
  * @template RetT
34
+ * @implements {UserFunc<ArgsT, RetT>}
42
35
  */
43
- export class UserFunc {
36
+ class UserFuncImpl {
44
37
  /**
45
38
  * @readonly
46
39
  * @type {UplcProgram}
@@ -72,10 +65,10 @@ export class UserFunc {
72
65
 
73
66
  /**
74
67
  * @param {ArgsT} namedArgs
75
- * @param {Option<UplcLoggingI>} logOptions
68
+ * @param {UplcLogger | undefined} logOptions
76
69
  * @returns {RetT}
77
70
  */
78
- eval(namedArgs, logOptions = None) {
71
+ eval(namedArgs, logOptions = undefined) {
79
72
  /**
80
73
  * @type {{[argName: string]: any}}
81
74
  */
@@ -89,7 +82,7 @@ export class UserFunc {
89
82
  if (argDetails) {
90
83
  const typeSchema = argDetails.type
91
84
 
92
- unsafeNamedArgs[argName] = new Cast(
85
+ unsafeNamedArgs[argName] = makeCast(
93
86
  typeSchema,
94
87
  this.props.castConfig
95
88
  ).toUplcData(argValue)
@@ -108,10 +101,10 @@ export class UserFunc {
108
101
  )
109
102
 
110
103
  if (this.props.returns) {
111
- return new Cast(
104
+ return makeCast(
112
105
  this.props.returns,
113
106
  this.props.castConfig
114
- ).fromUplcData(expectSome(/** @type {any} */ (result)))
107
+ ).fromUplcData(expectDefined(/** @type {any} */ (result)))
115
108
  } else {
116
109
  return /** @type {any} */ (undefined)
117
110
  }
@@ -119,10 +112,10 @@ export class UserFunc {
119
112
 
120
113
  /**
121
114
  * @param {UnsafeArgsT<ArgsT>} namedArgs
122
- * @param {Option<UplcLoggingI>} logOptions
115
+ * @param {UplcLogger | undefined} logOptions
123
116
  * @returns {RetT extends void ? void : UplcData}
124
117
  */
125
- evalUnsafe(namedArgs, logOptions = None) {
118
+ evalUnsafe(namedArgs, logOptions = undefined) {
126
119
  const result = this.profile(namedArgs, logOptions).result
127
120
 
128
121
  if (isLeft(result)) {
@@ -138,10 +131,10 @@ export class UserFunc {
138
131
 
139
132
  /**
140
133
  * @param {UnsafeArgsT<ArgsT>} namedArgs
141
- * @param {Option<UplcLoggingI>} logOptions - optional, passed to UplcProgram.eval if provided
134
+ * @param {UplcLogger | undefined} logOptions - optional, passed to UplcProgram.eval if provided
142
135
  * @returns {CekResult}
143
136
  */
144
- profile(namedArgs, logOptions = None) {
137
+ profile(namedArgs, logOptions = undefined) {
145
138
  const isMain = this.name == "main"
146
139
 
147
140
  /**
@@ -157,38 +150,38 @@ export class UserFunc {
157
150
  args.push(namedArgs[name])
158
151
  }
159
152
  } else {
160
- args.push(expectSome(namedArgs[name]))
153
+ args.push(expectDefined(namedArgs[name]))
161
154
  }
162
155
  } else {
163
156
  if (isOptional) {
164
157
  if (name in namedArgs && namedArgs[name]) {
165
- args.push(new ConstrData(0, [namedArgs[name]]))
158
+ args.push(makeConstrData(0, [namedArgs[name]]))
166
159
  } else {
167
- args.push(new ConstrData(1, []))
160
+ args.push(makeConstrData(1, []))
168
161
  }
169
162
  } else {
170
- args.push(expectSome(namedArgs[name]))
163
+ args.push(expectDefined(namedArgs[name]))
171
164
  }
172
165
  }
173
166
  })
174
167
 
175
168
  if (this.props.requiresScriptContext) {
176
- args.push(expectSome(namedArgs["$scriptContext"]))
169
+ args.push(expectDefined(namedArgs["$scriptContext"]))
177
170
  }
178
171
 
179
172
  if (this.props.requiresCurrentScript) {
180
- const currentScriptName = expectSome(
173
+ const currentScriptName = expectDefined(
181
174
  /** @type {any} */ (namedArgs)["$currentScript"]
182
175
  )
183
176
 
184
- const index = expectSome(
185
- expectSome(this.props.validatorIndices)[currentScriptName]
177
+ const index = expectDefined(
178
+ expectDefined(this.props.validatorIndices)[currentScriptName]
186
179
  )
187
180
 
188
- args.push(new ConstrData(index, []))
181
+ args.push(makeConstrData(index, []))
189
182
  }
190
183
 
191
- const argValues = args.map((a) => new UplcDataValue(a))
184
+ const argValues = args.map((a) => makeUplcDataValue(a))
192
185
 
193
186
  const cekResult = this.uplc.eval(argValues, {
194
187
  logOptions: logOptions ?? undefined
package/src/cast/index.js CHANGED
@@ -1,30 +1,3 @@
1
- import { Cast } from "./Cast.js"
2
- export { Cast }
1
+ export { makeCast } from "./Cast.js"
3
2
  export { configureCast } from "./Cast.js"
4
- export { UserFunc } from "./UserFunc.js"
5
-
6
- /**
7
- * @typedef {import("./Cast.js").CastConfig} CastConfig
8
- */
9
-
10
- /**
11
- * @template TStrict
12
- * @template TPermissive
13
- * @typedef {import("./Cast.js").ConfigurableCast<TStrict, TPermissive>} ConfigurableCast
14
- */
15
-
16
- /**
17
- * @template TStrict
18
- * @template TPermissive
19
- * @typedef {import("./Cast.js").CastLike<TStrict, TPermissive>} CastLike
20
- */
21
-
22
- /**
23
- * @template {CastLike<any, any>} C
24
- * @typedef {import("./PermissiveType.js").PermissiveType<C>} PermissiveType
25
- */
26
-
27
- /**
28
- * @template {CastLike<any, any>} C
29
- * @typedef {import("./StrictType.js").StrictType<C>} StrictType
30
- */
3
+ export { makeUserFunc } from "./UserFunc.js"
@@ -1,34 +1,30 @@
1
- import { StringWriter } from "@helios-lang/codec-utils"
2
- import { isSome } from "@helios-lang/type-utils"
1
+ import { makeStringWriter } from "@helios-lang/codec-utils"
2
+ import { isDefined as isSome } from "@helios-lang/type-utils"
3
3
  import { genTypes } from "./TypeSchema.js"
4
4
 
5
5
  /**
6
- * @typedef {import("./TypeCheckedModule.js").TypeCheckedModule} TypeCheckedModule
7
- * @typedef {import("./TypeCheckedModule.js").TypeCheckedUserFunc} TypeCheckedUserFunc
8
- * @typedef {import("./TypeCheckedValidator.js").TypeCheckedValidator} TypeCheckedValidator
9
- * @typedef {import("./TypeSchema.js").TypeSchema} TypeSchema
6
+ * @import { TypeSchema } from "@helios-lang/type-utils"
7
+ * @import { LoadedScriptsWriter, TypeCheckedModule, TypeCheckedUserFunc, TypeCheckedValidator } from "../index.js"
10
8
  */
11
9
 
12
- export class LoadedScriptsWriter {
13
- /**
14
- * @private
15
- */
16
- constructor() {
17
- this.definition = new StringWriter()
18
- this.declaration = new StringWriter()
19
- this.combined = new StringWriter()
20
- }
21
-
22
- /**
23
- * Constructs a LoadedScriptsWriter instance and initializes it be writing the header
24
- * @returns {LoadedScriptsWriter}
25
- */
26
- static new() {
27
- const w = new LoadedScriptsWriter()
10
+ /**
11
+ * Constructs a LoadedScriptsWriter instance and initializes it be writing the header
12
+ * @returns {LoadedScriptsWriter}
13
+ */
14
+ export function makeLoadedScriptsWriter() {
15
+ return new LoadedScriptsWriterImpl()
16
+ }
28
17
 
29
- w.writeHeaders()
18
+ /**
19
+ * @implements {LoadedScriptsWriter}
20
+ */
21
+ class LoadedScriptsWriterImpl {
22
+ constructor() {
23
+ this.definition = makeStringWriter()
24
+ this.declaration = makeStringWriter()
25
+ this.combined = makeStringWriter()
30
26
 
31
- return w
27
+ this.writeHeaders()
32
28
  }
33
29
 
34
30
  /**
@@ -132,31 +128,28 @@ export class LoadedScriptsWriter {
132
128
  }
133
129
 
134
130
  /**
131
+ * @private
135
132
  * @param {string} path
136
- * @param {string} typeName
137
- * @param {string[]} typeParams
133
+ * @param {string[]} typeNames
138
134
  * @returns {LoadedScriptsWriter}
139
135
  */
140
- writeImportType(path, typeName, typeParams = []) {
136
+ writeImportType(path, ...typeNames) {
141
137
  this.definition.writeLine("/**")
142
138
 
143
- for (let tp of typeParams) {
144
- this.definition.writeLine(` * @template ${tp}`)
145
- }
146
-
147
139
  this.definition
148
- .writeLine(
149
- ` * @typedef {import("${path}").${typeName}${typeParams.length > 0 ? `<${typeParams.join(", ")}>` : ""}} ${typeName}`
150
- )
140
+ .writeLine(` * @import { ${typeNames.join(", ")} } from "${path}";`)
151
141
  .writeLine(" */")
152
142
  ;[this.declaration, this.combined].forEach((w) => {
153
- w.writeLine(`import type { ${typeName} } from "${path}";`)
143
+ w.writeLine(
144
+ `import type { ${typeNames.join(", ")} } from "${path}";`
145
+ )
154
146
  })
155
147
 
156
148
  return this
157
149
  }
158
150
 
159
151
  /**
152
+ * @private
160
153
  * @param {string} path
161
154
  * @param {string[]} objectNames
162
155
  * @returns {LoadedScriptsWriter}
@@ -173,8 +166,21 @@ export class LoadedScriptsWriter {
173
166
  * @private
174
167
  */
175
168
  writeHeaders() {
176
- this.writeImport("@helios-lang/contract-utils", "Cast", "UserFunc")
177
169
  this.writeImport(
170
+ "@helios-lang/contract-utils",
171
+ "makeCast",
172
+ "makeUserFunc"
173
+ )
174
+
175
+ this.writeImportType("@helios-lang/codec-utils", "IntLike")
176
+ this.writeImportType(
177
+ "@helios-lang/contract-utils",
178
+ "Cast",
179
+ "CastConfig",
180
+ "ConfigurableCast",
181
+ "UserFunc"
182
+ )
183
+ this.writeImportType(
178
184
  "@helios-lang/ledger",
179
185
  "Address",
180
186
  "AssetClass",
@@ -186,8 +192,8 @@ export class LoadedScriptsWriter {
186
192
  "ScriptHash",
187
193
  "SpendingCredential",
188
194
  "StakingCredential",
189
- "StakingHash",
190
195
  "StakingValidatorHash",
196
+ "TimeLike",
191
197
  "TimeRange",
192
198
  "TxId",
193
199
  "TxInput",
@@ -197,19 +203,11 @@ export class LoadedScriptsWriter {
197
203
  "ValidatorHash",
198
204
  "Value"
199
205
  )
200
- this.writeImportType("@helios-lang/codec-utils", "IntLike")
201
- this.writeImportType("@helios-lang/contract-utils", "CastConfig")
202
- this.writeImportType(
203
- "@helios-lang/contract-utils",
204
- "ConfigurableCast",
205
- ["TStrict", "TPermissive"]
206
- )
207
- this.writeImportType("@helios-lang/ledger", "TimeLike")
208
- this.writeImportType("@helios-lang/uplc", "UplcData")
209
- this.writeImportType("@helios-lang/uplc", "UplcProgram")
206
+ this.writeImportType("@helios-lang/uplc", "UplcData", "UplcProgram")
210
207
  }
211
208
 
212
209
  /**
210
+ * @private
213
211
  * @param {Record<string, TypeSchema>} types
214
212
  */
215
213
  writeTypes(types) {
@@ -222,13 +220,13 @@ export class LoadedScriptsWriter {
222
220
  const tsTypes = genTypes(t)
223
221
 
224
222
  this.definition.write(
225
- ` ${key}: (config) => /** @type {Cast<${tsTypes[0]}, ${tsTypes[1]}>} */ (new Cast(${JSON.stringify(t)}, config)),\n`
223
+ ` ${key}: (config) => /** @type {Cast<${tsTypes[0]}, ${tsTypes[1]}>} */ (makeCast(${JSON.stringify(t)}, config)),\n`
226
224
  )
227
225
  this.declaration.write(
228
226
  ` ${key}: ConfigurableCast<${tsTypes[0]}, ${tsTypes[1]}>,\n`
229
227
  )
230
228
  this.combined.write(
231
- ` ${key}: (config: CastConfig) => new Cast<${tsTypes[0]}, ${tsTypes[1]}>(${JSON.stringify(t)}, config),\n`
229
+ ` ${key}: (config: CastConfig) => makeCast<${tsTypes[0]}, ${tsTypes[1]}>(${JSON.stringify(t)}, config),\n`
232
230
  )
233
231
  }
234
232
 
@@ -238,6 +236,7 @@ export class LoadedScriptsWriter {
238
236
  }
239
237
 
240
238
  /**
239
+ * @private
241
240
  * @param {Record<string, TypeCheckedUserFunc>} functions
242
241
  */
243
242
  writeFunctions(functions) {
@@ -252,13 +251,13 @@ export class LoadedScriptsWriter {
252
251
  const propsStr = `{...(${JSON.stringify(fn)}), castConfig: config, validatorIndices: __validatorIndices}`
253
252
 
254
253
  this.definition.write(
255
- ` "${key}": (uplc, config) => /** @type {UserFunc<${argsType}, ${retType}>} */ (new UserFunc(uplc, ${propsStr})),\n`
254
+ ` "${key}": (uplc, config) => /** @type {UserFunc<${argsType}, ${retType}>} */ (makeUserFunc(uplc, ${propsStr})),\n`
256
255
  )
257
256
  this.declaration.write(
258
257
  ` "${key}": (uplc: UplcProgram, config: CastConfig) => UserFunc<${argsType}, ${retType}>,\n`
259
258
  )
260
259
  this.combined.write(
261
- ` "${key}": (uplc: UplcProgram, config: CastConfig) => new UserFunc<${argsType}, ${retType}>(uplc, ${propsStr}),\n`
260
+ ` "${key}": (uplc: UplcProgram, config: CastConfig) => makeUserFunc<${argsType}, ${retType}>(uplc, ${propsStr}),\n`
262
261
  )
263
262
  }
264
263
 
@@ -320,8 +319,8 @@ ${isSome(currentScriptIndex) ? ` $currentScriptIndex: /** @type {const} */ ($
320
319
  $dependencies: /** @type {const} */ ([${v.moduleDepedencies.join(", ")}]),
321
320
  $hashDependencies: [${v.hashDependencies.filter((d) => d != v.name).join(", ")}],
322
321
  $dependsOnOwnHash: ${v.hashDependencies.some((d) => d == v.name)},
323
- $Redeemer: (config) => /** @type {Cast<${redeemerTypes[0]}, ${redeemerTypes[1]}>} */ (new Cast(${JSON.stringify(v.Redeemer)}, config)),
324
- ${datumTypes ? ` $Datum: (config) => /** @type {Cast<${datumTypes[0]}, ${datumTypes[1]}>} */ (new Cast(${JSON.stringify(v.Datum)}, config)),\n` : ""}`
322
+ $Redeemer: (config) => /** @type {Cast<${redeemerTypes[0]}, ${redeemerTypes[1]}>} */ (makeCast(${JSON.stringify(v.Redeemer)}, config)),
323
+ ${datumTypes ? ` $Datum: (config) => /** @type {Cast<${datumTypes[0]}, ${datumTypes[1]}>} */ (makeCast(${JSON.stringify(v.Datum)}, config)),\n` : ""}`
325
324
  )
326
325
 
327
326
  this.declaration.write(
@@ -349,8 +348,8 @@ ${isSome(currentScriptIndex) ? ` $currentScriptIndex: ${currentScriptIndex} a
349
348
  $dependencies: [${v.moduleDepedencies.join(", ")}] as const,
350
349
  $hashDependencies: [${v.hashDependencies.filter((d) => d != v.name).join(", ")}],
351
350
  $dependsOnOwnHash: ${v.hashDependencies.some((d) => d == v.name)} as boolean,
352
- $Redeemer: (config: CastConfig) => new Cast<${redeemerTypes[0]}, ${redeemerTypes[1]}>(${JSON.stringify(v.Redeemer)}, config),
353
- ${datumTypes ? ` $Datum: (config: CastConfig) => new Cast<${datumTypes[0]}, ${datumTypes[1]}>(${JSON.stringify(v.Datum)}, config),\n` : ""}`
351
+ $Redeemer: (config: CastConfig) => makeCast<${redeemerTypes[0]}, ${redeemerTypes[1]}>(${JSON.stringify(v.Redeemer)}, config),
352
+ ${datumTypes ? ` $Datum: (config: CastConfig) => makeCast<${datumTypes[0]}, ${datumTypes[1]}>(${JSON.stringify(v.Datum)}, config),\n` : ""}`
354
353
  )
355
354
 
356
355
  this.writeTypes(v.types)
@@ -362,6 +361,7 @@ ${datumTypes ? ` $Datum: (config: CastConfig) => new Cast<${datumTypes[0]}, $
362
361
  }
363
362
 
364
363
  /**
364
+ * @private
365
365
  * @param {Record<string, TypeCheckedValidator>} validators
366
366
  */
367
367
  writeValidatorIndices(validators) {
@@ -1,8 +1,8 @@
1
1
  /**
2
- * @typedef {import("@helios-lang/type-utils").TypeSchema} TypeSchema
2
+ * @import { TypeSchema } from "@helios-lang/type-utils"
3
3
  */
4
4
 
5
- const NONE = "null"
5
+ const NONE = "undefined"
6
6
 
7
7
  /**
8
8
  * TODO: handle recursive data structures
@@ -50,20 +50,12 @@ export function genTypes(schema) {
50
50
  case "Real":
51
51
  return ["number", "number"]
52
52
  case "SpendingCredential":
53
- return [
54
- "SpendingCredential",
55
- "SpendingCredential | PubKeyHash | ValidatorHash"
56
- ]
53
+ return ["SpendingCredential", "SpendingCredential"]
57
54
  case "StakingCredential":
58
- return [
59
- "StakingCredential",
60
- "StakingCredential | StakingHash | PubKeyHash | StakingValidatorHash"
61
- ]
55
+ return ["StakingCredential", "StakingCredential"]
62
56
  case "StakingHash":
63
- return [
64
- "StakingHash",
65
- "StakingHash | PubKeyHash | StakingValidatorHash"
66
- ]
57
+ // TODO: implement this
58
+ return ["never", "never"]
67
59
  case "StakingValidatorHash":
68
60
  return [
69
61
  "StakingValidatorHash",
@@ -1,14 +1 @@
1
- export { LoadedScriptsWriter } from "./LoadedScriptsWriter.js"
2
-
3
- /**
4
- * @typedef {import("./LoadedModule.js").LoadedModule} LoadedModule
5
- * @typedef {import("./LoadedValidator.js").LoadedValidator} LoadedValidator
6
- * @typedef {import("./TypeCheckedModule.js").TypeCheckedModule} TypeCheckedModule
7
- * @typedef {import("./TypeCheckedValidator.js").TypeCheckedValidator} TypeCheckedValidator
8
- * @typedef {import("./TypeSchema.js").TypeSchema} TypeSchema
9
- */
10
-
11
- /**
12
- * @template {LoadedValidator} V
13
- * @typedef {import("./LoadedValidator.js").ExtractDependencies<V>} ExtractDependencies
14
- */
1
+ export { makeLoadedScriptsWriter } from "./LoadedScriptsWriter.js"
@@ -1,86 +1,7 @@
1
1
  import { readHeader } from "@helios-lang/compiler-utils"
2
2
 
3
- export {}
4
-
5
- /**
6
- * @typedef {import("@helios-lang/uplc").PlutusVersion} PlutusVersion
7
- * @typedef {import("@helios-lang/uplc").UplcData} UplcData
8
- * @typedef {import("@helios-lang/uplc").UplcSourceMapJsonSafe} UplcSourceMapJsonSafe
9
- * @typedef {import("../codegen/index.js").TypeSchema} InternalTypeDetails
10
- * @typedef {import("../codegen/index.js").TypeCheckedModule} TypeCheckedModule
11
- * @typedef {import("../codegen/index.js").TypeCheckedValidator} TypeCheckedValidator
12
- */
13
-
14
- /**
15
- * @typedef {any} ScriptHashType
16
- */
17
-
18
- /**
19
- * if `debug` is true, the ir is included in the user functions where possible
20
- * @typedef {{
21
- * allValidatorHashTypes: Record<string, ScriptHashType>
22
- * allValidatorIndices?: Record<string, number>
23
- * hashDependencies: Record<string, string>
24
- * dependsOnOwnHash?: boolean
25
- * ownHash?: string
26
- * parameters?: Record<string, UplcData>
27
- * isTestnet: boolean
28
- * optimize: boolean
29
- * debug?: boolean
30
- * excludeUserFuncs?: Set<string>
31
- * onCompileUserFunc?: (props: {
32
- * name: string
33
- * cborHex: string
34
- * plutusVersion: PlutusVersion
35
- * ir?: string
36
- * sourceMap?: UplcSourceMapJsonSafe
37
- * alt?: {
38
- * cborHex: string
39
- * ir?: string
40
- * sourceMap?: UplcSourceMapJsonSafe
41
- * }
42
- * }) => void
43
- * }} CompileOptions
44
- */
45
-
46
- /**
47
- * @typedef {{
48
- * cborHex: string
49
- * plutusVersion: PlutusVersion
50
- * ir?: string
51
- * sourceMap?: import("@helios-lang/uplc").UplcSourceMapJsonSafe
52
- * }} CompileOutput
53
- */
54
-
55
- /**
56
- * @typedef {{
57
- * modules: {[name: string]: TypeCheckedModule}
58
- * validators: {[name: string]: TypeCheckedValidator}
59
- * }} TypeCheckOutput
60
- */
61
-
62
- /**
63
- * @typedef {{
64
- * name: string
65
- * purpose: string
66
- * sourceCode: string
67
- * }} SourceDetails
68
- */
69
-
70
- /**
71
- * @typedef {{
72
- * version: string
73
- * getScriptHashType: (purpose: string) => ScriptHashType
74
- * typeCheck: (validators: string[], modules: string[]) => ({
75
- * modules: {[name: string]: TypeCheckedModule},
76
- * validators: {[name: string]: TypeCheckedValidator}
77
- * })
78
- * compile: (main: string, modules: string[], options: CompileOptions) => CompileOutput
79
- * }} CompilerLib
80
- */
81
-
82
3
  /**
83
- * @typedef {Record<string, string[]>} DagDependencies
4
+ * @import { CompilerLib, ScriptHashType } from "../index.js"
84
5
  */
85
6
 
86
7
  /**
@@ -1,20 +1,12 @@
1
1
  import { bytesToHex } from "@helios-lang/codec-utils"
2
2
  import { readHeader } from "@helios-lang/compiler-utils"
3
- import { expectSome } from "@helios-lang/type-utils"
3
+ import { expectDefined } from "@helios-lang/type-utils"
4
4
  import { getValidatorTypes } from "./CompilerLib.js"
5
5
 
6
6
  /**
7
- * @typedef {import("@helios-lang/uplc").UplcData} UplcData
8
- * @typedef {import("../codegen/index.js").TypeCheckedModule} TypeCheckedModule
9
- * @typedef {import("../codegen/index.js").TypeCheckedValidator} TypeCheckedValidator
10
- * @typedef {import("../codegen/index.js").TypeSchema} TypeSchema
11
- * @typedef {import("./CompilerLib.js").CompileOptions} CompileOptions
12
- * @typedef {import("./CompilerLib.js").CompileOutput} CompileOutput
13
- * @typedef {import("./CompilerLib.js").CompilerLib} CompilerLib
14
- * @typedef {import("./CompilerLib.js").DagDependencies} DagDependencies
15
- * @typedef {import("./CompilerLib.js").ScriptHashType} ScriptHashType
16
- * @typedef {import("./CompilerLib.js").SourceDetails} SourceDetails
17
- * @typedef {import("./CompilerLib.js").TypeCheckOutput} TypeCheckOutput
7
+ * @import { TypeSchema } from "@helios-lang/type-utils"
8
+ * @import { UplcData } from "@helios-lang/uplc"
9
+ * @import { CompileOptions, CompileOutput, CompilerLib, DagDependencies, ScriptHashType, SourceDetails, TypeCheckOutput, TypeCheckedModule, TypeCheckedValidator } from "../index.js"
18
10
  */
19
11
 
20
12
  /**
@@ -130,10 +122,18 @@ import { getValidatorTypes } from "./CompilerLib.js"
130
122
  * }} UserTypes
131
123
  */
132
124
 
125
+ /**
126
+ * @param {any} lib
127
+ * @returns {CompilerLib}
128
+ */
129
+ export function makeCompilerLib_v0_16(lib) {
130
+ return new CompilerLib_v0_16(lib)
131
+ }
132
+
133
133
  /**
134
134
  * @implements {CompilerLib}
135
135
  */
136
- export class CompilerLib_v0_16 {
136
+ class CompilerLib_v0_16 {
137
137
  /**
138
138
  * @param {any} lib
139
139
  */
@@ -570,7 +570,7 @@ export class CompilerLib_v0_16 {
570
570
  const module_ =
571
571
  moduleName.value == program.name
572
572
  ? program.mainModule
573
- : expectSome(
573
+ : expectDefined(
574
574
  program.mainImportedModules.find(
575
575
  (m) => m.name.value == moduleName.value
576
576
  ),