Revert "Avoiding cannot use namespace as a value error"

This commit is contained in:
Daniel Fugere
2025-03-09 23:33:22 +09:00
committed by GitHub
parent d613fc92b6
commit 94401d7be4
13 changed files with 12 additions and 77 deletions
+1 -1
View File
@@ -27,7 +27,7 @@
"dependencies": {
"@wharfkit/antelope": "^1.0.0",
"@wharfkit/common": "^1.2.4",
"@wharfkit/contract": "^1.2.1",
"@wharfkit/contract": "^1.1.4",
"commander": "^11.0.0",
"eslint": "^8.48.0",
"node-fetch": "^2.6.1",
+1 -11
View File
@@ -187,7 +187,7 @@ export async function generateContract(contractName: string, abi: ABI, eslintrc?
tableTypes,
rowTypeAlias,
tablesTypeAlias,
...actionsNamespace,
actionsNamespace,
actionNamesInterface,
actionsTypeAlias,
...(actionResultValuesInterface ? [actionResultValuesInterface] : []),
@@ -198,16 +198,6 @@ export async function generateContract(contractName: string, abi: ABI, eslintrc?
ts.NodeFlags.None
)
// Add ESLint disable comment for no-empty-interface at the top of the file
if (sourceFile.statements.length > 0) {
ts.addSyntheticLeadingComment(
sourceFile.statements[0],
ts.SyntaxKind.MultiLineCommentTrivia,
' eslint-disable @typescript-eslint/no-empty-interface ',
true
)
}
return runPrettier(printer.printFile(sourceFile), eslintrc)
} catch (e) {
// eslint-disable-next-line no-console
+6 -34
View File
@@ -102,18 +102,22 @@ export function generateActionInterface(
return {actionInterface, typeInterfaces: removeDuplicateInterfaces(typeInterfaces)}
}
export function generateActionsNamespace(abi: ABI.Def): ts.Statement[] {
export function generateActionsNamespace(abi: ABI.Def): ts.ModuleDeclaration {
const actionStructsWithFields = getActionFieldFromAbi(abi)
const typeInterfaces: TypeInterfaceDeclaration[] = []
const actionParamInterfaces = abi.actions.map((action) => {
const actionStruct = actionStructsWithFields.find(
(actionStructWithField) => actionStructWithField.name === action.type
)
const interfaces = generateActionInterface(actionStruct, abi)
if (interfaces.actionInterface) {
typeInterfaces.push(...interfaces.typeInterfaces)
}
return interfaces.actionInterface
})
@@ -124,44 +128,12 @@ export function generateActionsNamespace(abi: ABI.Def): ts.Statement[] {
ts.NodeFlags.Namespace
)
// Create the namespace with its nested interfaces.
const actionParamsNamespace = ts.factory.createModuleDeclaration(
return ts.factory.createModuleDeclaration(
[ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
ts.factory.createIdentifier('ActionParams'),
ts.factory.createModuleBlock([actionParamsTypes, ...actionParamInterfaces]),
ts.NodeFlags.Namespace
)
// Create an empty interface for merging.
const actionParamsInterface = ts.factory.createInterfaceDeclaration(
[ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
ts.factory.createIdentifier('ActionParams'),
undefined,
undefined,
[] // no members
)
// Create a const declaration that merges with the namespace.
const actionParamsVar = ts.factory.createVariableStatement(
[ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
ts.factory.createVariableDeclarationList(
[
ts.factory.createVariableDeclaration(
ts.factory.createIdentifier('ActionParams'),
undefined,
ts.factory.createTypeReferenceNode('ActionParams', undefined),
ts.factory.createAsExpression(
ts.factory.createObjectLiteralExpression([], false),
ts.factory.createTypeReferenceNode('ActionParams', undefined)
)
),
],
ts.NodeFlags.Const
)
)
// Return the interface, the namespace, and the const as an array of statements.
return [actionParamsInterface, actionParamsNamespace, actionParamsVar]
}
function findParamTypeString(typeString: string, namespace = '', abi: ABI.Def): string {
-3
View File
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-empty-interface */
import type {
Action,
AssetType,
@@ -593,7 +592,6 @@ export interface TableTypes {
}
export type RowType<T> = T extends keyof TableTypes ? TableTypes[T] : any
export type TableNames = keyof TableTypes
export interface ActionParams {}
export namespace ActionParams {
export namespace Type {
export interface FORMAT {
@@ -823,7 +821,6 @@ export namespace ActionParams {
token_to_withdraw: AssetType
}
}
export const ActionParams: ActionParams = {} as ActionParams
export interface ActionNameParams {
acceptoffer: ActionParams.acceptoffer
addcolauth: ActionParams.addcolauth
-3
View File
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-empty-interface */
import type {
Action,
BytesType,
@@ -1010,7 +1009,6 @@ export interface TableTypes {
}
export type RowType<T> = T extends keyof TableTypes ? TableTypes[T] : any
export type TableNames = keyof TableTypes
export interface ActionParams {}
export namespace ActionParams {
export namespace Type {
export interface AccountCreate {
@@ -1426,7 +1424,6 @@ export namespace ActionParams {
to: NameType
}
}
export const ActionParams: ActionParams = {} as ActionParams
export interface ActionNameParams {
'account.add': ActionParams.accountadd
'account.buy': ActionParams.accountbuy
-3
View File
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-empty-interface */
import type {Action, BytesType, Checksum256Type, NameType, UInt16Type} from '@wharfkit/antelope'
import {
ABI,
@@ -182,7 +181,6 @@ export interface TableTypes {
}
export type RowType<T> = T extends keyof TableTypes ? TableTypes[T] : any
export type TableNames = keyof TableTypes
export interface ActionParams {}
export namespace ActionParams {
export namespace Type {
export interface permission_level {
@@ -236,7 +234,6 @@ export namespace ActionParams {
level: Type.permission_level
}
}
export const ActionParams: ActionParams = {} as ActionParams
export interface ActionNameParams {
approve: ActionParams.approve
cancel: ActionParams.cancel
-3
View File
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-empty-interface */
import type {Action, AssetType, NameType} from '@wharfkit/antelope'
import {ABI, Asset, Blob, Name, Struct} from '@wharfkit/antelope'
import type {ActionOptions, ContractArgs, PartialBy, Table} from '@wharfkit/contract'
@@ -83,7 +82,6 @@ export interface TableTypes {
}
export type RowType<T> = T extends keyof TableTypes ? TableTypes[T] : any
export type TableNames = keyof TableTypes
export interface ActionParams {}
export namespace ActionParams {
export namespace Type {}
export interface close {
@@ -115,7 +113,6 @@ export namespace ActionParams {
memo: string
}
}
export const ActionParams: ActionParams = {} as ActionParams
export interface ActionNameParams {
close: ActionParams.close
create: ActionParams.create
-3
View File
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-empty-interface */
import type {
Action,
AssetType,
@@ -1315,7 +1314,6 @@ export interface TableTypes {
}
export type RowType<T> = T extends keyof TableTypes ? TableTypes[T] : any
export type TableNames = keyof TableTypes
export interface ActionParams {}
export namespace ActionParams {
export namespace Type {
export interface permission_level {
@@ -1734,7 +1732,6 @@ export namespace ActionParams {
amount: AssetType
}
}
export const ActionParams: ActionParams = {} as ActionParams
export interface ActionNameParams {
activate: ActionParams.activate
bidname: ActionParams.bidname
-3
View File
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-empty-interface */
import type {
Action,
AssetType,
@@ -1339,7 +1338,6 @@ export interface TableTypes {
}
export type RowType<T> = T extends keyof TableTypes ? TableTypes[T] : any
export type TableNames = keyof TableTypes
export interface ActionParams {}
export namespace ActionParams {
export namespace Type {
export interface pair_uint32_uint64 {
@@ -1750,7 +1748,6 @@ export namespace ActionParams {
new_role: UInt8Type
}
}
export const ActionParams: ActionParams = {} as ActionParams
export interface ActionNameParams {
addbuilding: ActionParams.addbuilding
adddeposit: ActionParams.adddeposit
-3
View File
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-empty-interface */
import type {
Action,
AssetType,
@@ -129,7 +128,6 @@ export interface TableTypes {
}
export type RowType<T> = T extends keyof TableTypes ? TableTypes[T] : any
export type TableNames = keyof TableTypes
export interface ActionParams {}
export namespace ActionParams {
export namespace Type {
export interface PayrollConfig {
@@ -168,7 +166,6 @@ export namespace ActionParams {
sym: Asset.SymbolCodeType
}
}
export const ActionParams: ActionParams = {} as ActionParams
export interface ActionNameParams {
'payroll.add': ActionParams.payrolladd
'payroll.edit': ActionParams.payrolledit
-3
View File
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-empty-interface */
import type {
Action,
AssetType,
@@ -104,7 +103,6 @@ export interface TableTypes {
}
export type RowType<T> = T extends keyof TableTypes ? TableTypes[T] : any
export type TableNames = keyof TableTypes
export interface ActionParams {}
export namespace ActionParams {
export namespace Type {
export interface oracle_pair {
@@ -143,7 +141,6 @@ export namespace ActionParams {
weight: UInt16Type
}
}
export const ActionParams: ActionParams = {} as ActionParams
export interface ActionNameParams {
adduser: ActionParams.adduser
claim: ActionParams.claim
-3
View File
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-empty-interface */
import type {Action, Checksum256Type, NameType, UInt64Type} from '@wharfkit/antelope'
import {
ABI,
@@ -222,7 +221,6 @@ export interface TableTypes {
}
export type RowType<T> = T extends keyof TableTypes ? TableTypes[T] : any
export type TableNames = keyof TableTypes
export interface ActionParams {}
export namespace ActionParams {
export namespace Type {}
export interface callapi {}
@@ -269,7 +267,6 @@ export namespace ActionParams {
export interface wipe {}
export interface wipesome {}
}
export const ActionParams: ActionParams = {} as ActionParams
export interface ActionNameParams {
callapi: ActionParams.callapi
addoracle: ActionParams.addoracle
+4 -4
View File
@@ -673,10 +673,10 @@
dependencies:
tslib "^2.1.0"
"@wharfkit/contract@^1.2.1":
version "1.2.1"
resolved "https://registry.yarnpkg.com/@wharfkit/contract/-/contract-1.2.1.tgz#b917db9c156344ae7f5340ff9a388108963763e8"
integrity sha512-3UhCtDYCyapfM2nRTrslcbvko864d4MOpxRAz7TR/ZUbRAgZsxhYLFLEv1v23/SU+vsFzAHNBmvzkLEG0OLaHQ==
"@wharfkit/contract@^1.1.4":
version "1.1.4"
resolved "https://registry.yarnpkg.com/@wharfkit/contract/-/contract-1.1.4.tgz#5d65a7effa02bb71c98a7493cfdca2472578e6d5"
integrity sha512-7jRgyAHrxg0/RJzOoGn4r1Md2Kho2Bozxzv+sn3c5e7ii8w9nQjyyVnYmFEVRFh6pQ0BtR/pqh6wrYJYTfXQIA==
dependencies:
"@wharfkit/abicache" "^1.2.0"
"@wharfkit/antelope" "^1.0.4"