From 0550602ab87f34686f4237b38021caabb5bd1436 Mon Sep 17 00:00:00 2001 From: Yoav Farhi Date: Sat, 28 Mar 2026 23:36:16 +0300 Subject: [PATCH 1/2] docs: add logs command reference and backend function best practices Co-Authored-By: Claude Opus 4.6 (1M context) --- skills/base44-cli/SKILL.md | 19 +++++++++++++++ skills/base44-sdk/SKILL.md | 48 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/skills/base44-cli/SKILL.md b/skills/base44-cli/SKILL.md index b5a75ec..07015bd 100644 --- a/skills/base44-cli/SKILL.md +++ b/skills/base44-cli/SKILL.md @@ -387,6 +387,25 @@ 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 [function-name]` | 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 +``` + ## 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..5af47d2 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 [REST API](references/rest-api.md) from a local script instead of a backend function. + ## Common Patterns ### Filter and Sort Data From 829de71cfd8448c1551306d0d52f99fc46753b6b Mon Sep 17 00:00:00 2001 From: Yoav Farhi Date: Sat, 28 Mar 2026 23:46:09 +0300 Subject: [PATCH 2/2] =?UTF-8?q?docs:=20address=20review=20feedback=20?= =?UTF-8?q?=E2=80=94=20fix=20logs=20syntax,=20link,=20and=20log=20levels?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.6 (1M context) --- skills/base44-cli/SKILL.md | 4 +++- skills/base44-sdk/SKILL.md | 2 +- skills/base44-troubleshooter/references/project-logs.md | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/skills/base44-cli/SKILL.md b/skills/base44-cli/SKILL.md index 07015bd..94b1f60 100644 --- a/skills/base44-cli/SKILL.md +++ b/skills/base44-cli/SKILL.md @@ -391,7 +391,7 @@ Run one-off scripts against your app with the Base44 SDK pre-authenticated. Use | Command | Description | |---------|-------------| -| `base44 logs [function-name]` | View function execution logs | +| `base44 logs [options]` | View function execution logs | **Flags:** - `--function ` — Filter by function name (comma-separated for multiple) @@ -406,6 +406,8 @@ Run one-off scripts against your app with the Base44 SDK pre-authenticated. Use 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 5af47d2..0d2609b 100644 --- a/skills/base44-sdk/SKILL.md +++ b/skills/base44-sdk/SKILL.md @@ -273,7 +273,7 @@ while (true) { ### Use the REST API for data migrations -For one-time backfills or large data operations, use the [REST API](references/rest-api.md) from a local script instead of a backend function. +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 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 |