diff --git a/lib/aggregator-services/aggregatorService.d.ts b/lib/aggregator-services/aggregatorService.d.ts new file mode 100644 index 0000000..73a0aa0 --- /dev/null +++ b/lib/aggregator-services/aggregatorService.d.ts @@ -0,0 +1,24 @@ +import type { CostParameters } from '../cost-queue/CostQueue'; +export interface AggregatorService { + get description(): string; + initialize: () => Promise; + test: (operation: Operation) => Promise; + run: (operation: Operation) => Promise; +} +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[]; +} diff --git a/lib/aggregator-services/aggregatorService.js b/lib/aggregator-services/aggregatorService.js new file mode 100644 index 0000000..94e5bf9 --- /dev/null +++ b/lib/aggregator-services/aggregatorService.js @@ -0,0 +1,3 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +//# sourceMappingURL=aggregatorService.js.map \ No newline at end of file diff --git a/lib/aggregator-services/aggregatorService.js.map b/lib/aggregator-services/aggregatorService.js.map new file mode 100644 index 0000000..e4a2ff3 --- /dev/null +++ b/lib/aggregator-services/aggregatorService.js.map @@ -0,0 +1 @@ +{"version":3,"file":"aggregatorService.js","sourceRoot":"","sources":["aggregatorService.ts"],"names":[],"mappings":"","sourcesContent":["import type { CostParameters } from '../cost-queue/CostQueue';\n\nexport interface AggregatorService {\n get description(): string;\n initialize: () => Promise;\n test: (operation: Operation) => Promise;\n run: (operation: Operation) => Promise;\n}\n\nexport interface OperationTestResult {\n aggregatorService: AggregatorService;\n operation: Operation;\n runnable: boolean;\n operationResult?: OperationResult;\n costParameters?: CostParameters;\n}\n\nexport interface OperationResult {\n aggregatorService: AggregatorService;\n operation: Operation;\n resultLocation: string;\n}\n\nexport interface Operation {\n id: string;\n operation: string;\n sources: string[];\n}\n"]} \ No newline at end of file diff --git a/lib/aggregator-services/aggregatorService.ts b/lib/aggregator-services/aggregatorService.ts new file mode 100644 index 0000000..6bd71dc --- /dev/null +++ b/lib/aggregator-services/aggregatorService.ts @@ -0,0 +1,28 @@ +import type { CostParameters } from '../cost-queue/CostQueue'; + +export interface AggregatorService { + get description(): string; + initialize: () => Promise; + test: (operation: Operation) => Promise; + run: (operation: Operation) => Promise; +} + +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[]; +} diff --git a/lib/aggregator-services/aggregatorServiceSparql.d.ts b/lib/aggregator-services/aggregatorServiceSparql.d.ts new file mode 100644 index 0000000..cce5761 --- /dev/null +++ b/lib/aggregator-services/aggregatorServiceSparql.d.ts @@ -0,0 +1,7 @@ +import type { AggregatorService, Operation, OperationResult, OperationTestResult } from './aggregatorService'; +export declare class AggregatorServiceSPARQL implements AggregatorService { + initialize(): Promise; + test(operation: Operation): Promise; + run(operation: Operation): Promise; + get description(): string; +} diff --git a/lib/aggregator-services/aggregatorServiceSparql.js b/lib/aggregator-services/aggregatorServiceSparql.js new file mode 100644 index 0000000..f5f964c --- /dev/null +++ b/lib/aggregator-services/aggregatorServiceSparql.js @@ -0,0 +1,27 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.AggregatorServiceSPARQL = void 0; +class AggregatorServiceSPARQL { + async initialize() { + return undefined; + } + async test(operation) { + return { + aggregatorService: this, + operation, + runnable: false, + }; + } + async run(operation) { + return { + aggregatorService: this, + operation, + resultLocation: '', + }; + } + get description() { + return 'SPARQL'; + } +} +exports.AggregatorServiceSPARQL = AggregatorServiceSPARQL; +//# sourceMappingURL=aggregatorServiceSparql.js.map \ No newline at end of file diff --git a/lib/aggregator-services/aggregatorServiceSparql.js.map b/lib/aggregator-services/aggregatorServiceSparql.js.map new file mode 100644 index 0000000..5b8c264 --- /dev/null +++ b/lib/aggregator-services/aggregatorServiceSparql.js.map @@ -0,0 +1 @@ +{"version":3,"file":"aggregatorServiceSparql.js","sourceRoot":"","sources":["aggregatorServiceSparql.ts"],"names":[],"mappings":";;;AAEA,MAAa,uBAAuB;IAC3B,KAAK,CAAC,UAAU;QACrB,OAAO,SAAS,CAAC;IACnB,CAAC;IAEM,KAAK,CAAC,IAAI,CAAC,SAAoB;QACpC,OAAO;YACL,iBAAiB,EAAE,IAAI;YACvB,SAAS;YACT,QAAQ,EAAE,KAAK;SAChB,CAAC;IACJ,CAAC;IAEM,KAAK,CAAC,GAAG,CAAC,SAAoB;QACnC,OAAO;YACL,iBAAiB,EAAE,IAAI;YACvB,SAAS;YACT,cAAc,EAAE,EAAE;SACnB,CAAC;IACJ,CAAC;IAED,IAAW,WAAW;QACpB,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF;AAxBD,0DAwBC","sourcesContent":["import type { AggregatorService, Operation, OperationResult, OperationTestResult } from './aggregatorService';\n\nexport class AggregatorServiceSPARQL implements AggregatorService {\n public async initialize(): Promise {\n return undefined;\n }\n\n public async test(operation: Operation): Promise {\n return {\n aggregatorService: this,\n operation,\n runnable: false,\n };\n }\n\n public async run(operation: Operation): Promise {\n return {\n aggregatorService: this,\n operation,\n resultLocation: '',\n };\n }\n\n public get description(): string {\n return 'SPARQL';\n }\n}\n"]} \ No newline at end of file diff --git a/lib/aggregator-services/aggregatorServiceSparql.ts b/lib/aggregator-services/aggregatorServiceSparql.ts new file mode 100644 index 0000000..d399216 --- /dev/null +++ b/lib/aggregator-services/aggregatorServiceSparql.ts @@ -0,0 +1,27 @@ +import type { AggregatorService, Operation, OperationResult, OperationTestResult } from './aggregatorService'; + +export class AggregatorServiceSPARQL implements AggregatorService { + public async initialize(): Promise { + return undefined; + } + + public async test(operation: Operation): Promise { + return { + aggregatorService: this, + operation, + runnable: false, + }; + } + + public async run(operation: Operation): Promise { + return { + aggregatorService: this, + operation, + resultLocation: '', + }; + } + + public get description(): string { + return 'SPARQL'; + } +} diff --git a/lib/cost-queue/CostQueue.d.ts b/lib/cost-queue/CostQueue.d.ts new file mode 100644 index 0000000..5aea1ee --- /dev/null +++ b/lib/cost-queue/CostQueue.d.ts @@ -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; +}; diff --git a/lib/cost-queue/CostQueue.js b/lib/cost-queue/CostQueue.js new file mode 100644 index 0000000..1b5d585 --- /dev/null +++ b/lib/cost-queue/CostQueue.js @@ -0,0 +1,3 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +//# sourceMappingURL=CostQueue.js.map \ No newline at end of file diff --git a/lib/cost-queue/CostQueue.js.map b/lib/cost-queue/CostQueue.js.map new file mode 100644 index 0000000..fcfc05c --- /dev/null +++ b/lib/cost-queue/CostQueue.js.map @@ -0,0 +1 @@ +{"version":3,"file":"CostQueue.js","sourceRoot":"","sources":["CostQueue.ts"],"names":[],"mappings":"","sourcesContent":["import type { OperationTestResult } from '../aggregator-services/aggregatorService';\n\nexport interface CostQueueFactory {\n create: () => CostQueue;\n}\n\nexport interface CostQueue {\n length: number;\n push: (aggregatorService: OperationTestResult) => void;\n pop: () => OperationTestResult | undefined;\n}\n\nexport type CostParameters = {\n timeSeconds: number;\n};\n"]} \ No newline at end of file diff --git a/lib/cost-queue/CostQueue.ts b/lib/cost-queue/CostQueue.ts new file mode 100644 index 0000000..50c5b79 --- /dev/null +++ b/lib/cost-queue/CostQueue.ts @@ -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; +}; diff --git a/lib/cost-queue/CostQueueTime.d.ts b/lib/cost-queue/CostQueueTime.d.ts new file mode 100644 index 0000000..b18dbdf --- /dev/null +++ b/lib/cost-queue/CostQueueTime.d.ts @@ -0,0 +1,4 @@ +import type { CostQueue, CostQueueFactory } from './CostQueue'; +export declare class CostQueueTimeFactory implements CostQueueFactory { + create(): CostQueue; +} diff --git a/lib/cost-queue/CostQueueTime.js b/lib/cost-queue/CostQueueTime.js new file mode 100644 index 0000000..72e1ded --- /dev/null +++ b/lib/cost-queue/CostQueueTime.js @@ -0,0 +1,41 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.CostQueueTimeFactory = void 0; +const tinyqueue_1 = __importDefault(require("tinyqueue")); +class CostQueueTimeFactory { + create() { + return new CostQueueTime(); + } +} +exports.CostQueueTimeFactory = CostQueueTimeFactory; +class CostQueueTime { + priorityQueue; + get length() { + return this.priorityQueue.length; + } + constructor() { + this.priorityQueue = new tinyqueue_1.default([], compare); + } + push(aggregatorService) { + this.priorityQueue.push(aggregatorService); + } + pop() { + return this.priorityQueue.pop(); + } +} +function compare(a, b) { + 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; +} +//# sourceMappingURL=CostQueueTime.js.map \ No newline at end of file diff --git a/lib/cost-queue/CostQueueTime.js.map b/lib/cost-queue/CostQueueTime.js.map new file mode 100644 index 0000000..28b106a --- /dev/null +++ b/lib/cost-queue/CostQueueTime.js.map @@ -0,0 +1 @@ +{"version":3,"file":"CostQueueTime.js","sourceRoot":"","sources":["CostQueueTime.ts"],"names":[],"mappings":";;;;;;AAAA,0DAAkC;AAIlC,MAAa,oBAAoB;IACxB,MAAM;QACX,OAAO,IAAI,aAAa,EAAE,CAAC;IAC7B,CAAC;CACF;AAJD,oDAIC;AAED,MAAM,aAAa;IACA,aAAa,CAAiC;IAE/D,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC;IACnC,CAAC;IAED;QACE,IAAI,CAAC,aAAa,GAAG,IAAI,mBAAS,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;IAClD,CAAC;IAEM,IAAI,CAAC,iBAAsC;QAChD,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;IAC7C,CAAC;IAEM,GAAG;QACR,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,EAAE,CAAC;IAClC,CAAC;CACF;AAED,SAAS,OAAO,CAAC,CAAsB,EAAE,CAAsB;IAC7D,IAAI,CAAC,CAAC,cAAc,KAAK,SAAS,EAAE;QAClC,IAAI,CAAC,CAAC,cAAc,KAAK,SAAS,EAAE;YAClC,OAAO,CAAC,CAAC;SACV;QACD,OAAO,CAAC,CAAC,CAAC;KACX;IACD,IAAI,CAAC,CAAC,cAAc,KAAK,SAAS,EAAE;QAClC,OAAO,CAAC,CAAC;KACV;IACD,OAAO,CAAC,CAAC,cAAc,CAAC,WAAW,GAAG,CAAC,CAAC,cAAc,CAAC,WAAW,CAAC;AACrE,CAAC","sourcesContent":["import TinyQueue from 'tinyqueue';\nimport type { OperationTestResult } from '../aggregator-services/aggregatorService';\nimport type { CostQueue, CostQueueFactory } from './CostQueue';\n\nexport class CostQueueTimeFactory implements CostQueueFactory {\n public create(): CostQueue {\n return new CostQueueTime();\n }\n}\n\nclass CostQueueTime implements CostQueue {\n private readonly priorityQueue: TinyQueue;\n\n public get length(): number {\n return this.priorityQueue.length;\n }\n\n public constructor() {\n this.priorityQueue = new TinyQueue([], compare);\n }\n\n public push(aggregatorService: OperationTestResult): void {\n this.priorityQueue.push(aggregatorService);\n }\n\n public pop(): OperationTestResult | undefined {\n return this.priorityQueue.pop();\n }\n}\n\nfunction compare(a: OperationTestResult, b: OperationTestResult): number {\n if (a.costParameters === undefined) {\n if (b.costParameters === undefined) {\n return 0;\n }\n return -1;\n }\n if (b.costParameters === undefined) {\n return 1;\n }\n return a.costParameters.timeSeconds - b.costParameters.timeSeconds;\n}\n"]} \ No newline at end of file diff --git a/lib/cost-queue/CostQueueTime.ts b/lib/cost-queue/CostQueueTime.ts new file mode 100644 index 0000000..124ffc0 --- /dev/null +++ b/lib/cost-queue/CostQueueTime.ts @@ -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; + + 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; +} diff --git a/lib/endpoint/endpoint.d.ts b/lib/endpoint/endpoint.d.ts new file mode 100644 index 0000000..836377e --- /dev/null +++ b/lib/endpoint/endpoint.d.ts @@ -0,0 +1,5 @@ +export declare class Endpoint { + private readonly httpServer; + constructor(); + run(): void; +} diff --git a/lib/endpoint/endpoint.js b/lib/endpoint/endpoint.js new file mode 100644 index 0000000..d6e1115 --- /dev/null +++ b/lib/endpoint/endpoint.js @@ -0,0 +1,15 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Endpoint = void 0; +const node_http_1 = require("node:http"); +class Endpoint { + httpServer; + constructor() { + this.httpServer = (0, node_http_1.createServer)(); + } + run() { + this.httpServer.listen(8080); + } +} +exports.Endpoint = Endpoint; +//# sourceMappingURL=endpoint.js.map \ No newline at end of file diff --git a/lib/endpoint/endpoint.js.map b/lib/endpoint/endpoint.js.map new file mode 100644 index 0000000..a781e0b --- /dev/null +++ b/lib/endpoint/endpoint.js.map @@ -0,0 +1 @@ +{"version":3,"file":"endpoint.js","sourceRoot":"","sources":["endpoint.ts"],"names":[],"mappings":";;;AACA,yCAAyC;AAEzC,MAAa,QAAQ;IACF,UAAU,CAAS;IACpC;QACE,IAAI,CAAC,UAAU,GAAG,IAAA,wBAAY,GAAE,CAAC;IACnC,CAAC;IAEM,GAAG;QACR,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;CACF;AATD,4BASC","sourcesContent":["import type { Server } from 'node:http';\nimport { createServer } from 'node:http';\n\nexport class Endpoint {\n private readonly httpServer: Server;\n public constructor() {\n this.httpServer = createServer();\n }\n\n public run(): void {\n this.httpServer.listen(8080);\n }\n}\n"]} \ No newline at end of file diff --git a/lib/endpoint/endpoint.ts b/lib/endpoint/endpoint.ts new file mode 100644 index 0000000..436c18c --- /dev/null +++ b/lib/endpoint/endpoint.ts @@ -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); + } +} diff --git a/lib/index.d.ts b/lib/index.d.ts new file mode 100644 index 0000000..dddfcce --- /dev/null +++ b/lib/index.d.ts @@ -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'; diff --git a/lib/index.js b/lib/index.js new file mode 100644 index 0000000..0954453 --- /dev/null +++ b/lib/index.js @@ -0,0 +1,24 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +__exportStar(require("./endpoint/endpoint"), exports); +__exportStar(require("./aggregator-services/aggregatorService"), exports); +__exportStar(require("./aggregator-services/aggregatorServiceSparql"), exports); +__exportStar(require("./cost-queue/CostQueue"), exports); +__exportStar(require("./cost-queue/CostQueueTime"), exports); +__exportStar(require("./operation-registry/aggregatorServiceRegistry"), exports); +__exportStar(require("./operation-registry/aggregatorServiceRegistryHardcodedTestOnly"), exports); +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/lib/index.js.map b/lib/index.js.map new file mode 100644 index 0000000..8fdfa9f --- /dev/null +++ b/lib/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sDAAoC;AAEpC,0EAAwD;AACxD,gFAA8D;AAE9D,yDAAuC;AACvC,6DAA2C;AAE3C,iFAA+D;AAC/D,kGAAgF","sourcesContent":["export * from './endpoint/endpoint';\n\nexport * from './aggregator-services/aggregatorService';\nexport * from './aggregator-services/aggregatorServiceSparql';\n\nexport * from './cost-queue/CostQueue';\nexport * from './cost-queue/CostQueueTime';\n\nexport * from './operation-registry/aggregatorServiceRegistry';\nexport * from './operation-registry/aggregatorServiceRegistryHardcodedTestOnly';\n"]} \ No newline at end of file diff --git a/lib/index.ts b/lib/index.ts new file mode 100644 index 0000000..d16d850 --- /dev/null +++ b/lib/index.ts @@ -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'; diff --git a/lib/operation-registry/aggregatorServiceRegistry.d.ts b/lib/operation-registry/aggregatorServiceRegistry.d.ts new file mode 100644 index 0000000..e6148aa --- /dev/null +++ b/lib/operation-registry/aggregatorServiceRegistry.d.ts @@ -0,0 +1,5 @@ +import type { Operation, OperationResult } from '../aggregator-services/aggregatorService'; +export interface AggregatorServiceRegistry { + initializeServices: () => Promise; + run: (operation: Operation) => Promise; +} diff --git a/lib/operation-registry/aggregatorServiceRegistry.js b/lib/operation-registry/aggregatorServiceRegistry.js new file mode 100644 index 0000000..36664ee --- /dev/null +++ b/lib/operation-registry/aggregatorServiceRegistry.js @@ -0,0 +1,3 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +//# sourceMappingURL=aggregatorServiceRegistry.js.map \ No newline at end of file diff --git a/lib/operation-registry/aggregatorServiceRegistry.js.map b/lib/operation-registry/aggregatorServiceRegistry.js.map new file mode 100644 index 0000000..5b00508 --- /dev/null +++ b/lib/operation-registry/aggregatorServiceRegistry.js.map @@ -0,0 +1 @@ +{"version":3,"file":"aggregatorServiceRegistry.js","sourceRoot":"","sources":["aggregatorServiceRegistry.ts"],"names":[],"mappings":"","sourcesContent":["import type { Operation, OperationResult } from '../aggregator-services/aggregatorService';\n\nexport interface AggregatorServiceRegistry {\n initializeServices: () => Promise;\n run: (operation: Operation) => Promise;\n}\n"]} \ No newline at end of file diff --git a/lib/operation-registry/aggregatorServiceRegistry.ts b/lib/operation-registry/aggregatorServiceRegistry.ts new file mode 100644 index 0000000..651a868 --- /dev/null +++ b/lib/operation-registry/aggregatorServiceRegistry.ts @@ -0,0 +1,6 @@ +import type { Operation, OperationResult } from '../aggregator-services/aggregatorService'; + +export interface AggregatorServiceRegistry { + initializeServices: () => Promise; + run: (operation: Operation) => Promise; +} diff --git a/lib/operation-registry/aggregatorServiceRegistryHardcodedTestOnly.d.ts b/lib/operation-registry/aggregatorServiceRegistryHardcodedTestOnly.d.ts new file mode 100644 index 0000000..de88965 --- /dev/null +++ b/lib/operation-registry/aggregatorServiceRegistryHardcodedTestOnly.d.ts @@ -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; + run(operation: Operation): Promise; +} diff --git a/lib/operation-registry/aggregatorServiceRegistryHardcodedTestOnly.js b/lib/operation-registry/aggregatorServiceRegistryHardcodedTestOnly.js new file mode 100644 index 0000000..1d8239a --- /dev/null +++ b/lib/operation-registry/aggregatorServiceRegistryHardcodedTestOnly.js @@ -0,0 +1,32 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.AggregatorServiceRegistryHardcodedTestOnly = void 0; +class AggregatorServiceRegistryHardcodedTestOnly { + costQueueFactory; + aggregatorServices; + constructor(aggregatorServices, costQueueFactory) { + this.aggregatorServices = aggregatorServices; + this.costQueueFactory = costQueueFactory; + } + async initializeServices() { + await Promise.all(this.aggregatorServices.map(async (aggregatorService) => aggregatorService.initialize())); + } + async run(operation) { + const costQueue = this.costQueueFactory.create(); + await Promise.all(this.aggregatorServices.map(async (aggregatorService) => aggregatorService.test(operation).then((testResult) => { + if (testResult.runnable) { + costQueue.push(testResult); + } + }))); + let operationResult = costQueue.pop(); + while (operationResult === undefined || operationResult.operationResult === undefined) { + if (costQueue.length === 0) { + return undefined; + } + operationResult = costQueue.pop(); + } + return operationResult.operationResult; + } +} +exports.AggregatorServiceRegistryHardcodedTestOnly = AggregatorServiceRegistryHardcodedTestOnly; +//# sourceMappingURL=aggregatorServiceRegistryHardcodedTestOnly.js.map \ No newline at end of file diff --git a/lib/operation-registry/aggregatorServiceRegistryHardcodedTestOnly.js.map b/lib/operation-registry/aggregatorServiceRegistryHardcodedTestOnly.js.map new file mode 100644 index 0000000..adbfd71 --- /dev/null +++ b/lib/operation-registry/aggregatorServiceRegistryHardcodedTestOnly.js.map @@ -0,0 +1 @@ +{"version":3,"file":"aggregatorServiceRegistryHardcodedTestOnly.js","sourceRoot":"","sources":["aggregatorServiceRegistryHardcodedTestOnly.ts"],"names":[],"mappings":";;;AAIA,MAAa,0CAA0C;IACrC,gBAAgB,CAAmB;IACnC,kBAAkB,CAAsB;IAExD,YAAmB,kBAAuC,EAAE,gBAAkC;QAC5F,IAAI,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;QAC7C,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;IAC3C,CAAC;IAEM,KAAK,CAAC,kBAAkB;QAC7B,MAAM,OAAO,CAAC,GAAG,CACf,IAAI,CAAC,kBAAkB,CAAC,GAAG,CACzB,KAAK,EAAC,iBAAiB,EAAiB,EAAE,CAAC,iBAAiB,CAAC,UAAU,EAAE,CAC1E,CACF,CAAC;IACJ,CAAC;IAEM,KAAK,CAAC,GAAG,CAAC,SAAoB;QACnC,MAAM,SAAS,GAAG,IAAI,CAAC,gBAAgB,CAAC,MAAM,EAAE,CAAC;QAEjD,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAC3C,KAAK,EAAC,iBAAiB,EAAiB,EAAE,CAAC,iBAAiB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,CAC/E,CAAC,UAAU,EAAQ,EAAE;YACnB,IAAI,UAAU,CAAC,QAAQ,EAAE;gBACvB,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;aAC5B;QACH,CAAC,CACF,CACF,CAAC,CAAC;QAEH,IAAI,eAAe,GAAG,SAAS,CAAC,GAAG,EAAE,CAAC;QACtC,OAAO,eAAe,KAAK,SAAS,IAAI,eAAe,CAAC,eAAe,KAAK,SAAS,EAAE;YACrF,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE;gBAC1B,OAAO,SAAS,CAAC;aAClB;YACD,eAAe,GAAG,SAAS,CAAC,GAAG,EAAE,CAAC;SACnC;QAED,OAAO,eAAe,CAAC,eAAe,CAAC;IACzC,CAAC;CACF;AAxCD,gGAwCC","sourcesContent":["import type { AggregatorService, Operation, OperationResult } from '../aggregator-services/aggregatorService';\nimport type { CostQueueFactory } from '../cost-queue/CostQueue';\nimport type { AggregatorServiceRegistry } from './aggregatorServiceRegistry';\n\nexport class AggregatorServiceRegistryHardcodedTestOnly implements AggregatorServiceRegistry {\n public readonly costQueueFactory: CostQueueFactory;\n public readonly aggregatorServices: AggregatorService[];\n\n public constructor(aggregatorServices: AggregatorService[], costQueueFactory: CostQueueFactory) {\n this.aggregatorServices = aggregatorServices;\n this.costQueueFactory = costQueueFactory;\n }\n\n public async initializeServices(): Promise {\n await Promise.all(\n this.aggregatorServices.map(\n async(aggregatorService): Promise => aggregatorService.initialize(),\n ),\n );\n }\n\n public async run(operation: Operation): Promise {\n const costQueue = this.costQueueFactory.create();\n\n await Promise.all(this.aggregatorServices.map(\n async(aggregatorService): Promise => aggregatorService.test(operation).then(\n (testResult): void => {\n if (testResult.runnable) {\n costQueue.push(testResult);\n }\n },\n ),\n ));\n\n let operationResult = costQueue.pop();\n while (operationResult === undefined || operationResult.operationResult === undefined) {\n if (costQueue.length === 0) {\n return undefined;\n }\n operationResult = costQueue.pop();\n }\n\n return operationResult.operationResult;\n }\n}\n"]} \ No newline at end of file diff --git a/lib/operation-registry/aggregatorServiceRegistryHardcodedTestOnly.ts b/lib/operation-registry/aggregatorServiceRegistryHardcodedTestOnly.ts new file mode 100644 index 0000000..bb937ee --- /dev/null +++ b/lib/operation-registry/aggregatorServiceRegistryHardcodedTestOnly.ts @@ -0,0 +1,45 @@ +import type { AggregatorService, Operation, OperationResult } from '../aggregator-services/aggregatorService'; +import type { CostQueueFactory } from '../cost-queue/CostQueue'; +import type { AggregatorServiceRegistry } from './aggregatorServiceRegistry'; + +export class AggregatorServiceRegistryHardcodedTestOnly implements AggregatorServiceRegistry { + public readonly costQueueFactory: CostQueueFactory; + public readonly aggregatorServices: AggregatorService[]; + + public constructor(aggregatorServices: AggregatorService[], costQueueFactory: CostQueueFactory) { + this.aggregatorServices = aggregatorServices; + this.costQueueFactory = costQueueFactory; + } + + public async initializeServices(): Promise { + await Promise.all( + this.aggregatorServices.map( + async(aggregatorService): Promise => aggregatorService.initialize(), + ), + ); + } + + public async run(operation: Operation): Promise { + const costQueue = this.costQueueFactory.create(); + + await Promise.all(this.aggregatorServices.map( + async(aggregatorService): Promise => aggregatorService.test(operation).then( + (testResult): void => { + if (testResult.runnable) { + costQueue.push(testResult); + } + }, + ), + )); + + let operationResult = costQueue.pop(); + while (operationResult === undefined || operationResult.operationResult === undefined) { + if (costQueue.length === 0) { + return undefined; + } + operationResult = costQueue.pop(); + } + + return operationResult.operationResult; + } +} diff --git a/lib/tsconfig-eslint.json b/lib/tsconfig-eslint.json new file mode 100644 index 0000000..a896c34 --- /dev/null +++ b/lib/tsconfig-eslint.json @@ -0,0 +1,17 @@ +{ + "extends": "@tsconfig/node18/tsconfig.json", + "compilerOptions": { + "incremental": true, + "lib": [ "es2021" ], + "moduleResolution": "node16", + "declaration": true, + "inlineSources": true, + "newLine": "lf", + "preserveConstEnums": true, + "sourceMap": true, + "stripInternal": true + }, + "include": [ + "." + ] +}