first refactor
This commit is contained in:
parent
1f5dac28c7
commit
588f666943
84 changed files with 996 additions and 1062 deletions
29
libs/core/services/package.json
Normal file
29
libs/core/services/package.json
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
"name": "@stock-bot/services",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./dist/index.js"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"clean": "rm -rf dist"
|
||||
},
|
||||
"dependencies": {
|
||||
"@stock-bot/browser": "workspace:*",
|
||||
"@stock-bot/cache": "workspace:*",
|
||||
"@stock-bot/logger": "workspace:*",
|
||||
"@stock-bot/mongodb": "workspace:*",
|
||||
"@stock-bot/postgres": "workspace:*",
|
||||
"@stock-bot/proxy": "workspace:*",
|
||||
"@stock-bot/questdb": "workspace:*",
|
||||
"@stock-bot/queue": "workspace:*",
|
||||
"playwright": "^1.40.0"
|
||||
}
|
||||
}
|
||||
44
libs/core/services/src/index.ts
Normal file
44
libs/core/services/src/index.ts
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
import type { Browser as BrowserImplementation } from '@stock-bot/browser';
|
||||
import type { CacheProvider } from '@stock-bot/cache';
|
||||
import type { Logger as LoggerImplementation } from '@stock-bot/logger';
|
||||
import type { MongoDBClient as MongoDBImplementation } from '@stock-bot/mongodb';
|
||||
import type { PostgreSQLClient as PostgresImplementation } from '@stock-bot/postgres';
|
||||
import type { ProxyManager as ProxyImplementation } from '@stock-bot/proxy';
|
||||
import type { QuestDBClient as QuestDBImplementation } from '@stock-bot/questdb';
|
||||
import type {
|
||||
Queue as QueueImplementation,
|
||||
QueueManager as QueueManagerImplementation,
|
||||
} from '@stock-bot/queue';
|
||||
|
||||
/** Public capabilities, derived from the owning adapter instead of copied signatures. */
|
||||
type Public<T> = Pick<T, keyof T>;
|
||||
|
||||
export type Logger = Public<LoggerImplementation>;
|
||||
export type Queue = Public<QueueImplementation>;
|
||||
export type QueueManager = Public<QueueManagerImplementation>;
|
||||
export type MongoDBClient = Public<MongoDBImplementation>;
|
||||
export type PostgresClient = Public<PostgresImplementation>;
|
||||
export type QuestDBClient = Public<QuestDBImplementation>;
|
||||
export type Browser = Public<BrowserImplementation>;
|
||||
export type ProxyManager = Public<ProxyImplementation>;
|
||||
export type { CacheProvider, CacheStats } from '@stock-bot/cache';
|
||||
export type { BrowserContext, Page } from 'playwright';
|
||||
export type { ProxyInfo, ProxyStats } from '@stock-bot/proxy';
|
||||
|
||||
/** Disabled adapters are null; omitted capabilities are undefined. */
|
||||
export interface ServiceTypes {
|
||||
logger: Logger;
|
||||
cache?: CacheProvider | null;
|
||||
globalCache?: CacheProvider | null;
|
||||
queueManager?: QueueManager | null;
|
||||
queue?: Queue | null;
|
||||
proxy?: ProxyManager | null;
|
||||
browser?: Browser | null;
|
||||
mongodb?: MongoDBClient | null;
|
||||
postgres?: PostgresClient | null;
|
||||
questdb?: QuestDBClient | null;
|
||||
}
|
||||
|
||||
export interface IServiceContainer extends ServiceTypes {
|
||||
readonly custom?: Record<string, any>;
|
||||
}
|
||||
61
libs/core/services/test/contracts.type-test.ts
Normal file
61
libs/core/services/test/contracts.type-test.ts
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
import type { Browser as BrowserImplementation } from '@stock-bot/browser';
|
||||
import type { MongoDBClient as MongoDBImplementation } from '@stock-bot/mongodb';
|
||||
import type { PostgreSQLClient as PostgresImplementation } from '@stock-bot/postgres';
|
||||
import type { ProxyManager as ProxyImplementation } from '@stock-bot/proxy';
|
||||
import type { QuestDBClient as QuestDBImplementation } from '@stock-bot/questdb';
|
||||
import type {
|
||||
Queue as QueueImplementation,
|
||||
QueueManager as QueueManagerImplementation,
|
||||
} from '@stock-bot/queue';
|
||||
import type {
|
||||
Browser,
|
||||
IServiceContainer,
|
||||
MongoDBClient,
|
||||
PostgresClient,
|
||||
ProxyManager,
|
||||
QuestDBClient,
|
||||
Queue,
|
||||
QueueManager,
|
||||
} from '../src';
|
||||
|
||||
// Implementations must remain assignable to the capabilities injected into consumers.
|
||||
declare const implementations: {
|
||||
browser: BrowserImplementation;
|
||||
mongodb: MongoDBImplementation;
|
||||
postgres: PostgresImplementation;
|
||||
proxy: ProxyImplementation;
|
||||
questdb: QuestDBImplementation;
|
||||
queue: QueueImplementation;
|
||||
queueManager: QueueManagerImplementation;
|
||||
};
|
||||
implementations satisfies {
|
||||
browser: Browser;
|
||||
mongodb: MongoDBClient;
|
||||
postgres: PostgresClient;
|
||||
proxy: ProxyManager;
|
||||
questdb: QuestDBClient;
|
||||
queue: Queue;
|
||||
queueManager: QueueManager;
|
||||
};
|
||||
|
||||
declare const services: IServiceContainer;
|
||||
services.queueManager?.getQueue('symbols').add('sync', {
|
||||
handler: 'symbols',
|
||||
operation: 'sync',
|
||||
payload: {},
|
||||
});
|
||||
services.postgres?.connected;
|
||||
services.mongodb?.collection<{ symbol: string }>('symbols').findOne({ symbol: 'AAPL' });
|
||||
services.browser?.createPageWithProxy('https://example.com');
|
||||
|
||||
// These obsolete APIs must not silently return through a copied service interface.
|
||||
// @ts-expect-error An individual queue is not a queue manager.
|
||||
services.queue?.getQueue('symbols');
|
||||
// @ts-expect-error The queue adapter exposes add(), not addJob().
|
||||
services.queue?.addJob('sync', {});
|
||||
// @ts-expect-error PostgreSQL exposes connected as a property.
|
||||
services.postgres?.isConnected();
|
||||
// @ts-expect-error The browser capability is the managed adapter, not a Playwright Browser.
|
||||
services.browser?.newPage();
|
||||
// @ts-expect-error A typed collection retains its document fields.
|
||||
services.mongodb?.collection<{ symbol: string }>('symbols').findOne({ symbol: 123 });
|
||||
19
libs/core/services/tsconfig.json
Normal file
19
libs/core/services/tsconfig.json
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"extends": "../../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"rootDir": "./src",
|
||||
"outDir": "./dist",
|
||||
"composite": true
|
||||
},
|
||||
"include": ["src/**/*.ts"],
|
||||
"references": [
|
||||
{ "path": "../../services/browser" },
|
||||
{ "path": "../cache" },
|
||||
{ "path": "../logger" },
|
||||
{ "path": "../../data/mongodb" },
|
||||
{ "path": "../../data/postgres" },
|
||||
{ "path": "../../services/proxy" },
|
||||
{ "path": "../../data/questdb" },
|
||||
{ "path": "../queue" }
|
||||
]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue