Skip to content
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
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@subsquid/cli",
"description": "squid cli tool",
"version": "2.9.2",
"version": "2.10.0",
"license": "GPL-3.0-or-later",
"repository": "git@github.com:subsquid/squid-cli.git",
"publishConfig": {
Expand Down Expand Up @@ -51,7 +51,7 @@
"tsc": "tsc --noEmit",
"pkg:build": "./bin/pkg-build.sh",
"pkg:compress": "./bin/pkg-compress.sh",
"upg": "npx npm-check-updates -u -i"
"upg": "yarn upgrade-interactive"
},
"jest": {
"moduleFileExtensions": [
Expand Down Expand Up @@ -132,5 +132,6 @@
"prettier": "^3.2.5",
"ts-jest": "^29.1.2",
"typescript": "~5.3.3"
}
},
"packageManager": "yarn@4.1.1"
}
34 changes: 34 additions & 0 deletions src/api/gateways.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { api } from './api';

export type Provider = {
provider: string;
dataSourceUrl: string;
release: string;
};

export type Gateway = {
network: string;
providers: Provider[];
};

export type GatewaysResponse = {
archives: Gateway[];
};

export async function getSubstrateGateways() {
const { body } = await api<GatewaysResponse>({
method: 'get',
path: 'https://cdn.subsquid.io/archives/substrate.json',
});

return body.archives;
}

export async function getEvmGateways() {
const { body } = await api<GatewaysResponse>({
method: 'get',
path: 'https://cdn.subsquid.io/archives/evm.json',
});

return body.archives;
}
5 changes: 3 additions & 2 deletions src/api/squids.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export async function versionHistoryLogs({
orderBy?: string;
container?: string[];
level?: string[];
search?: string;
};
abortController?: AbortController;
}): Promise<LogsResponse> {
Expand Down Expand Up @@ -97,7 +98,7 @@ export async function versionLogsFollow({
orgCode: string;
squidName: string;
versionName: string;
query: { container?: string[]; level?: string[] };
query: { container?: string[]; level?: string[]; search?: string };
abortController?: AbortController;
}) {
const { body } = await api<NodeJS.ReadableStream>({
Expand All @@ -123,7 +124,7 @@ export async function streamSquidLogs({
squidName: string;
versionName: string;
onLog: (log: string) => unknown;
query?: { container?: string[]; level?: string[] };
query?: { container?: string[]; level?: string[]; search?: string };
abortController?: AbortController;
}) {
let attempt = 0;
Expand Down
36 changes: 27 additions & 9 deletions src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ function hasLockFile(squidDir: string, lockFile?: string) {
}
}

function createSquidIgnore(squidDir: string) {
export function createSquidIgnore(squidDir: string) {
const ig = ignore().add(
// default ignore patterns
['node_modules', '.git'],
Expand All @@ -296,16 +296,34 @@ function createSquidIgnore(squidDir: string) {
for (const ignoreFilePath of ignoreFilePaths) {
const ignoreDir = path.dirname(ignoreFilePath);

const patterns = fs.readFileSync(ignoreFilePath).toString().split('\n');
for (const pattern of patterns) {
if (pattern.length === 0 || pattern.startsWith('#')) continue;
const raw = fs.readFileSync(ignoreFilePath).toString();
const patterns = getIgnorePatterns(ignoreDir, raw);

let fullPattern = pattern.startsWith('/') ? pattern : `**/${pattern}`;
fullPattern = ignoreDir === '.' ? fullPattern : `/${ignoreDir}/${fullPattern}`;

ig.add(fullPattern);
}
ig.add(patterns);
}

return ig;
}

export function getIgnorePatterns(ignoreDir: string, raw: string) {
const lines = raw.split('\n');

const patterns: string[] = [];
for (let line of lines) {
line = line.trim();

if (line.length === 0) continue;
if (line.startsWith('#')) continue;

let pattern = line.startsWith('/') || line.startsWith('*/') || line.startsWith('**/') ? line : `**/${line}`;
pattern = ignoreDir === '.' ? pattern : `${toRootPattern(ignoreDir)}${toRootPattern(pattern)}`;

patterns.push(pattern);
}

return patterns;
}

function toRootPattern(pattern: string) {
return pattern.startsWith('/') ? pattern : `/${pattern}`;
}
28 changes: 28 additions & 0 deletions src/commands/deploy.unit.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { getIgnorePatterns } from './deploy';

describe('Deploy', () => {
describe('get squid ignore paths', () => {
const squidignore = [
'/.git',
'/builds',
'#comment',
' /abi ',
'test',
' ',
'.env',
'',
'# another comment',
'**/foo',
].join('\n');

it('root', () => {
const patterns = getIgnorePatterns('.', squidignore);
expect(patterns).toEqual(['/.git', '/builds', '/abi', '**/test', '**/.env', '**/foo']);
});

it('dir', () => {
const patterns = getIgnorePatterns('dir', squidignore);
expect(patterns).toEqual(['/dir/.git', '/dir/builds', '/dir/abi', '/dir/**/test', '/dir/**/.env', '/dir/**/foo']);
});
});
});
88 changes: 88 additions & 0 deletions src/commands/gateways/ls.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { Flags } from '@oclif/core';
import chalk from 'chalk';
import Table from 'cli-table3';
import { maxBy } from 'lodash';

import { Gateway, getEvmGateways, getSubstrateGateways } from '../../api/gateways';
import { CliCommand } from '../../command';

export default class Ls extends CliCommand {
static description = 'List available gateways';

static flags = {
type: Flags.string({
char: 't',
description: 'Filter gateways by network type',
options: ['evm', 'substrate'],
helpValue: '<evm|substrate>',
required: false,
}),
search: Flags.string({
char: 's',
description: 'Search gateways',
required: false,
}),
};

async run(): Promise<void> {
const {
flags: { type, search },
} = await this.parse(Ls);

const [evm, substrate] = await Promise.all([
!type || type === 'evm' ? getEvmGateways() : [],
!type || type === 'substrate' ? getSubstrateGateways() : [],
]);

const maxNameLength = maxBy([...evm, ...substrate], (g) => g.network.length)?.network.length;

switch (type) {
case 'evm':
this.processGateways(evm, { search, summary: 'EVM', maxNameLength });
break;
case 'substrate':
this.processGateways(substrate, { search, summary: 'Substrate', maxNameLength });
break;
default:
this.processGateways(evm, { search, summary: 'EVM', maxNameLength });
this.log();
this.processGateways(substrate, { search, summary: 'Substrate', maxNameLength });
}
}

processGateways(
gateways: Gateway[],
{ summary, search, maxNameLength }: { search?: string; summary?: string; maxNameLength?: number },
) {
if (summary) {
this.log(chalk.bold(summary));
}

gateways = search
? gateways.filter((g) => g.network.toLocaleLowerCase().includes(search.toLocaleLowerCase()))
: gateways;

if (!gateways.length) {
return this.log('No gateways found');
}

const table = new Table({
wordWrap: true,
colWidths: [maxNameLength ? maxNameLength + 2 : null],
head: ['Name', 'Release', 'Gateway URL'],
wrapOnWordBoundary: false,

style: {
head: ['bold'],
border: ['gray'],
compact: true,
},
});

gateways.map(({ network, providers }) => {
table.push([network, chalk.dim(providers[0].release), providers[0].dataSourceUrl]);
});

this.log(table.toString());
}
}
69 changes: 45 additions & 24 deletions src/commands/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ export default class Logs extends CliCommand {
required: false,
default: '1d',
}),
search: Flags.string({
char: 's',
summary: 'Filter by content',
required: false,
}),
follow: Flags.boolean({
char: 'f',
summary: 'Follow',
Expand All @@ -73,7 +78,7 @@ export default class Logs extends CliCommand {

async run(): Promise<void> {
const {
flags: { follow, pageSize, container, level, since, org },
flags: { follow, pageSize, container, level, since, org, search },
args: { name },
} = await this.parse(Logs);

Expand All @@ -85,32 +90,44 @@ export default class Logs extends CliCommand {
this.log(`Fetching logs from ${fromDate.toISOString()}...`);

if (follow) {
await this.fetchLogs(orgCode, squidName, versionName, {
limit: 30,
from: fromDate,
await this.fetchLogs({
orgCode,
squidName,
versionName,
reverse: true,
container,
level,
query: {
limit: 30,
from: fromDate,
container,
level,
search,
},
});
await streamSquidLogs({
orgCode,
squidName,
versionName,
onLog: (l) => this.log(l),
query: { container, level },
query: { container, level, search },
});
debugLog(`done`);
return;
}

let cursor = undefined;
do {
const { hasLogs, nextPage }: LogResult = await this.fetchLogs(orgCode, squidName, versionName, {
limit: pageSize,
from: fromDate,
nextPage: cursor,
container,
level,
const { hasLogs, nextPage }: LogResult = await this.fetchLogs({
orgCode,
squidName,
versionName,
query: {
limit: pageSize,
from: fromDate,
nextPage: cursor,
container,
level,
search,
},
});
if (!hasLogs) {
this.log('No logs found');
Expand All @@ -128,23 +145,27 @@ export default class Logs extends CliCommand {
} while (cursor);
}

async fetchLogs(
orgCode: string,
squidName: string,
versionName: string,
{
reverse,
...query
}: {
async fetchLogs({
orgCode,
squidName,
query,
versionName,
reverse,
}: {
orgCode: string;
squidName: string;
versionName: string;
reverse?: boolean;
query: {
limit: number;
from: Date;
container?: string[];
nextPage?: string;
orderBy?: string;
reverse?: boolean;
level?: string[];
},
): Promise<LogResult> {
search?: string;
};
}): Promise<LogResult> {
// eslint-disable-next-line prefer-const
let { logs, nextPage } = await versionHistoryLogs({ orgCode, squidName, versionName, query });
if (reverse) {
Expand Down
Loading