From 5f0cd23f964d8ec54a4a724e8b7d9831825473b6 Mon Sep 17 00:00:00 2001 From: Scott Twiname Date: Mon, 2 Dec 2024 14:37:41 +1300 Subject: [PATCH] Fix circular imports --- .../node-core/src/db/migration-service/migration.ts | 12 +++++------- packages/node-core/src/db/sync-helper.ts | 6 +++--- packages/node-core/src/indexer/sandbox.ts | 2 +- .../node-core/src/subcommands/forceClean.service.ts | 3 +-- packages/node-core/src/utils/graphql.ts | 6 +++++- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/packages/node-core/src/db/migration-service/migration.ts b/packages/node-core/src/db/migration-service/migration.ts index aa5cdf35cb..469e7cc02f 100644 --- a/packages/node-core/src/db/migration-service/migration.ts +++ b/packages/node-core/src/db/migration-service/migration.ts @@ -23,12 +23,10 @@ import {isEqual, uniq} from 'lodash'; import {NodeConfig} from '../../configure/NodeConfig'; import {HistoricalMode, StoreService} from '../../indexer'; import {getLogger} from '../../logger'; -import {EnumType, getColumnOption, modelsTypeToModelAttributes} from '../../utils'; +import {EnumType, getColumnOption, modelsTypeToModelAttributes, enumNameToHash} from '../../utils'; import {formatAttributes, formatColumnName, modelToTableName} from '../sequelizeUtil'; import * as syncHelper from '../sync-helper'; -type RemovedIndexes = Record; - const logger = getLogger('db-manager'); export class Migration { @@ -358,8 +356,8 @@ export class Migration { // It is difficult for sequelize use replacement, instead we use escape to avoid injection // UPDATE: this comment got syntax error with cockroach db, disable it for now. Waiting to be fixed. // See https://github.com/cockroachdb/cockroach/issues/44135 - const enumTypeName = syncHelper.enumNameToHash(e.name); - const enumTypeNameDeprecated = `${this.schemaName}_enum_${syncHelper.enumNameToHash(e.name)}`; + const enumTypeName = enumNameToHash(e.name); + const enumTypeNameDeprecated = `${this.schemaName}_enum_${enumNameToHash(e.name)}`; let type: string | null = null; @@ -397,8 +395,8 @@ export class Migration { } dropEnum(e: GraphQLEnumsType): void { - const enumTypeName = syncHelper.enumNameToHash(e.name); - const enumTypeNameDeprecated = `${this.schemaName}_enum_${syncHelper.enumNameToHash(e.name)}`; + const enumTypeName = enumNameToHash(e.name); + const enumTypeNameDeprecated = `${this.schemaName}_enum_${enumNameToHash(e.name)}`; [enumTypeName, enumTypeNameDeprecated].forEach((typeName) => { if (this.enumTypeMap.has(typeName)) { diff --git a/packages/node-core/src/db/sync-helper.ts b/packages/node-core/src/db/sync-helper.ts index 4c15a3d816..8cdd15f6a8 100644 --- a/packages/node-core/src/db/sync-helper.ts +++ b/packages/node-core/src/db/sync-helper.ts @@ -297,9 +297,9 @@ export function createSchemaTriggerFunction(schema: string): string { $$ LANGUAGE plpgsql;`; } -export function enumNameToHash(enumName: string): string { - return blake2AsHex(enumName).substr(2, 10); -} +// export function enumNameToHash(enumName: string): string { +// return blake2AsHex(enumName).substr(2, 10); +// } export function getExistedIndexesQuery(schema: string): string { return `SELECT indexname FROM pg_indexes WHERE schemaname = '${schema}'`; diff --git a/packages/node-core/src/indexer/sandbox.ts b/packages/node-core/src/indexer/sandbox.ts index 2aaddd7332..099d2c8418 100644 --- a/packages/node-core/src/indexer/sandbox.ts +++ b/packages/node-core/src/indexer/sandbox.ts @@ -11,7 +11,7 @@ import {SourceMapConsumer, NullableMappedPosition} from 'source-map'; import {NodeVM, NodeVMOptions, VMError, VMScript} from 'vm2'; import {NodeConfig} from '../configure/NodeConfig'; import {getLogger} from '../logger'; -import {timeout} from '../utils'; +import {timeout} from '../utils/promise'; export const SANDBOX_DEFAULT_BUILTINS = ['assert', 'buffer', 'crypto', 'util', 'path', 'url', 'stream']; diff --git a/packages/node-core/src/subcommands/forceClean.service.ts b/packages/node-core/src/subcommands/forceClean.service.ts index 5e3a1ab8e7..54ad7289dc 100644 --- a/packages/node-core/src/subcommands/forceClean.service.ts +++ b/packages/node-core/src/subcommands/forceClean.service.ts @@ -5,11 +5,10 @@ import {Inject, Injectable} from '@nestjs/common'; import {getAllEntitiesRelations} from '@subql/utils'; import {QueryTypes, Sequelize} from '@subql/x-sequelize'; import {NodeConfig} from '../configure'; -import {enumNameToHash} from '../db'; import {MonitorService} from '../indexer'; import {ISubqueryProject} from '../indexer/types'; import {getLogger} from '../logger'; -import {getEnumDeprecated, getExistingProjectSchema} from '../utils'; +import {getEnumDeprecated, getExistingProjectSchema, enumNameToHash} from '../utils'; const logger = getLogger('Force-clean'); diff --git a/packages/node-core/src/utils/graphql.ts b/packages/node-core/src/utils/graphql.ts index 3e48958f2c..62fd243294 100644 --- a/packages/node-core/src/utils/graphql.ts +++ b/packages/node-core/src/utils/graphql.ts @@ -13,10 +13,14 @@ import { isNull, GraphQLEntityField, GraphQLJsonFieldType, + blake2AsHex, } from '@subql/utils'; import {ModelAttributes, ModelAttributeColumnOptions} from '@subql/x-sequelize'; import {isArray, isObject} from 'lodash'; -import {enumNameToHash} from '../db'; + +export function enumNameToHash(enumName: string): string { + return blake2AsHex(enumName).substr(2, 10); +} export interface EnumType { enumValues: string[];