diff --git a/runner/src/context/__snapshots__/context.test.ts.snap b/runner/src/context-builder/__snapshots__/context-builder.test.ts.snap similarity index 100% rename from runner/src/context/__snapshots__/context.test.ts.snap rename to runner/src/context-builder/__snapshots__/context-builder.test.ts.snap diff --git a/runner/src/context-builder/__snapshots__/context.test.ts.snap b/runner/src/context-builder/__snapshots__/context.test.ts.snap new file mode 100644 index 00000000..05235ed9 --- /dev/null +++ b/runner/src/context-builder/__snapshots__/context.test.ts.snap @@ -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], + }, +} +`; diff --git a/runner/src/context/context.test.ts b/runner/src/context-builder/context-builder.test.ts similarity index 99% rename from runner/src/context/context.test.ts rename to runner/src/context-builder/context-builder.test.ts index 786a5cb9..8a55b13c 100644 --- a/runner/src/context/context.test.ts +++ b/runner/src/context-builder/context-builder.test.ts @@ -3,7 +3,7 @@ import type fetch from 'node-fetch'; import type DmlHandler from '../dml-handler'; import IndexerConfig from '../indexer-config'; import { LogLevel } from '../indexer-meta/log-entry'; -import ContextBuilder from './context'; +import ContextBuilder from './context-builder'; describe('ContextBuilder unit tests', () => { const MOCK_CONFIG = { diff --git a/runner/src/context/context.ts b/runner/src/context-builder/context-builder.ts similarity index 100% rename from runner/src/context/context.ts rename to runner/src/context-builder/context-builder.ts diff --git a/runner/src/context-builder/index.ts b/runner/src/context-builder/index.ts new file mode 100644 index 00000000..c3486cba --- /dev/null +++ b/runner/src/context-builder/index.ts @@ -0,0 +1,2 @@ +export { default } from './context-builder'; +export type { ContextObject } from './context-builder'; diff --git a/runner/src/context/index.ts b/runner/src/context/index.ts deleted file mode 100644 index b931cee5..00000000 --- a/runner/src/context/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { default } from './context'; -export type { ContextObject } from './context'; diff --git a/runner/src/indexer/indexer.test.ts b/runner/src/indexer/indexer.test.ts index be57a3d7..e104f9de 100644 --- a/runner/src/indexer/indexer.test.ts +++ b/runner/src/indexer/indexer.test.ts @@ -7,8 +7,8 @@ import { LogLevel } from '../indexer-meta/log-entry'; import IndexerConfig from '../indexer-config/indexer-config'; import { IndexerStatus } from '../indexer-meta'; import type IndexerMeta from '../indexer-meta'; -import ContextBuilder from '../context'; -import { type ContextObject } from '../context'; +import ContextBuilder from '../context-builder'; +import { type ContextObject } from '../context-builder'; describe('Indexer unit tests', () => { const SIMPLE_REDIS_STREAM = 'test:stream'; diff --git a/runner/src/indexer/indexer.ts b/runner/src/indexer/indexer.ts index 71859ed0..b7e60102 100644 --- a/runner/src/indexer/indexer.ts +++ b/runner/src/indexer/indexer.ts @@ -9,7 +9,7 @@ import LogEntry from '../indexer-meta/log-entry'; import type IndexerConfig from '../indexer-config'; import { IndexerStatus } from '../indexer-meta'; import { type IndexerMetaInterface } from '../indexer-meta/indexer-meta'; -import type ContextBuilder from '../context'; +import type ContextBuilder from '../context-builder'; interface Dependencies { contextBuilder: ContextBuilder @@ -28,7 +28,7 @@ export default class Indexer { tracer = trace.getTracer('queryapi-runner-indexer'); private readonly logger: typeof logger; - private readonly deps: Required; + readonly deps: Required; private currentStatus?: string; constructor ( diff --git a/runner/src/local-indexer/local-indexer.ts b/runner/src/local-indexer/local-indexer.ts index d84dfeba..56b1ac7b 100644 --- a/runner/src/local-indexer/local-indexer.ts +++ b/runner/src/local-indexer/local-indexer.ts @@ -1,3 +1,4 @@ +import ContextBuilder from '../context-builder'; import InMemoryDmlHandler from '../dml-handler/in-memory-dml-handler'; import IndexerConfig from '../indexer-config'; import { type LocalIndexerConfig } from '../indexer-config/indexer-config'; @@ -20,8 +21,9 @@ export default class LocalIndexer { logLevel: config.logLevel, }); const dmlHandler = new InMemoryDmlHandler(config.schema); + const contextBuilder = new ContextBuilder(fullIndexerConfig, { dmlHandler }); const indexerMeta = new NoOpIndexerMeta(config); - this.indexer = new Indexer(fullIndexerConfig, { indexerMeta, dmlHandler }); + this.indexer = new Indexer(fullIndexerConfig, { indexerMeta, contextBuilder }); this.lakeClient = new LakeClient(); } diff --git a/runner/src/stream-handler/worker.ts b/runner/src/stream-handler/worker.ts index c25f2849..cbd241b1 100644 --- a/runner/src/stream-handler/worker.ts +++ b/runner/src/stream-handler/worker.ts @@ -15,7 +15,7 @@ import parentLogger from '../logger'; import { wrapSpan } from '../utility'; import { type PostgresConnectionParams } from '../pg-client'; import DmlHandler from '../dml-handler/dml-handler'; -import ContextBuilder from '../context'; +import ContextBuilder from '../context-builder'; if (isMainThread) { throw new Error('Worker should not be run on main thread'); diff --git a/runner/tests/integration.test.ts b/runner/tests/integration.test.ts index a3aa4925..0790571f 100644 --- a/runner/tests/integration.test.ts +++ b/runner/tests/integration.test.ts @@ -15,7 +15,7 @@ import { LogLevel } from '../src/indexer-meta/log-entry'; import IndexerConfig from '../src/indexer-config'; import IndexerMeta from '../src/indexer-meta/indexer-meta'; import DmlHandler from '../src/dml-handler/dml-handler'; -import ContextBuilder from '../src/context'; +import ContextBuilder from '../src/context-builder'; describe('Indexer integration', () => { jest.setTimeout(300_000);