tina4-nodejs 3.13.21 → 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.21)
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.21 — 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
 
@@ -589,8 +589,15 @@ db.getColumns(table): { name, type, nullable?, default?, primaryKey? }[]
589
589
  // auto-creates Postgres sequences, and uses native Firebird generators.
590
590
  db.getNextId(table, pkColumn?, generatorName?): number
591
591
 
592
- // Query cache (TINA4_DB_CACHE=true)
593
- db.cacheStats(): { enabled, size, ttl }
592
+ // DB query cache — request-scoped auto cache is ON by default (TINA4_AUTO_CACHING=true,
593
+ // TTL TINA4_AUTO_CACHING_TTL=5s): dedupes identical db.fetch()/ORM reads within a request,
594
+ // flushed on any write. Persistent cross-request cache opt-in via TINA4_DB_CACHE=true
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).
600
+ db.cacheStats(): { enabled, size, ttl, mode } // mode: "request" | "persistent" | "off"
594
601
  db.cacheClear(): void
595
602
 
596
603
  // Connection pool access (null when pooling disabled)
@@ -879,7 +886,7 @@ container.reset(); // clear all registrations + cached instances
879
886
 
880
887
  ## Module: Response Cache (`packages/core/src/cache.ts`)
881
888
 
882
- 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`.
883
890
 
884
891
  ```typescript
885
892
  import {
@@ -889,20 +896,27 @@ import {
889
896
  // Middleware on a route
890
897
  get("/api/products", listProducts).middleware(responseCache({ ttl: 60 }));
891
898
 
892
- // Direct key/value usage (same shape across all four frameworks)
893
- cacheSet("user:1", { name: "Alice" }, 120);
894
- const u = cacheGet("user:1");
895
- cacheDelete("user:1");
896
- 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();
897
905
 
898
- cacheStats(); // { hits, misses, size, backend }
906
+ await cacheStats(); // { hits, misses, size, backend } — reflects the real KV backend
899
907
  ```
900
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
+
901
913
  Environment:
902
- - `TINA4_CACHE_BACKEND` — `memory` | `redis` | `file` (default: `memory`)
903
- - `TINA4_CACHE_URL` — `redis://localhost:6379` (redis backend only)
904
- - `TINA4_CACHE_TTL` — default TTL seconds (default: `0` = disabled)
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
917
+ - `TINA4_CACHE_TTL` — default TTL seconds (default: `60`)
905
918
  - `TINA4_CACHE_MAX_ENTRIES` — max entries (default: `1000`)
919
+ - `TINA4_CACHE_DIR` — directory for the `file` backend (default: `data/cache`)
906
920
 
907
921
  ## Firebird-Specific Rules
908
922
 
@@ -1098,12 +1112,13 @@ When adding new features, add a corresponding `test/<feature>.test.ts` file.
1098
1112
  ## v3 Features Summary
1099
1113
 
1100
1114
  - **45 built-in features**, zero third-party dependencies
1101
- - **3,684 tests** passing across all modules
1115
+ - **3,787 tests** passing across all modules
1102
1116
  - **Race-safe `getNextId()`** with atomic sequence table (`tina4_sequences`) for SQLite/MySQL/MSSQL; PostgreSQL auto-creates sequences
1103
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)
1104
1118
  - **Production server auto-detect**: `npx tina4nodejs serve --production` auto-uses cluster mode
1105
1119
  - **`npx tina4nodejs generate`**: model, route, migration, middleware scaffolding
1106
- - **Database**: 5 engines (SQLite, PostgreSQL, MySQL, MSSQL, Firebird), query caching (`TINA4_DB_CACHE=true`)
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
1107
1122
  - **Sessions**: file backend (default). `TINA4_SESSION_SAMESITE` env var (default: Lax)
1108
1123
  - **Queue**: file/RabbitMQ/Kafka/MongoDB backends, configured via env vars
1109
1124
  - **Cache**: memory/Redis/file backends
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
 
5
5
 
6
- "version": "3.13.21",
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
  }