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 @subql dependencies #111

Merged
merged 2 commits into from
May 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
6 changes: 1 addition & 5 deletions packages/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,14 @@
"@nestjs/schedule": "^3.0.1",
"@subql/common": "^3.5.1",
"@subql/common-near": "workspace:*",
"@subql/node-core": "^10.0.0",
"@subql/node-core": "^10.1.0",
"@subql/types-near": "workspace:*",
"cron-converter": "^1.0.2",
"lodash": "^4.17.21",
"near-api-js": "^2.1.4",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"yargs": "^16.2.0"
},
"peerDependencies": {
"@apollo/client": "^3.7.16"
},
"devDependencies": {
"@nestjs/schematics": "^9.2.0",
"@nestjs/testing": "^9.4.0",
Expand Down
9 changes: 2 additions & 7 deletions packages/node/src/configure/SubqueryProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
isCustomDs,
} from '@subql/common-near';
import {
CronFilter,
insertBlockFiltersCronSchedules,
loadProjectTemplates,
updateDataSourcesV1_0_0,
Expand All @@ -25,17 +26,11 @@ import {
RuntimeDatasourceTemplate,
} from '@subql/types-near';
import { buildSchemaFromString } from '@subql/utils';
import Cron from 'cron-converter';
import { GraphQLSchema } from 'graphql';

const { version: packageVersion } = require('../../package.json');

export type SubqlProjectBlockFilter = NearBlockFilter & {
cronSchedule?: {
schedule: Cron.Seeker;
next: number;
};
};
export type SubqlProjectBlockFilter = NearBlockFilter & CronFilter;

export type NearProjectDsTemplate =
| RuntimeDatasourceTemplate
Expand Down
42 changes: 13 additions & 29 deletions packages/node/src/utils/near.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
// SPDX-License-Identifier: GPL-3.0

import { BN } from '@polkadot/util';
import { getLogger, Header, IBlock } from '@subql/node-core';
import {
getLogger,
Header,
IBlock,
filterBlockTimestamp,
} from '@subql/node-core';
import {
NearBlockFilter,
NearTransactionFilter,
Expand Down Expand Up @@ -277,10 +282,13 @@ export function filterBlock(
): NearBlock | undefined {
if (!filter) return block;
if (!filterBlockModulo(block, filter)) return;
if (filter.timestamp) {
if (!filterBlockTimestamp(block, filter as SubqlProjectBlockFilter)) {
return;
}
if (
!filterBlockTimestamp(
block.header.timestamp,
filter as SubqlProjectBlockFilter,
)
) {
return;
}

return block;
Expand All @@ -295,30 +303,6 @@ export function filterBlockModulo(
return block.header.height % modulo === 0;
}

export function filterBlockTimestamp(
block: NearBlock,
filter: SubqlProjectBlockFilter,
): boolean {
const unixTimestamp = block.header.timestamp;
if (unixTimestamp > filter.cronSchedule.next) {
logger.info(
`Block with timestamp ${new Date(
unixTimestamp,
).toString()} is about to be indexed`,
);
logger.info(
`Next block will be indexed at ${new Date(
filter.cronSchedule.next,
).toString()}`,
);
filter.cronSchedule.schedule.prev();
return true;
} else {
filter.cronSchedule.schedule.prev();
return false;
}
}

export function filterTransaction(
transaction: NearTransaction,
filter?: NearTransactionFilter,
Expand Down
78 changes: 78 additions & 0 deletions scripts/update_versions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/bin/sh
set -e

LIGHT_BLUE='\033[1;34m'
YELLOW='\033[1;33m'
NC='\033[0m'

# Function to echo unreleased changes from CHANGELOG.md
echo_unreleased_changes() {
local changelog_file="$1"

# Check if the provided argument is a valid file
if [ ! -f "$changelog_file" ]; then
echo "Changelog doesn't exist"
return 1
fi

# Use sed to extract the line number of the start and end of the unreleased changes
local start_line=$(sed -n '/## \[Unreleased\]/=' "$changelog_file")
local end_line=$(sed -n '/## \[/=' "$changelog_file" | sed -n 2p)

# Use awk to extract the unreleased changes
local changes=$(awk "NR > $start_line && NR < $end_line" "$changelog_file")

# Check if there are any changes
if [ -z "$changes" ]; then
echo "No unreleased changes found. Please include some changes and try again"
exit 1
else
echo "Unreleased Changes:\n${LIGHT_BLUE}$changes${NC}\n"
fi
}

prepare_package_release() {
local dir="$1"

# Check if the provided argument is a valid file
if [ ! -d "$dir" ]; then
echo "Expected $dir to be a directory"
exit 1
fi

# Movde into the directory in the path
cd "$dir"

# Get the version from package.json
VERSION=$(jq -r '.version' package.json)
NAME=$(jq -r '.name' package.json)

# Check if the version is a prerelease (ends with a hyphen and one or more digits)
if [[ $VERSION =~ -[0-9]+$ ]]; then
# Prompt the user for the version bump
echo "Please select the version bump for ${YELLOW}$NAME${NC}"
echo_unreleased_changes "./CHANGELOG.md"
read -p "Version bump (major, minor or patch): " BUMP

# Update the package.json version
yarn version $BUMP

# Run the changelog:release command
yarn changelog:release
fi

# Back to previous dir
cd -
}

## Warning this will not automatically update packages that just have dependency changes
## E.g. when @subql/common is updated, @subql/common-substrate should also be updated
## It also doesn't do things in order of dependencies
for dir in packages/*; do
# Check the path is a directory and is tracked by git
if [ -d "$dir" ] && [[ $(git ls-files "$dir") ]]; then
prepare_package_release "$dir"
fi
done

# prepare_package_release "$1"
51 changes: 24 additions & 27 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2762,9 +2762,9 @@ __metadata:
languageName: node
linkType: hard

"@subql/node-core@npm:^10.0.0":
version: 10.0.0
resolution: "@subql/node-core@npm:10.0.0"
"@subql/node-core@npm:^10.1.0":
version: 10.1.0
resolution: "@subql/node-core@npm:10.1.0"
dependencies:
"@apollo/client": ^3.8.8
"@nestjs/common": ^9.4.0
Expand All @@ -2773,10 +2773,11 @@ __metadata:
"@subql/common": 3.5.1
"@subql/testing": 2.1.1
"@subql/types": 3.5.0
"@subql/utils": 2.9.1
"@subql/utils": 2.9.2
"@willsoto/nestjs-prometheus": ^5.4.0
async-lock: ^1.4.0
async-mutex: ^0.4.0
cron-converter: ^2.0.1
cross-fetch: ^3.1.6
csv-stringify: ^6.4.5
dayjs: ^1.10.7
Expand All @@ -2789,7 +2790,7 @@ __metadata:
toposort-class: ^1.0.1
vm2: ^3.9.19
yargs: ^16.2.0
checksum: c52c304ea23c10a171ef411b877032c88733eb6a2262b4a167de9484f7e1fed567bdc36ad1bcb7f9a610d1774a348bd203dc82dd1f7c52f693ff7756c4097d4f
checksum: b7df8c672e93bc6339d47c4a8c806dd8fca7c1a24e0ce0ac065925928151bc476b8cf9f6149e85c472085f81800d601a79ea6fd8e1e0ca09636b09fdc3371dd0
languageName: node
linkType: hard

Expand All @@ -2806,24 +2807,21 @@ __metadata:
"@nestjs/testing": ^9.4.0
"@subql/common": ^3.5.1
"@subql/common-near": "workspace:*"
"@subql/node-core": ^10.0.0
"@subql/node-core": ^10.1.0
"@subql/types-near": "workspace:*"
"@types/express": ^4.17.13
"@types/jest": ^27.4.0
"@types/lodash": ^4.14.178
"@types/pino": ^6.3.12
"@types/tar": ^6.1.1
"@types/yargs": ^16.0.4
cron-converter: ^1.0.2
dotenv: ^15.0.1
lodash: ^4.17.21
near-api-js: ^2.1.4
nodemon: ^2.0.15
reflect-metadata: ^0.1.13
rimraf: ^3.0.2
yargs: ^16.2.0
peerDependencies:
"@apollo/client": ^3.7.16
bin:
subql-node-near: ./bin/run
languageName: unknown
Expand Down Expand Up @@ -2869,9 +2867,9 @@ __metadata:
languageName: node
linkType: hard

"@subql/utils@npm:2.9.1":
version: 2.9.1
resolution: "@subql/utils@npm:2.9.1"
"@subql/utils@npm:2.9.2":
version: 2.9.2
resolution: "@subql/utils@npm:2.9.2"
dependencies:
"@polkadot/util": ^12.5.1
"@polkadot/util-crypto": ^12.5.1
Expand All @@ -2887,7 +2885,7 @@ __metadata:
rotating-file-stream: ^3.0.2
semver: ^7.5.2
tar: ^6.2.1
checksum: 555c215f44ac6f6828ade30c3643e260bf99ef3c14381d14a9e9ba3c9fa5cfd0a4e938b3a2fbd907379ad2b832bb79a5071f96966b32d751824affb9cea266c8
checksum: fd2f32136d0324e3b19e826e4760e90db36e66b580ee244e77fa96124389d3253923c74ab98a07799803ba2421c285b68bc42b295e8a3b48376db34405adb872
languageName: node
linkType: hard

Expand Down Expand Up @@ -4893,13 +4891,12 @@ __metadata:
languageName: node
linkType: hard

"cron-converter@npm:^1.0.2":
version: 1.0.2
resolution: "cron-converter@npm:1.0.2"
"cron-converter@npm:^2.0.1":
version: 2.0.1
resolution: "cron-converter@npm:2.0.1"
dependencies:
moment-timezone: ~0.5
sprintf-js: ~1
checksum: 7bbd01f29a6fc5a8a8c8dabda3a6468b7040acd374beadbf103d6c86f9e85c961a0937cfa2a997e4bfcdcd6bd07cde658a3009b899130e69e6c9ceb5f0a82ac3
luxon: ^3.1.0
checksum: 74ef69ec7e9020183cfa8f117fe687c654ba32f863ae8cf86a834b5baafd1321ee0d9caa62cc8e6e4cfe02b255f237ed0a0f91f0da78d01eb49317d06bf76f3d
languageName: node
linkType: hard

Expand Down Expand Up @@ -8364,6 +8361,13 @@ __metadata:
languageName: node
linkType: hard

"luxon@npm:^3.1.0":
version: 3.4.4
resolution: "luxon@npm:3.4.4"
checksum: 36c1f99c4796ee4bfddf7dc94fa87815add43ebc44c8934c924946260a58512f0fd2743a629302885df7f35ccbd2d13f178c15df046d0e3b6eb71db178f1c60c
languageName: node
linkType: hard

"luxon@npm:~3.3.0":
version: 3.3.0
resolution: "luxon@npm:3.3.0"
Expand Down Expand Up @@ -8719,7 +8723,7 @@ __metadata:
languageName: node
linkType: hard

"moment-timezone@npm:^0.5.35, moment-timezone@npm:~0.5":
"moment-timezone@npm:^0.5.35":
version: 0.5.43
resolution: "moment-timezone@npm:0.5.43"
dependencies:
Expand Down Expand Up @@ -10614,13 +10618,6 @@ __metadata:
languageName: node
linkType: hard

"sprintf-js@npm:~1":
version: 1.1.3
resolution: "sprintf-js@npm:1.1.3"
checksum: a3fdac7b49643875b70864a9d9b469d87a40dfeaf5d34d9d0c5b1cda5fd7d065531fcb43c76357d62254c57184a7b151954156563a4d6a747015cfb41021cad0
languageName: node
linkType: hard

"sprintf-js@npm:~1.0.2":
version: 1.0.3
resolution: "sprintf-js@npm:1.0.3"
Expand Down
Loading