tina4-nodejs 3.13.92 → 3.13.95

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 (193) hide show
  1. package/CLAUDE.md +170 -28
  2. package/README.md +2 -2
  3. package/package.json +13 -9
  4. package/packages/cli/dist/bin.js +33126 -30055
  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 +33062 -29908
  8. package/packages/core/src/ai.ts +7 -1
  9. package/packages/core/src/auth.ts +191 -39
  10. package/packages/core/src/background.ts +19 -19
  11. package/packages/core/src/cache.ts +492 -49
  12. package/packages/core/src/devAdmin.ts +79 -32
  13. package/packages/core/src/devMailbox.ts +20 -44
  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 +7 -6
  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 +81 -13
  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 +109 -13
  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 +6 -9
  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 +751 -414
  32. package/packages/core/src/session.ts +244 -27
  33. package/packages/core/src/sessionHandlers/childError.ts +72 -0
  34. package/packages/core/src/sessionHandlers/databaseHandler.ts +338 -48
  35. package/packages/core/src/sessionHandlers/memcachedHandler.ts +181 -0
  36. package/packages/core/src/sessionHandlers/mongoClient.ts +293 -202
  37. package/packages/core/src/sessionHandlers/mongoHandler.ts +88 -8
  38. package/packages/core/src/sessionHandlers/respClient.ts +16 -143
  39. package/packages/core/src/sessionHandlers/sqlClient.ts +290 -0
  40. package/packages/core/src/sessionHandlers/syncBridge.ts +190 -0
  41. package/packages/core/src/sessionHandlers/syncSocket.ts +236 -0
  42. package/packages/core/src/testClient.ts +18 -5
  43. package/packages/core/src/trustedProxy.ts +249 -0
  44. package/packages/core/src/types.ts +29 -5
  45. package/packages/core/src/websocket.ts +66 -0
  46. package/packages/frond/dist/index.js +74 -31
  47. package/packages/frond/src/engine.ts +99 -33
  48. package/packages/orm/dist/index.js +26554 -23400
  49. package/packages/orm/src/adapters/firebird.ts +183 -56
  50. package/packages/orm/src/adapters/mongodb.ts +25 -4
  51. package/packages/orm/src/adapters/mssql.ts +114 -29
  52. package/packages/orm/src/adapters/mysql.ts +103 -40
  53. package/packages/orm/src/adapters/odbc.ts +44 -21
  54. package/packages/orm/src/adapters/postgres.ts +118 -26
  55. package/packages/orm/src/adapters/sqlDialect.ts +120 -0
  56. package/packages/orm/src/adapters/sqlite.ts +64 -25
  57. package/packages/orm/src/baseModel.ts +135 -40
  58. package/packages/orm/src/cachedDatabase.ts +43 -19
  59. package/packages/orm/src/connectTimeout.ts +265 -0
  60. package/packages/orm/src/database.ts +338 -198
  61. package/packages/orm/src/databaseResult.ts +65 -13
  62. package/packages/orm/src/databaseUrl.ts +484 -0
  63. package/packages/orm/src/docstore.ts +386 -145
  64. package/packages/orm/src/index.ts +13 -3
  65. package/packages/orm/src/migration.ts +18 -3
  66. package/packages/orm/src/queryBuilder.ts +38 -4
  67. package/packages/orm/src/sqlTranslator.ts +310 -4
  68. package/packages/orm/src/types.ts +15 -4
  69. package/types/cli/src/bin.d.ts +92 -0
  70. package/types/cli/src/commands/build.d.ts +2 -0
  71. package/types/cli/src/commands/generate.d.ts +47 -0
  72. package/types/cli/src/commands/init.d.ts +1 -0
  73. package/types/cli/src/commands/metrics.d.ts +6 -0
  74. package/types/cli/src/commands/migrate.d.ts +1 -0
  75. package/types/cli/src/commands/migrateCreate.d.ts +1 -0
  76. package/types/cli/src/commands/migrateRollback.d.ts +1 -0
  77. package/types/cli/src/commands/migrateStatus.d.ts +1 -0
  78. package/types/cli/src/commands/queue.d.ts +20 -0
  79. package/types/cli/src/commands/routes.d.ts +1 -0
  80. package/types/cli/src/commands/seed.d.ts +1 -0
  81. package/types/cli/src/commands/serve.d.ts +6 -0
  82. package/types/cli/src/commands/test.d.ts +1 -0
  83. package/types/core/src/ai.d.ts +64 -0
  84. package/types/core/src/api.d.ts +262 -0
  85. package/types/core/src/auth.d.ts +177 -0
  86. package/types/core/src/authGate.d.ts +20 -0
  87. package/types/core/src/background.d.ts +34 -0
  88. package/types/core/src/cache.d.ts +163 -0
  89. package/types/core/src/constants.d.ts +38 -0
  90. package/types/core/src/container.d.ts +44 -0
  91. package/types/core/src/context/chunker.d.ts +31 -0
  92. package/types/core/src/context/index.d.ts +93 -0
  93. package/types/core/src/devAdmin.d.ts +179 -0
  94. package/types/core/src/devMailbox.d.ts +54 -0
  95. package/types/core/src/dispatchPipeline.d.ts +117 -0
  96. package/types/core/src/docs.d.ts +141 -0
  97. package/types/core/src/docsAutoDiscovery.d.ts +6 -0
  98. package/types/core/src/dotenv.d.ts +87 -0
  99. package/types/core/src/env.d.ts +28 -0
  100. package/types/core/src/errorOverlay.d.ts +36 -0
  101. package/types/core/src/events.d.ts +75 -0
  102. package/types/core/src/fakeData.d.ts +55 -0
  103. package/types/core/src/feedback.d.ts +90 -0
  104. package/types/core/src/graphql.d.ts +207 -0
  105. package/types/core/src/health.d.ts +22 -0
  106. package/types/core/src/htmlElement.d.ts +75 -0
  107. package/types/core/src/i18n.d.ts +37 -0
  108. package/types/core/src/index.d.ts +92 -0
  109. package/types/core/src/job.d.ts +39 -0
  110. package/types/core/src/logger.d.ts +200 -0
  111. package/types/core/src/mcp.d.ts +248 -0
  112. package/types/core/src/messenger.d.ts +191 -0
  113. package/types/core/src/metrics.d.ts +41 -0
  114. package/types/core/src/middleware.d.ts +330 -0
  115. package/types/core/src/mqtt.d.ts +257 -0
  116. package/types/core/src/mqttMessage.d.ts +67 -0
  117. package/types/core/src/plan.d.ts +96 -0
  118. package/types/core/src/projectIndex.d.ts +56 -0
  119. package/types/core/src/queue.d.ts +268 -0
  120. package/types/core/src/queueBackends/kafkaBackend.d.ts +117 -0
  121. package/types/core/src/queueBackends/liteBackend.d.ts +128 -0
  122. package/types/core/src/queueBackends/mongoBackend.d.ts +119 -0
  123. package/types/core/src/queueBackends/rabbitmqBackend.d.ts +55 -0
  124. package/types/core/src/rateLimiter.d.ts +49 -0
  125. package/types/core/src/request.d.ts +25 -0
  126. package/types/core/src/response.d.ts +28 -0
  127. package/types/core/src/routeDiscovery.d.ts +12 -0
  128. package/types/core/src/router.d.ts +366 -0
  129. package/types/core/src/scss.d.ts +19 -0
  130. package/types/core/src/server.d.ts +146 -0
  131. package/types/core/src/service.d.ts +115 -0
  132. package/types/core/src/session.d.ts +341 -0
  133. package/types/core/src/sessionHandlers/childError.d.ts +34 -0
  134. package/types/core/src/sessionHandlers/databaseHandler.d.ts +97 -0
  135. package/types/core/src/sessionHandlers/memcachedHandler.d.ts +60 -0
  136. package/types/core/src/sessionHandlers/mongoClient.d.ts +35 -0
  137. package/types/core/src/sessionHandlers/mongoHandler.d.ts +109 -0
  138. package/types/core/src/sessionHandlers/respClient.d.ts +22 -0
  139. package/types/core/src/sessionHandlers/sqlClient.d.ts +39 -0
  140. package/types/core/src/sessionHandlers/syncBridge.d.ts +91 -0
  141. package/types/core/src/sessionHandlers/syncSocket.d.ts +49 -0
  142. package/types/core/src/sessionHandlers/valkeyHandler.d.ts +65 -0
  143. package/types/core/src/static.d.ts +2 -0
  144. package/types/core/src/test.d.ts +94 -0
  145. package/types/core/src/testClient.d.ts +36 -0
  146. package/types/core/src/testing.d.ts +58 -0
  147. package/types/core/src/trustedProxy.d.ts +44 -0
  148. package/types/core/src/types.d.ts +242 -0
  149. package/types/core/src/validator.d.ts +52 -0
  150. package/types/core/src/websocket.d.ts +402 -0
  151. package/types/core/src/websocketBackplane.d.ts +166 -0
  152. package/types/core/src/websocketConnection.d.ts +54 -0
  153. package/types/core/src/wsdl.d.ts +101 -0
  154. package/types/frond/src/engine.d.ts +263 -0
  155. package/types/frond/src/index.d.ts +2 -0
  156. package/types/orm/src/adapters/firebird.d.ts +183 -0
  157. package/types/orm/src/adapters/mongodb.d.ts +81 -0
  158. package/types/orm/src/adapters/mssql.d.ts +77 -0
  159. package/types/orm/src/adapters/mysql.d.ts +67 -0
  160. package/types/orm/src/adapters/odbc.d.ts +94 -0
  161. package/types/orm/src/adapters/postgres.d.ts +86 -0
  162. package/types/orm/src/adapters/sqlDialect.d.ts +71 -0
  163. package/types/orm/src/adapters/sqlite.d.ts +68 -0
  164. package/types/orm/src/autoCrud.d.ts +73 -0
  165. package/types/orm/src/baseModel.d.ts +427 -0
  166. package/types/orm/src/cachedDatabase.d.ts +190 -0
  167. package/types/orm/src/connectTimeout.d.ts +100 -0
  168. package/types/orm/src/database.d.ts +655 -0
  169. package/types/orm/src/databaseResult.d.ts +109 -0
  170. package/types/orm/src/databaseUrl.d.ts +125 -0
  171. package/types/orm/src/docstore.d.ts +241 -0
  172. package/types/orm/src/fakeData.d.ts +22 -0
  173. package/types/orm/src/index.d.ts +43 -0
  174. package/types/orm/src/migration.d.ts +275 -0
  175. package/types/orm/src/model.d.ts +7 -0
  176. package/types/orm/src/query.d.ts +14 -0
  177. package/types/orm/src/queryBuilder.d.ts +193 -0
  178. package/types/orm/src/realtime/index.d.ts +7 -0
  179. package/types/orm/src/realtime/models/attachment.d.ts +43 -0
  180. package/types/orm/src/realtime/models/channel.d.ts +32 -0
  181. package/types/orm/src/realtime/models/channelMember.d.ts +32 -0
  182. package/types/orm/src/realtime/models/message.d.ts +36 -0
  183. package/types/orm/src/realtime/models/workspace.d.ts +26 -0
  184. package/types/orm/src/realtime/realtime.d.ts +24 -0
  185. package/types/orm/src/realtime/storage.d.ts +61 -0
  186. package/types/orm/src/seeder.d.ts +118 -0
  187. package/types/orm/src/sqlTranslator.d.ts +258 -0
  188. package/types/orm/src/types.d.ts +148 -0
  189. package/types/orm/src/validation.d.ts +6 -0
  190. package/types/swagger/src/generator.d.ts +46 -0
  191. package/types/swagger/src/index.d.ts +2 -0
  192. package/types/swagger/src/ui.d.ts +11 -0
  193. package/packages/core/src/sessionHandlers/redisHandler.ts +0 -206
@@ -1,206 +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 { createRequire } from "node:module";
21
- import type { SessionHandler } from "../session.js";
22
- import { respCommandSync } from "./respClient.js";
23
-
24
- // Resolve packages relative to this module so the optional `redis` driver is
25
- // detected exactly as a consumer would resolve it (createRequire works in ESM).
26
- const moduleRequire = createRequire(import.meta.url);
27
- function redisDriverAvailable(): boolean {
28
- try {
29
- moduleRequire.resolve("redis");
30
- return true;
31
- } catch {
32
- return false;
33
- }
34
- }
35
-
36
- interface SessionData {
37
- _created: number;
38
- _accessed: number;
39
- [key: string]: unknown;
40
- }
41
-
42
- export interface RedisNpmSessionConfig {
43
- host?: string;
44
- port?: number;
45
- url?: string;
46
- password?: string;
47
- prefix?: string;
48
- db?: number;
49
- // Unified SessionConfig fields are tolerated (and ignored) so the central
50
- // Session can forward its config object without a structural mismatch.
51
- backend?: string;
52
- path?: string;
53
- ttl?: number;
54
- redisHost?: string;
55
- redisPort?: number;
56
- redisPassword?: string;
57
- redisPrefix?: string;
58
- redisDb?: number;
59
- }
60
-
61
- /**
62
- * Redis session handler using the `redis` npm package.
63
- *
64
- * Falls back to raw TCP (RESP protocol) if the `redis` package is not
65
- * installed, matching the approach used by the Valkey handler.
66
- *
67
- * Stores session data as JSON strings with Redis TTL for automatic expiry.
68
- */
69
- export class RedisNpmSessionHandler implements SessionHandler {
70
- private host: string;
71
- private port: number;
72
- private url: string;
73
- private password: string;
74
- private prefix: string;
75
- private db: number;
76
-
77
- constructor(config?: RedisNpmSessionConfig) {
78
- this.url = config?.url
79
- ?? process.env.TINA4_SESSION_REDIS_URL
80
- ?? "";
81
- this.host = config?.host
82
- ?? process.env.TINA4_SESSION_REDIS_HOST
83
- ?? "127.0.0.1";
84
- this.port = config?.port
85
- ?? (process.env.TINA4_SESSION_REDIS_PORT
86
- ? parseInt(process.env.TINA4_SESSION_REDIS_PORT, 10)
87
- : 6379);
88
- this.password = config?.password
89
- ?? process.env.TINA4_SESSION_REDIS_PASSWORD
90
- ?? "";
91
- this.prefix = config?.prefix
92
- ?? process.env.TINA4_SESSION_REDIS_PREFIX
93
- ?? "tina4:session:";
94
- this.db = config?.db
95
- ?? (process.env.TINA4_SESSION_REDIS_DB
96
- ? parseInt(process.env.TINA4_SESSION_REDIS_DB, 10)
97
- : 0);
98
- }
99
-
100
- /** Resolve a host/port for the raw-RESP path (parses TINA4_SESSION_REDIS_URL if set). */
101
- private resolveHostPort(): { host: string; port: number } {
102
- if (this.url) {
103
- try {
104
- const u = new URL(this.url);
105
- return { host: u.hostname || "127.0.0.1", port: parseInt(u.port, 10) || 6379 };
106
- } catch {
107
- return { host: this.host, port: this.port };
108
- }
109
- }
110
- return { host: this.host, port: this.port };
111
- }
112
-
113
- /**
114
- * Execute a Redis command synchronously.
115
- *
116
- * Prefers the official `redis` driver when it is installed (the class's reason
117
- * to exist); otherwise speaks raw RESP via the shared {@link respCommandSync}
118
- * transport — same correct path as the Valkey handler, no `redis` dependency.
119
- *
120
- * A genuine key miss yields `""`; a transport/connection FAILURE (server
121
- * unreachable, rejected AUTH, timeout) THROWS so the Session boundary can
122
- * distinguish "not found" (silent) from "backend failed" (log-loud + degrade).
123
- */
124
- private execSync(args: string[]): string {
125
- if (redisDriverAvailable()) {
126
- return this.execViaNpm(args);
127
- }
128
- const { host, port } = this.resolveHostPort();
129
- return respCommandSync({ host, port, password: this.password, db: this.db }, args, "Redis");
130
- }
131
-
132
- /** Drive the command through the `redis` npm client in a short-lived child. */
133
- private execViaNpm(args: string[]): string {
134
- const script = `
135
- const useUrl = ${JSON.stringify(!!this.url)};
136
- const url = ${JSON.stringify(this.url)};
137
- const host = ${JSON.stringify(this.host)};
138
- const port = ${this.port};
139
- const password = ${JSON.stringify(this.password)};
140
- const db = ${this.db};
141
- const args = ${JSON.stringify(args)};
142
- (async () => {
143
- try {
144
- const redis = require("redis");
145
- const clientOpts = useUrl
146
- ? { url }
147
- : { socket: { host, port }, password: password || undefined, database: db };
148
- const client = redis.createClient(clientOpts);
149
- client.on("error", () => {});
150
- await client.connect();
151
- const cmd = args[0].toUpperCase();
152
- let result;
153
- if (cmd === "GET") result = await client.get(args[1]);
154
- else if (cmd === "SET") result = await client.set(args[1], args[2]);
155
- else if (cmd === "SETEX") result = await client.setEx(args[1], parseInt(args[2], 10), args[3]);
156
- else if (cmd === "DEL") result = await client.del(args[1]);
157
- await client.quit();
158
- const out = (result === null || result === undefined) ? "__NULL__" : String(result);
159
- process.stdout.write(out, () => process.exit(0));
160
- } catch (err) {
161
- process.stderr.write(String((err && err.message) || err));
162
- process.exit(1);
163
- }
164
- })();
165
- `;
166
- let result: string;
167
- try {
168
- result = execFileSync(process.execPath, ["-e", script], {
169
- encoding: "utf-8",
170
- timeout: 5000,
171
- stdio: ["pipe", "pipe", "pipe"],
172
- });
173
- } catch (err) {
174
- throw new Error(`Redis command failed: ${(err as Error).message}`);
175
- }
176
- if (result === "__NULL__") return ""; // genuine key miss
177
- return result;
178
- }
179
-
180
- private key(sessionId: string): string {
181
- return `${this.prefix}${sessionId}`;
182
- }
183
-
184
- read(sessionId: string): SessionData | null {
185
- const raw = this.execSync(["GET", this.key(sessionId)]);
186
- if (!raw) return null; // key miss — normal "no session yet", NOT an error
187
- try {
188
- return JSON.parse(raw) as SessionData;
189
- } catch {
190
- return null;
191
- }
192
- }
193
-
194
- write(sessionId: string, data: SessionData, ttl: number): void {
195
- const json = JSON.stringify(data);
196
- if (ttl > 0) {
197
- this.execSync(["SETEX", this.key(sessionId), String(ttl), json]);
198
- } else {
199
- this.execSync(["SET", this.key(sessionId), json]);
200
- }
201
- }
202
-
203
- destroy(sessionId: string): void {
204
- this.execSync(["DEL", this.key(sessionId)]);
205
- }
206
- }