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

refactor: Move Context object to new class #929

Merged
merged 17 commits into from
Aug 9, 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ redis/
node_modules/
.vscode/
runner/yarn.lock
**/.DS_Store

3 changes: 0 additions & 3 deletions core-indexers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
},
"author": "",
"license": "ISC",
"dependencies": {
"queryapi-runner": "file:../runner"
},
"devDependencies": {
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.7.0",
Expand Down
42 changes: 40 additions & 2 deletions core-indexers/receiver-blocks/unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'fs';
import LocalIndexer from 'queryapi-runner/src/local-indexer';
import LocalIndexer from 'queryapi-runner/src/indexer/local-indexer';
import { LocalIndexerConfig } from 'queryapi-runner/src/indexer-config/indexer-config';
import { LogLevel } from 'queryapi-runner/src/indexer-meta/log-entry';
import path from 'path';
Expand All @@ -15,6 +15,44 @@ describe('Receiver Blocks Indexer Tests', () => {

test('Try executing on a block', async () => {
const localIndexer = new LocalIndexer(indexerConfig);
await localIndexer.executeOnBlock(123621232);
const context = localIndexer.getContext();

// Run on one block to populate receivers table and initial bitmap
await localIndexer.executeOnBlock(100000000);
const receivers = await context.db.Receivers.select({
receiver: 'app.nearcrowd.near'
});
const tokenSweatId = receivers[0].id;

const correctBitmapOne = {
first_block_height: 100000000,
block_date: '2023-08-30',
receiver_id: tokenSweatId,
bitmap: 'wA==',
last_elias_gamma_start_bit: 1,
max_index: 0,
};
const correctBitmapTwo = {
first_block_height: 100000000,
block_date: '2023-08-30',
receiver_id: tokenSweatId,
bitmap: 'oA==',
last_elias_gamma_start_bit: 1,
max_index: 1,
};

let bitmap = await context.db.Bitmaps.select({
receiver_id: tokenSweatId
});
expect(bitmap.length).toBe(1);
expect(bitmap[0]).toEqual(correctBitmapOne);

// Run on second block and verify bitmap update
await localIndexer.executeOnBlock(100000001);
bitmap = await context.db.Bitmaps.select({
receiver_id: tokenSweatId
});
expect(bitmap.length).toBe(1);
expect(bitmap[0]).toEqual(correctBitmapTwo);
});
});
5 changes: 4 additions & 1 deletion core-indexers/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
"target": "es2018", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
"lib": ["es2021"], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
"module": "commonjs", /* Specify what module code is generated. */
"rootDir": "..",
"rootDir": "..",
"paths": {
"@queryapi-runner/*": ["../runner/*"], /* Allow imports from runner using queryapi-runner alias */
},
"moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
"resolveJsonModule": true, /* Enable importing .json files. */
"allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
Expand Down
Binary file removed runner/.DS_Store
Binary file not shown.
1 change: 0 additions & 1 deletion runner/src/dml-handler/index.ts

This file was deleted.

1 change: 1 addition & 0 deletions runner/src/indexer-config/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { default } from './indexer-config';
export { ProvisioningConfig, LocalIndexerConfig } from './indexer-config';
72 changes: 0 additions & 72 deletions runner/src/indexer/__snapshots__/indexer.test.ts.snap

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`ContextBuilder unit tests Context object social api can fetch from the near social api 1`] = `
[
[
"https://api.near.social/index",
{
"body": "{"action":"post","key":"main","options":{"limit":1,"order":"desc"}}",
"headers": {
"Content-Type": "application/json",
},
"method": "POST",
},
],
]
`;

exports[`ContextBuilder unit tests ContextBuilder adds CRUD operations for table 1`] = `
{
"delete": [Function],
"insert": [Function],
"select": [Function],
"update": [Function],
"upsert": [Function],
}
`;

exports[`ContextBuilder unit tests ContextBuilder can parse various schemas 1`] = `
{
"Posts": {
"delete": [Function],
"insert": [Function],
"select": [Function],
"update": [Function],
"upsert": [Function],
},
}
`;

exports[`ContextBuilder unit tests ContextBuilder can parse various schemas 2`] = `
{
"Comments": {
"delete": [Function],
"insert": [Function],
"select": [Function],
"update": [Function],
"upsert": [Function],
},
"PostLikes": {
"delete": [Function],
"insert": [Function],
"select": [Function],
"update": [Function],
"upsert": [Function],
},
"Posts": {
"delete": [Function],
"insert": [Function],
"select": [Function],
"update": [Function],
"upsert": [Function],
},
}
`;

exports[`ContextBuilder unit tests ContextBuilder can parse various schemas 3`] = `
{
"CommentsTable": {
"delete": [Function],
"insert": [Function],
"select": [Function],
"update": [Function],
"upsert": [Function],
},
"Posts": {
"delete": [Function],
"insert": [Function],
"select": [Function],
"update": [Function],
"upsert": [Function],
},
}
`;

exports[`ContextBuilder unit tests ContextBuilder can parse various schemas 4`] = `
{
"AnotherTable": {
"delete": [Function],
"insert": [Function],
"select": [Function],
"update": [Function],
"upsert": [Function],
},
"Comments": {
"delete": [Function],
"insert": [Function],
"select": [Function],
"update": [Function],
"upsert": [Function],
},
"ComposerQuest": {
"delete": [Function],
"insert": [Function],
"select": [Function],
"update": [Function],
"upsert": [Function],
},
"ContractorQuest": {
"delete": [Function],
"insert": [Function],
"select": [Function],
"update": [Function],
"upsert": [Function],
},
"CreatorQuest": {
"delete": [Function],
"insert": [Function],
"select": [Function],
"update": [Function],
"upsert": [Function],
},
"MyTable1": {
"delete": [Function],
"insert": [Function],
"select": [Function],
"update": [Function],
"upsert": [Function],
},
"PostLikes": {
"delete": [Function],
"insert": [Function],
"select": [Function],
"update": [Function],
"upsert": [Function],
},
"Posts": {
"delete": [Function],
"insert": [Function],
"select": [Function],
"update": [Function],
"upsert": [Function],
},
"ThirdTable": {
"delete": [Function],
"insert": [Function],
"select": [Function],
"update": [Function],
"upsert": [Function],
},
"YetAnotherTable": {
"delete": [Function],
"insert": [Function],
"select": [Function],
"update": [Function],
"upsert": [Function],
},
}
`;
Loading
Loading