@wrelik/jobs 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/package.json +20 -0
- package/src/index.ts +37 -0
- package/tsconfig.json +7 -0
package/CHANGELOG.md
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@wrelik/jobs",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"main": "./dist/index.js",
|
|
5
|
+
"types": "./dist/index.d.ts",
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"inngest": "^3.11.0"
|
|
8
|
+
},
|
|
9
|
+
"devDependencies": {
|
|
10
|
+
"tsup": "^8.0.1",
|
|
11
|
+
"vitest": "^1.2.2",
|
|
12
|
+
"@wrelik/eslint-config": "0.1.0",
|
|
13
|
+
"@wrelik/tsconfig": "0.1.0"
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsup src/index.ts --format cjs,esm --dts --clean",
|
|
17
|
+
"lint": "eslint src/",
|
|
18
|
+
"test": "vitest run --passWithNoTests"
|
|
19
|
+
}
|
|
20
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Inngest, EventSchemas, type GetEvents } from 'inngest';
|
|
2
|
+
|
|
3
|
+
// Define the event types map that apps can extend via module augmentation?
|
|
4
|
+
// For now, we use a generic approach or require strict schemas.
|
|
5
|
+
// The user requirement says "Enforce event naming convention" was for analytics.
|
|
6
|
+
// For jobs: emit(eventName, payload), createFunction(name, trigger, handler).
|
|
7
|
+
|
|
8
|
+
let client: Inngest;
|
|
9
|
+
|
|
10
|
+
export function initJobs(appId: string, eventSchema?: any) {
|
|
11
|
+
// We can pass schemas if we want strict typing
|
|
12
|
+
client = new Inngest({ id: appId });
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function getClient() {
|
|
16
|
+
if (!client) throw new Error('Jobs not initialized');
|
|
17
|
+
return client;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export async function emit(eventName: string, payload: any) {
|
|
21
|
+
return getClient().send({
|
|
22
|
+
name: eventName,
|
|
23
|
+
data: payload,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Wrapper for createFunction to lock down options if needed
|
|
28
|
+
export function createFunction(
|
|
29
|
+
name: string,
|
|
30
|
+
trigger: { event: string } | { cron: string },
|
|
31
|
+
handler: (args: any) => Promise<any>,
|
|
32
|
+
) {
|
|
33
|
+
return getClient().createFunction({ id: name }, trigger, handler);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Export the client for advance usage if necessary
|
|
37
|
+
export { client as inngest };
|