Skip to content
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ npm install sidequest
yarn add sidequest
```

Make sure you are using Node.js >= 22.6.0. Also, [Sidequest does not run with Bun yet](https://github.com/sidequestjs/sidequest/issues/72).

To keep the application minimal, the main package does _not_ include the backend drivers. Thus you need to install only the driver you will use:

**PostgreSQL (recommended)**
Expand Down
24 changes: 24 additions & 0 deletions packages/docs/engine/backends.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,26 @@ await Sidequest.start({
});
```

**Using Knex Configuration Object:**

```typescript
import { Sidequest } from "sidequest";

await Sidequest.start({
backend: {
driver: "@sidequest/postgres-backend",
config: {
connection: "postgres://user:password@localhost:5432/mydb",
pool: {
min: 2,
max: 10,
},
searchPath: ["sidequest", "public"],
},
},
});
```

**Advantages:**

- **Excellent concurrency**: Advanced locking mechanisms prevent job conflicts
Expand Down Expand Up @@ -350,6 +370,10 @@ export class MyCustomBackend implements Backend {
// Count jobs by state
}

async countJobsByQueues(): Promise<Record<string, JobCounts>>; {
// Count jobs by queue
}

async countJobsOverTime(timeRange: string): Promise<({ timestamp: Date } & JobCounts)[]> {
// Count jobs over time for analytics
}
Expand Down
4 changes: 4 additions & 0 deletions packages/docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ description: Installation instructions for Sidequest.js

To get started with Sidequest.js, you need to install the main package along with the backend driver of your choice. Below are the installation instructions for different package managers.

::: warning
Make sure you are using Node.js >= 22.6.0. Also, [Sidequest does not run with Bun](https://github.com/sidequestjs/sidequest/issues/72).
:::

## Main Package (Required)

To get started with Sidequest, first install the main package:
Expand Down
1 change: 1 addition & 0 deletions packages/sidequest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"test:ci": "npx vitest run"
},
"dependencies": {
"@sidequest/backend": "workspace:*",
"@sidequest/core": "workspace:*",
"@sidequest/dashboard": "workspace:*",
"@sidequest/engine": "workspace:*"
Expand Down
1 change: 1 addition & 0 deletions packages/sidequest/src/operations/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./job";
export * from "./queue";
export * from "./sidequest";
export * from "./types";
3 changes: 2 additions & 1 deletion packages/sidequest/src/operations/sidequest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { Job } from "@sidequest/core";
import { NonNullableEngineConfig } from "@sidequest/engine";
import { JobOperations } from "./job";
import { QueueOperations } from "./queue";
import { Sidequest, SidequestConfig } from "./sidequest";
import { Sidequest } from "./sidequest";
import { SidequestConfig } from "./types";

// Mock dependencies
const mockSidequestDashboard = vi.hoisted(() => ({
Expand Down
13 changes: 5 additions & 8 deletions packages/sidequest/src/operations/sidequest.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { JobClassType, logger } from "@sidequest/core";
import { DashboardConfig, SidequestDashboard } from "@sidequest/dashboard";
import { Engine, EngineConfig } from "@sidequest/engine";
import { SidequestDashboard } from "@sidequest/dashboard";
import { Engine } from "@sidequest/engine";
import { JobOperations } from "./job";
import { QueueOperations } from "./queue";

export type SidequestConfig = EngineConfig & {
dashboard?: Omit<DashboardConfig, "backendConfig">;
};
import { KnownDrivers, SidequestConfig, SidequestEngineConfig } from "./types";

/**
* Main entry point for the Sidequest job processing system.
Expand Down Expand Up @@ -78,7 +75,7 @@ export class Sidequest {
* });
* ```
*/
static async configure(config?: EngineConfig) {
static async configure<TDriver extends string = KnownDrivers>(config?: SidequestEngineConfig<TDriver>) {
const _config = await this.engine.configure(config);
const backend = this.engine.getBackend();
this.job.setBackend(backend);
Expand All @@ -105,7 +102,7 @@ export class Sidequest {
* });
* ```
*/
static async start(config?: SidequestConfig) {
static async start<TDriver extends string = KnownDrivers>(config?: SidequestConfig<TDriver>) {
try {
const engineConfig = await this.configure(config);

Expand Down
58 changes: 58 additions & 0 deletions packages/sidequest/src/operations/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { SQLDriverConfig } from "@sidequest/backend";
import { DashboardConfig } from "@sidequest/dashboard";
import { EngineConfig } from "@sidequest/engine";

/**
* Known backend driver identifiers
*/
export type KnownSQLDrivers = "@sidequest/postgres-backend" | "@sidequest/mysql-backend" | "@sidequest/sqlite-backend";

/**
* Known MongoDB driver identifier
*/
export type KnownMongoDriver = "@sidequest/mongo-backend";

/**
* All known backend driver identifiers
*/
export type KnownDrivers = KnownSQLDrivers | KnownMongoDriver;

/**
* Strongly typed backend configuration that automatically infers config type based on driver
*/
export type StronglyTypedBackendConfig<TDriver extends string = KnownDrivers> = TDriver extends KnownSQLDrivers
? {
/** SQL backend driver identifier */
driver: TDriver;
/** Database configuration - can be a connection string or detailed config object */
config: string | SQLDriverConfig;
}
: TDriver extends KnownMongoDriver
? {
/** MongoDB backend driver identifier */
driver: TDriver;
/** MongoDB connection string */
config: string;
}
: {
/** Custom backend driver identifier */
driver: TDriver;
/** Custom configuration - type is unknown for flexibility */
config: unknown;
};

/**
* Sidequest engine configuration with strongly typed backend
*/
export type SidequestEngineConfig<TDriver extends string = KnownDrivers> = Omit<EngineConfig, "backend"> & {
/** Backend configuration with driver-specific typing */
backend: StronglyTypedBackendConfig<TDriver>;
};

/**
* Complete Sidequest configuration
*/
export type SidequestConfig<TDriver extends string = KnownDrivers> = SidequestEngineConfig<TDriver> & {
/** Optional dashboard configuration */
dashboard?: Omit<DashboardConfig, "backendConfig">;
};
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11421,6 +11421,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "sidequest@workspace:packages/sidequest"
dependencies:
"@sidequest/backend": "workspace:*"
"@sidequest/core": "workspace:*"
"@sidequest/dashboard": "workspace:*"
"@sidequest/engine": "workspace:*"
Expand Down
Loading