tina4-nodejs 3.13.23 → 3.13.24

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.
package/CLAUDE.md CHANGED
@@ -1,10 +1,10 @@
1
- # CLAUDE.md — AI Developer Guide for tina4-nodejs (v3.13.23)
1
+ # CLAUDE.md — AI Developer Guide for tina4-nodejs (v3.13.24)
2
2
 
3
3
  > This file helps AI assistants (Claude, Copilot, Cursor, etc.) understand and work on this codebase effectively.
4
4
 
5
5
  ## What This Project Is
6
6
 
7
- Tina4 for Node.js/TypeScript v3.13.23 — The Intelligent Native Application 4ramework. A convention-over-configuration structural paradigm. The developer writes TypeScript; Tina4 is invisible infrastructure.
7
+ Tina4 for Node.js/TypeScript v3.13.24 — The Intelligent Native Application 4ramework. A convention-over-configuration structural paradigm. The developer writes TypeScript; Tina4 is invisible infrastructure.
8
8
 
9
9
  The philosophy: zero ceremony, batteries included, file system as source of truth.
10
10
 
@@ -592,8 +592,11 @@ db.getNextId(table, pkColumn?, generatorName?): number
592
592
  // DB query cache — request-scoped auto cache is ON by default (TINA4_AUTO_CACHING=true,
593
593
  // TTL TINA4_AUTO_CACHING_TTL=5s): dedupes identical db.fetch()/ORM reads within a request,
594
594
  // flushed on any write. Persistent cross-request cache opt-in via TINA4_DB_CACHE=true
595
- // (TTL TINA4_DB_CACHE_TTL=30s). cacheStats()/cacheClear() are now real (the DB query cache
596
- // is wired previously db.cacheStats() hardcoded size:0 and db.cacheClear() was a no-op).
595
+ // (TTL TINA4_DB_CACHE_TTL=30s), configured via TINA4_DB_CACHE_BACKEND + TINA4_DB_CACHE_URL.
596
+ // NODE CHARACTERISTIC: because db.fetch() is synchronous, Node's persistent DB query cache
597
+ // runs IN-PROCESS (per-instance), not distributed. For cross-instance caching in Node, use
598
+ // the async KV API (await cacheGet/cacheSet). The other three frameworks route this through
599
+ // the backend (distributed). cacheStats()/cacheClear() are real (the DB query cache is wired).
597
600
  db.cacheStats(): { enabled, size, ttl, mode } // mode: "request" | "persistent" | "off"
598
601
  db.cacheClear(): void
599
602
 
@@ -883,7 +886,7 @@ container.reset(); // clear all registrations + cached instances
883
886
 
884
887
  ## Module: Response Cache (`packages/core/src/cache.ts`)
885
888
 
886
- Multi-backend cache. Used as middleware to cache GET responses, or directly via `cacheGet`/`cacheSet` for arbitrary key/value caching. Backends: memory (default), redis/valkey, file.
889
+ Unified multi-backend cache. Used as middleware to cache GET responses, or directly via the **async** KV API (`cacheGet`/`cacheSet`/…) for arbitrary key/value caching. Seven backends, selected by `TINA4_CACHE_BACKEND`: `memory` (default), `file`, `redis`, `valkey`, `memcached`, `mongodb`, `database`.
887
890
 
888
891
  ```typescript
889
892
  import {
@@ -893,21 +896,27 @@ import {
893
896
  // Middleware on a route
894
897
  get("/api/products", listProducts).middleware(responseCache({ ttl: 60 }));
895
898
 
896
- // Direct key/value usage (same shape across all four frameworks)
897
- cacheSet("user:1", { name: "Alice" }, 120);
898
- const u = cacheGet("user:1");
899
- cacheDelete("user:1");
900
- cacheClear();
899
+ // Direct key/value usage Node's KV API is ASYNC (await), matching Node's
900
+ // async-everywhere idiom. All 7 backends use native async clients (no child processes).
901
+ await cacheSet("user:1", { name: "Alice" }, 120);
902
+ const u = await cacheGet("user:1");
903
+ await cacheDelete("user:1");
904
+ await cacheClear();
901
905
 
902
- cacheStats(); // { hits, misses, size, backend } — now reflects the real KV backend
903
- // (previously it wrongly read the response-cache middleware store)
906
+ await cacheStats(); // { hits, misses, size, backend } — reflects the real KV backend
904
907
  ```
905
908
 
909
+ **Node characteristic (by design, not a bug):** the async KV API supports all 7 backends with native async clients. Because Node's middleware runner and `db.fetch()` are synchronous, the **`responseCache` middleware and the persistent DB query cache run in-process (per-instance) in Node** — distributed/cross-instance caching in Node is done via the async KV API (`await cacheGet`/`await cacheSet`). The other three frameworks route those auto-paths through the configured backend (distributed). A full async middleware/DB pipeline is a future-major item.
910
+
911
+ **Graceful fallback**: if a configured backend's driver is missing or the service/credentials are unreachable or wrong, the cache logs a warning and falls back to the **file** backend — a real persistent cache, never a silent no-op.
912
+
906
913
  Environment:
907
- - `TINA4_CACHE_BACKEND` — `memory` | `redis` | `file` (default: `memory`)
908
- - `TINA4_CACHE_URL` — `redis://localhost:6379` (redis backend only)
914
+ - `TINA4_CACHE_BACKEND` — `memory` (default) | `file` | `redis` | `valkey` | `memcached` | `mongodb` | `database`
915
+ - `TINA4_CACHE_URL` — connection for redis/valkey/memcached/mongodb (`redis://localhost:6379`, `mongodb://host`), OR a SQL URL for `database` (falls back to `TINA4_DATABASE_URL`)
916
+ - `TINA4_CACHE_USERNAME` / `TINA4_CACHE_PASSWORD` — credentials (mirror `TINA4_DATABASE_USERNAME`/`_PASSWORD`); may also be embedded in `TINA4_CACHE_URL` (`redis://user:pass@host`, `redis://:pass@host`, `mongodb://user:pass@host`). memcached is unauthenticated
909
917
  - `TINA4_CACHE_TTL` — default TTL seconds (default: `60`)
910
918
  - `TINA4_CACHE_MAX_ENTRIES` — max entries (default: `1000`)
919
+ - `TINA4_CACHE_DIR` — directory for the `file` backend (default: `data/cache`)
911
920
 
912
921
  ## Firebird-Specific Rules
913
922
 
@@ -1103,12 +1112,13 @@ When adding new features, add a corresponding `test/<feature>.test.ts` file.
1103
1112
  ## v3 Features Summary
1104
1113
 
1105
1114
  - **45 built-in features**, zero third-party dependencies
1106
- - **3,708 tests** passing across all modules
1115
+ - **3,787 tests** passing across all modules
1107
1116
  - **Race-safe `getNextId()`** with atomic sequence table (`tina4_sequences`) for SQLite/MySQL/MSSQL; PostgreSQL auto-creates sequences
1108
1117
  - **Frond template engine optimizations**: pre-compiled regexes, lazy loop context (copy-on-write), filter chain caching, path split caching, inline common filters (11-15% speedup)
1109
1118
  - **Production server auto-detect**: `npx tina4nodejs serve --production` auto-uses cluster mode
1110
1119
  - **`npx tina4nodejs generate`**: model, route, migration, middleware scaffolding
1111
- - **Database**: 5 engines (SQLite, PostgreSQL, MySQL, MSSQL, Firebird), DB query caching — request-scoped auto cache **on by default** (`TINA4_AUTO_CACHING=true`, TTL `TINA4_AUTO_CACHING_TTL=5`s) dedupes identical `db.fetch()`/ORM reads within a request and flushes on writes; persistent cross-request cache opt-in via `TINA4_DB_CACHE=true` (TTL `TINA4_DB_CACHE_TTL=30`s). `db.cacheStats()`/`db.cacheClear()` are now real (the DB query cache is wired; was dead code)
1120
+ - **Database**: 5 engines (SQLite, PostgreSQL, MySQL, MSSQL, Firebird), DB query caching — request-scoped auto cache **on by default** (`TINA4_AUTO_CACHING=true`, TTL `TINA4_AUTO_CACHING_TTL=5`s) dedupes identical `db.fetch()`/ORM reads within a request and flushes on writes; persistent cross-request cache opt-in via `TINA4_DB_CACHE=true` (TTL `TINA4_DB_CACHE_TTL=30`s) configured via `TINA4_DB_CACHE_BACKEND` + `TINA4_DB_CACHE_URL`. `db.cacheStats()` reports `mode` (request/persistent/off). **Node characteristic**: `db.fetch()` is synchronous, so the persistent DB query cache runs in-process (per-instance) in Node — cross-instance caching uses the async KV API (`await cacheGet`/`cacheSet`)
1121
+ - **Cache**: unified backend set — `memory` (default), `file`, `redis`, `valkey`, `memcached`, `mongodb`, `database` — via `TINA4_CACHE_BACKEND` (+ `TINA4_CACHE_URL`/credentials); file-backend fallback if a backend is unreachable. KV API is async (`await cacheGet`/`cacheSet`) with native async clients; the `responseCache` middleware runs in-process (per-instance) since Node's middleware runner is synchronous
1112
1122
  - **Sessions**: file backend (default). `TINA4_SESSION_SAMESITE` env var (default: Lax)
1113
1123
  - **Queue**: file/RabbitMQ/Kafka/MongoDB backends, configured via env vars
1114
1124
  - **Cache**: memory/Redis/file backends
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
 
5
5
 
6
- "version": "3.13.23",
6
+ "version": "3.13.24",
7
7
 
8
8
  "type": "module",
9
9
  "description": "Tina4 for Node.js/TypeScript \u2014 54 built-in features, zero dependencies",
@@ -66,6 +66,7 @@
66
66
  "devDependencies": {
67
67
  "typescript": "^5.7.0",
68
68
  "tsx": "^4.19.0",
69
- "esbuild": "^0.24.0"
69
+ "esbuild": "^0.24.0",
70
+ "mongodb": "^6.0.0"
70
71
  }
71
72
  }