Skip to content

Commit

Permalink
Fix bigint and decimal transformers not added for null type entity fi…
Browse files Browse the repository at this point in the history
…eld in codegen
  • Loading branch information
nikugogoi committed Nov 6, 2023
1 parent 8a720ef commit 1f7961d
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 72 deletions.
1 change: 1 addition & 0 deletions packages/cli/src/job-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export class JobRunnerCmd {

const jobRunner = new JobRunner(config.jobQueue, indexer, jobQueue);

// Delete all active and pending (before completed) jobs to start job-runner without old queued jobs
await jobRunner.jobQueue.deleteAllJobs('completed');
await jobRunner.resetToPrevIndexedBlock();

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ export class ServerCmd {
assert(eventWatcher);

if (config.server.kind === KIND_ACTIVE) {
// Delete jobs before completed state to prevent creating jobs after completion of processing previous block.
// Delete all active and pending (before completed) jobs to prevent creating jobs after completion of processing previous block
await jobQueue.deleteAllJobs('completed');
await eventWatcher.start();
}
Expand Down
140 changes: 70 additions & 70 deletions packages/codegen/src/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,45 +347,46 @@ export class Entity {
});

entityObject.columns.forEach((column: any) => {
// Implement bigintTransformer for bigint type.
if (column.tsType === 'bigint') {
column.columnOptions.push(
{
option: 'transformer',
value: 'bigintTransformer'
}
);

if (importObject) {
importObject.toImport.add('bigintTransformer');
} else {
importObject = {
toImport: new Set(['bigintTransformer']),
from: '@cerc-io/util'
};
if (column.tsType.includes('bigint')) {
// Check if it is of array type
if (column.tsType.includes('bigint[]')) {
// Implement bigintArrayTransformer for array of bigint type.
column.columnOptions.push(
{
option: 'transformer',
value: 'bigintArrayTransformer'
}
);

entityObject.imports.push(importObject);
}
}
if (importObject) {
importObject.toImport.add('bigintArrayTransformer');
} else {
importObject = {
toImport: new Set(['bigintArrayTransformer']),
from: '@cerc-io/util'
};

// Implement bigintArrayTransformer for array of bigint type.
if (column.tsType === 'bigint[]') {
column.columnOptions.push(
{
option: 'transformer',
value: 'bigintArrayTransformer'
entityObject.imports.push(importObject);
}
);

if (importObject) {
importObject.toImport.add('bigintArrayTransformer');
} else {
importObject = {
toImport: new Set(['bigintArrayTransformer']),
from: '@cerc-io/util'
};
// Implement bigintTransformer for bigint type.
column.columnOptions.push(
{
option: 'transformer',
value: 'bigintTransformer'
}
);

if (importObject) {
importObject.toImport.add('bigintTransformer');
} else {
importObject = {
toImport: new Set(['bigintTransformer']),
from: '@cerc-io/util'
};

entityObject.imports.push(importObject);
entityObject.imports.push(importObject);
}
}
}
});
Expand All @@ -399,49 +400,48 @@ export class Entity {
let isDecimalRequired = false;

entityObject.columns.forEach((column: any) => {
// Implement decimalTransformer for Decimal type.
if (column.tsType === 'Decimal') {
if (column.tsType.includes('Decimal')) {
isDecimalRequired = true;

column.columnOptions.push(
{
option: 'transformer',
value: 'decimalTransformer'
}
);

if (importObject) {
importObject.toImport.add('decimalTransformer');
} else {
importObject = {
toImport: new Set(['decimalTransformer']),
from: '@cerc-io/util'
};
// Check if it is of array type
if (column.tsType.includes('Decimal[]')) {
// Implement decimalArrayTransformer for array of Decimal type.
column.columnOptions.push(
{
option: 'transformer',
value: 'decimalArrayTransformer'
}
);

entityObject.imports.push(importObject);
}
}
if (importObject) {
importObject.toImport.add('decimalArrayTransformer');
} else {
importObject = {
toImport: new Set(['decimalArrayTransformer']),
from: '@cerc-io/util'
};

// Implement decimalArrayTransformer for array of Decimal type.
if (column.tsType === 'Decimal[]') {
isDecimalRequired = true;

column.columnOptions.push(
{
option: 'transformer',
value: 'decimalArrayTransformer'
entityObject.imports.push(importObject);
}
);

if (importObject) {
importObject.toImport.add('decimalArrayTransformer');
} else {
importObject = {
toImport: new Set(['decimalArrayTransformer']),
from: '@cerc-io/util'
};
// Implement decimalTransformer for Decimal type.
column.columnOptions.push(
{
option: 'transformer',
value: 'decimalTransformer'
}
);

entityObject.imports.push(importObject);
if (importObject) {
importObject.toImport.add('decimalTransformer');
} else {
importObject = {
toImport: new Set(['decimalTransformer']),
from: '@cerc-io/util'
};

entityObject.imports.push(importObject);
}
}
}
});
Expand Down
8 changes: 8 additions & 0 deletions packages/codegen/src/templates/indexer-template.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,14 @@ export class Indexer implements IndexerInterface {
return this._baseIndexer.fetchEventsAndSaveBlocks(blocks, this._eventSignaturesMap, this.parseEventNameAndArgs.bind(this));
}

async fetchAndSaveFilteredEventsAndBlocks (startBlock: number, endBlock: number): Promise<{ blockProgress: BlockProgress, events: DeepPartial<Event>[] }[]> {
return this._baseIndexer.fetchAndSaveFilteredEventsAndBlocks(startBlock, endBlock, this._eventSignaturesMap, this.parseEventNameAndArgs.bind(this));
}

async fetchEventsForContracts (blockHash: string, blockNumber: number, addresses: string[]): Promise<DeepPartial<Event>[]> {
return this._baseIndexer.fetchEventsForContracts(blockHash, blockNumber, addresses, this._eventSignaturesMap, this.parseEventNameAndArgs.bind(this));
}

async saveBlockAndFetchEvents (block: DeepPartial<BlockProgress>): Promise<[BlockProgress, DeepPartial<Event>[]]> {
return this._saveBlockAndFetchEvents(block);
}
Expand Down
1 change: 0 additions & 1 deletion packages/util/src/job-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ export class JobRunner {
} else {
// Check that startBlock is one greater than previous batch end block
if (startBlock - 1 !== this._historicalProcessingCompletedUpto) {
// TODO: Debug jobQueue deleteJobs for historical processing not working
await this.jobQueue.markComplete(
job,
{ isComplete: false }
Expand Down
1 change: 1 addition & 0 deletions packages/util/src/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export const resetJobs = async (config: Config): Promise<void> => {

const jobQueue = new JobQueue({ dbConnectionString, maxCompletionLag: maxCompletionLagInSecs });
await jobQueue.start();
// Delete all active and pending (before completed) jobs
await jobQueue.deleteAllJobs('completed');
};

Expand Down

0 comments on commit 1f7961d

Please sign in to comment.