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

Sync with main SDK for project upgrades feature #60

Merged
merged 13 commits into from
Oct 4, 2023
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module.exports = {
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
'plugin:jest/recommended',
],
rules: {
// rules turned off in upstream project (also required when recommended-requiring-type-checking is extended)
Expand Down
51 changes: 51 additions & 0 deletions .github/workflows/node-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,54 @@ jobs:
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}


node-build-push-docker-subquery:

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 100
token: ${{ secrets.REPO_TOKEN }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v1

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: subquerynetwork
password: ${{ secrets.SQ_DOCKERHUB_TOKEN }}

## node
- name: Get updated node version
id: get-node-version
run: |
sh .github/workflows/scripts/nodeVersion.sh

- name: Build and push
if: github.event.inputs.isLatest == 'false'
uses: docker/build-push-action@v2
with:
push: true
platforms: arm64,amd64
file: ./packages/node/Dockerfile
tags: subquerynetwork/subql-node-near:v${{ steps.get-node-version.outputs.NODE_VERSION }},
build-args: RELEASE_VERSION=${{ steps.get-node-version.outputs.NODE_VERSION }}

- name: Build and push
if: github.event.inputs.isLatest == 'true'
uses: docker/build-push-action@v2
with:
push: true
platforms: arm64,amd64
file: ./packages/node/Dockerfile
tags: subquerynetwork/subql-node-near:v${{ steps.get-node-version.outputs.NODE_VERSION }},subquerynetwork/subql-node-near:latest
build-args: RELEASE_VERSION=${{ steps.get-node-version.outputs.NODE_VERSION }}

- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-header": "^3.1.1",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-jest": "^27.2.3",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-sort-destructure-keys": "^1.4.0",
"husky": "^7.0.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/common-near/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"main": "dist/index.js",
"license": "GPL-3.0",
"dependencies": {
"@subql/common": "2.6.0",
"@subql/common": "^3.1.1",
"@subql/types-near": "workspace:*",
"js-yaml": "^4.1.0",
"reflect-metadata": "^0.1.13"
Expand Down
8 changes: 0 additions & 8 deletions packages/common-near/src/project/load.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: GPL-3.0

import {getManifestPath, loadFromJsonOrYaml} from '@subql/common';
// import {NodeVM, VMScript} from 'vm2';
import {NearProjectManifestVersioned, VersionedProjectManifest} from './versioned';

Expand All @@ -10,10 +9,3 @@ export function parseNearProjectManifest(raw: unknown): NearProjectManifestVersi
projectManifest.validate();
return projectManifest;
}

export function loadNearProjectManifest(file: string): NearProjectManifestVersioned {
const doc = loadFromJsonOrYaml(getManifestPath(file));
const projectManifest = new NearProjectManifestVersioned(doc as VersionedProjectManifest);
projectManifest.validate();
return projectManifest;
}
45 changes: 9 additions & 36 deletions packages/common-near/src/project/models.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: GPL-3.0

import {BaseMapping, FileReference} from '@subql/common';
import {BlockFilterImpl, ProcessorImpl} from '@subql/common';
import {BaseMapping, FileReference, Processor} from '@subql/types-core';
import {
CustomDataSourceAsset as NearCustomDataSourceAsset,
NearBlockFilter,
Expand All @@ -13,21 +14,17 @@
NearTransactionFilter,
NearActionHandler,
NearHandlerKind,
NearNetworkFilter,
NearRuntimeDatasource,
NearRuntimeHandler,
NearRuntimeHandlerFilter,

Check warning on line 19 in packages/common-near/src/project/models.ts

View workflow job for this annotation

GitHub Actions / code-style

'NearRuntimeHandlerFilter' is defined but never used
NearCustomDatasource,
ActionType,
NearReceiptHandler,
NearReceiptFilter,
} from '@subql/types-near';
import BN from 'bn.js';
import {plainToClass, Transform, Type} from 'class-transformer';
import {
ArrayMaxSize,
IsArray,
IsBoolean,
IsEnum,
IsInt,
IsOptional,
Expand All @@ -41,18 +38,7 @@
ValidateIf,
} from 'class-validator';

export class BlockFilter implements NearBlockFilter {
@IsOptional()
@IsArray()
@ArrayMaxSize(2)
specVersion?: [number, number];
@IsOptional()
@IsInt()
modulo?: number;
@IsOptional()
@IsString()
timestamp?: string;
}
export class BlockFilter extends BlockFilterImpl implements NearBlockFilter {}

export class TransactionFilter extends BlockFilter implements NearTransactionFilter {
@IsOptional()
Expand All @@ -64,7 +50,7 @@
}

export function IsActionType(validationOptions?: ValidationOptions) {
return function (object: object, propertyName: string) {

Check warning on line 53 in packages/common-near/src/project/models.ts

View workflow job for this annotation

GitHub Actions / code-style

Missing return type on function
registerDecorator({
name: 'isActionType',
target: object.constructor,
Expand All @@ -72,7 +58,7 @@
constraints: [],
options: validationOptions,
validator: {
validate(value: any, args: ValidationArguments) {

Check warning on line 61 in packages/common-near/src/project/models.ts

View workflow job for this annotation

GitHub Actions / code-style

Unexpected any. Specify a different type

Check warning on line 61 in packages/common-near/src/project/models.ts

View workflow job for this annotation

GitHub Actions / code-style

'args' is defined but never used
return Object.values(ActionType).includes(value);
},
},
Expand Down Expand Up @@ -181,7 +167,7 @@
filter?: Record<string, unknown>;
}

export class RuntimeMapping implements BaseMapping<NearRuntimeHandlerFilter, NearRuntimeHandler> {
export class RuntimeMapping implements BaseMapping<NearRuntimeHandler> {
@Transform((params) => {
const handlers: NearRuntimeHandler[] = params.value;
return handlers.map((handler) => {
Expand All @@ -195,7 +181,7 @@
case NearHandlerKind.Block:
return plainToClass(BlockHandler, handler);
default:
throw new Error(`handler ${(handler as any).kind} not supported`);

Check warning on line 184 in packages/common-near/src/project/models.ts

View workflow job for this annotation

GitHub Actions / code-style

Unexpected any. Specify a different type
}
});
})
Expand All @@ -206,7 +192,7 @@
file: string;
}

export class CustomMapping implements BaseMapping<Record<string, unknown>, NearCustomHandler> {
export class CustomMapping implements BaseMapping<NearCustomHandler> {
@IsArray()
@Type(() => CustomHandler)
@ValidateNested()
Expand All @@ -215,12 +201,6 @@
file: string;
}

export class SubqlNetworkFilterImpl implements NearNetworkFilter {
@IsString()
@IsOptional()
specName?: string;
}

export class RuntimeDataSourceBase implements NearRuntimeDatasource {
@IsEnum(NearDatasourceKind, {groups: [NearDatasourceKind.Runtime]})
kind: NearDatasourceKind.Runtime;
Expand All @@ -232,19 +212,15 @@
@IsOptional()
@IsInt()
startBlock?: number;
@IsOptional()
@ValidateNested()
@Type(() => SubqlNetworkFilterImpl)
filter?: NearNetworkFilter;
}

export class FileReferenceImpl implements FileReference {
@IsString()
file: string;
}

export class CustomDataSourceBase<K extends string, T extends NearNetworkFilter, M extends CustomMapping, O = any>
implements NearCustomDatasource<K, T, M, O>
export class CustomDataSourceBase<K extends string, M extends CustomMapping, O = any>

Check warning on line 222 in packages/common-near/src/project/models.ts

View workflow job for this annotation

GitHub Actions / code-style

'O' is defined but never used

Check warning on line 222 in packages/common-near/src/project/models.ts

View workflow job for this annotation

GitHub Actions / code-style

Unexpected any. Specify a different type
implements NearCustomDatasource<K, M>
{
@IsString()
kind: K;
Expand All @@ -257,10 +233,7 @@
@Type(() => FileReferenceImpl)
@ValidateNested({each: true})
assets: Map<string, NearCustomDataSourceAsset>;
@Type(() => FileReferenceImpl)
@IsObject()
processor: FileReference;
@IsOptional()
@Type(() => ProcessorImpl)
@IsObject()
filter?: T;
processor: Processor;
}
4 changes: 1 addition & 3 deletions packages/common-near/src/project/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: GPL-3.0

import {IProjectManifest, ProjectNetworkConfig} from '@subql/common';
import {IProjectManifest, ProjectNetworkConfig} from '@subql/types-core';
import {NearDatasource} from '@subql/types-near';

// All of these used to be redefined in this file, re-exporting for simplicity
Expand All @@ -16,7 +16,6 @@ export {
NearTransactionFilter,
NearActionFilter,
NearDatasourceProcessor,
NearNetworkFilter,
NearRuntimeHandlerFilter,
NearDatasourceKind,
RuntimeHandlerInputMap as NearRuntimeHandlerInputMap,
Expand All @@ -26,6 +25,5 @@ export {
export type INearProjectManifest = IProjectManifest<NearDatasource>;

export interface NearProjectNetworkConfig extends ProjectNetworkConfig {
genesisHash?: string;
chainId?: string;
}
15 changes: 9 additions & 6 deletions packages/common-near/src/project/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,38 @@ import {
NearDatasource,
NearDatasourceKind,
NearHandlerKind,
NearNetworkFilter,
NearRuntimeDatasource,
NearMapping,
NearCustomHandler,
} from '@subql/types-near';

export function isBlockHandlerProcessor<T extends NearNetworkFilter, E>(
export function isBlockHandlerProcessor<T extends Record<string, unknown>, E>(
hp: SecondLayerHandlerProcessor<NearHandlerKind, T, unknown>
): hp is SecondLayerHandlerProcessor<NearHandlerKind.Block, T, E> {
return hp.baseHandlerKind === NearHandlerKind.Block;
}

export function isTransactionHandlerProcessor<T extends NearNetworkFilter, E>(
export function isTransactionHandlerProcessor<T extends Record<string, unknown>, E>(
hp: SecondLayerHandlerProcessor<NearHandlerKind, T, unknown>
): hp is SecondLayerHandlerProcessor<NearHandlerKind.Transaction, T, E> {
return hp.baseHandlerKind === NearHandlerKind.Transaction;
}

export function isActionHandlerProcessor<T extends NearNetworkFilter, E>(
export function isActionHandlerProcessor<T extends Record<string, unknown>, E>(
hp: SecondLayerHandlerProcessor<NearHandlerKind, T, unknown>
): hp is SecondLayerHandlerProcessor<NearHandlerKind.Action, T, E> {
return hp.baseHandlerKind === NearHandlerKind.Action;
}

export function isReceiptHandlerProcessor<T extends NearNetworkFilter, E>(
export function isReceiptHandlerProcessor<T extends Record<string, unknown>, E>(
hp: SecondLayerHandlerProcessor<NearHandlerKind, T, unknown>
): hp is SecondLayerHandlerProcessor<NearHandlerKind.Receipt, T, E> {
return hp.baseHandlerKind === NearHandlerKind.Receipt;
}

export function isCustomDs<F extends NearNetworkFilter>(ds: NearDatasource): ds is NearCustomDatasource<string, F> {
export function isCustomDs<F extends NearMapping<NearCustomHandler>>(
ds: NearDatasource
): ds is NearCustomDatasource<string, F> {
return ds.kind !== NearDatasourceKind.Runtime && !!(ds as NearCustomDatasource<string, F>).processor;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const NEAR_SUPPORTED_VERSIONS = {

type Versions = keyof typeof NEAR_SUPPORTED_VERSIONS;

type ProjectManifestImpls = InstanceType<(typeof NEAR_SUPPORTED_VERSIONS)[Versions]>;
export type ProjectManifestImpls = InstanceType<(typeof NEAR_SUPPORTED_VERSIONS)[Versions]>;

export function manifestIsV1_0_0(manifest: INearProjectManifest): manifest is ProjectManifestV1_0_0Impl {
return manifest.specVersion === '1.0.0';
Expand Down Expand Up @@ -43,7 +43,7 @@ export class NearProjectManifestVersioned implements INearProjectManifest {
}

toDeployment(): string | undefined {
return this._impl.toDeployment();
return this._impl.deployment.toYaml();
}

validate(): void {
Expand Down
1 change: 0 additions & 1 deletion packages/common-near/src/project/versioned/v1_0_0/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
// SPDX-License-Identifier: GPL-3.0

export * from './model';
export * from './types';
Loading
Loading