Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export modular near #117

Merged
merged 3 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/common-near/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- Add alias `parseProjectManifest`, also follow type of `INetworkCommonModule` (#116)

## [3.5.0] - 2024-05-02
### Changed
- Update dependencies and apply changes to match (#109)
Expand Down
4 changes: 2 additions & 2 deletions packages/common-near/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"main": "dist/index.js",
"license": "GPL-3.0",
"dependencies": {
"@subql/common": "^3.5.1",
"@subql/common": "^4.0.0",
"@subql/types-near": "workspace:*",
"js-yaml": "^4.1.0",
"reflect-metadata": "^0.1.13"
Expand All @@ -24,7 +24,7 @@
"class-validator": "*"
},
"devDependencies": {
"@types/bn.js": "4.11.6",
"@types/bn.js": "5.1.5",
"@types/js-yaml": "^4.0.4",
"@types/pino": "^6.3.12"
}
Expand Down
10 changes: 10 additions & 0 deletions packages/common-near/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,13 @@
// SPDX-License-Identifier: GPL-3.0

export * from './project';

import {INetworkCommonModule} from '@subql/types-core';
import {NearDatasource, NearRuntimeDatasource, NearCustomDatasource} from '@subql/types-near';
import * as p from './project';

// This provides a compiled time check to ensure that the correct exports are provided
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const _ = {
...p,
} satisfies INetworkCommonModule<NearDatasource, NearRuntimeDatasource, NearCustomDatasource>;
3 changes: 3 additions & 0 deletions packages/common-near/src/project/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ export * from './models';
export * from './types';
export * from './utils';
export * from './versioned';

import {parseNearProjectManifest} from './load';
export {parseNearProjectManifest as parseProjectManifest};
6 changes: 3 additions & 3 deletions packages/common-near/src/project/versioned/v1_0_0/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

export class NearRunnerNodeImpl extends RunnerNodeImpl {
@Equals(NEAR_NODE_NAME, {message: `Runner Near node name incorrect, suppose be '${NEAR_NODE_NAME}'`})
name: string;
name: string = NEAR_NODE_NAME;
}

export class NearRuntimeDataSourceImpl extends RuntimeDataSourceBase implements NearRuntimeDatasource {
Expand All @@ -36,7 +36,7 @@
}
}

export class NearCustomDataSourceImpl<K extends string = string, M extends BaseMapping<any> = BaseMapping<any>>

Check warning on line 39 in packages/common-near/src/project/versioned/v1_0_0/model.ts

View workflow job for this annotation

GitHub Actions / code-style

Unexpected any. Specify a different type
extends CustomDataSourceBase<K, M>
implements NearCustomDatasource<K, M>
{
Expand Down Expand Up @@ -80,7 +80,7 @@
@ValidateNested()
@Type(() => FileType)
@IsOptional()
chaintypes?: FileType;
chaintypes?: FileType = undefined;
}

export class DeploymentV1_0_0 extends BaseDeploymentV1_0_0 {
Expand Down Expand Up @@ -131,7 +131,7 @@
}

@Equals('1.0.0')
specVersion: string;
specVersion = '1.0.0';
@Type(() => NearCustomDataSourceImpl, {
discriminator: {
property: 'kind',
Expand Down
3 changes: 3 additions & 0 deletions packages/node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed
- Bump version with `@subql/common-near`, sync with `@subql/node-core`, add admin module

## [3.11.1] - 2024-05-02
### Fixed
- Sandbox Uint8Array and missing pg dep issue
Expand Down
4 changes: 4 additions & 0 deletions packages/node/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ RUN rm /app.tgz && \
yarn cache clean && \
rm -rf /root/.npm /root/.cache

# Create ./.monitor directory and set permissions
RUN mkdir -p .monitor && \
chown 1000:1000 .monitor

# Make the user not ROOT
USER 1000

Expand Down
3 changes: 1 addition & 2 deletions packages/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
"@nestjs/event-emitter": "^2.0.0",
"@nestjs/platform-express": "^9.4.0",
"@nestjs/schedule": "^3.0.1",
"@subql/common": "^3.5.1",
"@subql/common-near": "workspace:*",
"@subql/node-core": "^10.1.1",
"@subql/node-core": "^10.10.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is quite the version jump, are we sure its compatible? I think there is the admin api stuff

"@subql/types-near": "workspace:*",
"lodash": "^4.17.21",
"near-api-js": "^2.1.4",
Expand Down
13 changes: 13 additions & 0 deletions packages/node/src/admin/admin.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: GPL-3.0

import { Module } from '@nestjs/common';
import { adminControllers, adminServices } from '@subql/node-core';
import { FetchModule } from '../indexer/fetch.module';

@Module({
imports: [FetchModule],
controllers: [...adminControllers],
providers: [...adminServices],
})
export class AdminModule {}
2 changes: 2 additions & 0 deletions packages/node/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Module } from '@nestjs/common';
import { EventEmitterModule } from '@nestjs/event-emitter';
import { ScheduleModule } from '@nestjs/schedule';
import { DbModule } from '@subql/node-core';
import { AdminModule } from './admin/admin.module';
import { ConfigureModule } from './configure/configure.module';
import { FetchModule } from './indexer/fetch.module';
import { MetaModule } from './meta/meta.module';
Expand All @@ -17,6 +18,7 @@ import { MetaModule } from './meta/meta.module';
ScheduleModule.forRoot(),
FetchModule,
MetaModule,
AdminModule,
],
controllers: [],
})
Expand Down
4 changes: 2 additions & 2 deletions packages/node/src/indexer/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
ConnectionPoolService,
ApiService as BaseApiService,
IBlock,
exitWithError,
} from '@subql/node-core';
import * as Near from 'near-api-js';
import {
Expand Down Expand Up @@ -57,8 +58,7 @@ export class ApiService extends BaseApiService<
try {
network = this.project.network;
} catch (e) {
logger.error(e);
process.exit(1);
exitWithError(new Error(`Failed to init api`, { cause: e }), logger);
}

if (this.nodeConfig?.profiler) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
PoiSyncService,
InMemoryCacheService,
createIndexerWorker,
MonitorServiceInterface,
} from '@subql/node-core';
import { NearBlock, NearDatasource } from '@subql/types-near';
import { SubqueryProject } from '../../configure/SubqueryProject';
Expand Down Expand Up @@ -47,6 +48,7 @@ export class WorkerBlockDispatcherService
dynamicDsService: DynamicDsService,
unfinalizedBlocksSevice: UnfinalizedBlocksService,
connectionPoolState: ConnectionPoolStateManager<NearApiConnection>,
monitorService?: MonitorServiceInterface,
) {
super(
nodeConfig,
Expand All @@ -73,7 +75,9 @@ export class WorkerBlockDispatcherService
connectionPoolState,
project.root,
projectService.startHeight,
monitorService,
),
monitorService,
);
}

Expand Down
7 changes: 6 additions & 1 deletion packages/node/src/indexer/fetch.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
PoiSyncService,
InMemoryCacheService,
SandboxService,
MonitorService,
} from '@subql/node-core';
import { SubqueryProject } from '../configure/SubqueryProject';
import { ApiService } from './api.service';
Expand Down Expand Up @@ -58,6 +59,7 @@ import { UnfinalizedBlocksService } from './unfinalizedBlocks.service';
dynamicDsService: DynamicDsService,
unfinalizedBlocks: UnfinalizedBlocksService,
connectionPoolState: ConnectionPoolStateManager<NearApiConnection>,
monitorService?: MonitorService,
) =>
nodeConfig.workers
? new WorkerBlockDispatcherService(
Expand All @@ -73,6 +75,7 @@ import { UnfinalizedBlocksService } from './unfinalizedBlocks.service';
dynamicDsService,
unfinalizedBlocks,
connectionPoolState,
monitorService,
)
: new BlockDispatcherService(
apiService,
Expand Down Expand Up @@ -101,6 +104,7 @@ import { UnfinalizedBlocksService } from './unfinalizedBlocks.service';
DynamicDsService,
UnfinalizedBlocksService,
ConnectionPoolStateManager,
MonitorService,
],
},
FetchService,
Expand All @@ -118,7 +122,8 @@ import { UnfinalizedBlocksService } from './unfinalizedBlocks.service';
provide: 'IProjectService',
},
UnfinalizedBlocksService,
MonitorService,
],
exports: [StoreService, StoreCacheService],
exports: [StoreService, StoreCacheService, MonitorService, PoiService],
})
export class FetchModule {}
6 changes: 6 additions & 0 deletions packages/node/src/indexer/worker/worker-fetch.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
WorkerInMemoryCacheService,
SandboxService,
WorkerUnfinalizedBlocksService,
MonitorService,
WorkerMonitorService,
} from '@subql/node-core';
import { SubqueryProject } from '../../configure/SubqueryProject';
import { ApiService } from '../api.service';
Expand Down Expand Up @@ -69,6 +71,10 @@ import { WorkerService } from '../worker/worker.service';
useClass: ProjectService,
},
WorkerService,
{
provide: MonitorService,
useFactory: () => new WorkerMonitorService((global as any).host),
},
{
provide: UnfinalizedBlocksService,
useFactory: () =>
Expand Down
10 changes: 7 additions & 3 deletions packages/node/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
// SPDX-License-Identifier: GPL-3.0

import { NestFactory } from '@nestjs/core';
import { getLogger, getValidPort, NestLogger } from '@subql/node-core';
import {
exitWithError,
getLogger,
getValidPort,
NestLogger,
} from '@subql/node-core';
import { AppModule } from './app.module';
import { ApiService } from './indexer/api.service';
import { FetchService } from './indexer/fetch.service';
Expand Down Expand Up @@ -45,7 +50,6 @@ export async function bootstrap(): Promise<void> {

logger.info(`Node started on port: ${port}`);
} catch (e) {
logger.error(e, 'Node failed to start');
process.exit(1);
exitWithError(new Error('Node failed to start', { cause: e }), logger);
}
}
5 changes: 2 additions & 3 deletions packages/node/src/subcommands/testing.init.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: GPL-3.0

import { getLogger } from '@subql/node-core';
import { getLogger, exitWithError } from '@subql/node-core';
import { ConfigureModule } from '../configure/configure.module';
import { TestingService } from './testing.service';

Expand All @@ -13,8 +13,7 @@ export async function testingInit(): Promise<void> {
const testingService = new TestingService(nodeConfig, project);
await testingService.run();
} catch (e) {
logger.error(e, 'Testing failed');
process.exit(1);
exitWithError(new Error('Testing failed', { cause: e }), logger);
}
process.exit(0);
}
6 changes: 1 addition & 5 deletions packages/node/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"target": "es2017",
"sourceMap": true,
"tsBuildInfoFile": "dist/.tsbuildinfo",
"rootDir": "src",
"outDir": "./dist"
},
"references": [
{ "path": "../common-near" },
{ "path": "../types" },
],
"references": [{ "path": "../common-near" }, { "path": "../types" }],
"include": ["src/**/*"],
"exclude": ["node_modules", "test", "dist"]
}
3 changes: 3 additions & 0 deletions packages/types/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed
- Bump version with `@subql/types-core`

## [3.3.0] - 2024-05-02
### Changed
- Update dependencies and apply changes to match (#109)
Expand Down
2 changes: 1 addition & 1 deletion packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"/dist"
],
"dependencies": {
"@subql/types-core": "^0.7.0",
"@subql/types-core": "^0.9.0",
"bn.js": "5.2.1",
"near-api-js": "^1.1.0"
},
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es2017",
"target": "es2022",
"noImplicitAny": false,
"noImplicitThis": true,
"moduleResolution": "node",
Expand All @@ -11,7 +11,7 @@
"experimentalDecorators": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"lib": ["ES2017", "ES2020"],
"lib": ["ES2022"],
"emitDecoratorMetadata": true,
"declaration": true,
"sourceMap": true,
Expand Down
Loading
Loading