diff --git a/skills/base44-cli/SKILL.md b/skills/base44-cli/SKILL.md index b5a75ec..94b1f60 100644 --- a/skills/base44-cli/SKILL.md +++ b/skills/base44-cli/SKILL.md @@ -387,6 +387,27 @@ Run one-off scripts against your app with the Base44 SDK pre-authenticated. Use **SPA only**: Base44 hosting supports Single Page Applications with a single `index.html` entry point. All routes are served from `index.html` (client-side routing). +### Logs + +| Command | Description | +|---------|-------------| +| `base44 logs [options]` | View function execution logs | + +**Flags:** +- `--function ` — Filter by function name (comma-separated for multiple) +- `--level ` — Filter by log level +- `--since ` — Show logs after this time +- `--until ` — Show logs before this time +- `--limit ` — Results per page (1-1000) +- `--order ` — Sort order (default: desc) + +**Example:** +```bash +npx base44 logs --function my-function --level error --since 2024-03-01T00:00:00Z +``` + +For detailed logs documentation, see the base44-troubleshooter skill. + ## Quick Start 1. Install the CLI in your project: diff --git a/skills/base44-sdk/SKILL.md b/skills/base44-sdk/SKILL.md index c4cfbac..0d2609b 100644 --- a/skills/base44-sdk/SKILL.md +++ b/skills/base44-sdk/SKILL.md @@ -227,6 +227,54 @@ const base44 = createClient({ - Track custom events → `analytics.track()` - Log page views/activity → `appLogs.logUserInApp()` +## Backend Function Best Practices + +### Avoid scanning large collections + +Backend functions run in Deno with limited memory. Fetching large entity collections with `list()` may fail for collections with thousands of records. + +**Instead of scan-and-aggregate:** +```javascript +// ❌ Fragile — fails as collection grows +const allUsages = await base44.entities.Usage.list("-created_date", 5000); +const counts = {}; +for (const u of allUsages) { counts[u.user_id] = (counts[u.user_id] || 0) + 1; } +``` + +**Use incremental pre-computed stats:** +```javascript +// ✅ Update a stats record on each new event (via entity hook automation) +const stats = await base44.entities.UserStats.filter({ user_id: userId }, null, 1); +if (stats.length > 0) { + await base44.entities.UserStats.update(stats[0].id, { total: stats[0].total + 1 }); +} +``` + +### Use filter() with specific conditions + +`filter()` with targeted conditions returns smaller result sets and works reliably: +```javascript +// ✅ Small, targeted query +const userStats = await base44.entities.UserStats.filter({ user_id: "U123" }, null, 1); +``` + +### Use pagination for large reads + +When you need to process many records, paginate with `skip`: +```javascript +let skip = 0; +while (true) { + const batch = await base44.entities.Task.list("-created_date", 100, skip); + if (batch.length === 0) break; + // process batch + skip += 100; +} +``` + +### Use the REST API for data migrations + +For one-time backfills or large data operations, use the Base44 REST API (`https://app.base44.com/api/apps/{appId}/entities/{EntityName}`) from a local script instead of a backend function. + ## Common Patterns ### Filter and Sort Data diff --git a/skills/base44-troubleshooter/references/project-logs.md b/skills/base44-troubleshooter/references/project-logs.md index b58fa2a..7dae83e 100644 --- a/skills/base44-troubleshooter/references/project-logs.md +++ b/skills/base44-troubleshooter/references/project-logs.md @@ -15,7 +15,7 @@ npx base44 logs [options] | `--function ` | Filter by function name(s), comma-separated. If omitted, fetches logs for all project functions | No | | `--since ` | Show logs from this time (ISO format) | No | | `--until ` | Show logs until this time (ISO format) | No | -| `--level ` | Filter by log level: `log`, `info`, `warn`, `error`, `debug` | No | +| `--level ` | Filter by log level: `info`, `warning`, `error`, `debug` | No | | `-n, --limit ` | Number of results to return (1-1000, default: 50) | No | | `--order ` | Sort order: `asc` or `desc` (default: `desc`) | No |