tina4-nodejs 3.13.94 → 3.13.96

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 (123) hide show
  1. package/CLAUDE.md +158 -30
  2. package/README.md +1 -1
  3. package/package.json +3 -1
  4. package/packages/cli/dist/bin.js +30911 -28444
  5. package/packages/cli/src/commands/metrics.ts +17 -11
  6. package/packages/cli/src/commands/serve.ts +10 -9
  7. package/packages/core/dist/index.js +30810 -28261
  8. package/packages/core/public/css/tina4.min.css +1 -1
  9. package/packages/core/src/ai.ts +7 -1
  10. package/packages/core/src/auth.ts +191 -39
  11. package/packages/core/src/background.ts +19 -19
  12. package/packages/core/src/cache.ts +492 -49
  13. package/packages/core/src/devAdmin.ts +79 -32
  14. package/packages/core/src/dispatchPipeline.ts +285 -0
  15. package/packages/core/src/dotenv.ts +185 -40
  16. package/packages/core/src/index.ts +6 -7
  17. package/packages/core/src/logger.ts +257 -36
  18. package/packages/core/src/mcp.ts +1 -1
  19. package/packages/core/src/messenger.ts +294 -106
  20. package/packages/core/src/metrics.ts +199 -961
  21. package/packages/core/src/middleware.ts +390 -123
  22. package/packages/core/src/queue.ts +188 -32
  23. package/packages/core/src/queueBackends/kafkaBackend.ts +1 -1
  24. package/packages/core/src/queueBackends/liteBackend.ts +13 -0
  25. package/packages/core/src/queueBackends/mongoBackend.ts +101 -9
  26. package/packages/core/src/queueBackends/rabbitmqBackend.ts +22 -4
  27. package/packages/core/src/rateLimiter.ts +10 -5
  28. package/packages/core/src/request.ts +34 -16
  29. package/packages/core/src/response.ts +46 -1
  30. package/packages/core/src/router.ts +29 -4
  31. package/packages/core/src/server.ts +886 -421
  32. package/packages/core/src/session.ts +244 -27
  33. package/packages/core/src/sessionHandlers/databaseHandler.ts +338 -48
  34. package/packages/core/src/sessionHandlers/memcachedHandler.ts +181 -0
  35. package/packages/core/src/sessionHandlers/mongoClient.ts +293 -208
  36. package/packages/core/src/sessionHandlers/mongoHandler.ts +88 -8
  37. package/packages/core/src/sessionHandlers/respClient.ts +16 -147
  38. package/packages/core/src/sessionHandlers/sqlClient.ts +290 -0
  39. package/packages/core/src/sessionHandlers/syncBridge.ts +190 -0
  40. package/packages/core/src/sessionHandlers/syncSocket.ts +236 -0
  41. package/packages/core/src/testClient.ts +18 -5
  42. package/packages/core/src/trustedProxy.ts +249 -0
  43. package/packages/core/src/types.ts +29 -5
  44. package/packages/core/src/websocket.ts +66 -0
  45. package/packages/orm/dist/index.js +22717 -20168
  46. package/packages/orm/src/adapters/firebird.ts +183 -56
  47. package/packages/orm/src/adapters/mongodb.ts +25 -4
  48. package/packages/orm/src/adapters/mssql.ts +114 -29
  49. package/packages/orm/src/adapters/mysql.ts +103 -40
  50. package/packages/orm/src/adapters/odbc.ts +44 -21
  51. package/packages/orm/src/adapters/postgres.ts +118 -26
  52. package/packages/orm/src/adapters/sqlDialect.ts +120 -0
  53. package/packages/orm/src/adapters/sqlite.ts +60 -24
  54. package/packages/orm/src/autoCrud.ts +12 -10
  55. package/packages/orm/src/baseModel.ts +135 -40
  56. package/packages/orm/src/cachedDatabase.ts +43 -19
  57. package/packages/orm/src/connectTimeout.ts +265 -0
  58. package/packages/orm/src/database.ts +241 -197
  59. package/packages/orm/src/databaseResult.ts +51 -28
  60. package/packages/orm/src/databaseUrl.ts +484 -0
  61. package/packages/orm/src/docstore.ts +386 -145
  62. package/packages/orm/src/index.ts +13 -6
  63. package/packages/orm/src/migration.ts +44 -11
  64. package/packages/orm/src/model.ts +4 -0
  65. package/packages/orm/src/queryBuilder.ts +47 -6
  66. package/packages/orm/src/sqlTranslator.ts +310 -4
  67. package/packages/orm/src/types.ts +21 -77
  68. package/packages/swagger/dist/index.js +78 -20
  69. package/packages/swagger/src/generator.ts +172 -29
  70. package/types/core/src/ai.d.ts +1 -1
  71. package/types/core/src/auth.d.ts +28 -5
  72. package/types/core/src/background.d.ts +3 -3
  73. package/types/core/src/cache.d.ts +15 -12
  74. package/types/core/src/dispatchPipeline.d.ts +117 -0
  75. package/types/core/src/dotenv.d.ts +38 -16
  76. package/types/core/src/index.d.ts +6 -9
  77. package/types/core/src/logger.d.ts +93 -16
  78. package/types/core/src/messenger.d.ts +47 -6
  79. package/types/core/src/metrics.d.ts +25 -61
  80. package/types/core/src/middleware.d.ts +134 -11
  81. package/types/core/src/queue.d.ts +54 -5
  82. package/types/core/src/queueBackends/kafkaBackend.d.ts +1 -1
  83. package/types/core/src/queueBackends/liteBackend.d.ts +9 -0
  84. package/types/core/src/queueBackends/mongoBackend.d.ts +24 -2
  85. package/types/core/src/queueBackends/rabbitmqBackend.d.ts +3 -3
  86. package/types/core/src/router.d.ts +14 -3
  87. package/types/core/src/server.d.ts +15 -4
  88. package/types/core/src/session.d.ts +87 -2
  89. package/types/core/src/sessionHandlers/databaseHandler.d.ts +60 -5
  90. package/types/core/src/sessionHandlers/memcachedHandler.d.ts +60 -0
  91. package/types/core/src/sessionHandlers/mongoClient.d.ts +16 -5
  92. package/types/core/src/sessionHandlers/mongoHandler.d.ts +51 -3
  93. package/types/core/src/sessionHandlers/respClient.d.ts +2 -2
  94. package/types/core/src/sessionHandlers/sqlClient.d.ts +39 -0
  95. package/types/core/src/sessionHandlers/syncBridge.d.ts +91 -0
  96. package/types/core/src/sessionHandlers/syncSocket.d.ts +49 -0
  97. package/types/core/src/trustedProxy.d.ts +44 -0
  98. package/types/core/src/types.d.ts +28 -5
  99. package/types/core/src/websocket.d.ts +26 -0
  100. package/types/orm/src/adapters/firebird.d.ts +55 -10
  101. package/types/orm/src/adapters/mongodb.d.ts +2 -2
  102. package/types/orm/src/adapters/mssql.d.ts +18 -11
  103. package/types/orm/src/adapters/mysql.d.ts +11 -10
  104. package/types/orm/src/adapters/odbc.d.ts +9 -12
  105. package/types/orm/src/adapters/postgres.d.ts +11 -10
  106. package/types/orm/src/adapters/sqlDialect.d.ts +71 -0
  107. package/types/orm/src/adapters/sqlite.d.ts +15 -3
  108. package/types/orm/src/baseModel.d.ts +45 -9
  109. package/types/orm/src/cachedDatabase.d.ts +18 -5
  110. package/types/orm/src/connectTimeout.d.ts +100 -0
  111. package/types/orm/src/database.d.ts +78 -28
  112. package/types/orm/src/databaseResult.d.ts +29 -15
  113. package/types/orm/src/databaseUrl.d.ts +125 -0
  114. package/types/orm/src/docstore.d.ts +102 -43
  115. package/types/orm/src/index.d.ts +6 -4
  116. package/types/orm/src/migration.d.ts +4 -3
  117. package/types/orm/src/queryBuilder.d.ts +23 -3
  118. package/types/orm/src/sqlTranslator.d.ts +126 -2
  119. package/types/orm/src/types.d.ts +21 -38
  120. package/packages/core/src/scss.ts +0 -623
  121. package/packages/core/src/sessionHandlers/redisHandler.ts +0 -219
  122. package/types/core/src/scss.d.ts +0 -19
  123. package/types/core/src/sessionHandlers/redisHandler.d.ts +0 -60
@@ -1,219 +0,0 @@
1
- /**
2
- * Tina4 Redis Session Handler — Redis via `redis` npm package (optional dependency).
3
- *
4
- * Provides a session handler backed by the official `redis` npm package,
5
- * complementing the built-in raw-TCP RedisSessionHandler in session.ts.
6
- *
7
- * This handler uses synchronous child-process execution (same pattern as
8
- * valkeyHandler.ts) so it fits the synchronous SessionHandler interface
9
- * without requiring async refactoring.
10
- *
11
- * Configure via environment variables:
12
- * TINA4_SESSION_REDIS_HOST (default: "127.0.0.1")
13
- * TINA4_SESSION_REDIS_PORT (default: 6379)
14
- * TINA4_SESSION_REDIS_URL (optional — full redis:// URL, overrides host/port)
15
- * TINA4_SESSION_REDIS_PASSWORD (optional)
16
- * TINA4_SESSION_REDIS_PREFIX (default: "tina4:session:")
17
- * TINA4_SESSION_REDIS_DB (default: 0)
18
- */
19
- import { execFileSync } from "node:child_process";
20
- import { childFailureError } from "./childError.js";
21
- import { createRequire } from "node:module";
22
- import type { SessionHandler } from "../session.js";
23
- import { respCommandSync } from "./respClient.js";
24
-
25
- // Resolve packages relative to this module so the optional `redis` driver is
26
- // detected exactly as a consumer would resolve it (createRequire works in ESM).
27
- const moduleRequire = createRequire(import.meta.url);
28
- function redisDriverAvailable(): boolean {
29
- try {
30
- moduleRequire.resolve("redis");
31
- return true;
32
- } catch {
33
- return false;
34
- }
35
- }
36
-
37
- interface SessionData {
38
- _created: number;
39
- _accessed: number;
40
- [key: string]: unknown;
41
- }
42
-
43
- export interface RedisNpmSessionConfig {
44
- host?: string;
45
- port?: number;
46
- url?: string;
47
- password?: string;
48
- prefix?: string;
49
- db?: number;
50
- // Unified SessionConfig fields are tolerated (and ignored) so the central
51
- // Session can forward its config object without a structural mismatch.
52
- backend?: string;
53
- path?: string;
54
- ttl?: number;
55
- redisHost?: string;
56
- redisPort?: number;
57
- redisPassword?: string;
58
- redisPrefix?: string;
59
- redisDb?: number;
60
- }
61
-
62
- /**
63
- * Redis session handler using the `redis` npm package.
64
- *
65
- * Falls back to raw TCP (RESP protocol) if the `redis` package is not
66
- * installed, matching the approach used by the Valkey handler.
67
- *
68
- * Stores session data as JSON strings with Redis TTL for automatic expiry.
69
- */
70
- export class RedisNpmSessionHandler implements SessionHandler {
71
- private host: string;
72
- private port: number;
73
- private url: string;
74
- private password: string;
75
- private prefix: string;
76
- private db: number;
77
-
78
- constructor(config?: RedisNpmSessionConfig) {
79
- this.url = config?.url
80
- ?? process.env.TINA4_SESSION_REDIS_URL
81
- ?? "";
82
- this.host = config?.host
83
- ?? process.env.TINA4_SESSION_REDIS_HOST
84
- ?? "127.0.0.1";
85
- this.port = config?.port
86
- ?? (process.env.TINA4_SESSION_REDIS_PORT
87
- ? parseInt(process.env.TINA4_SESSION_REDIS_PORT, 10)
88
- : 6379);
89
- this.password = config?.password
90
- ?? process.env.TINA4_SESSION_REDIS_PASSWORD
91
- ?? "";
92
- this.prefix = config?.prefix
93
- ?? process.env.TINA4_SESSION_REDIS_PREFIX
94
- ?? "tina4:session:";
95
- this.db = config?.db
96
- ?? (process.env.TINA4_SESSION_REDIS_DB
97
- ? parseInt(process.env.TINA4_SESSION_REDIS_DB, 10)
98
- : 0);
99
- }
100
-
101
- /** Resolve a host/port for the raw-RESP path (parses TINA4_SESSION_REDIS_URL if set). */
102
- private resolveHostPort(): { host: string; port: number } {
103
- if (this.url) {
104
- try {
105
- const u = new URL(this.url);
106
- return { host: u.hostname || "127.0.0.1", port: parseInt(u.port, 10) || 6379 };
107
- } catch {
108
- return { host: this.host, port: this.port };
109
- }
110
- }
111
- return { host: this.host, port: this.port };
112
- }
113
-
114
- /**
115
- * Execute a Redis command synchronously.
116
- *
117
- * Prefers the official `redis` driver when it is installed (the class's reason
118
- * to exist); otherwise speaks raw RESP via the shared {@link respCommandSync}
119
- * transport — same correct path as the Valkey handler, no `redis` dependency.
120
- *
121
- * A genuine key miss yields `""`; a transport/connection FAILURE (server
122
- * unreachable, rejected AUTH, timeout) THROWS so the Session boundary can
123
- * distinguish "not found" (silent) from "backend failed" (log-loud + degrade).
124
- */
125
- private execSync(args: string[]): string {
126
- if (redisDriverAvailable()) {
127
- return this.execViaNpm(args);
128
- }
129
- const { host, port } = this.resolveHostPort();
130
- return respCommandSync({ host, port, password: this.password, db: this.db }, args, "Redis");
131
- }
132
-
133
- /** Drive the command through the `redis` npm client in a short-lived child. */
134
- private execViaNpm(args: string[]): string {
135
- const script = `
136
- const useUrl = ${JSON.stringify(!!this.url)};
137
- const url = ${JSON.stringify(this.url)};
138
- const host = ${JSON.stringify(this.host)};
139
- const port = ${this.port};
140
- const password = ${JSON.stringify(this.password)};
141
- const db = ${this.db};
142
- const args = ${JSON.stringify(args)};
143
- (async () => {
144
- try {
145
- const redis = require("redis");
146
- // reconnectStrategy: false — this child runs ONE command and exits, so
147
- // retrying inside it is pointless: the handler is called again on the
148
- // next request anyway. With the driver's default strategy a refused
149
- // connection never rejects, the child hangs until execFileSync's 5s
150
- // timeout kills it, and the caller is told "timed out" when the truth
151
- // is "connection refused". Off, connect() rejects in ~5ms with the real
152
- // reason -- a better message AND no 5s stall per request when Redis is
153
- // down.
154
- const clientOpts = useUrl
155
- ? { url, socket: { reconnectStrategy: false } }
156
- : { socket: { host, port, reconnectStrategy: false }, password: password || undefined, database: db };
157
- const client = redis.createClient(clientOpts);
158
- client.on("error", () => {});
159
- await client.connect();
160
- const cmd = args[0].toUpperCase();
161
- let result;
162
- if (cmd === "GET") result = await client.get(args[1]);
163
- else if (cmd === "SET") result = await client.set(args[1], args[2]);
164
- else if (cmd === "SETEX") result = await client.setEx(args[1], parseInt(args[2], 10), args[3]);
165
- else if (cmd === "DEL") result = await client.del(args[1]);
166
- await client.quit();
167
- const out = (result === null || result === undefined) ? "__NULL__" : String(result);
168
- process.stdout.write(out, () => process.exit(0));
169
- } catch (err) {
170
- // Exit from the write CALLBACK: stderr to a pipe is an async write and
171
- // a bare process.exit() truncates it, which left the parent with an
172
- // empty stderr and nothing but execFileSync's script-dump message.
173
- process.stderr.write(String((err && err.message) || err), () => process.exit(1));
174
- }
175
- })();
176
- `;
177
- let result: string;
178
- try {
179
- result = execFileSync(process.execPath, ["-e", script], {
180
- encoding: "utf-8",
181
- timeout: 5000,
182
- stdio: ["pipe", "pipe", "pipe"],
183
- });
184
- } catch (err) {
185
- // The child's stderr carries the driver's real reason; execFileSync's
186
- // message carries the whole generated script. Prefer the former.
187
- throw childFailureError("Redis", err);
188
- }
189
- if (result === "__NULL__") return ""; // genuine key miss
190
- return result;
191
- }
192
-
193
- private key(sessionId: string): string {
194
- return `${this.prefix}${sessionId}`;
195
- }
196
-
197
- read(sessionId: string): SessionData | null {
198
- const raw = this.execSync(["GET", this.key(sessionId)]);
199
- if (!raw) return null; // key miss — normal "no session yet", NOT an error
200
- try {
201
- return JSON.parse(raw) as SessionData;
202
- } catch {
203
- return null;
204
- }
205
- }
206
-
207
- write(sessionId: string, data: SessionData, ttl: number): void {
208
- const json = JSON.stringify(data);
209
- if (ttl > 0) {
210
- this.execSync(["SETEX", this.key(sessionId), String(ttl), json]);
211
- } else {
212
- this.execSync(["SET", this.key(sessionId), json]);
213
- }
214
- }
215
-
216
- destroy(sessionId: string): void {
217
- this.execSync(["DEL", this.key(sessionId)]);
218
- }
219
- }
@@ -1,19 +0,0 @@
1
- export interface ScssConfig {
2
- importPaths?: string[];
3
- variables?: Record<string, string>;
4
- }
5
- export declare class ScssCompiler {
6
- private _importPaths;
7
- private _variables;
8
- constructor(config?: ScssConfig);
9
- /** Compile an SCSS string to CSS. */
10
- compile(source: string): string;
11
- /** Compile an SCSS file to CSS. */
12
- compileFile(filePath: string): string;
13
- /** Add a directory to the import resolution path. */
14
- addImportPath(path: string): void;
15
- /** Set or override an SCSS variable. */
16
- setVariable(name: string, value: string): void;
17
- /** Compile all .scss files in a directory into a single CSS output file. */
18
- compileScss(scssDir?: string, output?: string, minify?: boolean): string;
19
- }
@@ -1,60 +0,0 @@
1
- import type { SessionHandler } from "../session.js";
2
- interface SessionData {
3
- _created: number;
4
- _accessed: number;
5
- [key: string]: unknown;
6
- }
7
- export interface RedisNpmSessionConfig {
8
- host?: string;
9
- port?: number;
10
- url?: string;
11
- password?: string;
12
- prefix?: string;
13
- db?: number;
14
- backend?: string;
15
- path?: string;
16
- ttl?: number;
17
- redisHost?: string;
18
- redisPort?: number;
19
- redisPassword?: string;
20
- redisPrefix?: string;
21
- redisDb?: number;
22
- }
23
- /**
24
- * Redis session handler using the `redis` npm package.
25
- *
26
- * Falls back to raw TCP (RESP protocol) if the `redis` package is not
27
- * installed, matching the approach used by the Valkey handler.
28
- *
29
- * Stores session data as JSON strings with Redis TTL for automatic expiry.
30
- */
31
- export declare class RedisNpmSessionHandler implements SessionHandler {
32
- private host;
33
- private port;
34
- private url;
35
- private password;
36
- private prefix;
37
- private db;
38
- constructor(config?: RedisNpmSessionConfig);
39
- /** Resolve a host/port for the raw-RESP path (parses TINA4_SESSION_REDIS_URL if set). */
40
- private resolveHostPort;
41
- /**
42
- * Execute a Redis command synchronously.
43
- *
44
- * Prefers the official `redis` driver when it is installed (the class's reason
45
- * to exist); otherwise speaks raw RESP via the shared {@link respCommandSync}
46
- * transport — same correct path as the Valkey handler, no `redis` dependency.
47
- *
48
- * A genuine key miss yields `""`; a transport/connection FAILURE (server
49
- * unreachable, rejected AUTH, timeout) THROWS so the Session boundary can
50
- * distinguish "not found" (silent) from "backend failed" (log-loud + degrade).
51
- */
52
- private execSync;
53
- /** Drive the command through the `redis` npm client in a short-lived child. */
54
- private execViaNpm;
55
- private key;
56
- read(sessionId: string): SessionData | null;
57
- write(sessionId: string, data: SessionData, ttl: number): void;
58
- destroy(sessionId: string): void;
59
- }
60
- export {};