miqro.js 0.1.0 → 0.1.2
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/README.md +9 -8
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +69 -7
- package/dist/index.d.ts +17 -0
- package/dist/index.js +3 -3
- package/dist/types.d.ts +24 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -7,22 +7,23 @@ Designed to process webhooks and run scheduled cron jobs utilizing file-based wo
|
|
|
7
7
|
|
|
8
8
|
Create a new project automatically in your current directory:
|
|
9
9
|
```bash
|
|
10
|
-
bunx miqro init
|
|
10
|
+
bunx miqro.js init
|
|
11
|
+
bun add miqro.js
|
|
11
12
|
```
|
|
12
13
|
|
|
13
|
-
This creates a `miqro.config.ts
|
|
14
|
+
This creates a `miqro.config.ts`, a `workflows/` directory, a basic `package.json`, and a `tsconfig.json`.
|
|
14
15
|
|
|
15
16
|
Start the development server with hot-reloading:
|
|
16
17
|
```bash
|
|
17
|
-
|
|
18
|
+
bun run dev
|
|
18
19
|
```
|
|
19
20
|
|
|
20
21
|
## Commands
|
|
21
22
|
|
|
22
|
-
- `miqro init
|
|
23
|
-
- `miqro dev`: Starts the engine in development mode with hot-reloading (`bun --watch`).
|
|
24
|
-
- `miqro start`: Starts the engine dynamically for production.
|
|
25
|
-
- `miqro build`: Compiles your project and workflows into a single standalone file at `./dist/index.js`.
|
|
23
|
+
- `miqro.js init` (or `miqro init`): Scaffolds `miqro.config.ts` and a `workflows/` directory.
|
|
24
|
+
- `miqro.js dev`: Starts the engine in development mode with hot-reloading (`bun --watch`).
|
|
25
|
+
- `miqro.js start`: Starts the engine dynamically for production.
|
|
26
|
+
- `miqro.js build`: Compiles your project and workflows into a single standalone file at `./dist/index.js`.
|
|
26
27
|
|
|
27
28
|
## Configuration
|
|
28
29
|
|
|
@@ -45,7 +46,7 @@ Miqro automatically discovers `.ts` or `.js` module exports and registers them.
|
|
|
45
46
|
|
|
46
47
|
### Webhook Workflow
|
|
47
48
|
|
|
48
|
-
Webhooks respond to `POST /
|
|
49
|
+
Webhooks respond to `POST /{id}`. Authentication supports `none`, `apiKey`, or `bearer`.
|
|
49
50
|
|
|
50
51
|
```typescript
|
|
51
52
|
// workflows/example-webhook.ts
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
CHANGED
|
@@ -2974,10 +2974,10 @@ async function startMiqroCore(config, staticWorkflows) {
|
|
|
2974
2974
|
uptime: process.uptime(),
|
|
2975
2975
|
loadedWorkflows: Object.keys(workflows).length
|
|
2976
2976
|
}));
|
|
2977
|
-
app.post("
|
|
2977
|
+
app.post("/:workflowId", async (c) => {
|
|
2978
2978
|
try {
|
|
2979
2979
|
const payload = await c.req.json();
|
|
2980
|
-
const workflowId = c.req.
|
|
2980
|
+
const workflowId = c.req.param("workflowId");
|
|
2981
2981
|
if (workflowId) {
|
|
2982
2982
|
const workflow = workflows[workflowId];
|
|
2983
2983
|
if (!workflow) {
|
|
@@ -3014,7 +3014,7 @@ async function startMiqroCore(config, staticWorkflows) {
|
|
|
3014
3014
|
console.log(`\uD83D\uDE80 Miqro started on http://localhost:${port}`);
|
|
3015
3015
|
if (Object.keys(workflows).length > 0) {
|
|
3016
3016
|
console.log(`Active Webhooks:
|
|
3017
|
-
${Object.keys(workflows).map((w) => ` - POST http://localhost:${port}
|
|
3017
|
+
${Object.keys(workflows).map((w) => ` - POST http://localhost:${port}/${w}`).join(`
|
|
3018
3018
|
`)}`);
|
|
3019
3019
|
} else {
|
|
3020
3020
|
console.log(`No workflows loaded.`);
|
|
@@ -3059,8 +3059,59 @@ export default {
|
|
|
3059
3059
|
if (!existsSync(workflowsPath)) {
|
|
3060
3060
|
await mkdir(workflowsPath, { recursive: true });
|
|
3061
3061
|
}
|
|
3062
|
-
|
|
3063
|
-
|
|
3062
|
+
const sampleWorkflowPath = resolve(workflowsPath, "sample.ts");
|
|
3063
|
+
if (!existsSync(sampleWorkflowPath)) {
|
|
3064
|
+
const sampleWorkflow = `import type { Workflow } from "miqro.js";
|
|
3065
|
+
|
|
3066
|
+
export default {
|
|
3067
|
+
config: {
|
|
3068
|
+
id: "hello-world",
|
|
3069
|
+
name: "Hello World Workflow",
|
|
3070
|
+
auth: { type: "none" },
|
|
3071
|
+
},
|
|
3072
|
+
execute: async (payload: any) => {
|
|
3073
|
+
console.log("Hello from Miqro!", payload);
|
|
3074
|
+
},
|
|
3075
|
+
} satisfies Workflow;
|
|
3076
|
+
`;
|
|
3077
|
+
await writeFile(sampleWorkflowPath, sampleWorkflow);
|
|
3078
|
+
}
|
|
3079
|
+
const pkgPath = resolve(process.cwd(), "package.json");
|
|
3080
|
+
if (!existsSync(pkgPath)) {
|
|
3081
|
+
const pkgContent = {
|
|
3082
|
+
name: "miqro-project",
|
|
3083
|
+
type: "module",
|
|
3084
|
+
scripts: {
|
|
3085
|
+
dev: "miqro dev",
|
|
3086
|
+
start: "miqro start",
|
|
3087
|
+
build: "miqro build"
|
|
3088
|
+
}
|
|
3089
|
+
};
|
|
3090
|
+
await writeFile(pkgPath, JSON.stringify(pkgContent, null, 2));
|
|
3091
|
+
}
|
|
3092
|
+
const tsconfigPath = resolve(process.cwd(), "tsconfig.json");
|
|
3093
|
+
if (!existsSync(tsconfigPath)) {
|
|
3094
|
+
const tsconfigContent = {
|
|
3095
|
+
compilerOptions: {
|
|
3096
|
+
lib: ["ESNext"],
|
|
3097
|
+
module: "esnext",
|
|
3098
|
+
target: "esnext",
|
|
3099
|
+
moduleResolution: "bundler",
|
|
3100
|
+
moduleDetection: "force",
|
|
3101
|
+
allowImportingTsExtensions: true,
|
|
3102
|
+
noEmit: true,
|
|
3103
|
+
strict: true,
|
|
3104
|
+
skipLibCheck: true,
|
|
3105
|
+
allowSyntheticDefaultImports: true
|
|
3106
|
+
}
|
|
3107
|
+
};
|
|
3108
|
+
await writeFile(tsconfigPath, JSON.stringify(tsconfigContent, null, 2));
|
|
3109
|
+
}
|
|
3110
|
+
console.log("\u2705 Created miqro.config.ts and workflows directory with a sample.");
|
|
3111
|
+
console.log(`
|
|
3112
|
+
\uD83D\uDC49 Next steps:`);
|
|
3113
|
+
console.log(" 1. Run: bun add miqro.js");
|
|
3114
|
+
console.log(" 2. Run: bun run dev");
|
|
3064
3115
|
process.exit(0);
|
|
3065
3116
|
}
|
|
3066
3117
|
const configPath = resolve(process.cwd(), "miqro.config.ts");
|
|
@@ -3153,8 +3204,19 @@ const staticWorkflowsList = [
|
|
|
3153
3204
|
console.log(`\u2705 Build successful! Run it with: bun run dist/${outName}`);
|
|
3154
3205
|
}
|
|
3155
3206
|
} else {
|
|
3156
|
-
console.error(
|
|
3157
|
-
console.error(
|
|
3207
|
+
console.error(`\u274C Unknown command: ${command}`);
|
|
3208
|
+
console.error(`
|
|
3209
|
+
Usage: miqro <command>
|
|
3210
|
+
`);
|
|
3211
|
+
console.error("Available commands:");
|
|
3212
|
+
console.error(" init - Scaffolds a new project with miqro.config.ts and sample workflow");
|
|
3213
|
+
console.error(" dev - Starts development server with hot-reloading");
|
|
3214
|
+
console.error(" start - Starts server in production mode");
|
|
3215
|
+
console.error(` build - Compiles project into a standalone executable at ./dist/index.js
|
|
3216
|
+
`);
|
|
3217
|
+
console.error("Example:");
|
|
3218
|
+
console.error(" bunx miqro.js init");
|
|
3219
|
+
console.error(" bunx miqro.js dev");
|
|
3158
3220
|
process.exit(1);
|
|
3159
3221
|
}
|
|
3160
3222
|
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { MiqroConfig, Workflow } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Core initialization logic that takes a pre-loaded array of workflows.
|
|
4
|
+
* Useful for static bundlers.
|
|
5
|
+
*/
|
|
6
|
+
export declare function startMiqroCore(config: Omit<MiqroConfig, "workflowsDir">, staticWorkflows: Workflow[]): Promise<{
|
|
7
|
+
port: string | number;
|
|
8
|
+
fetch: (request: Request, Env?: unknown, executionCtx?: import("hono").ExecutionContext) => Response | Promise<Response>;
|
|
9
|
+
}>;
|
|
10
|
+
/**
|
|
11
|
+
* Initializes and starts the Miqro application dynamically using a directory.
|
|
12
|
+
*/
|
|
13
|
+
export declare function startMiqro(config: MiqroConfig): Promise<{
|
|
14
|
+
port: string | number;
|
|
15
|
+
fetch: (request: Request, Env?: unknown, executionCtx?: import("hono").ExecutionContext) => Response | Promise<Response>;
|
|
16
|
+
}>;
|
|
17
|
+
export type { AuthConfig, Workflow, WorkflowConfig } from "./types";
|
package/dist/index.js
CHANGED
|
@@ -2973,10 +2973,10 @@ async function startMiqroCore(config, staticWorkflows) {
|
|
|
2973
2973
|
uptime: process.uptime(),
|
|
2974
2974
|
loadedWorkflows: Object.keys(workflows).length
|
|
2975
2975
|
}));
|
|
2976
|
-
app.post("
|
|
2976
|
+
app.post("/:workflowId", async (c) => {
|
|
2977
2977
|
try {
|
|
2978
2978
|
const payload = await c.req.json();
|
|
2979
|
-
const workflowId = c.req.
|
|
2979
|
+
const workflowId = c.req.param("workflowId");
|
|
2980
2980
|
if (workflowId) {
|
|
2981
2981
|
const workflow = workflows[workflowId];
|
|
2982
2982
|
if (!workflow) {
|
|
@@ -3013,7 +3013,7 @@ async function startMiqroCore(config, staticWorkflows) {
|
|
|
3013
3013
|
console.log(`\uD83D\uDE80 Miqro started on http://localhost:${port}`);
|
|
3014
3014
|
if (Object.keys(workflows).length > 0) {
|
|
3015
3015
|
console.log(`Active Webhooks:
|
|
3016
|
-
${Object.keys(workflows).map((w) => ` - POST http://localhost:${port}
|
|
3016
|
+
${Object.keys(workflows).map((w) => ` - POST http://localhost:${port}/${w}`).join(`
|
|
3017
3017
|
`)}`);
|
|
3018
3018
|
} else {
|
|
3019
3019
|
console.log(`No workflows loaded.`);
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type AuthConfig = {
|
|
2
|
+
type: "none";
|
|
3
|
+
} | {
|
|
4
|
+
type: "apiKey";
|
|
5
|
+
key: string;
|
|
6
|
+
} | {
|
|
7
|
+
type: "bearer";
|
|
8
|
+
token: string;
|
|
9
|
+
};
|
|
10
|
+
export interface WorkflowConfig {
|
|
11
|
+
id: string;
|
|
12
|
+
name: string;
|
|
13
|
+
description?: string;
|
|
14
|
+
auth: AuthConfig;
|
|
15
|
+
schedule?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface Workflow {
|
|
18
|
+
config: WorkflowConfig;
|
|
19
|
+
execute: (payload: unknown) => Promise<void> | void;
|
|
20
|
+
}
|
|
21
|
+
export interface MiqroConfig {
|
|
22
|
+
workflowsDir: string;
|
|
23
|
+
port?: number;
|
|
24
|
+
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "miqro.js",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Minimal, high-performance microservice engine.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"bin": {
|
|
8
|
-
"miqro": "dist/cli.js"
|
|
8
|
+
"miqro": "dist/cli.js",
|
|
9
|
+
"miqro.js": "dist/cli.js"
|
|
9
10
|
},
|
|
10
11
|
"files": [
|
|
11
12
|
"dist"
|