New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@latticexyz/schema-type

Package Overview
Dependencies
Maintainers
4
Versions
1656
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@latticexyz/schema-type - npm Package Compare versions

Comparing version 1.41.0 to 2.0.0-alpha.0

dist/typescript/AbiTypes.d.ts

211

dist/typescript/SchemaType.d.ts

@@ -201,212 +201,1 @@ export declare enum SchemaType {

}
export declare function getStaticByteLength(schemaType: SchemaType): number;
export declare const SchemaTypeId: Record<SchemaType, string>;
export type ArraySchemaType = SchemaType.UINT8_ARRAY | SchemaType.UINT16_ARRAY | SchemaType.UINT24_ARRAY | SchemaType.UINT32_ARRAY | SchemaType.UINT40_ARRAY | SchemaType.UINT48_ARRAY | SchemaType.UINT56_ARRAY | SchemaType.UINT64_ARRAY | SchemaType.UINT72_ARRAY | SchemaType.UINT80_ARRAY | SchemaType.UINT88_ARRAY | SchemaType.UINT96_ARRAY | SchemaType.UINT104_ARRAY | SchemaType.UINT112_ARRAY | SchemaType.UINT120_ARRAY | SchemaType.UINT128_ARRAY | SchemaType.UINT136_ARRAY | SchemaType.UINT144_ARRAY | SchemaType.UINT152_ARRAY | SchemaType.UINT160_ARRAY | SchemaType.UINT168_ARRAY | SchemaType.UINT176_ARRAY | SchemaType.UINT184_ARRAY | SchemaType.UINT192_ARRAY | SchemaType.UINT200_ARRAY | SchemaType.UINT208_ARRAY | SchemaType.UINT216_ARRAY | SchemaType.UINT224_ARRAY | SchemaType.UINT232_ARRAY | SchemaType.UINT240_ARRAY | SchemaType.UINT248_ARRAY | SchemaType.UINT256_ARRAY | SchemaType.INT8_ARRAY | SchemaType.INT16_ARRAY | SchemaType.INT24_ARRAY | SchemaType.INT32_ARRAY | SchemaType.INT40_ARRAY | SchemaType.INT48_ARRAY | SchemaType.INT56_ARRAY | SchemaType.INT64_ARRAY | SchemaType.INT72_ARRAY | SchemaType.INT80_ARRAY | SchemaType.INT88_ARRAY | SchemaType.INT96_ARRAY | SchemaType.INT104_ARRAY | SchemaType.INT112_ARRAY | SchemaType.INT120_ARRAY | SchemaType.INT128_ARRAY | SchemaType.INT136_ARRAY | SchemaType.INT144_ARRAY | SchemaType.INT152_ARRAY | SchemaType.INT160_ARRAY | SchemaType.INT168_ARRAY | SchemaType.INT176_ARRAY | SchemaType.INT184_ARRAY | SchemaType.INT192_ARRAY | SchemaType.INT200_ARRAY | SchemaType.INT208_ARRAY | SchemaType.INT216_ARRAY | SchemaType.INT224_ARRAY | SchemaType.INT232_ARRAY | SchemaType.INT240_ARRAY | SchemaType.INT248_ARRAY | SchemaType.INT256_ARRAY | SchemaType.BYTES1_ARRAY | SchemaType.BYTES2_ARRAY | SchemaType.BYTES3_ARRAY | SchemaType.BYTES4_ARRAY | SchemaType.BYTES5_ARRAY | SchemaType.BYTES6_ARRAY | SchemaType.BYTES7_ARRAY | SchemaType.BYTES8_ARRAY | SchemaType.BYTES9_ARRAY | SchemaType.BYTES10_ARRAY | SchemaType.BYTES11_ARRAY | SchemaType.BYTES12_ARRAY | SchemaType.BYTES13_ARRAY | SchemaType.BYTES14_ARRAY | SchemaType.BYTES15_ARRAY | SchemaType.BYTES16_ARRAY | SchemaType.BYTES17_ARRAY | SchemaType.BYTES18_ARRAY | SchemaType.BYTES19_ARRAY | SchemaType.BYTES20_ARRAY | SchemaType.BYTES21_ARRAY | SchemaType.BYTES22_ARRAY | SchemaType.BYTES23_ARRAY | SchemaType.BYTES24_ARRAY | SchemaType.BYTES25_ARRAY | SchemaType.BYTES26_ARRAY | SchemaType.BYTES27_ARRAY | SchemaType.BYTES28_ARRAY | SchemaType.BYTES29_ARRAY | SchemaType.BYTES30_ARRAY | SchemaType.BYTES31_ARRAY | SchemaType.BYTES32_ARRAY | SchemaType.BOOL_ARRAY | SchemaType.ADDRESS_ARRAY;
export declare const SchemaTypeArrayToElement: {
0: undefined;
1: undefined;
2: undefined;
3: undefined;
4: undefined;
5: undefined;
6: undefined;
7: undefined;
8: undefined;
9: undefined;
10: undefined;
11: undefined;
12: undefined;
13: undefined;
14: undefined;
15: undefined;
16: undefined;
17: undefined;
18: undefined;
19: undefined;
20: undefined;
21: undefined;
22: undefined;
23: undefined;
24: undefined;
25: undefined;
26: undefined;
27: undefined;
28: undefined;
29: undefined;
30: undefined;
31: undefined;
32: undefined;
33: undefined;
34: undefined;
35: undefined;
36: undefined;
37: undefined;
38: undefined;
39: undefined;
40: undefined;
41: undefined;
42: undefined;
43: undefined;
44: undefined;
45: undefined;
46: undefined;
47: undefined;
48: undefined;
49: undefined;
50: undefined;
51: undefined;
52: undefined;
53: undefined;
54: undefined;
55: undefined;
56: undefined;
57: undefined;
58: undefined;
59: undefined;
60: undefined;
61: undefined;
62: undefined;
63: undefined;
64: undefined;
65: undefined;
66: undefined;
67: undefined;
68: undefined;
69: undefined;
70: undefined;
71: undefined;
72: undefined;
73: undefined;
74: undefined;
75: undefined;
76: undefined;
77: undefined;
78: undefined;
79: undefined;
80: undefined;
81: undefined;
82: undefined;
83: undefined;
84: undefined;
85: undefined;
86: undefined;
87: undefined;
88: undefined;
89: undefined;
90: undefined;
91: undefined;
92: undefined;
93: undefined;
94: undefined;
95: undefined;
96: undefined;
97: undefined;
98: SchemaType;
99: SchemaType;
100: SchemaType;
101: SchemaType;
102: SchemaType;
103: SchemaType;
104: SchemaType;
105: SchemaType;
106: SchemaType;
107: SchemaType;
108: SchemaType;
109: SchemaType;
110: SchemaType;
111: SchemaType;
112: SchemaType;
113: SchemaType;
114: SchemaType;
115: SchemaType;
116: SchemaType;
117: SchemaType;
118: SchemaType;
119: SchemaType;
120: SchemaType;
121: SchemaType;
122: SchemaType;
123: SchemaType;
124: SchemaType;
125: SchemaType;
126: SchemaType;
127: SchemaType;
128: SchemaType;
129: SchemaType;
130: SchemaType;
131: SchemaType;
132: SchemaType;
133: SchemaType;
134: SchemaType;
135: SchemaType;
136: SchemaType;
137: SchemaType;
138: SchemaType;
139: SchemaType;
140: SchemaType;
141: SchemaType;
142: SchemaType;
143: SchemaType;
144: SchemaType;
145: SchemaType;
146: SchemaType;
147: SchemaType;
148: SchemaType;
149: SchemaType;
150: SchemaType;
151: SchemaType;
152: SchemaType;
153: SchemaType;
154: SchemaType;
155: SchemaType;
156: SchemaType;
157: SchemaType;
158: SchemaType;
159: SchemaType;
160: SchemaType;
161: SchemaType;
162: SchemaType;
163: SchemaType;
164: SchemaType;
165: SchemaType;
166: SchemaType;
167: SchemaType;
168: SchemaType;
169: SchemaType;
170: SchemaType;
171: SchemaType;
172: SchemaType;
173: SchemaType;
174: SchemaType;
175: SchemaType;
176: SchemaType;
177: SchemaType;
178: SchemaType;
179: SchemaType;
180: SchemaType;
181: SchemaType;
182: SchemaType;
183: SchemaType;
184: SchemaType;
185: SchemaType;
186: SchemaType;
187: SchemaType;
188: SchemaType;
189: SchemaType;
190: SchemaType;
191: SchemaType;
192: SchemaType;
193: SchemaType;
194: SchemaType;
195: SchemaType;
196: undefined;
197: undefined;
};
export type DynamicSchemaType = ArraySchemaType | SchemaType.BYTES | SchemaType.STRING;
/**
* Encode a table schema into a bytes32 hex string
* Port of `Schema.sol` from `@latticexyz/store`
* @param schema The schema to encode SchemaType[]
* @returns The encoded schema as a 32 byte hex string
*/
export declare function encodeSchema(schema: SchemaType[]): Uint8Array;

@@ -204,367 +204,2 @@ // WARNING: SchemaType enum MUST mirror the solidity version!

})(SchemaType || (SchemaType = {}));
export function getStaticByteLength(schemaType) {
const val = schemaType.valueOf();
if (val < 32) {
// uint8-256
return val + 1;
}
else if (val < 64) {
// int8-256, offset by 32
return val + 1 - 32;
}
else if (val < 96) {
// bytes1-32, offset by 64
return val + 1 - 64;
}
// Other static types
if (schemaType == SchemaType.BOOL) {
return 1;
}
else if (schemaType == SchemaType.ADDRESS) {
return 20;
}
// Return 0 for all dynamic types
return 0;
}
export const SchemaTypeId = {
[SchemaType.UINT8]: "uint8",
[SchemaType.UINT16]: "uint16",
[SchemaType.UINT24]: "uint24",
[SchemaType.UINT32]: "uint32",
[SchemaType.UINT40]: "uint40",
[SchemaType.UINT48]: "uint48",
[SchemaType.UINT56]: "uint56",
[SchemaType.UINT64]: "uint64",
[SchemaType.UINT72]: "uint72",
[SchemaType.UINT80]: "uint80",
[SchemaType.UINT88]: "uint88",
[SchemaType.UINT96]: "uint96",
[SchemaType.UINT104]: "uint104",
[SchemaType.UINT112]: "uint112",
[SchemaType.UINT120]: "uint120",
[SchemaType.UINT128]: "uint128",
[SchemaType.UINT136]: "uint136",
[SchemaType.UINT144]: "uint144",
[SchemaType.UINT152]: "uint152",
[SchemaType.UINT160]: "uint160",
[SchemaType.UINT168]: "uint168",
[SchemaType.UINT176]: "uint176",
[SchemaType.UINT184]: "uint184",
[SchemaType.UINT192]: "uint192",
[SchemaType.UINT200]: "uint200",
[SchemaType.UINT208]: "uint208",
[SchemaType.UINT216]: "uint216",
[SchemaType.UINT224]: "uint224",
[SchemaType.UINT232]: "uint232",
[SchemaType.UINT240]: "uint240",
[SchemaType.UINT248]: "uint248",
[SchemaType.UINT256]: "uint256",
[SchemaType.INT8]: "int8",
[SchemaType.INT16]: "int16",
[SchemaType.INT24]: "int24",
[SchemaType.INT32]: "int32",
[SchemaType.INT40]: "int40",
[SchemaType.INT48]: "int48",
[SchemaType.INT56]: "int56",
[SchemaType.INT64]: "int64",
[SchemaType.INT72]: "int72",
[SchemaType.INT80]: "int80",
[SchemaType.INT88]: "int88",
[SchemaType.INT96]: "int96",
[SchemaType.INT104]: "int104",
[SchemaType.INT112]: "int112",
[SchemaType.INT120]: "int120",
[SchemaType.INT128]: "int128",
[SchemaType.INT136]: "int136",
[SchemaType.INT144]: "int144",
[SchemaType.INT152]: "int152",
[SchemaType.INT160]: "int160",
[SchemaType.INT168]: "int168",
[SchemaType.INT176]: "int176",
[SchemaType.INT184]: "int184",
[SchemaType.INT192]: "int192",
[SchemaType.INT200]: "int200",
[SchemaType.INT208]: "int208",
[SchemaType.INT216]: "int216",
[SchemaType.INT224]: "int224",
[SchemaType.INT232]: "int232",
[SchemaType.INT240]: "int240",
[SchemaType.INT248]: "int248",
[SchemaType.INT256]: "int256",
[SchemaType.BYTES1]: "bytes1",
[SchemaType.BYTES2]: "bytes2",
[SchemaType.BYTES3]: "bytes3",
[SchemaType.BYTES4]: "bytes4",
[SchemaType.BYTES5]: "bytes5",
[SchemaType.BYTES6]: "bytes6",
[SchemaType.BYTES7]: "bytes7",
[SchemaType.BYTES8]: "bytes8",
[SchemaType.BYTES9]: "bytes9",
[SchemaType.BYTES10]: "bytes10",
[SchemaType.BYTES11]: "bytes11",
[SchemaType.BYTES12]: "bytes12",
[SchemaType.BYTES13]: "bytes13",
[SchemaType.BYTES14]: "bytes14",
[SchemaType.BYTES15]: "bytes15",
[SchemaType.BYTES16]: "bytes16",
[SchemaType.BYTES17]: "bytes17",
[SchemaType.BYTES18]: "bytes18",
[SchemaType.BYTES19]: "bytes19",
[SchemaType.BYTES20]: "bytes20",
[SchemaType.BYTES21]: "bytes21",
[SchemaType.BYTES22]: "bytes22",
[SchemaType.BYTES23]: "bytes23",
[SchemaType.BYTES24]: "bytes24",
[SchemaType.BYTES25]: "bytes25",
[SchemaType.BYTES26]: "bytes26",
[SchemaType.BYTES27]: "bytes27",
[SchemaType.BYTES28]: "bytes28",
[SchemaType.BYTES29]: "bytes29",
[SchemaType.BYTES30]: "bytes30",
[SchemaType.BYTES31]: "bytes31",
[SchemaType.BYTES32]: "bytes32",
[SchemaType.BOOL]: "bool",
[SchemaType.ADDRESS]: "address",
[SchemaType.UINT8_ARRAY]: "uint8[]",
[SchemaType.UINT16_ARRAY]: "uint16[]",
[SchemaType.UINT24_ARRAY]: "uint24[]",
[SchemaType.UINT32_ARRAY]: "uint32[]",
[SchemaType.UINT40_ARRAY]: "uint40[]",
[SchemaType.UINT48_ARRAY]: "uint48[]",
[SchemaType.UINT56_ARRAY]: "uint56[]",
[SchemaType.UINT64_ARRAY]: "uint64[]",
[SchemaType.UINT72_ARRAY]: "uint72[]",
[SchemaType.UINT80_ARRAY]: "uint80[]",
[SchemaType.UINT88_ARRAY]: "uint88[]",
[SchemaType.UINT96_ARRAY]: "uint96[]",
[SchemaType.UINT104_ARRAY]: "uint104[]",
[SchemaType.UINT112_ARRAY]: "uint112[]",
[SchemaType.UINT120_ARRAY]: "uint120[]",
[SchemaType.UINT128_ARRAY]: "uint128[]",
[SchemaType.UINT136_ARRAY]: "uint136[]",
[SchemaType.UINT144_ARRAY]: "uint144[]",
[SchemaType.UINT152_ARRAY]: "uint152[]",
[SchemaType.UINT160_ARRAY]: "uint160[]",
[SchemaType.UINT168_ARRAY]: "uint168[]",
[SchemaType.UINT176_ARRAY]: "uint176[]",
[SchemaType.UINT184_ARRAY]: "uint184[]",
[SchemaType.UINT192_ARRAY]: "uint192[]",
[SchemaType.UINT200_ARRAY]: "uint200[]",
[SchemaType.UINT208_ARRAY]: "uint208[]",
[SchemaType.UINT216_ARRAY]: "uint216[]",
[SchemaType.UINT224_ARRAY]: "uint224[]",
[SchemaType.UINT232_ARRAY]: "uint232[]",
[SchemaType.UINT240_ARRAY]: "uint240[]",
[SchemaType.UINT248_ARRAY]: "uint248[]",
[SchemaType.UINT256_ARRAY]: "uint256[]",
[SchemaType.INT8_ARRAY]: "int8[]",
[SchemaType.INT16_ARRAY]: "int16[]",
[SchemaType.INT24_ARRAY]: "int24[]",
[SchemaType.INT32_ARRAY]: "int32[]",
[SchemaType.INT40_ARRAY]: "int40[]",
[SchemaType.INT48_ARRAY]: "int48[]",
[SchemaType.INT56_ARRAY]: "int56[]",
[SchemaType.INT64_ARRAY]: "int64[]",
[SchemaType.INT72_ARRAY]: "int72[]",
[SchemaType.INT80_ARRAY]: "int80[]",
[SchemaType.INT88_ARRAY]: "int88[]",
[SchemaType.INT96_ARRAY]: "int96[]",
[SchemaType.INT104_ARRAY]: "int104[]",
[SchemaType.INT112_ARRAY]: "int112[]",
[SchemaType.INT120_ARRAY]: "int120[]",
[SchemaType.INT128_ARRAY]: "int128[]",
[SchemaType.INT136_ARRAY]: "int136[]",
[SchemaType.INT144_ARRAY]: "int144[]",
[SchemaType.INT152_ARRAY]: "int152[]",
[SchemaType.INT160_ARRAY]: "int160[]",
[SchemaType.INT168_ARRAY]: "int168[]",
[SchemaType.INT176_ARRAY]: "int176[]",
[SchemaType.INT184_ARRAY]: "int184[]",
[SchemaType.INT192_ARRAY]: "int192[]",
[SchemaType.INT200_ARRAY]: "int200[]",
[SchemaType.INT208_ARRAY]: "int208[]",
[SchemaType.INT216_ARRAY]: "int216[]",
[SchemaType.INT224_ARRAY]: "int224[]",
[SchemaType.INT232_ARRAY]: "int232[]",
[SchemaType.INT240_ARRAY]: "int240[]",
[SchemaType.INT248_ARRAY]: "int248[]",
[SchemaType.INT256_ARRAY]: "int256[]",
[SchemaType.BYTES1_ARRAY]: "bytes1[]",
[SchemaType.BYTES2_ARRAY]: "bytes2[]",
[SchemaType.BYTES3_ARRAY]: "bytes3[]",
[SchemaType.BYTES4_ARRAY]: "bytes4[]",
[SchemaType.BYTES5_ARRAY]: "bytes5[]",
[SchemaType.BYTES6_ARRAY]: "bytes6[]",
[SchemaType.BYTES7_ARRAY]: "bytes7[]",
[SchemaType.BYTES8_ARRAY]: "bytes8[]",
[SchemaType.BYTES9_ARRAY]: "bytes9[]",
[SchemaType.BYTES10_ARRAY]: "bytes10[]",
[SchemaType.BYTES11_ARRAY]: "bytes11[]",
[SchemaType.BYTES12_ARRAY]: "bytes12[]",
[SchemaType.BYTES13_ARRAY]: "bytes13[]",
[SchemaType.BYTES14_ARRAY]: "bytes14[]",
[SchemaType.BYTES15_ARRAY]: "bytes15[]",
[SchemaType.BYTES16_ARRAY]: "bytes16[]",
[SchemaType.BYTES17_ARRAY]: "bytes17[]",
[SchemaType.BYTES18_ARRAY]: "bytes18[]",
[SchemaType.BYTES19_ARRAY]: "bytes19[]",
[SchemaType.BYTES20_ARRAY]: "bytes20[]",
[SchemaType.BYTES21_ARRAY]: "bytes21[]",
[SchemaType.BYTES22_ARRAY]: "bytes22[]",
[SchemaType.BYTES23_ARRAY]: "bytes23[]",
[SchemaType.BYTES24_ARRAY]: "bytes24[]",
[SchemaType.BYTES25_ARRAY]: "bytes25[]",
[SchemaType.BYTES26_ARRAY]: "bytes26[]",
[SchemaType.BYTES27_ARRAY]: "bytes27[]",
[SchemaType.BYTES28_ARRAY]: "bytes28[]",
[SchemaType.BYTES29_ARRAY]: "bytes29[]",
[SchemaType.BYTES30_ARRAY]: "bytes30[]",
[SchemaType.BYTES31_ARRAY]: "bytes31[]",
[SchemaType.BYTES32_ARRAY]: "bytes32[]",
[SchemaType.BOOL_ARRAY]: "bool[]",
[SchemaType.ADDRESS_ARRAY]: "address[]",
[SchemaType.BYTES]: "bytes",
[SchemaType.STRING]: "string",
};
export const SchemaTypeArrayToElement = {
[SchemaType.UINT8_ARRAY]: SchemaType.UINT8,
[SchemaType.UINT16_ARRAY]: SchemaType.UINT16,
[SchemaType.UINT24_ARRAY]: SchemaType.UINT24,
[SchemaType.UINT32_ARRAY]: SchemaType.UINT32,
[SchemaType.UINT40_ARRAY]: SchemaType.UINT40,
[SchemaType.UINT48_ARRAY]: SchemaType.UINT48,
[SchemaType.UINT56_ARRAY]: SchemaType.UINT56,
[SchemaType.UINT64_ARRAY]: SchemaType.UINT64,
[SchemaType.UINT72_ARRAY]: SchemaType.UINT72,
[SchemaType.UINT80_ARRAY]: SchemaType.UINT80,
[SchemaType.UINT88_ARRAY]: SchemaType.UINT88,
[SchemaType.UINT96_ARRAY]: SchemaType.UINT96,
[SchemaType.UINT104_ARRAY]: SchemaType.UINT104,
[SchemaType.UINT112_ARRAY]: SchemaType.UINT112,
[SchemaType.UINT120_ARRAY]: SchemaType.UINT120,
[SchemaType.UINT128_ARRAY]: SchemaType.UINT128,
[SchemaType.UINT136_ARRAY]: SchemaType.UINT136,
[SchemaType.UINT144_ARRAY]: SchemaType.UINT144,
[SchemaType.UINT152_ARRAY]: SchemaType.UINT152,
[SchemaType.UINT160_ARRAY]: SchemaType.UINT160,
[SchemaType.UINT168_ARRAY]: SchemaType.UINT168,
[SchemaType.UINT176_ARRAY]: SchemaType.UINT176,
[SchemaType.UINT184_ARRAY]: SchemaType.UINT184,
[SchemaType.UINT192_ARRAY]: SchemaType.UINT192,
[SchemaType.UINT200_ARRAY]: SchemaType.UINT200,
[SchemaType.UINT208_ARRAY]: SchemaType.UINT208,
[SchemaType.UINT216_ARRAY]: SchemaType.UINT216,
[SchemaType.UINT224_ARRAY]: SchemaType.UINT224,
[SchemaType.UINT232_ARRAY]: SchemaType.UINT232,
[SchemaType.UINT240_ARRAY]: SchemaType.UINT240,
[SchemaType.UINT248_ARRAY]: SchemaType.UINT248,
[SchemaType.UINT256_ARRAY]: SchemaType.UINT256,
[SchemaType.INT8_ARRAY]: SchemaType.INT8,
[SchemaType.INT16_ARRAY]: SchemaType.INT16,
[SchemaType.INT24_ARRAY]: SchemaType.INT24,
[SchemaType.INT32_ARRAY]: SchemaType.INT32,
[SchemaType.INT40_ARRAY]: SchemaType.INT40,
[SchemaType.INT48_ARRAY]: SchemaType.INT48,
[SchemaType.INT56_ARRAY]: SchemaType.INT56,
[SchemaType.INT64_ARRAY]: SchemaType.INT64,
[SchemaType.INT72_ARRAY]: SchemaType.INT72,
[SchemaType.INT80_ARRAY]: SchemaType.INT80,
[SchemaType.INT88_ARRAY]: SchemaType.INT88,
[SchemaType.INT96_ARRAY]: SchemaType.INT96,
[SchemaType.INT104_ARRAY]: SchemaType.INT104,
[SchemaType.INT112_ARRAY]: SchemaType.INT112,
[SchemaType.INT120_ARRAY]: SchemaType.INT120,
[SchemaType.INT128_ARRAY]: SchemaType.INT128,
[SchemaType.INT136_ARRAY]: SchemaType.INT136,
[SchemaType.INT144_ARRAY]: SchemaType.INT144,
[SchemaType.INT152_ARRAY]: SchemaType.INT152,
[SchemaType.INT160_ARRAY]: SchemaType.INT160,
[SchemaType.INT168_ARRAY]: SchemaType.INT168,
[SchemaType.INT176_ARRAY]: SchemaType.INT176,
[SchemaType.INT184_ARRAY]: SchemaType.INT184,
[SchemaType.INT192_ARRAY]: SchemaType.INT192,
[SchemaType.INT200_ARRAY]: SchemaType.INT200,
[SchemaType.INT208_ARRAY]: SchemaType.INT208,
[SchemaType.INT216_ARRAY]: SchemaType.INT216,
[SchemaType.INT224_ARRAY]: SchemaType.INT224,
[SchemaType.INT232_ARRAY]: SchemaType.INT232,
[SchemaType.INT240_ARRAY]: SchemaType.INT240,
[SchemaType.INT248_ARRAY]: SchemaType.INT248,
[SchemaType.INT256_ARRAY]: SchemaType.INT256,
[SchemaType.BYTES1_ARRAY]: SchemaType.BYTES1,
[SchemaType.BYTES2_ARRAY]: SchemaType.BYTES2,
[SchemaType.BYTES3_ARRAY]: SchemaType.BYTES3,
[SchemaType.BYTES4_ARRAY]: SchemaType.BYTES4,
[SchemaType.BYTES5_ARRAY]: SchemaType.BYTES5,
[SchemaType.BYTES6_ARRAY]: SchemaType.BYTES6,
[SchemaType.BYTES7_ARRAY]: SchemaType.BYTES7,
[SchemaType.BYTES8_ARRAY]: SchemaType.BYTES8,
[SchemaType.BYTES9_ARRAY]: SchemaType.BYTES9,
[SchemaType.BYTES10_ARRAY]: SchemaType.BYTES10,
[SchemaType.BYTES11_ARRAY]: SchemaType.BYTES11,
[SchemaType.BYTES12_ARRAY]: SchemaType.BYTES12,
[SchemaType.BYTES13_ARRAY]: SchemaType.BYTES13,
[SchemaType.BYTES14_ARRAY]: SchemaType.BYTES14,
[SchemaType.BYTES15_ARRAY]: SchemaType.BYTES15,
[SchemaType.BYTES16_ARRAY]: SchemaType.BYTES16,
[SchemaType.BYTES17_ARRAY]: SchemaType.BYTES17,
[SchemaType.BYTES18_ARRAY]: SchemaType.BYTES18,
[SchemaType.BYTES19_ARRAY]: SchemaType.BYTES19,
[SchemaType.BYTES20_ARRAY]: SchemaType.BYTES20,
[SchemaType.BYTES21_ARRAY]: SchemaType.BYTES21,
[SchemaType.BYTES22_ARRAY]: SchemaType.BYTES22,
[SchemaType.BYTES23_ARRAY]: SchemaType.BYTES23,
[SchemaType.BYTES24_ARRAY]: SchemaType.BYTES24,
[SchemaType.BYTES25_ARRAY]: SchemaType.BYTES25,
[SchemaType.BYTES26_ARRAY]: SchemaType.BYTES26,
[SchemaType.BYTES27_ARRAY]: SchemaType.BYTES27,
[SchemaType.BYTES28_ARRAY]: SchemaType.BYTES28,
[SchemaType.BYTES29_ARRAY]: SchemaType.BYTES29,
[SchemaType.BYTES30_ARRAY]: SchemaType.BYTES30,
[SchemaType.BYTES31_ARRAY]: SchemaType.BYTES31,
[SchemaType.BYTES32_ARRAY]: SchemaType.BYTES32,
[SchemaType.BOOL_ARRAY]: SchemaType.BOOL,
[SchemaType.ADDRESS_ARRAY]: SchemaType.ADDRESS,
};
/**
* Encode a table schema into a bytes32 hex string
* Port of `Schema.sol` from `@latticexyz/store`
* @param schema The schema to encode SchemaType[]
* @returns The encoded schema as a 32 byte hex string
*/
export function encodeSchema(schema) {
if (schema.length > 28)
throw new Error("Schema can only have up to 28 fields");
const encodedSchema = new Uint8Array(32);
let length = 0;
let staticFields = 0;
// Compute the length of the schema and the number of static fields
// and store the schema types in the encoded schema
let hasDynamicFields = false;
for (let i = 0; i < schema.length; i++) {
const staticByteLength = getStaticByteLength(schema[i]);
// Increase the static field count if the field is static
if (staticByteLength > 0) {
// Revert if we have seen a dynamic field before, but now we see a static field
if (hasDynamicFields)
throw new Error("Static fields must come before dynamic fields in the schema");
staticFields++;
}
else {
// Flag that we have seen a dynamic field
hasDynamicFields = true;
}
length += staticByteLength;
encodedSchema[i + 4] = schema[i];
}
// Require max 14 dynamic fields
const dynamicFields = schema.length - staticFields;
if (dynamicFields > 14)
throw new Error("Schema can only have up to 14 dynamic fields");
// Store total static length, and number of static and dynamic fields
new DataView(encodedSchema.buffer).setUint16(0, length); // 2 length bytes
encodedSchema[2] = staticFields; // number of static fields
encodedSchema[3] = dynamicFields; // number of dynamic fields
return encodedSchema;
}
//# sourceMappingURL=SchemaType.js.map

8

package.json
{
"name": "@latticexyz/schema-type",
"license": "MIT",
"version": "1.41.0",
"version": "2.0.0-alpha.0",
"description": "SchemaType enum for various languages",
"main": "src/typescript/SchemaType.ts",
"source": "src/typescript/SchemaType.ts",
"main": "src/typescript/index.ts",
"source": "src/typescript/index.ts",
"type": "module",

@@ -31,3 +31,3 @@ "repository": {

},
"gitHead": "ecac84146f0288e3a129d1d3dbfaf373db86b1ab"
"gitHead": "fcb2166c25edd27ead54f0afa1b71d2583939603"
}

@@ -203,486 +203,1 @@ // WARNING: SchemaType enum MUST mirror the solidity version!

}
export function getStaticByteLength(schemaType: SchemaType) {
const val = schemaType.valueOf();
if (val < 32) {
// uint8-256
return val + 1;
} else if (val < 64) {
// int8-256, offset by 32
return val + 1 - 32;
} else if (val < 96) {
// bytes1-32, offset by 64
return val + 1 - 64;
}
// Other static types
if (schemaType == SchemaType.BOOL) {
return 1;
} else if (schemaType == SchemaType.ADDRESS) {
return 20;
}
// Return 0 for all dynamic types
return 0;
}
export const SchemaTypeId: Record<SchemaType, string> = {
[SchemaType.UINT8]: "uint8",
[SchemaType.UINT16]: "uint16",
[SchemaType.UINT24]: "uint24",
[SchemaType.UINT32]: "uint32",
[SchemaType.UINT40]: "uint40",
[SchemaType.UINT48]: "uint48",
[SchemaType.UINT56]: "uint56",
[SchemaType.UINT64]: "uint64",
[SchemaType.UINT72]: "uint72",
[SchemaType.UINT80]: "uint80",
[SchemaType.UINT88]: "uint88",
[SchemaType.UINT96]: "uint96",
[SchemaType.UINT104]: "uint104",
[SchemaType.UINT112]: "uint112",
[SchemaType.UINT120]: "uint120",
[SchemaType.UINT128]: "uint128",
[SchemaType.UINT136]: "uint136",
[SchemaType.UINT144]: "uint144",
[SchemaType.UINT152]: "uint152",
[SchemaType.UINT160]: "uint160",
[SchemaType.UINT168]: "uint168",
[SchemaType.UINT176]: "uint176",
[SchemaType.UINT184]: "uint184",
[SchemaType.UINT192]: "uint192",
[SchemaType.UINT200]: "uint200",
[SchemaType.UINT208]: "uint208",
[SchemaType.UINT216]: "uint216",
[SchemaType.UINT224]: "uint224",
[SchemaType.UINT232]: "uint232",
[SchemaType.UINT240]: "uint240",
[SchemaType.UINT248]: "uint248",
[SchemaType.UINT256]: "uint256",
[SchemaType.INT8]: "int8",
[SchemaType.INT16]: "int16",
[SchemaType.INT24]: "int24",
[SchemaType.INT32]: "int32",
[SchemaType.INT40]: "int40",
[SchemaType.INT48]: "int48",
[SchemaType.INT56]: "int56",
[SchemaType.INT64]: "int64",
[SchemaType.INT72]: "int72",
[SchemaType.INT80]: "int80",
[SchemaType.INT88]: "int88",
[SchemaType.INT96]: "int96",
[SchemaType.INT104]: "int104",
[SchemaType.INT112]: "int112",
[SchemaType.INT120]: "int120",
[SchemaType.INT128]: "int128",
[SchemaType.INT136]: "int136",
[SchemaType.INT144]: "int144",
[SchemaType.INT152]: "int152",
[SchemaType.INT160]: "int160",
[SchemaType.INT168]: "int168",
[SchemaType.INT176]: "int176",
[SchemaType.INT184]: "int184",
[SchemaType.INT192]: "int192",
[SchemaType.INT200]: "int200",
[SchemaType.INT208]: "int208",
[SchemaType.INT216]: "int216",
[SchemaType.INT224]: "int224",
[SchemaType.INT232]: "int232",
[SchemaType.INT240]: "int240",
[SchemaType.INT248]: "int248",
[SchemaType.INT256]: "int256",
[SchemaType.BYTES1]: "bytes1",
[SchemaType.BYTES2]: "bytes2",
[SchemaType.BYTES3]: "bytes3",
[SchemaType.BYTES4]: "bytes4",
[SchemaType.BYTES5]: "bytes5",
[SchemaType.BYTES6]: "bytes6",
[SchemaType.BYTES7]: "bytes7",
[SchemaType.BYTES8]: "bytes8",
[SchemaType.BYTES9]: "bytes9",
[SchemaType.BYTES10]: "bytes10",
[SchemaType.BYTES11]: "bytes11",
[SchemaType.BYTES12]: "bytes12",
[SchemaType.BYTES13]: "bytes13",
[SchemaType.BYTES14]: "bytes14",
[SchemaType.BYTES15]: "bytes15",
[SchemaType.BYTES16]: "bytes16",
[SchemaType.BYTES17]: "bytes17",
[SchemaType.BYTES18]: "bytes18",
[SchemaType.BYTES19]: "bytes19",
[SchemaType.BYTES20]: "bytes20",
[SchemaType.BYTES21]: "bytes21",
[SchemaType.BYTES22]: "bytes22",
[SchemaType.BYTES23]: "bytes23",
[SchemaType.BYTES24]: "bytes24",
[SchemaType.BYTES25]: "bytes25",
[SchemaType.BYTES26]: "bytes26",
[SchemaType.BYTES27]: "bytes27",
[SchemaType.BYTES28]: "bytes28",
[SchemaType.BYTES29]: "bytes29",
[SchemaType.BYTES30]: "bytes30",
[SchemaType.BYTES31]: "bytes31",
[SchemaType.BYTES32]: "bytes32",
[SchemaType.BOOL]: "bool",
[SchemaType.ADDRESS]: "address",
[SchemaType.UINT8_ARRAY]: "uint8[]",
[SchemaType.UINT16_ARRAY]: "uint16[]",
[SchemaType.UINT24_ARRAY]: "uint24[]",
[SchemaType.UINT32_ARRAY]: "uint32[]",
[SchemaType.UINT40_ARRAY]: "uint40[]",
[SchemaType.UINT48_ARRAY]: "uint48[]",
[SchemaType.UINT56_ARRAY]: "uint56[]",
[SchemaType.UINT64_ARRAY]: "uint64[]",
[SchemaType.UINT72_ARRAY]: "uint72[]",
[SchemaType.UINT80_ARRAY]: "uint80[]",
[SchemaType.UINT88_ARRAY]: "uint88[]",
[SchemaType.UINT96_ARRAY]: "uint96[]",
[SchemaType.UINT104_ARRAY]: "uint104[]",
[SchemaType.UINT112_ARRAY]: "uint112[]",
[SchemaType.UINT120_ARRAY]: "uint120[]",
[SchemaType.UINT128_ARRAY]: "uint128[]",
[SchemaType.UINT136_ARRAY]: "uint136[]",
[SchemaType.UINT144_ARRAY]: "uint144[]",
[SchemaType.UINT152_ARRAY]: "uint152[]",
[SchemaType.UINT160_ARRAY]: "uint160[]",
[SchemaType.UINT168_ARRAY]: "uint168[]",
[SchemaType.UINT176_ARRAY]: "uint176[]",
[SchemaType.UINT184_ARRAY]: "uint184[]",
[SchemaType.UINT192_ARRAY]: "uint192[]",
[SchemaType.UINT200_ARRAY]: "uint200[]",
[SchemaType.UINT208_ARRAY]: "uint208[]",
[SchemaType.UINT216_ARRAY]: "uint216[]",
[SchemaType.UINT224_ARRAY]: "uint224[]",
[SchemaType.UINT232_ARRAY]: "uint232[]",
[SchemaType.UINT240_ARRAY]: "uint240[]",
[SchemaType.UINT248_ARRAY]: "uint248[]",
[SchemaType.UINT256_ARRAY]: "uint256[]",
[SchemaType.INT8_ARRAY]: "int8[]",
[SchemaType.INT16_ARRAY]: "int16[]",
[SchemaType.INT24_ARRAY]: "int24[]",
[SchemaType.INT32_ARRAY]: "int32[]",
[SchemaType.INT40_ARRAY]: "int40[]",
[SchemaType.INT48_ARRAY]: "int48[]",
[SchemaType.INT56_ARRAY]: "int56[]",
[SchemaType.INT64_ARRAY]: "int64[]",
[SchemaType.INT72_ARRAY]: "int72[]",
[SchemaType.INT80_ARRAY]: "int80[]",
[SchemaType.INT88_ARRAY]: "int88[]",
[SchemaType.INT96_ARRAY]: "int96[]",
[SchemaType.INT104_ARRAY]: "int104[]",
[SchemaType.INT112_ARRAY]: "int112[]",
[SchemaType.INT120_ARRAY]: "int120[]",
[SchemaType.INT128_ARRAY]: "int128[]",
[SchemaType.INT136_ARRAY]: "int136[]",
[SchemaType.INT144_ARRAY]: "int144[]",
[SchemaType.INT152_ARRAY]: "int152[]",
[SchemaType.INT160_ARRAY]: "int160[]",
[SchemaType.INT168_ARRAY]: "int168[]",
[SchemaType.INT176_ARRAY]: "int176[]",
[SchemaType.INT184_ARRAY]: "int184[]",
[SchemaType.INT192_ARRAY]: "int192[]",
[SchemaType.INT200_ARRAY]: "int200[]",
[SchemaType.INT208_ARRAY]: "int208[]",
[SchemaType.INT216_ARRAY]: "int216[]",
[SchemaType.INT224_ARRAY]: "int224[]",
[SchemaType.INT232_ARRAY]: "int232[]",
[SchemaType.INT240_ARRAY]: "int240[]",
[SchemaType.INT248_ARRAY]: "int248[]",
[SchemaType.INT256_ARRAY]: "int256[]",
[SchemaType.BYTES1_ARRAY]: "bytes1[]",
[SchemaType.BYTES2_ARRAY]: "bytes2[]",
[SchemaType.BYTES3_ARRAY]: "bytes3[]",
[SchemaType.BYTES4_ARRAY]: "bytes4[]",
[SchemaType.BYTES5_ARRAY]: "bytes5[]",
[SchemaType.BYTES6_ARRAY]: "bytes6[]",
[SchemaType.BYTES7_ARRAY]: "bytes7[]",
[SchemaType.BYTES8_ARRAY]: "bytes8[]",
[SchemaType.BYTES9_ARRAY]: "bytes9[]",
[SchemaType.BYTES10_ARRAY]: "bytes10[]",
[SchemaType.BYTES11_ARRAY]: "bytes11[]",
[SchemaType.BYTES12_ARRAY]: "bytes12[]",
[SchemaType.BYTES13_ARRAY]: "bytes13[]",
[SchemaType.BYTES14_ARRAY]: "bytes14[]",
[SchemaType.BYTES15_ARRAY]: "bytes15[]",
[SchemaType.BYTES16_ARRAY]: "bytes16[]",
[SchemaType.BYTES17_ARRAY]: "bytes17[]",
[SchemaType.BYTES18_ARRAY]: "bytes18[]",
[SchemaType.BYTES19_ARRAY]: "bytes19[]",
[SchemaType.BYTES20_ARRAY]: "bytes20[]",
[SchemaType.BYTES21_ARRAY]: "bytes21[]",
[SchemaType.BYTES22_ARRAY]: "bytes22[]",
[SchemaType.BYTES23_ARRAY]: "bytes23[]",
[SchemaType.BYTES24_ARRAY]: "bytes24[]",
[SchemaType.BYTES25_ARRAY]: "bytes25[]",
[SchemaType.BYTES26_ARRAY]: "bytes26[]",
[SchemaType.BYTES27_ARRAY]: "bytes27[]",
[SchemaType.BYTES28_ARRAY]: "bytes28[]",
[SchemaType.BYTES29_ARRAY]: "bytes29[]",
[SchemaType.BYTES30_ARRAY]: "bytes30[]",
[SchemaType.BYTES31_ARRAY]: "bytes31[]",
[SchemaType.BYTES32_ARRAY]: "bytes32[]",
[SchemaType.BOOL_ARRAY]: "bool[]",
[SchemaType.ADDRESS_ARRAY]: "address[]",
[SchemaType.BYTES]: "bytes",
[SchemaType.STRING]: "string",
};
export type ArraySchemaType =
| SchemaType.UINT8_ARRAY
| SchemaType.UINT16_ARRAY
| SchemaType.UINT24_ARRAY
| SchemaType.UINT32_ARRAY
| SchemaType.UINT40_ARRAY
| SchemaType.UINT48_ARRAY
| SchemaType.UINT56_ARRAY
| SchemaType.UINT64_ARRAY
| SchemaType.UINT72_ARRAY
| SchemaType.UINT80_ARRAY
| SchemaType.UINT88_ARRAY
| SchemaType.UINT96_ARRAY
| SchemaType.UINT104_ARRAY
| SchemaType.UINT112_ARRAY
| SchemaType.UINT120_ARRAY
| SchemaType.UINT128_ARRAY
| SchemaType.UINT136_ARRAY
| SchemaType.UINT144_ARRAY
| SchemaType.UINT152_ARRAY
| SchemaType.UINT160_ARRAY
| SchemaType.UINT168_ARRAY
| SchemaType.UINT176_ARRAY
| SchemaType.UINT184_ARRAY
| SchemaType.UINT192_ARRAY
| SchemaType.UINT200_ARRAY
| SchemaType.UINT208_ARRAY
| SchemaType.UINT216_ARRAY
| SchemaType.UINT224_ARRAY
| SchemaType.UINT232_ARRAY
| SchemaType.UINT240_ARRAY
| SchemaType.UINT248_ARRAY
| SchemaType.UINT256_ARRAY
| SchemaType.INT8_ARRAY
| SchemaType.INT16_ARRAY
| SchemaType.INT24_ARRAY
| SchemaType.INT32_ARRAY
| SchemaType.INT40_ARRAY
| SchemaType.INT48_ARRAY
| SchemaType.INT56_ARRAY
| SchemaType.INT64_ARRAY
| SchemaType.INT72_ARRAY
| SchemaType.INT80_ARRAY
| SchemaType.INT88_ARRAY
| SchemaType.INT96_ARRAY
| SchemaType.INT104_ARRAY
| SchemaType.INT112_ARRAY
| SchemaType.INT120_ARRAY
| SchemaType.INT128_ARRAY
| SchemaType.INT136_ARRAY
| SchemaType.INT144_ARRAY
| SchemaType.INT152_ARRAY
| SchemaType.INT160_ARRAY
| SchemaType.INT168_ARRAY
| SchemaType.INT176_ARRAY
| SchemaType.INT184_ARRAY
| SchemaType.INT192_ARRAY
| SchemaType.INT200_ARRAY
| SchemaType.INT208_ARRAY
| SchemaType.INT216_ARRAY
| SchemaType.INT224_ARRAY
| SchemaType.INT232_ARRAY
| SchemaType.INT240_ARRAY
| SchemaType.INT248_ARRAY
| SchemaType.INT256_ARRAY
| SchemaType.BYTES1_ARRAY
| SchemaType.BYTES2_ARRAY
| SchemaType.BYTES3_ARRAY
| SchemaType.BYTES4_ARRAY
| SchemaType.BYTES5_ARRAY
| SchemaType.BYTES6_ARRAY
| SchemaType.BYTES7_ARRAY
| SchemaType.BYTES8_ARRAY
| SchemaType.BYTES9_ARRAY
| SchemaType.BYTES10_ARRAY
| SchemaType.BYTES11_ARRAY
| SchemaType.BYTES12_ARRAY
| SchemaType.BYTES13_ARRAY
| SchemaType.BYTES14_ARRAY
| SchemaType.BYTES15_ARRAY
| SchemaType.BYTES16_ARRAY
| SchemaType.BYTES17_ARRAY
| SchemaType.BYTES18_ARRAY
| SchemaType.BYTES19_ARRAY
| SchemaType.BYTES20_ARRAY
| SchemaType.BYTES21_ARRAY
| SchemaType.BYTES22_ARRAY
| SchemaType.BYTES23_ARRAY
| SchemaType.BYTES24_ARRAY
| SchemaType.BYTES25_ARRAY
| SchemaType.BYTES26_ARRAY
| SchemaType.BYTES27_ARRAY
| SchemaType.BYTES28_ARRAY
| SchemaType.BYTES29_ARRAY
| SchemaType.BYTES30_ARRAY
| SchemaType.BYTES31_ARRAY
| SchemaType.BYTES32_ARRAY
| SchemaType.BOOL_ARRAY
| SchemaType.ADDRESS_ARRAY;
export const SchemaTypeArrayToElement = {
[SchemaType.UINT8_ARRAY]: SchemaType.UINT8,
[SchemaType.UINT16_ARRAY]: SchemaType.UINT16,
[SchemaType.UINT24_ARRAY]: SchemaType.UINT24,
[SchemaType.UINT32_ARRAY]: SchemaType.UINT32,
[SchemaType.UINT40_ARRAY]: SchemaType.UINT40,
[SchemaType.UINT48_ARRAY]: SchemaType.UINT48,
[SchemaType.UINT56_ARRAY]: SchemaType.UINT56,
[SchemaType.UINT64_ARRAY]: SchemaType.UINT64,
[SchemaType.UINT72_ARRAY]: SchemaType.UINT72,
[SchemaType.UINT80_ARRAY]: SchemaType.UINT80,
[SchemaType.UINT88_ARRAY]: SchemaType.UINT88,
[SchemaType.UINT96_ARRAY]: SchemaType.UINT96,
[SchemaType.UINT104_ARRAY]: SchemaType.UINT104,
[SchemaType.UINT112_ARRAY]: SchemaType.UINT112,
[SchemaType.UINT120_ARRAY]: SchemaType.UINT120,
[SchemaType.UINT128_ARRAY]: SchemaType.UINT128,
[SchemaType.UINT136_ARRAY]: SchemaType.UINT136,
[SchemaType.UINT144_ARRAY]: SchemaType.UINT144,
[SchemaType.UINT152_ARRAY]: SchemaType.UINT152,
[SchemaType.UINT160_ARRAY]: SchemaType.UINT160,
[SchemaType.UINT168_ARRAY]: SchemaType.UINT168,
[SchemaType.UINT176_ARRAY]: SchemaType.UINT176,
[SchemaType.UINT184_ARRAY]: SchemaType.UINT184,
[SchemaType.UINT192_ARRAY]: SchemaType.UINT192,
[SchemaType.UINT200_ARRAY]: SchemaType.UINT200,
[SchemaType.UINT208_ARRAY]: SchemaType.UINT208,
[SchemaType.UINT216_ARRAY]: SchemaType.UINT216,
[SchemaType.UINT224_ARRAY]: SchemaType.UINT224,
[SchemaType.UINT232_ARRAY]: SchemaType.UINT232,
[SchemaType.UINT240_ARRAY]: SchemaType.UINT240,
[SchemaType.UINT248_ARRAY]: SchemaType.UINT248,
[SchemaType.UINT256_ARRAY]: SchemaType.UINT256,
[SchemaType.INT8_ARRAY]: SchemaType.INT8,
[SchemaType.INT16_ARRAY]: SchemaType.INT16,
[SchemaType.INT24_ARRAY]: SchemaType.INT24,
[SchemaType.INT32_ARRAY]: SchemaType.INT32,
[SchemaType.INT40_ARRAY]: SchemaType.INT40,
[SchemaType.INT48_ARRAY]: SchemaType.INT48,
[SchemaType.INT56_ARRAY]: SchemaType.INT56,
[SchemaType.INT64_ARRAY]: SchemaType.INT64,
[SchemaType.INT72_ARRAY]: SchemaType.INT72,
[SchemaType.INT80_ARRAY]: SchemaType.INT80,
[SchemaType.INT88_ARRAY]: SchemaType.INT88,
[SchemaType.INT96_ARRAY]: SchemaType.INT96,
[SchemaType.INT104_ARRAY]: SchemaType.INT104,
[SchemaType.INT112_ARRAY]: SchemaType.INT112,
[SchemaType.INT120_ARRAY]: SchemaType.INT120,
[SchemaType.INT128_ARRAY]: SchemaType.INT128,
[SchemaType.INT136_ARRAY]: SchemaType.INT136,
[SchemaType.INT144_ARRAY]: SchemaType.INT144,
[SchemaType.INT152_ARRAY]: SchemaType.INT152,
[SchemaType.INT160_ARRAY]: SchemaType.INT160,
[SchemaType.INT168_ARRAY]: SchemaType.INT168,
[SchemaType.INT176_ARRAY]: SchemaType.INT176,
[SchemaType.INT184_ARRAY]: SchemaType.INT184,
[SchemaType.INT192_ARRAY]: SchemaType.INT192,
[SchemaType.INT200_ARRAY]: SchemaType.INT200,
[SchemaType.INT208_ARRAY]: SchemaType.INT208,
[SchemaType.INT216_ARRAY]: SchemaType.INT216,
[SchemaType.INT224_ARRAY]: SchemaType.INT224,
[SchemaType.INT232_ARRAY]: SchemaType.INT232,
[SchemaType.INT240_ARRAY]: SchemaType.INT240,
[SchemaType.INT248_ARRAY]: SchemaType.INT248,
[SchemaType.INT256_ARRAY]: SchemaType.INT256,
[SchemaType.BYTES1_ARRAY]: SchemaType.BYTES1,
[SchemaType.BYTES2_ARRAY]: SchemaType.BYTES2,
[SchemaType.BYTES3_ARRAY]: SchemaType.BYTES3,
[SchemaType.BYTES4_ARRAY]: SchemaType.BYTES4,
[SchemaType.BYTES5_ARRAY]: SchemaType.BYTES5,
[SchemaType.BYTES6_ARRAY]: SchemaType.BYTES6,
[SchemaType.BYTES7_ARRAY]: SchemaType.BYTES7,
[SchemaType.BYTES8_ARRAY]: SchemaType.BYTES8,
[SchemaType.BYTES9_ARRAY]: SchemaType.BYTES9,
[SchemaType.BYTES10_ARRAY]: SchemaType.BYTES10,
[SchemaType.BYTES11_ARRAY]: SchemaType.BYTES11,
[SchemaType.BYTES12_ARRAY]: SchemaType.BYTES12,
[SchemaType.BYTES13_ARRAY]: SchemaType.BYTES13,
[SchemaType.BYTES14_ARRAY]: SchemaType.BYTES14,
[SchemaType.BYTES15_ARRAY]: SchemaType.BYTES15,
[SchemaType.BYTES16_ARRAY]: SchemaType.BYTES16,
[SchemaType.BYTES17_ARRAY]: SchemaType.BYTES17,
[SchemaType.BYTES18_ARRAY]: SchemaType.BYTES18,
[SchemaType.BYTES19_ARRAY]: SchemaType.BYTES19,
[SchemaType.BYTES20_ARRAY]: SchemaType.BYTES20,
[SchemaType.BYTES21_ARRAY]: SchemaType.BYTES21,
[SchemaType.BYTES22_ARRAY]: SchemaType.BYTES22,
[SchemaType.BYTES23_ARRAY]: SchemaType.BYTES23,
[SchemaType.BYTES24_ARRAY]: SchemaType.BYTES24,
[SchemaType.BYTES25_ARRAY]: SchemaType.BYTES25,
[SchemaType.BYTES26_ARRAY]: SchemaType.BYTES26,
[SchemaType.BYTES27_ARRAY]: SchemaType.BYTES27,
[SchemaType.BYTES28_ARRAY]: SchemaType.BYTES28,
[SchemaType.BYTES29_ARRAY]: SchemaType.BYTES29,
[SchemaType.BYTES30_ARRAY]: SchemaType.BYTES30,
[SchemaType.BYTES31_ARRAY]: SchemaType.BYTES31,
[SchemaType.BYTES32_ARRAY]: SchemaType.BYTES32,
[SchemaType.BOOL_ARRAY]: SchemaType.BOOL,
[SchemaType.ADDRESS_ARRAY]: SchemaType.ADDRESS,
} as {
[K in SchemaType]: K extends ArraySchemaType ? SchemaType : undefined;
};
export type DynamicSchemaType = ArraySchemaType | SchemaType.BYTES | SchemaType.STRING;
/**
* Encode a table schema into a bytes32 hex string
* Port of `Schema.sol` from `@latticexyz/store`
* @param schema The schema to encode SchemaType[]
* @returns The encoded schema as a 32 byte hex string
*/
export function encodeSchema(schema: SchemaType[]): Uint8Array {
if (schema.length > 28) throw new Error("Schema can only have up to 28 fields");
const encodedSchema = new Uint8Array(32);
let length = 0;
let staticFields = 0;
// Compute the length of the schema and the number of static fields
// and store the schema types in the encoded schema
let hasDynamicFields = false;
for (let i = 0; i < schema.length; i++) {
const staticByteLength = getStaticByteLength(schema[i]);
// Increase the static field count if the field is static
if (staticByteLength > 0) {
// Revert if we have seen a dynamic field before, but now we see a static field
if (hasDynamicFields) throw new Error("Static fields must come before dynamic fields in the schema");
staticFields++;
} else {
// Flag that we have seen a dynamic field
hasDynamicFields = true;
}
length += staticByteLength;
encodedSchema[i + 4] = schema[i];
}
// Require max 14 dynamic fields
const dynamicFields = schema.length - staticFields;
if (dynamicFields > 14) throw new Error("Schema can only have up to 14 dynamic fields");
// Store total static length, and number of static and dynamic fields
new DataView(encodedSchema.buffer).setUint16(0, length); // 2 length bytes
encodedSchema[2] = staticFields; // number of static fields
encodedSchema[3] = dynamicFields; // number of dynamic fields
return encodedSchema;
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc