flingit 0.0.3 → 0.0.5

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 (44) hide show
  1. package/README.md +8 -9
  2. package/dist/cli/commands/admin.d.ts +8 -0
  3. package/dist/cli/commands/admin.d.ts.map +1 -0
  4. package/dist/cli/commands/admin.js +231 -0
  5. package/dist/cli/commands/admin.js.map +1 -0
  6. package/dist/cli/commands/cron.d.ts +6 -0
  7. package/dist/cli/commands/cron.d.ts.map +1 -0
  8. package/dist/cli/commands/cron.js +201 -0
  9. package/dist/cli/commands/cron.js.map +1 -0
  10. package/dist/cli/commands/dev-worker.d.ts +12 -0
  11. package/dist/cli/commands/dev-worker.d.ts.map +1 -0
  12. package/dist/cli/commands/dev-worker.js +66 -0
  13. package/dist/cli/commands/dev-worker.js.map +1 -0
  14. package/dist/cli/commands/dev.d.ts +8 -1
  15. package/dist/cli/commands/dev.d.ts.map +1 -1
  16. package/dist/cli/commands/dev.js +137 -82
  17. package/dist/cli/commands/dev.js.map +1 -1
  18. package/dist/cli/commands/push.d.ts.map +1 -1
  19. package/dist/cli/commands/push.js +57 -37
  20. package/dist/cli/commands/push.js.map +1 -1
  21. package/dist/cli/deploy/assets.d.ts +8 -8
  22. package/dist/cli/deploy/assets.d.ts.map +1 -1
  23. package/dist/cli/deploy/assets.js +15 -15
  24. package/dist/cli/deploy/assets.js.map +1 -1
  25. package/dist/cli/deploy/bundler.d.ts +20 -3
  26. package/dist/cli/deploy/bundler.d.ts.map +1 -1
  27. package/dist/cli/deploy/bundler.js +89 -4
  28. package/dist/cli/deploy/bundler.js.map +1 -1
  29. package/dist/cli/index.js +4 -0
  30. package/dist/cli/index.js.map +1 -1
  31. package/dist/cli/utils/retry.d.ts +25 -0
  32. package/dist/cli/utils/retry.d.ts.map +1 -0
  33. package/dist/cli/utils/retry.js +34 -0
  34. package/dist/cli/utils/retry.js.map +1 -0
  35. package/dist/runtime/migrate.d.ts.map +1 -1
  36. package/dist/runtime/migrate.js +3 -2
  37. package/dist/runtime/migrate.js.map +1 -1
  38. package/dist/worker-runtime/index.d.ts +32 -3
  39. package/dist/worker-runtime/index.d.ts.map +1 -1
  40. package/dist/worker-runtime/index.js +31 -4
  41. package/dist/worker-runtime/index.js.map +1 -1
  42. package/package.json +1 -1
  43. package/templates/default/CLAUDE.md +37 -3
  44. package/templates/default/skills/fling/SKILL.md +24 -2
@@ -42,7 +42,7 @@ Run `npm start` (or `fling dev`) to start development:
42
42
  All primitives are imported from `"flingit"` in the backend:
43
43
 
44
44
  ```typescript
45
- import { app, db, migrate, secrets } from "flingit";
45
+ import { app, db, migrate, secrets, cron } from "flingit";
46
46
  ```
47
47
 
48
48
  ### HTTP Routes (Hono)
@@ -56,6 +56,8 @@ app.post("/api/data", async (c) => {
56
56
  });
57
57
  ```
58
58
 
59
+ **Note:** Paths starting with `/__` are reserved for internal platform use. Do not create routes with these prefixes.
60
+
59
61
  ### Migrations
60
62
 
61
63
  **IMPORTANT: Migrations MUST be idempotent** (safe to run multiple times).
@@ -89,6 +91,36 @@ await db.prepare("INSERT INTO items (name) VALUES (?)").bind(name).run();
89
91
  const apiKey = secrets.get("API_KEY"); // Throws if not set
90
92
  ```
91
93
 
94
+ ### Cron Jobs
95
+
96
+ Schedule tasks to run automatically on a schedule using standard cron syntax:
97
+
98
+ ```typescript
99
+ cron("daily-cleanup", "0 3 * * *", async () => {
100
+ // Runs at 3 AM daily
101
+ await db.prepare("DELETE FROM old_logs WHERE created_at < ?")
102
+ .bind(Date.now() - 86400000).run();
103
+ });
104
+
105
+ cron("hourly-report", "0 * * * *", async () => {
106
+ // Runs every hour - can return a result that's stored in history
107
+ const count = await processRecords();
108
+ return { processed: count };
109
+ });
110
+ ```
111
+
112
+ Cron expressions: `minute hour day-of-month month day-of-week`
113
+ - `"0 9 * * *"` - 9 AM daily
114
+ - `"*/15 * * * *"` - Every 15 minutes
115
+ - `"0 0 * * 1"` - Midnight on Mondays
116
+
117
+ Manage cron jobs with CLI:
118
+ ```bash
119
+ npm exec fling cron list # List all cron jobs
120
+ npm exec fling cron history <name> # View invocation history
121
+ npm exec fling cron trigger <name> # Manually trigger a job
122
+ ```
123
+
92
124
  ## React Frontend
93
125
 
94
126
  The frontend is a standard React + Vite setup. Call the backend API:
@@ -133,6 +165,8 @@ npm exec fling -- --prod logs # Deployed logs
133
165
  npm exec fling -- --prod db sql "SELECT 1" # Deployed D1
134
166
  ```
135
167
 
168
+ **Note:** Production logs have a delay of ~10 seconds or more before they appear.
169
+
136
170
  **Secrets:** Always stored locally in `.fling/secrets`. Use `fling push` to deploy secrets to production along with your code.
137
171
 
138
172
  ## Deployment
@@ -156,8 +190,8 @@ npm exec fling -- --prod db sql "SELECT 1" # Deployed D1
156
190
  Be aware of these constraints when building:
157
191
 
158
192
  ### Feature Scope
159
- - **Supported:** Frontend (React), backend (Hono API), database (SQLite/D1)
160
- - **Not yet supported:** Cron jobs, file/blob storage, websockets
193
+ - **Supported:** Frontend (React), backend (Hono API), database (SQLite/D1), cron jobs
194
+ - **Not yet supported:** File/blob storage, websockets
161
195
  - If the user needs unsupported features, encourage them to send feedback via `npm exec fling feedback`
162
196
 
163
197
  ### Backend Memory (128MB limit)
@@ -4,12 +4,13 @@ You are working on a Fling project - a personal software platform for building a
4
4
 
5
5
  ## Core Concepts
6
6
 
7
- Fling provides four primitives that work identically in local development and production:
7
+ Fling provides five primitives that work identically in local development and production:
8
8
 
9
9
  1. **HTTP** - Expose endpoints via Hono
10
10
  2. **Database** - SQLite locally, D1 in production
11
11
  3. **Secrets** - Secure credential management
12
12
  4. **Migrations** - Version your database schema
13
+ 5. **Cron** - Scheduled tasks that run on a schedule
13
14
 
14
15
  ## Project Structure
15
16
 
@@ -52,6 +53,20 @@ await db.prepare("CREATE TABLE IF NOT EXISTS items (id INTEGER PRIMARY KEY, name
52
53
 
53
54
  // Secrets (throws if not set)
54
55
  const token = secrets.get("API_TOKEN");
56
+
57
+ // Cron jobs - run on a schedule
58
+ import { cron } from "flingit";
59
+
60
+ cron("daily-cleanup", "0 3 * * *", async () => {
61
+ // Runs at 3 AM daily
62
+ await db.prepare("DELETE FROM old_logs WHERE created_at < ?").bind(Date.now() - 86400000).run();
63
+ });
64
+
65
+ cron("hourly-stats", "0 * * * *", async () => {
66
+ // Runs every hour
67
+ const stats = await generateStats();
68
+ return { processed: stats.count }; // Optional return value stored in history
69
+ });
55
70
  ```
56
71
 
57
72
  ```typescript
@@ -88,6 +103,9 @@ npm exec fling logs # View local logs
88
103
  npm exec fling push # Build and deploy to Cloudflare Workers
89
104
  npm exec fling project slug # Show current project slug and URL
90
105
  npm exec fling project slug:set <new-slug> # Change project slug (affects URL)
106
+ npm exec fling cron list # List registered cron jobs
107
+ npm exec fling cron history <name> # View invocation history
108
+ npm exec fling cron trigger <name> # Manually trigger a cron job
91
109
  ```
92
110
 
93
111
  ### Local vs Production (`--prod`)
@@ -106,6 +124,8 @@ npm exec fling -- --prod logs # Deployed logs
106
124
  npm exec fling -- --prod db sql "SELECT 1" # Deployed D1
107
125
  ```
108
126
 
127
+ **Note:** Production logs have a delay of ~10 seconds or more before they appear.
128
+
109
129
  ## Development
110
130
 
111
131
  Run `npm start` (or `fling dev`) to start development:
@@ -144,7 +164,7 @@ When the user's request is complete and working locally, deploy it:
144
164
 
145
165
  2. **Memory limit (~128MB)** - Workers have limited memory. Cannot process large datasets in memory. Use streaming, pagination, or chunked processing for large data.
146
166
 
147
- 3. **Feature scope** - Fling supports frontend, backend, and database. Not yet supported: cron jobs, file/blob storage, websockets. If users need these, encourage feedback via `npm exec fling feedback`.
167
+ 3. **Feature scope** - Fling supports frontend, backend, database, and cron jobs. Not yet supported: file/blob storage, websockets. If users need these, encourage feedback via `npm exec fling feedback`.
148
168
 
149
169
  4. **Database operations cannot be at module top-level** - They must be inside route handlers or functions called by them.
150
170
 
@@ -154,6 +174,8 @@ When the user's request is complete and working locally, deploy it:
154
174
 
155
175
  7. **Run commands yourself** - You have bash access. Don't ask the user to run `fling push`, `fling dev`, `npm start`, etc. Execute them directly.
156
176
 
177
+ 8. **Reserved paths (`/__*`)** - Paths starting with `/__` are reserved for internal platform use (e.g., `/__cron` for cron jobs). Do not create routes with these prefixes.
178
+
157
179
  **If the user's request might hit platform limitations, warn them early and suggest alternatives.**
158
180
 
159
181
  See API.md for detailed API reference and EXAMPLES.md for common patterns.