balda-js 0.0.1 → 0.0.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.
Files changed (74) hide show
  1. package/lib/cli.d.ts +6 -0
  2. package/lib/cli.js +929 -0
  3. package/lib/cli.js.map +1 -0
  4. package/lib/index.cjs +3384 -0
  5. package/lib/index.cjs.map +1 -0
  6. package/lib/index.d.cts +1492 -0
  7. package/lib/index.d.ts +1492 -0
  8. package/lib/index.js +3327 -0
  9. package/lib/index.js.map +1 -0
  10. package/package.json +1 -1
  11. package/.husky/pre-commit +0 -19
  12. package/.nvmrc +0 -1
  13. package/docs/README.md +0 -135
  14. package/docs/blog/authors.yml +0 -6
  15. package/docs/blog/tags.yml +0 -4
  16. package/docs/cli.md +0 -109
  17. package/docs/docs/core-concepts/controllers.md +0 -393
  18. package/docs/docs/core-concepts/middleware.md +0 -302
  19. package/docs/docs/core-concepts/request-response.md +0 -486
  20. package/docs/docs/core-concepts/routing.md +0 -388
  21. package/docs/docs/core-concepts/server.md +0 -332
  22. package/docs/docs/cron/overview.md +0 -70
  23. package/docs/docs/examples/rest-api.md +0 -595
  24. package/docs/docs/getting-started/configuration.md +0 -168
  25. package/docs/docs/getting-started/installation.md +0 -125
  26. package/docs/docs/getting-started/quick-start.md +0 -273
  27. package/docs/docs/intro.md +0 -46
  28. package/docs/docs/plugins/cookie.md +0 -424
  29. package/docs/docs/plugins/cors.md +0 -295
  30. package/docs/docs/plugins/file.md +0 -382
  31. package/docs/docs/plugins/helmet.md +0 -388
  32. package/docs/docs/plugins/json.md +0 -338
  33. package/docs/docs/plugins/log.md +0 -592
  34. package/docs/docs/plugins/overview.md +0 -390
  35. package/docs/docs/plugins/rate-limiter.md +0 -347
  36. package/docs/docs/plugins/static.md +0 -352
  37. package/docs/docs/plugins/swagger.md +0 -411
  38. package/docs/docs/plugins/urlencoded.md +0 -76
  39. package/docs/docs/testing/examples.md +0 -384
  40. package/docs/docs/testing/mock-server.md +0 -311
  41. package/docs/docs/testing/overview.md +0 -76
  42. package/docs/docusaurus.config.ts +0 -144
  43. package/docs/intro.md +0 -78
  44. package/docs/package.json +0 -46
  45. package/docs/sidebars.ts +0 -72
  46. package/docs/static/.nojekyll +0 -0
  47. package/docs/static/img/docusaurus-social-card.jpg +0 -0
  48. package/docs/static/img/docusaurus.png +0 -0
  49. package/docs/static/img/favicon.ico +0 -0
  50. package/docs/static/img/logo.svg +0 -1
  51. package/docs/static/img/undraw_docusaurus_mountain.svg +0 -37
  52. package/docs/static/img/undraw_docusaurus_react.svg +0 -170
  53. package/docs/static/img/undraw_docusaurus_tree.svg +0 -40
  54. package/docs/tsconfig.json +0 -8
  55. package/speed_test.sh +0 -3
  56. package/test/benchmark/index.ts +0 -17
  57. package/test/cli/cli.ts +0 -7
  58. package/test/commands/test.ts +0 -42
  59. package/test/controllers/file_upload.ts +0 -29
  60. package/test/controllers/urlencoded.ts +0 -13
  61. package/test/controllers/users.ts +0 -111
  62. package/test/cron/index.ts +0 -6
  63. package/test/cron/test_cron.ts +0 -8
  64. package/test/cron/test_cron_imported.ts +0 -8
  65. package/test/native_env.ts +0 -16
  66. package/test/resources/test.txt +0 -1
  67. package/test/server/index.ts +0 -3
  68. package/test/server/instance.ts +0 -63
  69. package/test/suite/upload.test.ts +0 -23
  70. package/test/suite/urlencoded.test.ts +0 -23
  71. package/test/suite/users.test.ts +0 -76
  72. package/todo.md +0 -9
  73. package/tsconfig.json +0 -24
  74. package/vitest.config.ts +0 -17
@@ -1,63 +0,0 @@
1
- import { NativeEnv } from "test/native_env";
2
- import { Server } from "../../src/server/server";
3
- import { defineLoggerConfig, logger } from "src/logger/logger";
4
-
5
- defineLoggerConfig({
6
- level: "debug",
7
- });
8
-
9
- const serverBuilder = new Server({
10
- port: new NativeEnv().get("PORT")
11
- ? parseInt(new NativeEnv().get("PORT"))
12
- : 80,
13
- host: new NativeEnv().get("HOST") ? new NativeEnv().get("HOST") : "0.0.0.0",
14
- controllerPatterns: ["./test/controllers/**/*.{ts,js}"],
15
- swagger: {
16
- type: "standard",
17
- models: {
18
- User: {
19
- type: "object",
20
- properties: {
21
- name: { type: "string" },
22
- age: { type: "number" },
23
- },
24
- },
25
- },
26
- },
27
- plugins: {
28
- static: "public",
29
- json: {
30
- sizeLimit: 1024 * 1024 * 20,
31
- },
32
- cors: {
33
- origin: "*",
34
- methods: ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"],
35
- allowedHeaders: ["Content-Type", "Authorization"],
36
- },
37
- helmet: {
38
- contentSecurityPolicy: false,
39
- },
40
- cookie: {
41
- secret: "secret",
42
- },
43
- urlencoded: {
44
- extended: true,
45
- },
46
- log: {
47
- logResponse: true,
48
- },
49
- },
50
- });
51
-
52
- serverBuilder.setErrorHandler((_req, res, next, error) => {
53
- logger.error(error);
54
- res.internalServerError({ error: "Internal server error" });
55
- return next();
56
- });
57
-
58
- serverBuilder.get("/", (_req, res) => {
59
- res.redirect("/docs");
60
- });
61
-
62
- export const mockServer = await serverBuilder.getMockServer();
63
- export const server = serverBuilder;
@@ -1,23 +0,0 @@
1
- import { describe, it, expect } from "vitest";
2
- import { mockServer } from "test/server/instance";
3
-
4
- describe("FileUploadController", () => {
5
- it("POST /file/upload returns all users", async () => {
6
- const uint8Array = new Uint8Array([1, 2, 3, 4, 5]);
7
- const formData = new FormData();
8
- formData.append("file", new Blob([uint8Array]), "test.txt");
9
-
10
- const res = await mockServer.post("/file/upload", {
11
- formData,
12
- });
13
-
14
- expect(res.assertStatus(200));
15
- expect(res.body()).toEqual({
16
- originalName: "test.txt",
17
- filename: "file",
18
- size: 5,
19
- mimetype: "application/octet-stream",
20
- otherFields: {},
21
- });
22
- });
23
- });
@@ -1,23 +0,0 @@
1
- import { describe, it, expect } from "vitest";
2
- import { mockServer } from "test/server/instance";
3
-
4
- describe("UrlencodedController", () => {
5
- it("POST /urlencoded returns all users", async () => {
6
- const res = await mockServer.post("/urlencoded", {
7
- urlencoded: {
8
- name: "John Doe",
9
- age: "30",
10
- email: "john.doe@example.com",
11
- },
12
- });
13
-
14
- expect(res.assertStatus(200));
15
- expect(
16
- res.assertBodySubset({
17
- name: "John Doe",
18
- age: "30",
19
- email: "john.doe@example.com",
20
- }),
21
- );
22
- });
23
- });
@@ -1,76 +0,0 @@
1
- import { describe, it, expect } from "vitest";
2
- import { mockServer } from "test/server/instance";
3
-
4
- describe("UsersController", () => {
5
- it("GET /users returns all users", async () => {
6
- const res = await mockServer.get("/users");
7
- expect(res.statusCode()).toBe(200);
8
- expect(Array.isArray(res.body() as any)).toBe(true);
9
- expect((res.body() as any).length).toBeGreaterThan(0);
10
- });
11
-
12
- it("GET /users?shouldFail=true should fail", async () => {
13
- const res = await mockServer.get("/users", {
14
- query: { shouldFail: "true" },
15
- });
16
- expect(res.statusCode()).toBe(500);
17
- });
18
-
19
- it("GET /users/:id returns a user if found", async () => {
20
- const res = await mockServer.get("/users/1");
21
- expect(res.statusCode()).toBe(200);
22
- expect(res.assertBodySubset({ id: 1 }));
23
- });
24
-
25
- it("GET /users/:id returns 404 if not found", async () => {
26
- const res = await mockServer.get("/users/999");
27
- expect(res.statusCode()).toBe(404);
28
- expect(res.assertBodyDeepEqual({ error: "User not found" }));
29
- });
30
-
31
- it("POST /users creates a new user", async () => {
32
- const newUser = { id: 3, email: "new@example.com", name: "New", age: 30 };
33
- const res = await mockServer.post("/users", { body: newUser });
34
- expect(res.statusCode()).toBe(201);
35
- expect(res.assertBodyDeepEqual(newUser));
36
- });
37
-
38
- it("POST /users returns 409 if user exists", async () => {
39
- const existingUser = {
40
- id: 1,
41
- email: "john.doe@example.com",
42
- name: "John Doe",
43
- age: 20,
44
- };
45
- const res = await mockServer.post("/users", { body: existingUser });
46
- expect(res.statusCode()).toBe(409);
47
- expect(res.assertBodyDeepEqual({ error: "User already exists" }));
48
- });
49
-
50
- it("PATCH /users/:id updates a user", async () => {
51
- const res = await mockServer.patch("/users/1", {
52
- body: { name: "Updated" },
53
- });
54
- expect(res.statusCode()).toBe(200);
55
- expect(res.assertBodySubset({ id: 1, name: "Updated" }));
56
- });
57
-
58
- it("PATCH /users/:id returns 404 if not found", async () => {
59
- const res = await mockServer.patch("/users/999", {
60
- body: { name: "Nope" },
61
- });
62
- expect(res.statusCode()).toBe(404);
63
- expect(res.assertBodyDeepEqual({ error: "User not found" }));
64
- });
65
-
66
- it("DELETE /users/:id deletes a user", async () => {
67
- const res = await mockServer.delete("/users/1");
68
- expect(res.statusCode()).toBe(204);
69
- });
70
-
71
- it("DELETE /users/:id returns 404 if not found", async () => {
72
- const res = await mockServer.delete("/users/999");
73
- expect(res.statusCode()).toBe(404);
74
- expect(res.assertBodyDeepEqual({ error: "User not found" }));
75
- });
76
- });
package/todo.md DELETED
@@ -1,9 +0,0 @@
1
- Features to implement
2
-
3
- - test tap function on all runtimes
4
- - validation ajv + type box - to do better
5
- - documentation - fix security not showing up
6
- - base middlewares (file, helmet, rate_limit) - to test better
7
- - file type in typebox and ajv
8
- - named middlewares ?
9
-
package/tsconfig.json DELETED
@@ -1,24 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2022",
4
- "module": "ESNext",
5
- "moduleResolution": "bundler",
6
- "esModuleInterop": true,
7
- "allowSyntheticDefaultImports": true,
8
- "strict": true,
9
- "skipLibCheck": true,
10
- "forceConsistentCasingInFileNames": true,
11
- "declaration": true,
12
- "outDir": "./lib",
13
- "types": ["node", "deno", "bun-types"],
14
- "experimentalDecorators": true,
15
- "emitDecoratorMetadata": true,
16
- "baseUrl": ".",
17
- "paths": {
18
- "src/*": ["src/*"],
19
- "test/*": ["test/*"]
20
- }
21
- },
22
- "include": ["src/**/*", "test/**/*", "trash/commands", "src/cli.ts"],
23
- "exclude": ["node_modules", "lib"]
24
- }
package/vitest.config.ts DELETED
@@ -1,17 +0,0 @@
1
- import { resolve } from "path";
2
- import { defineConfig } from "vitest/config";
3
-
4
- export default defineConfig({
5
- test: {
6
- globals: true,
7
- environment: "node",
8
- include: ["test/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"],
9
- exclude: ["node_modules", "dist", ".idea", ".git", ".cache"],
10
- },
11
- resolve: {
12
- alias: {
13
- src: resolve(__dirname, "./src"),
14
- test: resolve(__dirname, "./test"),
15
- },
16
- },
17
- });