@latticexyz/schema-type 2.0.0-alpha.1.26 → 2.0.0-alpha.1.261
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.
- package/dist/typescript/deprecated/index.js +2 -0
- package/dist/typescript/deprecated/index.js.map +1 -0
- package/dist/typescript/index.js +1 -8
- package/dist/typescript/index.js.map +1 -1
- package/package.json +24 -8
- package/src/typescript/arrayAbiTypes.ts +17 -0
- package/src/typescript/deprecated/index.ts +4 -0
- package/src/typescript/deprecated/mappings/AbiTypeToDefaultValue.ts +208 -0
- package/src/typescript/deprecated/mappings/AbiTypeToPrimitiveType.ts +12 -0
- package/src/typescript/{AbiTypeToSchemaType.ts → deprecated/mappings/AbiTypeToSchemaType.ts} +2 -2
- package/src/typescript/{SchemaTypeArrayToElement.ts → deprecated/mappings/SchemaTypeArrayToElement.ts} +4 -4
- package/src/typescript/{SchemaTypeToAbiType.ts → deprecated/mappings/SchemaTypeToAbiType.ts} +1 -1
- package/src/typescript/deprecated/mappings/SchemaTypeToPrimitiveType.ts +9 -0
- package/src/typescript/deprecated/mappings/index.ts +5 -0
- package/src/typescript/{SchemaTypeToPrimitive.ts → deprecated/mappings/types.test-d.ts} +25 -2
- package/src/typescript/{AbiTypes.ts → deprecated/types/AbiTypes.ts} +2 -2
- package/src/typescript/{ArraySchemaType.ts → deprecated/types/ArraySchemaType.ts} +1 -1
- package/src/typescript/deprecated/types/DynamicSchemaType.ts +4 -0
- package/src/typescript/deprecated/types/StaticAbiTypes.ts +10 -0
- package/src/typescript/deprecated/types/StaticArray.ts +3 -0
- package/src/typescript/deprecated/types/StaticSchemaType.ts +4 -0
- package/src/typescript/deprecated/types/index.ts +8 -0
- package/src/typescript/{encodeSchema.ts → deprecated/utils/encodeSchema.ts} +2 -2
- package/src/typescript/deprecated/utils/getAbiTypeDefaultValue.ts +11 -0
- package/src/typescript/{getStaticByteLength.ts → deprecated/utils/getStaticByteLength.ts} +1 -1
- package/src/typescript/deprecated/utils/index.ts +3 -0
- package/src/typescript/dynamicAbiTypes.test-d.ts +66 -0
- package/src/typescript/dynamicAbiTypes.ts +124 -0
- package/src/typescript/index.ts +6 -15
- package/src/typescript/schemaAbiTypeToDefaultValue.ts +8 -0
- package/src/typescript/schemaAbiTypeToPrimitiveType.ts +7 -0
- package/src/typescript/schemaAbiTypes.test.ts +17 -0
- package/src/typescript/schemaAbiTypes.ts +213 -0
- package/src/typescript/staticAbiTypes.test-d.ts +58 -0
- package/src/typescript/staticAbiTypes.ts +219 -0
- package/src/typescript/utils.ts +23 -0
- package/dist/typescript/AbiTypeToSchemaType.d.ts +0 -4
- package/dist/typescript/AbiTypeToSchemaType.js +0 -3
- package/dist/typescript/AbiTypeToSchemaType.js.map +0 -1
- package/dist/typescript/AbiTypes.d.ts +0 -4
- package/dist/typescript/AbiTypes.js +0 -3
- package/dist/typescript/AbiTypes.js.map +0 -1
- package/dist/typescript/ArraySchemaType.d.ts +0 -2
- package/dist/typescript/ArraySchemaType.js +0 -2
- package/dist/typescript/ArraySchemaType.js.map +0 -1
- package/dist/typescript/DynamicSchemaType.d.ts +0 -3
- package/dist/typescript/DynamicSchemaType.js +0 -2
- package/dist/typescript/DynamicSchemaType.js.map +0 -1
- package/dist/typescript/SchemaType.d.ts +0 -200
- package/dist/typescript/SchemaType.js +0 -204
- package/dist/typescript/SchemaType.js.map +0 -1
- package/dist/typescript/SchemaTypeArrayToElement.d.ts +0 -201
- package/dist/typescript/SchemaTypeArrayToElement.js +0 -102
- package/dist/typescript/SchemaTypeArrayToElement.js.map +0 -1
- package/dist/typescript/SchemaTypeToAbiType.d.ts +0 -200
- package/dist/typescript/SchemaTypeToAbiType.js +0 -202
- package/dist/typescript/SchemaTypeToAbiType.js.map +0 -1
- package/dist/typescript/SchemaTypeToPrimitive.d.ts +0 -201
- package/dist/typescript/SchemaTypeToPrimitive.js +0 -2
- package/dist/typescript/SchemaTypeToPrimitive.js.map +0 -1
- package/dist/typescript/StaticAbiTypes.d.ts +0 -4
- package/dist/typescript/StaticAbiTypes.js +0 -5
- package/dist/typescript/StaticAbiTypes.js.map +0 -1
- package/dist/typescript/StaticSchemaType.d.ts +0 -3
- package/dist/typescript/StaticSchemaType.js +0 -2
- package/dist/typescript/StaticSchemaType.js.map +0 -1
- package/dist/typescript/encodeSchema.d.ts +0 -8
- package/dist/typescript/encodeSchema.js +0 -43
- package/dist/typescript/encodeSchema.js.map +0 -1
- package/dist/typescript/getStaticByteLength.d.ts +0 -2
- package/dist/typescript/getStaticByteLength.js +0 -26
- package/dist/typescript/getStaticByteLength.js.map +0 -1
- package/dist/typescript/index.d.ts +0 -14
- package/src/typescript/DynamicSchemaType.ts +0 -4
- package/src/typescript/StaticAbiTypes.ts +0 -10
- package/src/typescript/StaticSchemaType.ts +0 -4
- /package/src/typescript/{SchemaType.ts → deprecated/SchemaType.ts} +0 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AbiTypes } from "./AbiTypes";
|
|
2
|
+
import { AbiTypeToSchemaType } from "../mappings/AbiTypeToSchemaType";
|
|
3
|
+
import { getStaticByteLength } from "../utils/getStaticByteLength";
|
|
4
|
+
import { SchemaTypeToAbiType } from "../mappings/SchemaTypeToAbiType";
|
|
5
|
+
import { StaticSchemaType } from "./StaticSchemaType";
|
|
6
|
+
|
|
7
|
+
export type StaticAbiType = (typeof SchemaTypeToAbiType)[StaticSchemaType];
|
|
8
|
+
export const StaticAbiTypes = AbiTypes.filter(
|
|
9
|
+
(abiType) => getStaticByteLength(AbiTypeToSchemaType[abiType]) > 0
|
|
10
|
+
) as StaticAbiType[];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type { AbiType } from "./AbiTypes";
|
|
2
|
+
export { AbiTypes } from "./AbiTypes";
|
|
3
|
+
export type { ArraySchemaType } from "./ArraySchemaType";
|
|
4
|
+
export type { DynamicSchemaType } from "./DynamicSchemaType";
|
|
5
|
+
export type { StaticAbiType } from "./StaticAbiTypes";
|
|
6
|
+
export { StaticAbiTypes } from "./StaticAbiTypes";
|
|
7
|
+
export type { StaticArray } from "./StaticArray";
|
|
8
|
+
export type { StaticSchemaType } from "./StaticSchemaType";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getStaticByteLength } from "./getStaticByteLength
|
|
2
|
-
import { SchemaType } from "
|
|
1
|
+
import { getStaticByteLength } from "./getStaticByteLength";
|
|
2
|
+
import { SchemaType } from "../SchemaType";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Encode a table schema into a bytes32 hex string
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AbiTypeToPrimitiveType } from "../mappings";
|
|
2
|
+
import { AbiTypeToDefaultValue } from "../mappings/AbiTypeToDefaultValue";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Return a value corresponding to the Solidity default value for a given abi type
|
|
6
|
+
*/
|
|
7
|
+
export function getAbiTypeDefaultValue<T extends string>(abiType: T) {
|
|
8
|
+
// Remove fixed array lengths (eg map uint256[10] to uint256[])
|
|
9
|
+
const normalizedType = abiType.replace(/(\w+)\[\d+\]/g, "$1[]");
|
|
10
|
+
return AbiTypeToDefaultValue[normalizedType as keyof typeof AbiTypeToDefaultValue] as AbiTypeToPrimitiveType<T>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { describe, expectTypeOf, it } from "vitest";
|
|
2
|
+
import { Hex } from "viem";
|
|
3
|
+
import { DynamicAbiTypeToPrimitiveType } from "./dynamicAbiTypes";
|
|
4
|
+
|
|
5
|
+
describe("DynamicAbiTypeToPrimitiveType", () => {
|
|
6
|
+
it("maps uint8 array to number array", () => {
|
|
7
|
+
expectTypeOf<DynamicAbiTypeToPrimitiveType<"uint8[]">>().toMatchTypeOf<readonly number[]>();
|
|
8
|
+
});
|
|
9
|
+
it("maps uint32 array to number array", () => {
|
|
10
|
+
expectTypeOf<DynamicAbiTypeToPrimitiveType<"uint32[]">>().toMatchTypeOf<readonly number[]>();
|
|
11
|
+
});
|
|
12
|
+
it("maps uint48 array to number array", () => {
|
|
13
|
+
expectTypeOf<DynamicAbiTypeToPrimitiveType<"uint48[]">>().toMatchTypeOf<readonly number[]>();
|
|
14
|
+
});
|
|
15
|
+
it("maps uint56 array to bigint array", () => {
|
|
16
|
+
expectTypeOf<DynamicAbiTypeToPrimitiveType<"uint56[]">>().toMatchTypeOf<readonly bigint[]>();
|
|
17
|
+
});
|
|
18
|
+
it("maps uint256 array to bigint array", () => {
|
|
19
|
+
expectTypeOf<DynamicAbiTypeToPrimitiveType<"uint256[]">>().toMatchTypeOf<readonly bigint[]>();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("maps int8 array to number array", () => {
|
|
23
|
+
expectTypeOf<DynamicAbiTypeToPrimitiveType<"int8[]">>().toMatchTypeOf<readonly number[]>();
|
|
24
|
+
});
|
|
25
|
+
it("maps int32 array to number array", () => {
|
|
26
|
+
expectTypeOf<DynamicAbiTypeToPrimitiveType<"int32[]">>().toMatchTypeOf<readonly number[]>();
|
|
27
|
+
});
|
|
28
|
+
it("maps int48 array to number array", () => {
|
|
29
|
+
expectTypeOf<DynamicAbiTypeToPrimitiveType<"int48[]">>().toMatchTypeOf<readonly number[]>();
|
|
30
|
+
});
|
|
31
|
+
it("maps int56 array to bigint array", () => {
|
|
32
|
+
expectTypeOf<DynamicAbiTypeToPrimitiveType<"int56[]">>().toMatchTypeOf<readonly bigint[]>();
|
|
33
|
+
});
|
|
34
|
+
it("maps int256 array to bigint array", () => {
|
|
35
|
+
expectTypeOf<DynamicAbiTypeToPrimitiveType<"int256[]">>().toMatchTypeOf<readonly bigint[]>();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("maps bytes1 array to hex array", () => {
|
|
39
|
+
expectTypeOf<DynamicAbiTypeToPrimitiveType<"bytes1[]">>().toMatchTypeOf<readonly Hex[]>();
|
|
40
|
+
});
|
|
41
|
+
it("maps bytes2 array to hex array", () => {
|
|
42
|
+
expectTypeOf<DynamicAbiTypeToPrimitiveType<"bytes2[]">>().toMatchTypeOf<readonly Hex[]>();
|
|
43
|
+
});
|
|
44
|
+
it("maps bytes8 array to hex array", () => {
|
|
45
|
+
expectTypeOf<DynamicAbiTypeToPrimitiveType<"bytes8[]">>().toMatchTypeOf<readonly Hex[]>();
|
|
46
|
+
});
|
|
47
|
+
it("maps bytes32 array to hex array", () => {
|
|
48
|
+
expectTypeOf<DynamicAbiTypeToPrimitiveType<"bytes32[]">>().toMatchTypeOf<readonly Hex[]>();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("maps bool array to boolean array", () => {
|
|
52
|
+
expectTypeOf<DynamicAbiTypeToPrimitiveType<"bool[]">>().toMatchTypeOf<readonly boolean[]>();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("maps address array to hex array", () => {
|
|
56
|
+
expectTypeOf<DynamicAbiTypeToPrimitiveType<"address[]">>().toMatchTypeOf<readonly Hex[]>();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("maps bytes to hex", () => {
|
|
60
|
+
expectTypeOf<DynamicAbiTypeToPrimitiveType<"bytes">>().toMatchTypeOf<Hex>();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("maps string to string", () => {
|
|
64
|
+
expectTypeOf<DynamicAbiTypeToPrimitiveType<"string">>().toMatchTypeOf<string>();
|
|
65
|
+
});
|
|
66
|
+
});
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { Hex } from "viem";
|
|
2
|
+
import { DynamicAbiType } from "./schemaAbiTypes";
|
|
3
|
+
import { LiteralToBroad } from "./utils";
|
|
4
|
+
|
|
5
|
+
// Variable-length ABI types, where their lengths are encoded by a PackedCounter within the record
|
|
6
|
+
|
|
7
|
+
export type DynamicPrimitiveType =
|
|
8
|
+
| readonly number[]
|
|
9
|
+
| readonly bigint[]
|
|
10
|
+
| readonly Hex[]
|
|
11
|
+
| readonly boolean[]
|
|
12
|
+
| Hex
|
|
13
|
+
| string;
|
|
14
|
+
|
|
15
|
+
export const dynamicAbiTypeToDefaultValue = {
|
|
16
|
+
"uint8[]": [] as readonly number[],
|
|
17
|
+
"uint16[]": [] as readonly number[],
|
|
18
|
+
"uint24[]": [] as readonly number[],
|
|
19
|
+
"uint32[]": [] as readonly number[],
|
|
20
|
+
"uint40[]": [] as readonly number[],
|
|
21
|
+
"uint48[]": [] as readonly number[],
|
|
22
|
+
"uint56[]": [] as readonly bigint[],
|
|
23
|
+
"uint64[]": [] as readonly bigint[],
|
|
24
|
+
"uint72[]": [] as readonly bigint[],
|
|
25
|
+
"uint80[]": [] as readonly bigint[],
|
|
26
|
+
"uint88[]": [] as readonly bigint[],
|
|
27
|
+
"uint96[]": [] as readonly bigint[],
|
|
28
|
+
"uint104[]": [] as readonly bigint[],
|
|
29
|
+
"uint112[]": [] as readonly bigint[],
|
|
30
|
+
"uint120[]": [] as readonly bigint[],
|
|
31
|
+
"uint128[]": [] as readonly bigint[],
|
|
32
|
+
"uint136[]": [] as readonly bigint[],
|
|
33
|
+
"uint144[]": [] as readonly bigint[],
|
|
34
|
+
"uint152[]": [] as readonly bigint[],
|
|
35
|
+
"uint160[]": [] as readonly bigint[],
|
|
36
|
+
"uint168[]": [] as readonly bigint[],
|
|
37
|
+
"uint176[]": [] as readonly bigint[],
|
|
38
|
+
"uint184[]": [] as readonly bigint[],
|
|
39
|
+
"uint192[]": [] as readonly bigint[],
|
|
40
|
+
"uint200[]": [] as readonly bigint[],
|
|
41
|
+
"uint208[]": [] as readonly bigint[],
|
|
42
|
+
"uint216[]": [] as readonly bigint[],
|
|
43
|
+
"uint224[]": [] as readonly bigint[],
|
|
44
|
+
"uint232[]": [] as readonly bigint[],
|
|
45
|
+
"uint240[]": [] as readonly bigint[],
|
|
46
|
+
"uint248[]": [] as readonly bigint[],
|
|
47
|
+
"uint256[]": [] as readonly bigint[],
|
|
48
|
+
|
|
49
|
+
"int8[]": [] as readonly number[],
|
|
50
|
+
"int16[]": [] as readonly number[],
|
|
51
|
+
"int24[]": [] as readonly number[],
|
|
52
|
+
"int32[]": [] as readonly number[],
|
|
53
|
+
"int40[]": [] as readonly number[],
|
|
54
|
+
"int48[]": [] as readonly number[],
|
|
55
|
+
"int56[]": [] as readonly bigint[],
|
|
56
|
+
"int64[]": [] as readonly bigint[],
|
|
57
|
+
"int72[]": [] as readonly bigint[],
|
|
58
|
+
"int80[]": [] as readonly bigint[],
|
|
59
|
+
"int88[]": [] as readonly bigint[],
|
|
60
|
+
"int96[]": [] as readonly bigint[],
|
|
61
|
+
"int104[]": [] as readonly bigint[],
|
|
62
|
+
"int112[]": [] as readonly bigint[],
|
|
63
|
+
"int120[]": [] as readonly bigint[],
|
|
64
|
+
"int128[]": [] as readonly bigint[],
|
|
65
|
+
"int136[]": [] as readonly bigint[],
|
|
66
|
+
"int144[]": [] as readonly bigint[],
|
|
67
|
+
"int152[]": [] as readonly bigint[],
|
|
68
|
+
"int160[]": [] as readonly bigint[],
|
|
69
|
+
"int168[]": [] as readonly bigint[],
|
|
70
|
+
"int176[]": [] as readonly bigint[],
|
|
71
|
+
"int184[]": [] as readonly bigint[],
|
|
72
|
+
"int192[]": [] as readonly bigint[],
|
|
73
|
+
"int200[]": [] as readonly bigint[],
|
|
74
|
+
"int208[]": [] as readonly bigint[],
|
|
75
|
+
"int216[]": [] as readonly bigint[],
|
|
76
|
+
"int224[]": [] as readonly bigint[],
|
|
77
|
+
"int232[]": [] as readonly bigint[],
|
|
78
|
+
"int240[]": [] as readonly bigint[],
|
|
79
|
+
"int248[]": [] as readonly bigint[],
|
|
80
|
+
"int256[]": [] as readonly bigint[],
|
|
81
|
+
|
|
82
|
+
"bytes1[]": [] as readonly Hex[],
|
|
83
|
+
"bytes2[]": [] as readonly Hex[],
|
|
84
|
+
"bytes3[]": [] as readonly Hex[],
|
|
85
|
+
"bytes4[]": [] as readonly Hex[],
|
|
86
|
+
"bytes5[]": [] as readonly Hex[],
|
|
87
|
+
"bytes6[]": [] as readonly Hex[],
|
|
88
|
+
"bytes7[]": [] as readonly Hex[],
|
|
89
|
+
"bytes8[]": [] as readonly Hex[],
|
|
90
|
+
"bytes9[]": [] as readonly Hex[],
|
|
91
|
+
"bytes10[]": [] as readonly Hex[],
|
|
92
|
+
"bytes11[]": [] as readonly Hex[],
|
|
93
|
+
"bytes12[]": [] as readonly Hex[],
|
|
94
|
+
"bytes13[]": [] as readonly Hex[],
|
|
95
|
+
"bytes14[]": [] as readonly Hex[],
|
|
96
|
+
"bytes15[]": [] as readonly Hex[],
|
|
97
|
+
"bytes16[]": [] as readonly Hex[],
|
|
98
|
+
"bytes17[]": [] as readonly Hex[],
|
|
99
|
+
"bytes18[]": [] as readonly Hex[],
|
|
100
|
+
"bytes19[]": [] as readonly Hex[],
|
|
101
|
+
"bytes20[]": [] as readonly Hex[],
|
|
102
|
+
"bytes21[]": [] as readonly Hex[],
|
|
103
|
+
"bytes22[]": [] as readonly Hex[],
|
|
104
|
+
"bytes23[]": [] as readonly Hex[],
|
|
105
|
+
"bytes24[]": [] as readonly Hex[],
|
|
106
|
+
"bytes25[]": [] as readonly Hex[],
|
|
107
|
+
"bytes26[]": [] as readonly Hex[],
|
|
108
|
+
"bytes27[]": [] as readonly Hex[],
|
|
109
|
+
"bytes28[]": [] as readonly Hex[],
|
|
110
|
+
"bytes29[]": [] as readonly Hex[],
|
|
111
|
+
"bytes30[]": [] as readonly Hex[],
|
|
112
|
+
"bytes31[]": [] as readonly Hex[],
|
|
113
|
+
"bytes32[]": [] as readonly Hex[],
|
|
114
|
+
|
|
115
|
+
"bool[]": [] as readonly boolean[],
|
|
116
|
+
"address[]": [] as readonly Hex[],
|
|
117
|
+
|
|
118
|
+
bytes: "0x",
|
|
119
|
+
string: "",
|
|
120
|
+
} as const satisfies Record<DynamicAbiType, DynamicPrimitiveType>;
|
|
121
|
+
|
|
122
|
+
export type DynamicAbiTypeToPrimitiveType<TDynamicAbiType extends DynamicAbiType = DynamicAbiType> = LiteralToBroad<
|
|
123
|
+
(typeof dynamicAbiTypeToDefaultValue)[TDynamicAbiType]
|
|
124
|
+
>;
|
package/src/typescript/index.ts
CHANGED
|
@@ -1,15 +1,6 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
export { SchemaType } from "./SchemaType.js";
|
|
9
|
-
export { encodeSchema } from "./encodeSchema.js";
|
|
10
|
-
export { getStaticByteLength } from "./getStaticByteLength.js";
|
|
11
|
-
export { SchemaTypeArrayToElement } from "./SchemaTypeArrayToElement.js";
|
|
12
|
-
export { SchemaTypeToAbiType } from "./SchemaTypeToAbiType.js";
|
|
13
|
-
export { AbiTypeToSchemaType } from "./AbiTypeToSchemaType.js";
|
|
14
|
-
export { AbiTypes } from "./AbiTypes.js";
|
|
15
|
-
export { StaticAbiTypes } from "./StaticAbiTypes.js";
|
|
1
|
+
export * from "./arrayAbiTypes";
|
|
2
|
+
export * from "./dynamicAbiTypes";
|
|
3
|
+
export * from "./schemaAbiTypes";
|
|
4
|
+
export * from "./schemaAbiTypeToDefaultValue";
|
|
5
|
+
export * from "./staticAbiTypes";
|
|
6
|
+
export * from "./schemaAbiTypeToPrimitiveType";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { SchemaAbiType } from "./schemaAbiTypes";
|
|
2
|
+
import { DynamicAbiTypeToPrimitiveType, dynamicAbiTypeToDefaultValue } from "./dynamicAbiTypes";
|
|
3
|
+
import { StaticAbiTypeToPrimitiveType, staticAbiTypeToDefaultValue } from "./staticAbiTypes";
|
|
4
|
+
|
|
5
|
+
export const schemaAbiTypeToDefaultValue = {
|
|
6
|
+
...staticAbiTypeToDefaultValue,
|
|
7
|
+
...dynamicAbiTypeToDefaultValue,
|
|
8
|
+
} as const satisfies Record<SchemaAbiType, StaticAbiTypeToPrimitiveType | DynamicAbiTypeToPrimitiveType>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { schemaAbiTypeToDefaultValue } from "./schemaAbiTypeToDefaultValue";
|
|
2
|
+
import { SchemaAbiType } from "./schemaAbiTypes";
|
|
3
|
+
import { LiteralToBroad } from "./utils";
|
|
4
|
+
|
|
5
|
+
export type SchemaAbiTypeToPrimitiveType<T extends SchemaAbiType> = LiteralToBroad<
|
|
6
|
+
(typeof schemaAbiTypeToDefaultValue)[T]
|
|
7
|
+
>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import { schemaAbiTypes } from "./schemaAbiTypes";
|
|
4
|
+
|
|
5
|
+
describe("schemaAbiTypes", () => {
|
|
6
|
+
it("should be in sync with SchemaType.sol", async () => {
|
|
7
|
+
const source = await fs.readFile(`${__dirname}/../solidity/SchemaType.sol`, "utf8");
|
|
8
|
+
const matches = source.match(/enum SchemaType \{([\s\S]+?)\}/);
|
|
9
|
+
const soliditySchemaTypes = matches?.[1].replace(/\s/g, "").split(",") ?? [];
|
|
10
|
+
|
|
11
|
+
const soliditySchemaTypesAsAbiTypes = soliditySchemaTypes.map((soliditySchemaType) =>
|
|
12
|
+
soliditySchemaType.replace(/_ARRAY$/, "[]").toLowerCase()
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
expect(soliditySchemaTypesAsAbiTypes).toStrictEqual(schemaAbiTypes);
|
|
16
|
+
});
|
|
17
|
+
});
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { AbiType } from "abitype";
|
|
2
|
+
import { TupleSplit } from "./utils";
|
|
3
|
+
|
|
4
|
+
// Keep this array in sync with SchemaType.sol enum
|
|
5
|
+
export const schemaAbiTypes = [
|
|
6
|
+
"uint8",
|
|
7
|
+
"uint16",
|
|
8
|
+
"uint24",
|
|
9
|
+
"uint32",
|
|
10
|
+
"uint40",
|
|
11
|
+
"uint48",
|
|
12
|
+
"uint56",
|
|
13
|
+
"uint64",
|
|
14
|
+
"uint72",
|
|
15
|
+
"uint80",
|
|
16
|
+
"uint88",
|
|
17
|
+
"uint96",
|
|
18
|
+
"uint104",
|
|
19
|
+
"uint112",
|
|
20
|
+
"uint120",
|
|
21
|
+
"uint128",
|
|
22
|
+
"uint136",
|
|
23
|
+
"uint144",
|
|
24
|
+
"uint152",
|
|
25
|
+
"uint160",
|
|
26
|
+
"uint168",
|
|
27
|
+
"uint176",
|
|
28
|
+
"uint184",
|
|
29
|
+
"uint192",
|
|
30
|
+
"uint200",
|
|
31
|
+
"uint208",
|
|
32
|
+
"uint216",
|
|
33
|
+
"uint224",
|
|
34
|
+
"uint232",
|
|
35
|
+
"uint240",
|
|
36
|
+
"uint248",
|
|
37
|
+
"uint256",
|
|
38
|
+
"int8",
|
|
39
|
+
"int16",
|
|
40
|
+
"int24",
|
|
41
|
+
"int32",
|
|
42
|
+
"int40",
|
|
43
|
+
"int48",
|
|
44
|
+
"int56",
|
|
45
|
+
"int64",
|
|
46
|
+
"int72",
|
|
47
|
+
"int80",
|
|
48
|
+
"int88",
|
|
49
|
+
"int96",
|
|
50
|
+
"int104",
|
|
51
|
+
"int112",
|
|
52
|
+
"int120",
|
|
53
|
+
"int128",
|
|
54
|
+
"int136",
|
|
55
|
+
"int144",
|
|
56
|
+
"int152",
|
|
57
|
+
"int160",
|
|
58
|
+
"int168",
|
|
59
|
+
"int176",
|
|
60
|
+
"int184",
|
|
61
|
+
"int192",
|
|
62
|
+
"int200",
|
|
63
|
+
"int208",
|
|
64
|
+
"int216",
|
|
65
|
+
"int224",
|
|
66
|
+
"int232",
|
|
67
|
+
"int240",
|
|
68
|
+
"int248",
|
|
69
|
+
"int256",
|
|
70
|
+
"bytes1",
|
|
71
|
+
"bytes2",
|
|
72
|
+
"bytes3",
|
|
73
|
+
"bytes4",
|
|
74
|
+
"bytes5",
|
|
75
|
+
"bytes6",
|
|
76
|
+
"bytes7",
|
|
77
|
+
"bytes8",
|
|
78
|
+
"bytes9",
|
|
79
|
+
"bytes10",
|
|
80
|
+
"bytes11",
|
|
81
|
+
"bytes12",
|
|
82
|
+
"bytes13",
|
|
83
|
+
"bytes14",
|
|
84
|
+
"bytes15",
|
|
85
|
+
"bytes16",
|
|
86
|
+
"bytes17",
|
|
87
|
+
"bytes18",
|
|
88
|
+
"bytes19",
|
|
89
|
+
"bytes20",
|
|
90
|
+
"bytes21",
|
|
91
|
+
"bytes22",
|
|
92
|
+
"bytes23",
|
|
93
|
+
"bytes24",
|
|
94
|
+
"bytes25",
|
|
95
|
+
"bytes26",
|
|
96
|
+
"bytes27",
|
|
97
|
+
"bytes28",
|
|
98
|
+
"bytes29",
|
|
99
|
+
"bytes30",
|
|
100
|
+
"bytes31",
|
|
101
|
+
"bytes32",
|
|
102
|
+
"bool",
|
|
103
|
+
"address",
|
|
104
|
+
"uint8[]",
|
|
105
|
+
"uint16[]",
|
|
106
|
+
"uint24[]",
|
|
107
|
+
"uint32[]",
|
|
108
|
+
"uint40[]",
|
|
109
|
+
"uint48[]",
|
|
110
|
+
"uint56[]",
|
|
111
|
+
"uint64[]",
|
|
112
|
+
"uint72[]",
|
|
113
|
+
"uint80[]",
|
|
114
|
+
"uint88[]",
|
|
115
|
+
"uint96[]",
|
|
116
|
+
"uint104[]",
|
|
117
|
+
"uint112[]",
|
|
118
|
+
"uint120[]",
|
|
119
|
+
"uint128[]",
|
|
120
|
+
"uint136[]",
|
|
121
|
+
"uint144[]",
|
|
122
|
+
"uint152[]",
|
|
123
|
+
"uint160[]",
|
|
124
|
+
"uint168[]",
|
|
125
|
+
"uint176[]",
|
|
126
|
+
"uint184[]",
|
|
127
|
+
"uint192[]",
|
|
128
|
+
"uint200[]",
|
|
129
|
+
"uint208[]",
|
|
130
|
+
"uint216[]",
|
|
131
|
+
"uint224[]",
|
|
132
|
+
"uint232[]",
|
|
133
|
+
"uint240[]",
|
|
134
|
+
"uint248[]",
|
|
135
|
+
"uint256[]",
|
|
136
|
+
"int8[]",
|
|
137
|
+
"int16[]",
|
|
138
|
+
"int24[]",
|
|
139
|
+
"int32[]",
|
|
140
|
+
"int40[]",
|
|
141
|
+
"int48[]",
|
|
142
|
+
"int56[]",
|
|
143
|
+
"int64[]",
|
|
144
|
+
"int72[]",
|
|
145
|
+
"int80[]",
|
|
146
|
+
"int88[]",
|
|
147
|
+
"int96[]",
|
|
148
|
+
"int104[]",
|
|
149
|
+
"int112[]",
|
|
150
|
+
"int120[]",
|
|
151
|
+
"int128[]",
|
|
152
|
+
"int136[]",
|
|
153
|
+
"int144[]",
|
|
154
|
+
"int152[]",
|
|
155
|
+
"int160[]",
|
|
156
|
+
"int168[]",
|
|
157
|
+
"int176[]",
|
|
158
|
+
"int184[]",
|
|
159
|
+
"int192[]",
|
|
160
|
+
"int200[]",
|
|
161
|
+
"int208[]",
|
|
162
|
+
"int216[]",
|
|
163
|
+
"int224[]",
|
|
164
|
+
"int232[]",
|
|
165
|
+
"int240[]",
|
|
166
|
+
"int248[]",
|
|
167
|
+
"int256[]",
|
|
168
|
+
"bytes1[]",
|
|
169
|
+
"bytes2[]",
|
|
170
|
+
"bytes3[]",
|
|
171
|
+
"bytes4[]",
|
|
172
|
+
"bytes5[]",
|
|
173
|
+
"bytes6[]",
|
|
174
|
+
"bytes7[]",
|
|
175
|
+
"bytes8[]",
|
|
176
|
+
"bytes9[]",
|
|
177
|
+
"bytes10[]",
|
|
178
|
+
"bytes11[]",
|
|
179
|
+
"bytes12[]",
|
|
180
|
+
"bytes13[]",
|
|
181
|
+
"bytes14[]",
|
|
182
|
+
"bytes15[]",
|
|
183
|
+
"bytes16[]",
|
|
184
|
+
"bytes17[]",
|
|
185
|
+
"bytes18[]",
|
|
186
|
+
"bytes19[]",
|
|
187
|
+
"bytes20[]",
|
|
188
|
+
"bytes21[]",
|
|
189
|
+
"bytes22[]",
|
|
190
|
+
"bytes23[]",
|
|
191
|
+
"bytes24[]",
|
|
192
|
+
"bytes25[]",
|
|
193
|
+
"bytes26[]",
|
|
194
|
+
"bytes27[]",
|
|
195
|
+
"bytes28[]",
|
|
196
|
+
"bytes29[]",
|
|
197
|
+
"bytes30[]",
|
|
198
|
+
"bytes31[]",
|
|
199
|
+
"bytes32[]",
|
|
200
|
+
"bool[]",
|
|
201
|
+
"address[]",
|
|
202
|
+
"bytes",
|
|
203
|
+
"string",
|
|
204
|
+
] as const satisfies readonly AbiType[];
|
|
205
|
+
|
|
206
|
+
export type SchemaAbiType = (typeof schemaAbiTypes)[number];
|
|
207
|
+
|
|
208
|
+
// These are defined here to keep the index position (98) consolidated, since we use it both in runtime code and type definition
|
|
209
|
+
export const staticAbiTypes = schemaAbiTypes.slice(0, 98) as any as TupleSplit<typeof schemaAbiTypes, 98>[0];
|
|
210
|
+
export const dynamicAbiTypes = schemaAbiTypes.slice(98) as any as TupleSplit<typeof schemaAbiTypes, 98>[1];
|
|
211
|
+
|
|
212
|
+
export type StaticAbiType = (typeof staticAbiTypes)[number];
|
|
213
|
+
export type DynamicAbiType = (typeof dynamicAbiTypes)[number];
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { describe, expectTypeOf, it } from "vitest";
|
|
2
|
+
import { Hex } from "viem";
|
|
3
|
+
import { StaticAbiTypeToPrimitiveType } from "./staticAbiTypes";
|
|
4
|
+
|
|
5
|
+
describe("StaticAbiTypeToPrimitiveType", () => {
|
|
6
|
+
it("maps uint8 to number", () => {
|
|
7
|
+
expectTypeOf<StaticAbiTypeToPrimitiveType<"uint8">>().toBeNumber();
|
|
8
|
+
});
|
|
9
|
+
it("maps uint32 to number", () => {
|
|
10
|
+
expectTypeOf<StaticAbiTypeToPrimitiveType<"uint32">>().toBeNumber();
|
|
11
|
+
});
|
|
12
|
+
it("maps uint48 to number", () => {
|
|
13
|
+
expectTypeOf<StaticAbiTypeToPrimitiveType<"uint48">>().toBeNumber();
|
|
14
|
+
});
|
|
15
|
+
it("maps uint56 to number", () => {
|
|
16
|
+
expectTypeOf<StaticAbiTypeToPrimitiveType<"uint56">>().toMatchTypeOf<bigint>();
|
|
17
|
+
});
|
|
18
|
+
it("maps uint256 to number", () => {
|
|
19
|
+
expectTypeOf<StaticAbiTypeToPrimitiveType<"uint256">>().toMatchTypeOf<bigint>();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("maps int8 to number", () => {
|
|
23
|
+
expectTypeOf<StaticAbiTypeToPrimitiveType<"int8">>().toBeNumber();
|
|
24
|
+
});
|
|
25
|
+
it("maps int32 to number", () => {
|
|
26
|
+
expectTypeOf<StaticAbiTypeToPrimitiveType<"int32">>().toBeNumber();
|
|
27
|
+
});
|
|
28
|
+
it("maps int48 to number", () => {
|
|
29
|
+
expectTypeOf<StaticAbiTypeToPrimitiveType<"int48">>().toBeNumber();
|
|
30
|
+
});
|
|
31
|
+
it("maps int56 to number", () => {
|
|
32
|
+
expectTypeOf<StaticAbiTypeToPrimitiveType<"int56">>().toMatchTypeOf<bigint>();
|
|
33
|
+
});
|
|
34
|
+
it("maps int256 to number", () => {
|
|
35
|
+
expectTypeOf<StaticAbiTypeToPrimitiveType<"int256">>().toMatchTypeOf<bigint>();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("maps bytes1 to hex", () => {
|
|
39
|
+
expectTypeOf<StaticAbiTypeToPrimitiveType<"bytes1">>().toMatchTypeOf<Hex>();
|
|
40
|
+
});
|
|
41
|
+
it("maps bytes2 to hex", () => {
|
|
42
|
+
expectTypeOf<StaticAbiTypeToPrimitiveType<"bytes2">>().toMatchTypeOf<Hex>();
|
|
43
|
+
});
|
|
44
|
+
it("maps bytes8 to hex", () => {
|
|
45
|
+
expectTypeOf<StaticAbiTypeToPrimitiveType<"bytes8">>().toMatchTypeOf<Hex>();
|
|
46
|
+
});
|
|
47
|
+
it("maps bytes32 to hex", () => {
|
|
48
|
+
expectTypeOf<StaticAbiTypeToPrimitiveType<"bytes32">>().toMatchTypeOf<Hex>();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("maps bool to boolean", () => {
|
|
52
|
+
expectTypeOf<StaticAbiTypeToPrimitiveType<"bool">>().toBeBoolean();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("maps address to hex", () => {
|
|
56
|
+
expectTypeOf<StaticAbiTypeToPrimitiveType<"address">>().toMatchTypeOf<Hex>();
|
|
57
|
+
});
|
|
58
|
+
});
|