Skip to content

Commit ebf9f35

Browse files
authored
fix: revert companion pattern except constants (#1193)
* chore: use unbuild & revert enums replacement * chore: revert constants & build * chore: tsup adjustments
1 parent 84f9f02 commit ebf9f35

File tree

14 files changed

+296
-190
lines changed

14 files changed

+296
-190
lines changed

package-lock.json

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/types/account.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,19 +78,19 @@ export type SimulateTransactionDetails = {
7878

7979
export type EstimateFeeAction =
8080
| {
81-
type: TransactionType.INVOKE;
81+
type: typeof TransactionType.INVOKE;
8282
payload: AllowArray<Call>;
8383
}
8484
| {
85-
type: TransactionType.DECLARE;
85+
type: typeof TransactionType.DECLARE;
8686
payload: DeclareContractPayload;
8787
}
8888
| {
89-
type: TransactionType.DEPLOY_ACCOUNT;
89+
type: typeof TransactionType.DEPLOY_ACCOUNT;
9090
payload: DeployAccountContractPayload;
9191
}
9292
| {
93-
type: TransactionType.DEPLOY;
93+
type: typeof TransactionType.DEPLOY;
9494
payload: UniversalDeployerContractPayload;
9595
};
9696

src/types/api/rpcspec_0_6/contract.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export type ABI = Array<
1111
FUNCTION | CONSTRUCTOR | L1_HANDLER | EVENT | STRUCT | ENUM | INTERFACE | IMPL
1212
>;
1313

14-
export type FUNCTION = {
14+
type FUNCTION = {
1515
type: 'function';
1616
name: string;
1717
inputs: Array<{
@@ -24,7 +24,7 @@ export type FUNCTION = {
2424
state_mutability: 'view' | 'external';
2525
};
2626

27-
export type CONSTRUCTOR = {
27+
type CONSTRUCTOR = {
2828
type: 'constructor';
2929
name: 'constructor';
3030
inputs: Array<{
@@ -33,7 +33,7 @@ export type CONSTRUCTOR = {
3333
}>;
3434
};
3535

36-
export type L1_HANDLER = {
36+
type L1_HANDLER = {
3737
type: 'l1_handler';
3838
name: string;
3939
inputs: Array<{
@@ -46,22 +46,22 @@ export type L1_HANDLER = {
4646
state_mutability: 'view' | 'external';
4747
};
4848

49-
export type EVENT = {
49+
type EVENT = {
5050
type: 'event';
5151
name: string;
5252
} & (ENUM_EVENT | STRUCT_EVENT);
5353

54-
export type STRUCT_EVENT = {
54+
type STRUCT_EVENT = {
5555
kind: 'struct';
5656
members: Array<EVENT_FIELD>;
5757
};
5858

59-
export type ENUM_EVENT = {
59+
type ENUM_EVENT = {
6060
kind: 'enum';
6161
variants: Array<EVENT_FIELD>;
6262
};
6363

64-
export type STRUCT = {
64+
type STRUCT = {
6565
type: 'struct';
6666
name: string;
6767
members: Array<{
@@ -70,7 +70,7 @@ export type STRUCT = {
7070
}>;
7171
};
7272

73-
export type ENUM = {
73+
type ENUM = {
7474
type: 'enum';
7575
name: string;
7676
variants: Array<{
@@ -79,21 +79,19 @@ export type ENUM = {
7979
}>;
8080
};
8181

82-
export type INTERFACE = {
82+
type INTERFACE = {
8383
type: 'interface';
8484
name: string;
8585
items: Array<FUNCTION>;
8686
};
8787

88-
export type IMPL = {
88+
type IMPL = {
8989
type: 'impl';
9090
name: string;
9191
interface_name: string;
9292
};
9393

94-
export type EVENT_KIND = 'struct' | 'enum';
95-
96-
export type EVENT_FIELD = {
94+
type EVENT_FIELD = {
9795
name: string;
9896
type: string;
9997
kind: 'key' | 'data' | 'nested';

src/types/api/rpcspec_0_6/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
* version 0.6.0
33
*/
44

5-
export { Methods } from './methods';
6-
export { ABI } from './contract';
5+
export * from './methods';
6+
export * from './contract';
77
export * as Errors from './errors';
88
export * as SPEC from './components';
99
export * from './nonspec';

src/types/api/rpcspec_0_6/methods.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ import {
3939
TransactionWithHash,
4040
} from './nonspec';
4141

42-
export type Methods = ReadMethods & WriteMethods & TraceMethods;
43-
4442
type ReadMethods = {
4543
// Returns the version of the Starknet JSON-RPC specification being used
4644
starknet_specVersion: {
@@ -328,3 +326,5 @@ type TraceMethods = {
328326
errors: Errors.BLOCK_NOT_FOUND | Errors.TRANSACTION_EXECUTION_ERROR;
329327
};
330328
};
329+
330+
export type Methods = ReadMethods & WriteMethods & TraceMethods;

src/types/api/rpcspec_0_6/nonspec.ts

Lines changed: 87 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
TXN_RECEIPT,
4040
TXN_STATUS,
4141
} from './components';
42+
import { ValuesType } from '../../helpers/valuesType';
4243

4344
// METHOD RESPONSES
4445
// response starknet_getClass
@@ -107,84 +108,106 @@ export type NonceUpdates = NONCE_UPDATE[];
107108
export type ReplacedClasses = REPLACED_CLASS[];
108109

109110
// Enums Derived From Spec Types (require manual check for changes)
110-
export enum ETransactionType {
111-
DECLARE = 'DECLARE',
112-
DEPLOY = 'DEPLOY',
113-
DEPLOY_ACCOUNT = 'DEPLOY_ACCOUNT',
114-
INVOKE = 'INVOKE',
115-
L1_HANDLER = 'L1_HANDLER',
116-
}
117-
118-
export enum ESimulationFlag {
119-
SKIP_VALIDATE = 'SKIP_VALIDATE',
120-
SKIP_FEE_CHARGE = 'SKIP_FEE_CHARGE',
121-
}
122-
123-
export enum ETransactionStatus {
124-
RECEIVED = 'RECEIVED',
125-
REJECTED = 'REJECTED',
126-
ACCEPTED_ON_L2 = 'ACCEPTED_ON_L2',
127-
ACCEPTED_ON_L1 = 'ACCEPTED_ON_L1',
128-
}
129-
130-
export enum ETransactionFinalityStatus {
131-
ACCEPTED_ON_L2 = 'ACCEPTED_ON_L2',
132-
ACCEPTED_ON_L1 = 'ACCEPTED_ON_L1',
133-
}
134-
135-
export enum ETransactionExecutionStatus {
136-
SUCCEEDED = 'SUCCEEDED',
137-
REVERTED = 'REVERTED',
138-
}
139-
140-
export enum EBlockTag {
141-
PENDING = 'pending',
142-
LATEST = 'latest',
143-
}
111+
export const ETransactionType = {
112+
DECLARE: 'DECLARE',
113+
DEPLOY: 'DEPLOY',
114+
DEPLOY_ACCOUNT: 'DEPLOY_ACCOUNT',
115+
INVOKE: 'INVOKE',
116+
L1_HANDLER: 'L1_HANDLER',
117+
} as const;
118+
119+
export type ETransactionType = ValuesType<typeof ETransactionType>;
120+
121+
export const ESimulationFlag = {
122+
SKIP_VALIDATE: 'SKIP_VALIDATE',
123+
SKIP_FEE_CHARGE: 'SKIP_FEE_CHARGE',
124+
} as const;
125+
126+
export type ESimulationFlag = ValuesType<typeof ESimulationFlag>;
127+
128+
export const ETransactionStatus = {
129+
RECEIVED: 'RECEIVED',
130+
REJECTED: 'REJECTED',
131+
ACCEPTED_ON_L2: 'ACCEPTED_ON_L2',
132+
ACCEPTED_ON_L1: 'ACCEPTED_ON_L1',
133+
} as const;
134+
135+
export type ETransactionStatus = ValuesType<typeof ETransactionStatus>;
136+
137+
export const ETransactionFinalityStatus = {
138+
ACCEPTED_ON_L2: 'ACCEPTED_ON_L2',
139+
ACCEPTED_ON_L1: 'ACCEPTED_ON_L1',
140+
} as const;
141+
142+
export type ETransactionFinalityStatus = ValuesType<typeof ETransactionFinalityStatus>;
143+
144+
export const ETransactionExecutionStatus = {
145+
SUCCEEDED: 'SUCCEEDED',
146+
REVERTED: 'REVERTED',
147+
} as const;
148+
149+
export type ETransactionExecutionStatus = ValuesType<typeof ETransactionExecutionStatus>;
150+
151+
export const EBlockTag = {
152+
PENDING: 'pending',
153+
LATEST: 'latest',
154+
} as const;
155+
156+
export type EBlockTag = ValuesType<typeof EBlockTag>;
144157

145158
// 'L1' | 'L2'
146-
export enum EDataAvailabilityMode {
147-
L1 = 'L1',
148-
L2 = 'L2',
149-
}
159+
export const EDataAvailabilityMode = {
160+
L1: 'L1',
161+
L2: 'L2',
162+
} as const;
163+
164+
export type EDataAvailabilityMode = ValuesType<typeof EDataAvailabilityMode>;
150165

151166
// 0 | 1
152-
export enum EDAMode {
153-
L1,
154-
L2,
155-
}
167+
export const EDAMode = {
168+
L1: 0,
169+
L2: 1,
170+
} as const;
171+
172+
export type EDAMode = ValuesType<typeof EDAMode>;
156173

157174
/**
158175
* V_ Transaction versions HexString
159176
* F_ Fee Transaction Versions HexString (2 ** 128 + TRANSACTION_VERSION)
160177
*/
161-
export enum ETransactionVersion {
162-
V0 = '0x0',
163-
V1 = '0x1',
164-
V2 = '0x2',
165-
V3 = '0x3',
166-
F0 = '0x100000000000000000000000000000000',
167-
F1 = '0x100000000000000000000000000000001',
168-
F2 = '0x100000000000000000000000000000002',
169-
F3 = '0x100000000000000000000000000000003',
170-
}
178+
export const ETransactionVersion = {
179+
V0: '0x0',
180+
V1: '0x1',
181+
V2: '0x2',
182+
V3: '0x3',
183+
F0: '0x100000000000000000000000000000000',
184+
F1: '0x100000000000000000000000000000001',
185+
F2: '0x100000000000000000000000000000002',
186+
F3: '0x100000000000000000000000000000003',
187+
} as const;
188+
189+
export type ETransactionVersion = ValuesType<typeof ETransactionVersion>;
171190

172191
/**
173192
* Old Transaction Versions
174193
*/
175-
export enum ETransactionVersion2 {
176-
V0 = '0x0',
177-
V1 = '0x1',
178-
V2 = '0x2',
179-
F0 = '0x100000000000000000000000000000000',
180-
F1 = '0x100000000000000000000000000000001',
181-
F2 = '0x100000000000000000000000000000002',
182-
}
194+
export const ETransactionVersion2 = {
195+
V0: '0x0',
196+
V1: '0x1',
197+
V2: '0x2',
198+
F0: '0x100000000000000000000000000000000',
199+
F1: '0x100000000000000000000000000000001',
200+
F2: '0x100000000000000000000000000000002',
201+
} as const;
202+
203+
export type ETransactionVersion2 = ValuesType<typeof ETransactionVersion2>;
183204

184205
/**
185206
* V3 Transaction Versions
186207
*/
187-
export enum ETransactionVersion3 {
188-
V3 = '0x3',
189-
F3 = '0x100000000000000000000000000000003',
190-
}
208+
export const ETransactionVersion3 = {
209+
V3: '0x3',
210+
F3: '0x100000000000000000000000000000003',
211+
} as const;
212+
213+
export type ETransactionVersion3 = ValuesType<typeof ETransactionVersion3>;

0 commit comments

Comments
 (0)