Skip to content

Commit

Permalink
initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
maartyman committed Dec 16, 2023
1 parent 2af1c24 commit 414c9dd
Show file tree
Hide file tree
Showing 33 changed files with 433 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/aggregator-services/aggregatorService.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { CostParameters } from '../cost-queue/CostQueue';
export interface AggregatorService {
get description(): string;
initialize: () => Promise<void>;
test: (operation: Operation) => Promise<OperationTestResult>;
run: (operation: Operation) => Promise<OperationResult | undefined>;
}
export interface OperationTestResult {
aggregatorService: AggregatorService;
operation: Operation;
runnable: boolean;
operationResult?: OperationResult;
costParameters?: CostParameters;
}
export interface OperationResult {
aggregatorService: AggregatorService;
operation: Operation;
resultLocation: string;
}
export interface Operation {
id: string;
operation: string;
sources: string[];
}
3 changes: 3 additions & 0 deletions lib/aggregator-services/aggregatorService.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/aggregator-services/aggregatorService.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions lib/aggregator-services/aggregatorService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type { CostParameters } from '../cost-queue/CostQueue';

export interface AggregatorService {
get description(): string;
initialize: () => Promise<void>;
test: (operation: Operation) => Promise<OperationTestResult>;
run: (operation: Operation) => Promise<OperationResult | undefined>;
}

export interface OperationTestResult {
aggregatorService: AggregatorService;
operation: Operation;
runnable: boolean;
operationResult?: OperationResult;
costParameters?: CostParameters;
}

export interface OperationResult {
aggregatorService: AggregatorService;
operation: Operation;
resultLocation: string;
}

export interface Operation {
id: string;
operation: string;
sources: string[];
}
7 changes: 7 additions & 0 deletions lib/aggregator-services/aggregatorServiceSparql.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { AggregatorService, Operation, OperationResult, OperationTestResult } from './aggregatorService';
export declare class AggregatorServiceSPARQL implements AggregatorService {
initialize(): Promise<void>;
test(operation: Operation): Promise<OperationTestResult>;
run(operation: Operation): Promise<OperationResult>;
get description(): string;
}
27 changes: 27 additions & 0 deletions lib/aggregator-services/aggregatorServiceSparql.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/aggregator-services/aggregatorServiceSparql.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions lib/aggregator-services/aggregatorServiceSparql.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { AggregatorService, Operation, OperationResult, OperationTestResult } from './aggregatorService';

export class AggregatorServiceSPARQL implements AggregatorService {
public async initialize(): Promise<void> {
return undefined;
}

public async test(operation: Operation): Promise<OperationTestResult> {
return {
aggregatorService: this,
operation,
runnable: false,
};
}

public async run(operation: Operation): Promise<OperationResult> {
return {
aggregatorService: this,
operation,
resultLocation: '',
};
}

public get description(): string {
return 'SPARQL';
}
}
12 changes: 12 additions & 0 deletions lib/cost-queue/CostQueue.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { OperationTestResult } from '../aggregator-services/aggregatorService';
export interface CostQueueFactory {
create: () => CostQueue;
}
export interface CostQueue {
length: number;
push: (aggregatorService: OperationTestResult) => void;
pop: () => OperationTestResult | undefined;
}
export type CostParameters = {
timeSeconds: number;
};
3 changes: 3 additions & 0 deletions lib/cost-queue/CostQueue.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/cost-queue/CostQueue.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions lib/cost-queue/CostQueue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { OperationTestResult } from '../aggregator-services/aggregatorService';

export interface CostQueueFactory {
create: () => CostQueue;
}

export interface CostQueue {
length: number;
push: (aggregatorService: OperationTestResult) => void;
pop: () => OperationTestResult | undefined;
}

export type CostParameters = {
timeSeconds: number;
};
4 changes: 4 additions & 0 deletions lib/cost-queue/CostQueueTime.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import type { CostQueue, CostQueueFactory } from './CostQueue';
export declare class CostQueueTimeFactory implements CostQueueFactory {
create(): CostQueue;
}
41 changes: 41 additions & 0 deletions lib/cost-queue/CostQueueTime.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/cost-queue/CostQueueTime.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions lib/cost-queue/CostQueueTime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import TinyQueue from 'tinyqueue';
import type { OperationTestResult } from '../aggregator-services/aggregatorService';
import type { CostQueue, CostQueueFactory } from './CostQueue';

export class CostQueueTimeFactory implements CostQueueFactory {
public create(): CostQueue {
return new CostQueueTime();
}
}

class CostQueueTime implements CostQueue {
private readonly priorityQueue: TinyQueue<OperationTestResult>;

public get length(): number {
return this.priorityQueue.length;
}

public constructor() {
this.priorityQueue = new TinyQueue([], compare);
}

public push(aggregatorService: OperationTestResult): void {
this.priorityQueue.push(aggregatorService);
}

public pop(): OperationTestResult | undefined {
return this.priorityQueue.pop();
}
}

function compare(a: OperationTestResult, b: OperationTestResult): number {
if (a.costParameters === undefined) {
if (b.costParameters === undefined) {
return 0;
}
return -1;
}
if (b.costParameters === undefined) {
return 1;
}
return a.costParameters.timeSeconds - b.costParameters.timeSeconds;
}
5 changes: 5 additions & 0 deletions lib/endpoint/endpoint.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export declare class Endpoint {
private readonly httpServer;
constructor();
run(): void;
}
15 changes: 15 additions & 0 deletions lib/endpoint/endpoint.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/endpoint/endpoint.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions lib/endpoint/endpoint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { Server } from 'node:http';
import { createServer } from 'node:http';

export class Endpoint {
private readonly httpServer: Server;
public constructor() {
this.httpServer = createServer();
}

public run(): void {
this.httpServer.listen(8080);
}
}
7 changes: 7 additions & 0 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export * from './endpoint/endpoint';
export * from './aggregator-services/aggregatorService';
export * from './aggregator-services/aggregatorServiceSparql';
export * from './cost-queue/CostQueue';
export * from './cost-queue/CostQueueTime';
export * from './operation-registry/aggregatorServiceRegistry';
export * from './operation-registry/aggregatorServiceRegistryHardcodedTestOnly';
24 changes: 24 additions & 0 deletions lib/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export * from './endpoint/endpoint';

export * from './aggregator-services/aggregatorService';
export * from './aggregator-services/aggregatorServiceSparql';

export * from './cost-queue/CostQueue';
export * from './cost-queue/CostQueueTime';

export * from './operation-registry/aggregatorServiceRegistry';
export * from './operation-registry/aggregatorServiceRegistryHardcodedTestOnly';
5 changes: 5 additions & 0 deletions lib/operation-registry/aggregatorServiceRegistry.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { Operation, OperationResult } from '../aggregator-services/aggregatorService';
export interface AggregatorServiceRegistry {
initializeServices: () => Promise<void>;
run: (operation: Operation) => Promise<OperationResult | undefined>;
}
3 changes: 3 additions & 0 deletions lib/operation-registry/aggregatorServiceRegistry.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/operation-registry/aggregatorServiceRegistry.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions lib/operation-registry/aggregatorServiceRegistry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { Operation, OperationResult } from '../aggregator-services/aggregatorService';

export interface AggregatorServiceRegistry {
initializeServices: () => Promise<void>;
run: (operation: Operation) => Promise<OperationResult | undefined>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { AggregatorService, Operation, OperationResult } from '../aggregator-services/aggregatorService';
import type { CostQueueFactory } from '../cost-queue/CostQueue';
import type { AggregatorServiceRegistry } from './aggregatorServiceRegistry';
export declare class AggregatorServiceRegistryHardcodedTestOnly implements AggregatorServiceRegistry {
readonly costQueueFactory: CostQueueFactory;
readonly aggregatorServices: AggregatorService[];
constructor(aggregatorServices: AggregatorService[], costQueueFactory: CostQueueFactory);
initializeServices(): Promise<void>;
run(operation: Operation): Promise<OperationResult | undefined>;
}
Loading

0 comments on commit 414c9dd

Please sign in to comment.