@nilejs/cli 0.0.4 → 0.0.6
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/package.json +1 -1
- package/template/.env.example +1 -1
- package/template/package.json +2 -2
- package/template/src/index.ts +25 -21
package/package.json
CHANGED
package/template/.env.example
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
# Add your environment variables here
|
package/template/package.json
CHANGED
|
@@ -13,14 +13,14 @@
|
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"@nilejs/nile": "latest",
|
|
15
15
|
"@electric-sql/pglite": "^0.2.5",
|
|
16
|
-
"drizzle-orm": "^0.
|
|
16
|
+
"drizzle-orm": "^0.45.2",
|
|
17
17
|
"pino": "^10.3.1",
|
|
18
18
|
"slang-ts": "^0.0.7",
|
|
19
19
|
"zod": "^4.3.6"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@types/bun": "latest",
|
|
23
|
-
"drizzle-kit": "^0.31.
|
|
23
|
+
"drizzle-kit": "^0.31.10",
|
|
24
24
|
"typescript": "^5"
|
|
25
25
|
}
|
|
26
26
|
}
|
package/template/src/index.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { createLogger, createNileServer } from "@nilejs/nile";
|
|
2
2
|
import { sql } from "drizzle-orm";
|
|
3
|
-
import { safeTry } from "slang-ts";
|
|
3
|
+
import { Err, Ok, safeTry } from "slang-ts";
|
|
4
4
|
import { db } from "@/db/client";
|
|
5
5
|
import { services } from "@/services/services.config";
|
|
6
6
|
|
|
7
|
-
const logger = createLogger("{{projectName}}", {
|
|
7
|
+
const logger = createLogger("{{projectName}}", {
|
|
8
|
+
mode: "dev",
|
|
9
|
+
chunking: "monthly",
|
|
10
|
+
});
|
|
8
11
|
|
|
9
|
-
/**
|
|
10
|
-
* Push schema to PGLite on boot.
|
|
11
|
-
* Creates the tasks table if it doesn't exist.
|
|
12
|
-
*/
|
|
12
|
+
/** Push schema to PGLite on boot */
|
|
13
13
|
const pushSchema = async () => {
|
|
14
14
|
const result = await safeTry(() =>
|
|
15
15
|
db.execute(sql`
|
|
@@ -29,7 +29,7 @@ const pushSchema = async () => {
|
|
|
29
29
|
}
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
-
const server = createNileServer({
|
|
32
|
+
const server = await createNileServer({
|
|
33
33
|
serverName: "{{projectName}}",
|
|
34
34
|
services,
|
|
35
35
|
resources: { logger, database: db },
|
|
@@ -39,29 +39,33 @@ const server = createNileServer({
|
|
|
39
39
|
port: 8000,
|
|
40
40
|
allowedOrigins: ["http://localhost:8000"],
|
|
41
41
|
enableStatus: true,
|
|
42
|
+
discovery: { enabled: true },
|
|
42
43
|
},
|
|
43
44
|
onBoot: {
|
|
44
|
-
fn: async () => {
|
|
45
|
+
fn: async (ctx) => {
|
|
45
46
|
await pushSchema();
|
|
46
|
-
logger
|
|
47
|
+
ctx.resources?.logger?.info({
|
|
47
48
|
atFunction: "onBoot",
|
|
48
|
-
message: "{{projectName}} booted
|
|
49
|
+
message: "{{projectName}} booted - PGLite schema ready",
|
|
49
50
|
});
|
|
51
|
+
return Ok(null);
|
|
50
52
|
},
|
|
51
53
|
},
|
|
52
54
|
});
|
|
53
55
|
|
|
56
|
+
// Register custom middleware (runs before all service requests)
|
|
57
|
+
server.rest?.addMiddleware("/api", async (c, next) => {
|
|
58
|
+
const start = performance.now();
|
|
59
|
+
await next();
|
|
60
|
+
const ms = (performance.now() - start).toFixed(1);
|
|
61
|
+
logger.info({
|
|
62
|
+
atFunction: "requestLog",
|
|
63
|
+
message: `${c.req.method} ${c.req.path} - ${ms}ms`,
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
54
67
|
if (server.rest) {
|
|
55
68
|
const port = server.config.rest?.port ?? 8000;
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
Bun.serve({ port, fetch });
|
|
59
|
-
|
|
60
|
-
console.log(`\n{{projectName}} listening on http://localhost:${port}`);
|
|
61
|
-
console.log("\nTry it:");
|
|
62
|
-
console.log(` curl -X POST http://localhost:${port}/api/services \\`);
|
|
63
|
-
console.log(` -H "Content-Type: application/json" \\`);
|
|
64
|
-
console.log(
|
|
65
|
-
` -d '{"intent":"explore","service":"*","action":"*","payload":{}}'`
|
|
66
|
-
);
|
|
69
|
+
Bun.serve({ port, fetch: server.rest.app.fetch });
|
|
70
|
+
console.log(`\n{{projectName}} listening on http://localhost:${port}\n`);
|
|
67
71
|
}
|