Skip to content

Commit dfa140c

Browse files
Merge pull request #61 from IntersectMBO/feat/use-json-compatible-schemas
feat/use json compatible schemas
2 parents abda828 + 0dcf415 commit dfa140c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1438
-1046
lines changed

.changeset/quick-parrots-see.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@evolution-sdk/evolution": patch
3+
---
4+
5+
upgrade modules

docs/content/docs/modules/core/CBOR.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ export declare const isRecord: (
536536
export declare const isTag: (
537537
u: unknown,
538538
overrideOptions?: ParseOptions | number
539-
) => u is { readonly value: CBOR; readonly _tag: "Tag"; readonly tag: number }
539+
) => u is { readonly _tag: "Tag"; readonly tag: number; readonly value: CBOR }
540540
```
541541
542542
## map

docs/content/docs/modules/core/Coin.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ coin = uint
109109
**Signature**
110110
111111
```ts
112-
export declare const Coin: Schema.refine<bigint, typeof Schema.BigIntFromSelf>
112+
export declare const Coin: Schema.refine<bigint, typeof Schema.BigInt>
113113
```
114114
115115
Added in v2.0.0

docs/content/docs/modules/core/Data.mdx

Lines changed: 77 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ parent: Modules
3737
- [arbitraryPlutusMap](#arbitraryplutusmap)
3838
- [model](#model)
3939
- [Data (type alias)](#data-type-alias)
40+
- [DataEncoded (type alias)](#dataencoded-type-alias)
4041
- [List (type alias)](#list-type-alias)
4142
- [Map (type alias)](#map-type-alias)
4243
- [predicates](#predicates)
@@ -48,6 +49,8 @@ parent: Modules
4849
- [schemas](#schemas)
4950
- [ByteArray](#bytearray-1)
5051
- [Constr (class)](#constr-class)
52+
- [[Equal.symbol] (method)](#equalsymbol-method)
53+
- [[Hash.symbol] (method)](#hashsymbol-method)
5154
- [DataSchema](#dataschema)
5255
- [FromCBORBytes](#fromcborbytes)
5356
- [FromCBORHex](#fromcborhex)
@@ -255,7 +258,7 @@ Creates an arbitrary that generates PlutusBigInt values
255258
**Signature**
256259

257260
```ts
258-
export declare const arbitraryPlutusBigInt: () => FastCheck.Arbitrary<Int>
261+
export declare const arbitraryPlutusBigInt: () => FastCheck.Arbitrary<bigint>
259262
```
260263

261264
Added in v2.0.0
@@ -267,7 +270,7 @@ Creates an arbitrary that generates PlutusBytes values
267270
**Signature**
268271

269272
```ts
270-
export declare const arbitraryPlutusBytes: () => FastCheck.Arbitrary<ByteArray>
273+
export declare const arbitraryPlutusBytes: () => FastCheck.Arbitrary<Uint8Array>
271274
```
272275

273276
Added in v2.0.0
@@ -349,7 +352,40 @@ Constructor Index Limits:
349352
**Signature**
350353

351354
```ts
352-
export type Data = Constr | ReadonlyMap<Data, Data> | ReadonlyArray<Data> | bigint | string
355+
export type Data =
356+
// Constr (runtime with bigint index)
357+
| Constr
358+
// Map (using standard Map since Schema.Map produces Map<K,V>)
359+
| globalThis.Map<Data, Data>
360+
// List
361+
| ReadonlyArray<Data>
362+
// Int (runtime as bigint)
363+
| bigint
364+
// ByteArray (runtime as Uint8Array)
365+
| Uint8Array
366+
```
367+
368+
Added in v2.0.0
369+
370+
## DataEncoded (type alias)
371+
372+
PlutusData encoded type (for JSON/CBOR encoding)
373+
Based on Conway CDDL specification
374+
375+
**Signature**
376+
377+
```ts
378+
export type DataEncoded =
379+
// Constr (encoded with string index)
380+
| { readonly index: string; readonly fields: ReadonlyArray<DataEncoded> }
381+
// Map (encoded as array of [key, value] pairs)
382+
| ReadonlyArray<readonly [DataEncoded, DataEncoded]>
383+
// List
384+
| ReadonlyArray<DataEncoded>
385+
// Int (encoded as string)
386+
| string
387+
// ByteArray (encoded as hex string)
388+
| string
353389
```
354390
355391
Added in v2.0.0
@@ -373,7 +409,7 @@ PlutusMap type alias
373409
**Signature**
374410
375411
```ts
376-
export type Map = ReadonlyMap<Data, Data>
412+
export type Map = globalThis.Map<Data, Data>
377413
```
378414
379415
Added in v2.0.0
@@ -387,7 +423,7 @@ Type guard to check if a value is a PlutusBytes
387423
**Signature**
388424
389425
```ts
390-
export declare const isBytes: (u: unknown, overrideOptions?: ParseOptions | number) => u is string
426+
export declare const isBytes: (u: unknown, overrideOptions?: ParseOptions | number) => u is Uint8Array
391427
```
392428
393429
Added in v2.0.0
@@ -435,7 +471,7 @@ Type guard to check if a value is a PlutusMap
435471
**Signature**
436472
437473
```ts
438-
export declare const isMap: (u: unknown, overrideOptions?: ParseOptions | number) => u is ReadonlyMap<Data, Data>
474+
export declare const isMap: (u: unknown, overrideOptions?: ParseOptions | number) => u is globalThis.Map<Data, Data>
439475
```
440476
441477
Added in v2.0.0
@@ -449,7 +485,7 @@ Schema for PlutusBytes data type
449485
**Signature**
450486
451487
```ts
452-
export declare const ByteArray: Schema.refine<string, typeof Schema.String>
488+
export declare const ByteArray: Schema.Schema<Uint8Array, string, never>
453489
```
454490
455491
Added in v2.0.0
@@ -466,22 +502,30 @@ export declare class Constr
466502

467503
Added in v2.0.0
468504

505+
### [Equal.symbol] (method)
506+
507+
**Signature**
508+
509+
```ts
510+
[Equal.symbol](that: unknown): boolean
511+
```
512+
513+
### [Hash.symbol] (method)
514+
515+
**Signature**
516+
517+
```ts
518+
[Hash.symbol](): number
519+
```
520+
469521
## DataSchema
470522

471523
Combined schema for PlutusData type with proper recursion
472524

473525
**Signature**
474526

475527
```ts
476-
export declare const DataSchema: Schema.Union<
477-
[
478-
Schema.ReadonlyMapFromSelf<Schema.suspend<Data, Data, never>, Schema.suspend<Data, Data, never>>,
479-
Schema.Array$<Schema.suspend<Data, Data, never>>,
480-
Schema.SchemaClass<bigint, bigint, never>,
481-
Schema.refine<string, typeof Schema.String>,
482-
typeof Constr
483-
]
484-
>
528+
export declare const DataSchema: Schema.Schema<Data, DataEncoded, never>
485529
```
486530

487531
Added in v2.0.0
@@ -502,15 +546,7 @@ export declare const FromCBORBytes: (
502546
Schema.declare<CBOR.CBOR, CBOR.CBOR, readonly [], never>,
503547
never
504548
>,
505-
Schema.transformOrFail<
506-
Schema.Schema<CBOR.CBOR, CBOR.CBOR, never>,
507-
Schema.SchemaClass<
508-
string | bigint | Constr | readonly Data[] | ReadonlyMap<Data, Data>,
509-
string | bigint | Constr | readonly Data[] | ReadonlyMap<Data, Data>,
510-
never
511-
>,
512-
never
513-
>
549+
Schema.transformOrFail<Schema.Schema<CBOR.CBOR, CBOR.CBOR, never>, Schema.SchemaClass<Data, Data, never>, never>
514550
>
515551
```
516552

@@ -534,15 +570,7 @@ export declare const FromCBORHex: (
534570
Schema.declare<CBOR.CBOR, CBOR.CBOR, readonly [], never>,
535571
never
536572
>,
537-
Schema.transformOrFail<
538-
Schema.Schema<CBOR.CBOR, CBOR.CBOR, never>,
539-
Schema.SchemaClass<
540-
string | bigint | Constr | readonly Data[] | ReadonlyMap<Data, Data>,
541-
string | bigint | Constr | readonly Data[] | ReadonlyMap<Data, Data>,
542-
never
543-
>,
544-
never
545-
>
573+
Schema.transformOrFail<Schema.Schema<CBOR.CBOR, CBOR.CBOR, never>, Schema.SchemaClass<Data, Data, never>, never>
546574
>
547575
>
548576
```
@@ -584,11 +612,7 @@ plutusDataToCBORValue and cborValueToPlutusData functions.
584612
```ts
585613
export declare const FromCDDL: Schema.transformOrFail<
586614
Schema.Schema<CBOR.CBOR, CBOR.CBOR, never>,
587-
Schema.SchemaClass<
588-
string | bigint | Constr | readonly Data[] | ReadonlyMap<Data, Data>,
589-
string | bigint | Constr | readonly Data[] | ReadonlyMap<Data, Data>,
590-
never
591-
>,
615+
Schema.SchemaClass<Data, Data, never>,
592616
never
593617
>
594618
```
@@ -618,7 +642,11 @@ Note: JavaScript's Number.MAX_SAFE_INTEGER (2^53-1) is much smaller than CBOR's
618642
**Signature**
619643

620644
```ts
621-
export declare const IntSchema: Schema.SchemaClass<bigint, bigint, never>
645+
export declare const IntSchema: Schema.transformOrFail<
646+
Schema.SchemaClass<string, string, never>,
647+
typeof Schema.BigIntFromSelf,
648+
never
649+
>
622650
```
623651
624652
Added in v2.0.0
@@ -630,7 +658,7 @@ Schema for PlutusList data type
630658
**Signature**
631659
632660
```ts
633-
export declare const ListSchema: Schema.Array$<Schema.suspend<Data, Data, never>>
661+
export declare const ListSchema: Schema.Array$<Schema.suspend<Data, DataEncoded, never>>
634662
```
635663
636664
Added in v2.0.0
@@ -642,9 +670,9 @@ Schema for PlutusMap data type
642670
**Signature**
643671
644672
```ts
645-
export declare const MapSchema: Schema.ReadonlyMapFromSelf<
646-
Schema.suspend<Data, Data, never>,
647-
Schema.suspend<Data, Data, never>
673+
export declare const MapSchema: Schema.transform<
674+
Schema.Array$<Schema.Tuple2<Schema.suspend<Data, DataEncoded, never>, Schema.suspend<Data, DataEncoded, never>>>,
675+
Schema.MapFromSelf<Schema.SchemaClass<Data, Data, never>, Schema.SchemaClass<Data, Data, never>>
648676
>
649677
```
650678
@@ -671,10 +699,7 @@ Decode PlutusData from CBOR bytes
671699
**Signature**
672700
673701
```ts
674-
export declare const fromCBORBytes: (
675-
bytes: Uint8Array,
676-
options?: CBOR.CodecOptions
677-
) => string | bigint | Constr | readonly Data[] | ReadonlyMap<Data, Data>
702+
export declare const fromCBORBytes: (bytes: Uint8Array, options?: CBOR.CodecOptions) => Data
678703
```
679704
680705
Added in v2.0.0
@@ -686,10 +711,7 @@ Decode PlutusData from CBOR hex string
686711
**Signature**
687712
688713
```ts
689-
export declare const fromCBORHex: (
690-
hex: string,
691-
options?: CBOR.CodecOptions
692-
) => string | bigint | Constr | readonly Data[] | ReadonlyMap<Data, Data>
714+
export declare const fromCBORHex: (hex: string, options?: CBOR.CodecOptions) => Data
693715
```
694716
695717
Added in v2.0.0
@@ -713,10 +735,7 @@ Encode PlutusData to CBOR bytes
713735
**Signature**
714736
715737
```ts
716-
export declare const toCBORBytes: (
717-
input: string | bigint | Constr | readonly Data[] | ReadonlyMap<Data, Data>,
718-
options?: CBOR.CodecOptions
719-
) => Uint8Array
738+
export declare const toCBORBytes: (input: Data, options?: CBOR.CodecOptions) => Uint8Array
720739
```
721740
722741
Added in v2.0.0
@@ -728,10 +747,7 @@ Encode PlutusData to CBOR hex string
728747
**Signature**
729748
730749
```ts
731-
export declare const toCBORHex: (
732-
input: string | bigint | Constr | readonly Data[] | ReadonlyMap<Data, Data>,
733-
options?: CBOR.CodecOptions
734-
) => string
750+
export declare const toCBORHex: (input: Data, options?: CBOR.CodecOptions) => string
735751
```
736752
737753
Added in v2.0.0
@@ -766,7 +782,7 @@ export declare const matchData: <T>(
766782
Map: (entries: ReadonlyArray<[Data, Data]>) => T
767783
List: (items: ReadonlyArray<Data>) => T
768784
Int: (value: bigint) => T
769-
Bytes: (bytes: string) => T
785+
Bytes: (bytes: Uint8Array) => T
770786
Constr: (constr: Constr) => T
771787
}
772788
) => T

docs/content/docs/modules/core/EpochNo.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ Schema for validating epoch numbers (0-255).
9292
**Signature**
9393
9494
```ts
95-
export declare const EpochNoSchema: Schema.refine<bigint, typeof Schema.BigIntFromSelf>
95+
export declare const EpochNoSchema: Schema.refine<bigint, typeof Schema.BigInt>
9696
```
9797
9898
Added in v2.0.0

0 commit comments

Comments
 (0)