chadstart 1.0.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.
Files changed (115) hide show
  1. package/.dockerignore +10 -0
  2. package/.env.example +46 -0
  3. package/.github/workflows/browser-test.yml +34 -0
  4. package/.github/workflows/docker-publish.yml +54 -0
  5. package/.github/workflows/docs.yml +31 -0
  6. package/.github/workflows/npm-chadstart.yml +27 -0
  7. package/.github/workflows/npm-sdk.yml +38 -0
  8. package/.github/workflows/test.yml +85 -0
  9. package/.weblate +9 -0
  10. package/Dockerfile +23 -0
  11. package/README.md +348 -0
  12. package/admin/index.html +2802 -0
  13. package/admin/login.html +207 -0
  14. package/chadstart.example.yml +416 -0
  15. package/chadstart.schema.json +367 -0
  16. package/chadstart.yaml +53 -0
  17. package/cli/cli.js +295 -0
  18. package/core/api-generator.js +606 -0
  19. package/core/auth.js +298 -0
  20. package/core/db.js +384 -0
  21. package/core/entity-engine.js +166 -0
  22. package/core/error-reporter.js +132 -0
  23. package/core/file-storage.js +97 -0
  24. package/core/functions-engine.js +353 -0
  25. package/core/openapi.js +171 -0
  26. package/core/plugin-loader.js +92 -0
  27. package/core/realtime.js +93 -0
  28. package/core/schema-validator.js +50 -0
  29. package/core/seeder.js +231 -0
  30. package/core/telemetry.js +119 -0
  31. package/core/upload.js +372 -0
  32. package/core/workers/php_worker.php +19 -0
  33. package/core/workers/python_worker.py +33 -0
  34. package/core/workers/ruby_worker.rb +21 -0
  35. package/core/yaml-loader.js +64 -0
  36. package/demo/chadstart.yaml +178 -0
  37. package/demo/docker-compose.yml +31 -0
  38. package/demo/functions/greet.go +39 -0
  39. package/demo/functions/hello.cpp +18 -0
  40. package/demo/functions/hello.py +13 -0
  41. package/demo/functions/hello.rb +10 -0
  42. package/demo/functions/onTodoCreated.js +13 -0
  43. package/demo/functions/ping.sh +13 -0
  44. package/demo/functions/stats.js +22 -0
  45. package/demo/public/index.html +522 -0
  46. package/docker-compose.yml +17 -0
  47. package/docs/access-policies.md +155 -0
  48. package/docs/admin-ui.md +29 -0
  49. package/docs/angular.md +69 -0
  50. package/docs/astro.md +71 -0
  51. package/docs/auth.md +160 -0
  52. package/docs/cli.md +56 -0
  53. package/docs/config.md +127 -0
  54. package/docs/crud.md +627 -0
  55. package/docs/deploy.md +113 -0
  56. package/docs/docker.md +59 -0
  57. package/docs/entities.md +385 -0
  58. package/docs/functions.md +196 -0
  59. package/docs/getting-started.md +79 -0
  60. package/docs/groups.md +85 -0
  61. package/docs/index.md +5 -0
  62. package/docs/llm-rules.md +81 -0
  63. package/docs/middlewares.md +78 -0
  64. package/docs/overrides/home.html +350 -0
  65. package/docs/plugins.md +59 -0
  66. package/docs/react.md +75 -0
  67. package/docs/realtime.md +43 -0
  68. package/docs/s3-storage.md +40 -0
  69. package/docs/security.md +23 -0
  70. package/docs/stylesheets/extra.css +375 -0
  71. package/docs/svelte.md +71 -0
  72. package/docs/telemetry.md +97 -0
  73. package/docs/upload.md +168 -0
  74. package/docs/validation.md +115 -0
  75. package/docs/vue.md +86 -0
  76. package/docs/webhooks.md +87 -0
  77. package/index.js +11 -0
  78. package/locales/en/admin.json +169 -0
  79. package/mkdocs.yml +82 -0
  80. package/package.json +65 -0
  81. package/playwright.config.js +24 -0
  82. package/public/.gitkeep +0 -0
  83. package/sdk/README.md +284 -0
  84. package/sdk/package.json +39 -0
  85. package/sdk/scripts/build.js +58 -0
  86. package/sdk/src/index.js +368 -0
  87. package/sdk/test/sdk.test.cjs +340 -0
  88. package/sdk/types/index.d.ts +217 -0
  89. package/server/express-server.js +734 -0
  90. package/test/access-policies.test.js +96 -0
  91. package/test/ai.test.js +81 -0
  92. package/test/api-keys.test.js +361 -0
  93. package/test/auth.test.js +122 -0
  94. package/test/browser/admin-ui.spec.js +127 -0
  95. package/test/browser/global-setup.js +71 -0
  96. package/test/browser/global-teardown.js +11 -0
  97. package/test/db.test.js +227 -0
  98. package/test/entity-engine.test.js +193 -0
  99. package/test/error-reporter.test.js +140 -0
  100. package/test/functions-engine.test.js +240 -0
  101. package/test/groups.test.js +212 -0
  102. package/test/hot-reload.test.js +153 -0
  103. package/test/i18n.test.js +173 -0
  104. package/test/middleware.test.js +76 -0
  105. package/test/openapi.test.js +67 -0
  106. package/test/schema-validator.test.js +83 -0
  107. package/test/sdk.test.js +90 -0
  108. package/test/seeder.test.js +279 -0
  109. package/test/settings.test.js +109 -0
  110. package/test/telemetry.test.js +254 -0
  111. package/test/test.js +17 -0
  112. package/test/upload.test.js +265 -0
  113. package/test/validation.test.js +96 -0
  114. package/test/yaml-loader.test.js +93 -0
  115. package/utils/logger.js +24 -0
@@ -0,0 +1,31 @@
1
+ # demo/docker-compose.yml
2
+ # ─────────────────────────────────────────────────────────────────────────────
3
+ # Run the ChadStart Todo demo with Docker Compose.
4
+ #
5
+ # Usage (from this directory):
6
+ # cp ../.env.example .env # create your .env — at minimum set TOKEN_SECRET_KEY
7
+ # docker compose up --build
8
+ #
9
+ # The build context is the repo root so the image is always built from
10
+ # the current source, keeping the schema and code in sync.
11
+ # ─────────────────────────────────────────────────────────────────────────────
12
+
13
+ services:
14
+ app:
15
+ build:
16
+ context: .. # repo root — Dockerfile lives there
17
+ ports:
18
+ - "3000:3000"
19
+ env_file:
20
+ - path: .env
21
+ required: false # optional — defaults are safe for local dev
22
+ environment:
23
+ NODE_ENV: production
24
+ JWT_SECRET: changeme_asdklanion2iorn1i2n9qjw0m90m129qmd920
25
+ volumes:
26
+ - ./chadstart.yaml:/app/chadstart.yaml:ro
27
+ - ./data:/app/data
28
+ - ./public:/app/public
29
+ - ./uploads:/app/uploads
30
+ - ./functions:/app/functions:ro
31
+ restart: unless-stopped
@@ -0,0 +1,39 @@
1
+ // greet.go — ChadStart Go function
2
+ // Returns a greeting from the Go runtime.
3
+ //
4
+ // Runtime: go
5
+ // Trigger: GET /api/fn/greet/go (public)
6
+ //
7
+ // ChadStart passes event JSON via stdin; result must be printed as JSON to stdout.
8
+
9
+ package main
10
+
11
+ import (
12
+ "encoding/json"
13
+ "fmt"
14
+ "os"
15
+ )
16
+
17
+ type Event struct {
18
+ Query map[string]string `json:"query"`
19
+ }
20
+
21
+ func main() {
22
+ var evt Event
23
+ dec := json.NewDecoder(os.Stdin)
24
+ // ignore decode errors — event may be wrapped in {"event":...}
25
+ _ = dec.Decode(&evt)
26
+
27
+ name := "World"
28
+ if evt.Query != nil {
29
+ if n, ok := evt.Query["name"]; ok && n != "" {
30
+ name = n
31
+ }
32
+ }
33
+
34
+ result := map[string]string{
35
+ "message": fmt.Sprintf("Hello, %s!", name),
36
+ "runtime": "go",
37
+ }
38
+ json.NewEncoder(os.Stdout).Encode(result)
39
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * hello.cpp — ChadStart C++ function
3
+ * Reads the event JSON from stdin and returns a greeting.
4
+ *
5
+ * Runtime: c++
6
+ * Trigger: GET /api/fn/greet/cpp (public)
7
+ */
8
+ #include <iostream>
9
+ #include <string>
10
+
11
+ int main() {
12
+ // Consume stdin (ChadStart passes the serialized event as JSON)
13
+ std::string line;
14
+ while (std::getline(std::cin, line)) {}
15
+
16
+ std::cout << "{\"message\":\"Hello, World!\",\"runtime\":\"c++\"}" << std::endl;
17
+ return 0;
18
+ }
@@ -0,0 +1,13 @@
1
+ # hello.py — ChadStart Python function
2
+ # Returns a greeting from the Python runtime.
3
+ #
4
+ # Runtime: python
5
+ # Trigger: GET /api/fn/greet/python (public)
6
+
7
+
8
+ def handler(event, ctx):
9
+ name = (event.get("query") or {}).get("name", "World")
10
+ return {
11
+ "message": f"Hello, {name}!",
12
+ "runtime": "python",
13
+ }
@@ -0,0 +1,10 @@
1
+ # hello.rb — ChadStart Ruby function
2
+ # Returns a greeting from the Ruby runtime.
3
+ #
4
+ # Runtime: ruby
5
+ # Trigger: GET /api/fn/greet/ruby (public)
6
+
7
+ def handler(event, ctx)
8
+ name = ((event['query'] || {})['name'] || 'World')
9
+ { 'message' => "Hello, #{name}!", 'runtime' => 'ruby' }
10
+ end
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+ /**
3
+ * onTodoCreated.js — ChadStart JS event-triggered function
4
+ * Fires when a new Todo is created (event: todo.created).
5
+ *
6
+ * Runtime: js
7
+ * Trigger: event — todo.created
8
+ */
9
+ module.exports = async function handler(event, ctx) {
10
+ const todo = event.data || event;
11
+ console.log(`[todo.created] New todo: "${todo.title}" (id: ${todo.id})`);
12
+ return { received: true, todoId: todo.id };
13
+ };
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env bash
2
+ # ping.sh — ChadStart Bash function
3
+ # Returns a simple pong response.
4
+ #
5
+ # Runtime: bash
6
+ # Trigger: GET /api/fn/ping (public)
7
+ # cron: @hourly
8
+
9
+ set -euo pipefail
10
+
11
+ # ChadStart passes event JSON via stdin (or first arg).
12
+ # For a ping we ignore the input and return JSON on stdout.
13
+ echo '{"pong":true,"runtime":"bash","ts":"'"$(date -u +%Y-%m-%dT%H:%M:%SZ)"'"}'
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+ /**
3
+ * stats.js — ChadStart JS function
4
+ * Returns todo statistics: total, completed, and pending counts.
5
+ *
6
+ * Runtime: js (default)
7
+ * Trigger: GET /api/fn/stats (public)
8
+ */
9
+ module.exports = async function handler(event, ctx) {
10
+ const { chadstart } = ctx;
11
+ if (!chadstart) {
12
+ return { total: 0, completed: 0, pending: 0 };
13
+ }
14
+ // Use perPage:1 so we only fetch counts from the DB — no row data transferred.
15
+ const [all, done] = await Promise.all([
16
+ chadstart.todos.findAll({ perPage: 1 }),
17
+ chadstart.todos.findAll({ completed: true, perPage: 1 }),
18
+ ]);
19
+ const total = all.total ?? 0;
20
+ const completed = done.total ?? 0;
21
+ return { total, completed, pending: total - completed };
22
+ };