@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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@helios-lang/contract-utils",
3
- "version": "0.2.81",
3
+ "version": "0.3.0",
4
4
  "description": "Convenience and type-safety utilities for using Helios validators from within Typescript",
5
5
  "main": "src/index.js",
6
6
  "types": "types/index.d.ts",
@@ -37,12 +37,12 @@
37
37
  },
38
38
  "dependencies": {
39
39
  "@helios-lang/cli-utils": "^0.1.10",
40
- "@helios-lang/codec-utils": "^0.2.1",
41
- "@helios-lang/compiler-utils": "^0.2.1",
42
- "@helios-lang/crypto": "0.1.17",
43
- "@helios-lang/ledger": "^0.5.12",
44
- "@helios-lang/type-utils": "^0.1.25",
45
- "@helios-lang/uplc": "^0.6.1"
40
+ "@helios-lang/codec-utils": "^0.3.1",
41
+ "@helios-lang/compiler-utils": "^0.3.2",
42
+ "@helios-lang/crypto": "0.2.0",
43
+ "@helios-lang/ledger": "^0.6.4",
44
+ "@helios-lang/type-utils": "^0.2.8",
45
+ "@helios-lang/uplc": "^0.7.5"
46
46
  },
47
47
  "scripts": {
48
48
  "build": "pnpm run prettify && pnpm run build:types && pnpm run test:suite",
package/src/cast/Cast.js CHANGED
@@ -1,82 +1,81 @@
1
1
  import { decodeUtf8, encodeUtf8 } from "@helios-lang/codec-utils"
2
2
  import {
3
- Address,
4
- AssetClass,
5
- DatumHash,
6
- MintingPolicyHash,
7
- PubKey,
8
- PubKeyHash,
9
- ScriptHash,
10
- SpendingCredential,
11
- StakingCredential,
12
- StakingHash,
13
- StakingValidatorHash,
14
- TimeRange,
15
- TxId,
16
- TxInput,
17
- TxOutput,
18
- TxOutputDatum,
19
- TxOutputId,
20
- ValidatorHash,
21
- Value
3
+ convertSpendingCredentialToUplcData,
4
+ convertStakingCredentialToUplcData,
5
+ convertUplcDataToAssetClass,
6
+ convertUplcDataToMintingPolicyHash,
7
+ convertUplcDataToPubKey,
8
+ convertUplcDataToPubKeyHash,
9
+ convertUplcDataToShelleyAddress,
10
+ convertUplcDataToSpendingCredential,
11
+ convertUplcDataToStakingCredential,
12
+ convertUplcDataToStakingValidatorHash,
13
+ convertUplcDataToTimeRange,
14
+ convertUplcDataToTxId,
15
+ convertUplcDataToTxInput,
16
+ convertUplcDataToTxOutput,
17
+ convertUplcDataToTxOutputDatum,
18
+ convertUplcDataToTxOutputId,
19
+ convertUplcDataToValidatorHash,
20
+ convertUplcDataToValue,
21
+ makeAddress,
22
+ makeAssetClass,
23
+ makeDatumHash,
24
+ makeMintingPolicyHash,
25
+ makePubKey,
26
+ makePubKeyHash,
27
+ makeStakingValidatorHash,
28
+ makeTimeRange,
29
+ makeTxId,
30
+ makeTxOutputDatum,
31
+ makeTxOutputId,
32
+ makeValidatorHash,
33
+ makeValue
22
34
  } from "@helios-lang/ledger"
23
- import { None, expectSome } from "@helios-lang/type-utils"
35
+ import { expectDefined } from "@helios-lang/type-utils"
24
36
  import {
25
- ByteArrayData,
26
- ConstrData,
27
- IntData,
28
- ListData,
29
- MapData,
30
- decodeBoolData,
31
- decodeOptionData,
32
- decodeRealData,
33
- encodeBoolData,
34
- encodeOptionData,
35
- encodeRealData
37
+ uplcDataToBool,
38
+ unwrapUplcDataOption,
39
+ uplcDataToReal,
40
+ boolToUplcData,
41
+ wrapUplcDataOption,
42
+ realToUplcData,
43
+ expectByteArrayData,
44
+ expectConstrData,
45
+ expectIntData,
46
+ expectListData,
47
+ expectMapData,
48
+ makeByteArrayData,
49
+ makeConstrData,
50
+ makeIntData,
51
+ makeListData,
52
+ makeMapData
36
53
  } from "@helios-lang/uplc"
37
54
 
38
55
  /**
39
- * @typedef {import("@helios-lang/uplc").UplcData} UplcData
40
- * @typedef {import("../codegen/index.js").TypeSchema} TypeSchema
41
- */
42
-
43
- /**
44
- * @typedef {{
45
- * isMainnet: boolean
46
- * }} CastConfig
56
+ * @import { TxInput, TxOutput } from "@helios-lang/ledger"
57
+ * @import { TypeSchema } from "@helios-lang/type-utils"
58
+ * @import { UplcData } from "@helios-lang/uplc"
59
+ * @import { Cast, CastConfig, CastLike, SchemaToUplcContext, UplcToSchemaContext } from "../index.js"
47
60
  */
48
61
 
49
62
  /**
50
63
  * @template TStrict
51
- * @template TPermissive
52
- * @typedef {(config: CastConfig) => Cast<TStrict, TPermissive>} ConfigurableCast
53
- */
54
-
55
- /**
56
- * StrictType and PermissiveType work for both Cast and ConfigurableCast
57
- * @template TStrict
58
- * @template TPermissive
59
- * @typedef {Cast<TStrict, TPermissive> | ConfigurableCast<TStrict, TPermissive>} CastLike
60
- */
61
-
62
- /**
63
- * @typedef {Object} SchemaToUplcContext
64
- * @property {Record<string, TypeSchema>} defs - symbol table permitting recursive schema references
65
- * @property {string} dataPath - provides developer-facing cues for any parsing errors, showing the deep field path of any error
66
- */
67
-
68
- /**
69
- * @typedef {Object} UplcToSchemaContext
70
- * @property {Record<string, TypeSchema>} defs - symbol table permitting recursive schema references
71
- * @property {string} dataPath - provides developer-facing cues for any parsing errors, showing the deep field path of any error
72
- * @property {CastConfig} config - has isMainnet indicator
64
+ * @template TPermissive=TStrict
65
+ * @param {TypeSchema} schema
66
+ * @param {CastConfig} config
67
+ * @returns {Cast<TStrict, TPermissive>}
73
68
  */
69
+ export function makeCast(schema, config) {
70
+ return new CastImpl(schema, config)
71
+ }
74
72
 
75
73
  /**
76
74
  * @template TStrict
77
75
  * @template TPermissive=TStrict
76
+ * @implements {Cast<TStrict, TPermissive>}
78
77
  */
79
- export class Cast {
78
+ class CastImpl {
80
79
  /**
81
80
  * @readonly
82
81
  * @type {TypeSchema}
@@ -98,6 +97,13 @@ export class Cast {
98
97
  this.config = config
99
98
  }
100
99
 
100
+ /**
101
+ * @type {"Cast"}
102
+ */
103
+ get kind() {
104
+ return "Cast"
105
+ }
106
+
101
107
  /**
102
108
  * @param {UplcData} data
103
109
  * @param {string} [dataPath] - can be used to indicate the kind or context of data-decoding
@@ -170,7 +176,7 @@ function schemaToUplc(schema, x, inputContextOnly) {
170
176
  const kind = schema.kind
171
177
  switch (kind) {
172
178
  case "reference": {
173
- const def = expectSome(defs[schema.id])
179
+ const def = expectDefined(defs[schema.id])
174
180
  return schemaToUplcWithDataPath(def, x, {
175
181
  defs,
176
182
  dataPath: `${dataPath}::ref{${schema.id}}`
@@ -181,68 +187,68 @@ function schemaToUplc(schema, x, inputContextOnly) {
181
187
 
182
188
  switch (name) {
183
189
  case "Address":
184
- return Address.new(x).toUplcData()
190
+ return makeAddress(x).toUplcData()
185
191
  case "Any":
186
- return new IntData(0n)
192
+ return makeIntData(0n)
187
193
  case "AssetClass":
188
- return AssetClass.new(x).toUplcData()
194
+ return makeAssetClass(x).toUplcData()
189
195
  case "Bool":
190
- return encodeBoolData(x)
196
+ return boolToUplcData(x)
191
197
  case "ByteArray":
192
- return new ByteArrayData(x)
198
+ return makeByteArrayData(x)
193
199
  case "Credential":
194
200
  case "SpendingCredential":
195
- return SpendingCredential.new(x).toUplcData()
201
+ return convertSpendingCredentialToUplcData(x)
196
202
  case "Data":
197
203
  return x
198
204
  case "DatumHash":
199
- return DatumHash.new(x).toUplcData()
205
+ return makeDatumHash(x).toUplcData()
200
206
  case "DCert":
201
207
  return x.toUplcData()
202
208
  case "Duration":
203
209
  case "Int":
204
- return new IntData(x)
210
+ return makeIntData(x)
205
211
  case "MintingPolicyHash":
206
- return MintingPolicyHash.new(x).toUplcData()
212
+ return makeMintingPolicyHash(x).toUplcData()
207
213
  case "PubKey":
208
- return PubKey.new(x).toUplcData()
214
+ return makePubKey(x).toUplcData()
209
215
  case "PubKeyHash":
210
- return PubKeyHash.new(x).toUplcData()
216
+ return makePubKeyHash(x).toUplcData()
211
217
  case "Real":
212
- return encodeRealData(x)
218
+ return realToUplcData(x)
213
219
  case "Ratio":
214
- return new ListData([new IntData(x[0]), new IntData(x[1])])
220
+ return makeListData([makeIntData(x[0]), makeIntData(x[1])])
215
221
  case "ScriptHash":
216
- return ScriptHash.new(x).toUplcData()
222
+ return makeByteArrayData(makeValidatorHash(x).bytes)
217
223
  case "StakingCredential":
218
- return StakingCredential.new(x).toUplcData()
224
+ return convertStakingCredentialToUplcData(makePubKeyHash(x))
219
225
  case "StakingHash":
220
- return StakingHash.new(x).toUplcData()
226
+ throw new Error("not yet implemented")
221
227
  case "StakingValidatorHash":
222
- return StakingValidatorHash.new(x).toUplcData()
228
+ return makeStakingValidatorHash(x).toUplcData()
223
229
  case "String":
224
- return new ByteArrayData(encodeUtf8(x))
230
+ return makeByteArrayData(encodeUtf8(x))
225
231
  case "Time":
226
- return new IntData(x)
232
+ return makeIntData(x)
227
233
  case "TimeRange":
228
- return TimeRange.new(x).toUplcData()
234
+ return makeTimeRange(x).toUplcData()
229
235
  case "TxId":
230
- return TxId.new(x).toUplcData()
236
+ return makeTxId(x).toUplcData()
231
237
  case "TxInput":
232
238
  return /** @type {TxInput} */ (x).toUplcData()
233
239
  case "TxOutput":
234
240
  return /** @type {TxOutput} */ (x).toUplcData()
235
241
  case "TxOutputDatum":
236
242
  return x
237
- ? (TxOutputDatum.new(x)?.toUplcData() ??
238
- new ConstrData(0, []))
239
- : new ConstrData(0, [])
243
+ ? (makeTxOutputDatum(x)?.toUplcData() ??
244
+ makeConstrData(0, []))
245
+ : makeConstrData(0, [])
240
246
  case "TxOutputId":
241
- return TxOutputId.new(x).toUplcData()
247
+ return makeTxOutputId(x).toUplcData()
242
248
  case "ValidatorHash":
243
- return ValidatorHash.new(x).toUplcData()
249
+ return makeValidatorHash(x).toUplcData()
244
250
  case "Value":
245
- return Value.new(x).toUplcData()
251
+ return makeValue(x).toUplcData()
246
252
  default:
247
253
  throw new Error(
248
254
  `schemaToUplc not yet implemented for ${name}`
@@ -250,7 +256,7 @@ function schemaToUplc(schema, x, inputContextOnly) {
250
256
  }
251
257
  }
252
258
  case "list":
253
- return new ListData(
259
+ return makeListData(
254
260
  x.map((x, i) =>
255
261
  schemaToUplcWithDataPath(schema.itemType, x, {
256
262
  defs,
@@ -265,7 +271,7 @@ function schemaToUplc(schema, x, inputContextOnly) {
265
271
  : Array.isArray(x)
266
272
  ? x
267
273
  : Object.entries(x)
268
- return new MapData(
274
+ return makeMapData(
269
275
  entries.map(([k, v], i) => {
270
276
  const displayKey = "string" == typeof k ? `'${k}'` : `@{i}`
271
277
  return [
@@ -282,7 +288,7 @@ function schemaToUplc(schema, x, inputContextOnly) {
282
288
  )
283
289
  }
284
290
  case "tuple":
285
- return new ListData(
291
+ return makeListData(
286
292
  x.map((x, i) =>
287
293
  schemaToUplcWithDataPath(schema.itemTypes[i], x, {
288
294
  defs,
@@ -291,13 +297,13 @@ function schemaToUplc(schema, x, inputContextOnly) {
291
297
  )
292
298
  )
293
299
  case "option":
294
- return encodeOptionData(
300
+ return wrapUplcDataOption(
295
301
  x
296
302
  ? schemaToUplcWithDataPath(schema.someType, x, {
297
303
  defs,
298
304
  dataPath: `${dataPath}::Some`
299
305
  })
300
- : None
306
+ : undefined
301
307
  )
302
308
  case "struct": {
303
309
  defs[schema.id] = schema
@@ -313,7 +319,7 @@ function schemaToUplc(schema, x, inputContextOnly) {
313
319
  }
314
320
  )
315
321
  case "list":
316
- return new ListData(
322
+ return makeListData(
317
323
  schema.fieldTypes.map(({ name, type }) =>
318
324
  schemaToUplcWithDataPath(type, x[name], {
319
325
  defs,
@@ -355,7 +361,7 @@ function schemaToUplc(schema, x, inputContextOnly) {
355
361
  if (ft) {
356
362
  const encodingKey = ft.key || ft.name
357
363
  const encodingInfo = ft.key ? ` as '${ft.key}'` : ""
358
- const keyData = new ByteArrayData(
364
+ const keyData = makeByteArrayData(
359
365
  encodeUtf8(encodingKey)
360
366
  )
361
367
 
@@ -377,7 +383,7 @@ function schemaToUplc(schema, x, inputContextOnly) {
377
383
  //
378
384
  // We just return our MapData, and we don't care whether it's used in any particular context.
379
385
 
380
- return new MapData(pairs)
386
+ return makeMapData(pairs)
381
387
  }
382
388
  default:
383
389
  throw new Error(
@@ -401,7 +407,7 @@ function schemaToUplc(schema, x, inputContextOnly) {
401
407
 
402
408
  // Gives the encoding of nested data a context to prevent a second ConstrData wrapper on the MapData
403
409
  // ... only for the first field.
404
- return new ConstrData(
410
+ return makeConstrData(
405
411
  tag,
406
412
  schema.variantTypes[tag].fieldTypes.map((f, i) =>
407
413
  schemaToUplcWithDataPath(f.type, variantFields[f.name], {
@@ -414,7 +420,7 @@ function schemaToUplc(schema, x, inputContextOnly) {
414
420
  case "variant":
415
421
  defs[schema.id] = schema
416
422
 
417
- return new ConstrData(
423
+ return makeConstrData(
418
424
  schema.tag,
419
425
  schema.fieldTypes.map(({ name, type }) =>
420
426
  schemaToUplcWithDataPath(type, x[name], {
@@ -470,19 +476,22 @@ function uplcToSchema(schema, data, inputContextOnly) {
470
476
 
471
477
  switch (name) {
472
478
  case "Address":
473
- return Address.fromUplcData(config.isMainnet, data)
479
+ return convertUplcDataToShelleyAddress(
480
+ config.isMainnet,
481
+ data
482
+ )
474
483
  case "Any":
475
484
  // TODO: should this throw an error?
476
485
  return null
477
486
  case "AssetClass":
478
- return AssetClass.fromUplcData(data)
487
+ return convertUplcDataToAssetClass(data)
479
488
  case "Bool":
480
- return decodeBoolData(data, true)
489
+ return uplcDataToBool(data, true)
481
490
  case "ByteArray":
482
- return ByteArrayData.expect(data).bytes
491
+ return expectByteArrayData(data).bytes
483
492
  case "SpendingCredential":
484
493
  case "Credential":
485
- return SpendingCredential.fromUplcData(data)
494
+ return convertUplcDataToSpendingCredential(data)
486
495
  case "Data":
487
496
  return data
488
497
  case "DCert":
@@ -491,56 +500,56 @@ function uplcToSchema(schema, data, inputContextOnly) {
491
500
  )
492
501
  case "Duration":
493
502
  case "Int":
494
- return IntData.expect(data).value
503
+ return expectIntData(data).value
495
504
  case "MintingPolicyHash":
496
- return MintingPolicyHash.fromUplcData(data)
505
+ return convertUplcDataToMintingPolicyHash(data)
497
506
  case "PubKey":
498
- return PubKey.fromUplcData(data)
507
+ return convertUplcDataToPubKey(data)
499
508
  case "PubKeyHash":
500
- return PubKeyHash.fromUplcData(data)
509
+ return convertUplcDataToPubKeyHash(data)
501
510
  case "Ratio": {
502
- const [top, bottom] = ListData.expect(data).items
511
+ const [top, bottom] = expectListData(data).items
503
512
  return [
504
- IntData.expect(top).value,
505
- IntData.expect(bottom).value
513
+ expectIntData(top).value,
514
+ expectIntData(bottom).value
506
515
  ]
507
516
  }
508
517
  case "Real":
509
- return decodeRealData(data)
518
+ return uplcDataToReal(data)
510
519
  case "ScriptHash":
511
- return ScriptHash.fromUplcData(data)
520
+ return expectByteArrayData(data).bytes
512
521
  case "StakingCredential":
513
- return StakingCredential.fromUplcData(data)
522
+ return convertUplcDataToStakingCredential(data)
514
523
  case "StakingHash":
515
- return StakingHash.fromUplcData(data)
524
+ throw new Error("not yet implemented")
516
525
  case "StakingValidatorHash":
517
- return StakingValidatorHash.fromUplcData(data)
526
+ return convertUplcDataToStakingValidatorHash(data)
518
527
  case "String":
519
- return decodeUtf8(ByteArrayData.expect(data).bytes)
528
+ return decodeUtf8(expectByteArrayData(data).bytes)
520
529
  case "Time":
521
- return Number(IntData.expect(data).value) // a number has enough precision to represent ms since 1970 for another 142000 years
530
+ return Number(expectIntData(data).value) // a number has enough precision to represent ms since 1970 for another 142000 years
522
531
  case "TimeRange":
523
- return TimeRange.fromUplcData(data)
532
+ return convertUplcDataToTimeRange(data)
524
533
  case "TxId":
525
- return TxId.fromUplcData(data)
534
+ return convertUplcDataToTxId(data)
526
535
  case "TxInput":
527
- return TxInput.fromUplcData(config.isMainnet, data)
536
+ return convertUplcDataToTxInput(config.isMainnet, data)
528
537
  case "TxOutput":
529
- return TxOutput.fromUplcData(config.isMainnet, data)
538
+ return convertUplcDataToTxOutput(config.isMainnet, data)
530
539
  case "TxOutputDatum":
531
- return TxOutputDatum.fromUplcData(data)
540
+ return convertUplcDataToTxOutputDatum(data)
532
541
  case "TxOutputId":
533
- return TxOutputId.fromUplcData(data)
542
+ return convertUplcDataToTxOutputId(data)
534
543
  case "ValidatorHash":
535
- return ValidatorHash.fromUplcData(data)
544
+ return convertUplcDataToValidatorHash(data)
536
545
  case "Value":
537
- return Value.fromUplcData(data)
546
+ return convertUplcDataToValue(data)
538
547
  default:
539
548
  throw new Error(`not yet implemented for ${name}`)
540
549
  }
541
550
  }
542
551
  case "list":
543
- return ListData.expect(data).items.map((x, i) =>
552
+ return expectListData(data).items.map((x, i) =>
544
553
  uplcToSchemaWithDataPath(schema.itemType, x, {
545
554
  ...context,
546
555
  dataPath: `${dataPath}[${i}]`
@@ -548,7 +557,7 @@ function uplcToSchema(schema, data, inputContextOnly) {
548
557
  )
549
558
  case "map":
550
559
  return new Map(
551
- MapData.expect(data).items.map(([k, v], i) => {
560
+ expectMapData(data).items.map(([k, v], i) => {
552
561
  const key = uplcToSchemaWithDataPath(schema.keyType, k, {
553
562
  ...context,
554
563
  dataPath: `${dataPath}[mapKey @${i}]`
@@ -565,20 +574,20 @@ function uplcToSchema(schema, data, inputContextOnly) {
565
574
  })
566
575
  )
567
576
  case "tuple":
568
- return ListData.expect(data).items.map((x, i) =>
577
+ return expectListData(data).items.map((x, i) =>
569
578
  uplcToSchemaWithDataPath(schema.itemTypes[i], x, {
570
579
  ...context,
571
580
  dataPath: `${dataPath}[tuple@${i}]`
572
581
  })
573
582
  )
574
583
  case "option": {
575
- const optionData = decodeOptionData(data)
584
+ const optionData = unwrapUplcDataOption(data)
576
585
  return optionData
577
586
  ? uplcToSchemaWithDataPath(schema.someType, optionData, {
578
587
  ...context,
579
588
  dataPath: `${dataPath}::Some`
580
589
  })
581
- : None
590
+ : undefined
582
591
  }
583
592
  case "struct": {
584
593
  defs[schema.id] = schema
@@ -592,7 +601,7 @@ function uplcToSchema(schema, data, inputContextOnly) {
592
601
  )
593
602
  }
594
603
  case "list": {
595
- const fields = ListData.expect(data).items
604
+ const fields = expectListData(data).items
596
605
 
597
606
  if (fields.length != schema.fieldTypes.length) {
598
607
  throw new Error(
@@ -616,7 +625,7 @@ function uplcToSchema(schema, data, inputContextOnly) {
616
625
  }
617
626
  case "map": {
618
627
  // never uses a ConstrData (one MAY be used in the Enum layer, if needed)
619
- const encodedEntries = MapData.expect(data).items
628
+ const encodedEntries = expectMapData(data).items
620
629
 
621
630
  if (encodedEntries.length != schema.fieldTypes.length) {
622
631
  throw new Error(
@@ -632,7 +641,7 @@ function uplcToSchema(schema, data, inputContextOnly) {
632
641
  return encodedEntries.findIndex(([key, _]) => {
633
642
  return (
634
643
  targetName ==
635
- decodeUtf8(ByteArrayData.expect(key).bytes)
644
+ decodeUtf8(expectByteArrayData(key).bytes)
636
645
  )
637
646
  })
638
647
  }
@@ -640,7 +649,7 @@ function uplcToSchema(schema, data, inputContextOnly) {
640
649
  return Object.fromEntries(
641
650
  schema.fieldTypes
642
651
  .map(({ name, type, key: encodingKey }) => {
643
- const i = expectSome(
652
+ const i = expectDefined(
644
653
  findSerializedFieldIndex(
645
654
  encodingKey || name
646
655
  )
@@ -692,7 +701,7 @@ function uplcToSchema(schema, data, inputContextOnly) {
692
701
  }
693
702
  case "enum": {
694
703
  defs[schema.id] = schema
695
- const { tag, fields } = ConstrData.expect(data)
704
+ const { tag, fields } = expectConstrData(data)
696
705
 
697
706
  const variantSchema = schema.variantTypes[tag]
698
707
 
@@ -727,7 +736,7 @@ function uplcToSchema(schema, data, inputContextOnly) {
727
736
  }
728
737
  case "variant": {
729
738
  defs[schema.id] = schema
730
- const { fields } = ConstrData.expect(data)
739
+ const { fields } = expectConstrData(data)
731
740
 
732
741
  return Object.fromEntries(
733
742
  fields.map((field, i) => [
@@ -752,9 +761,9 @@ function uplcToSchema(schema, data, inputContextOnly) {
752
761
  * @returns {Cast<TStrict, TPermissive>}
753
762
  */
754
763
  export function configureCast(cast, config) {
755
- if (cast instanceof Cast) {
764
+ if ("kind" in cast && cast.kind == "Cast") {
756
765
  return cast
757
766
  } else {
758
- return cast(config)
767
+ return /** @type {any} */ (cast)(config)
759
768
  }
760
769
  }