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.
- package/CLAUDE.md +170 -28
- package/README.md +2 -2
- package/package.json +13 -9
- package/packages/cli/dist/bin.js +33126 -30055
- package/packages/cli/src/commands/metrics.ts +17 -11
- package/packages/cli/src/commands/serve.ts +10 -9
- package/packages/core/dist/index.js +33062 -29908
- package/packages/core/src/ai.ts +7 -1
- package/packages/core/src/auth.ts +191 -39
- package/packages/core/src/background.ts +19 -19
- package/packages/core/src/cache.ts +492 -49
- package/packages/core/src/devAdmin.ts +79 -32
- package/packages/core/src/devMailbox.ts +20 -44
- package/packages/core/src/dispatchPipeline.ts +285 -0
- package/packages/core/src/dotenv.ts +185 -40
- package/packages/core/src/index.ts +7 -6
- package/packages/core/src/logger.ts +257 -36
- package/packages/core/src/mcp.ts +1 -1
- package/packages/core/src/messenger.ts +81 -13
- package/packages/core/src/metrics.ts +199 -961
- package/packages/core/src/middleware.ts +390 -123
- package/packages/core/src/queue.ts +188 -32
- package/packages/core/src/queueBackends/kafkaBackend.ts +109 -13
- package/packages/core/src/queueBackends/liteBackend.ts +13 -0
- package/packages/core/src/queueBackends/mongoBackend.ts +101 -9
- package/packages/core/src/queueBackends/rabbitmqBackend.ts +22 -4
- package/packages/core/src/rateLimiter.ts +10 -5
- package/packages/core/src/request.ts +6 -9
- package/packages/core/src/response.ts +46 -1
- package/packages/core/src/router.ts +29 -4
- package/packages/core/src/server.ts +751 -414
- package/packages/core/src/session.ts +244 -27
- package/packages/core/src/sessionHandlers/childError.ts +72 -0
- package/packages/core/src/sessionHandlers/databaseHandler.ts +338 -48
- package/packages/core/src/sessionHandlers/memcachedHandler.ts +181 -0
- package/packages/core/src/sessionHandlers/mongoClient.ts +293 -202
- package/packages/core/src/sessionHandlers/mongoHandler.ts +88 -8
- package/packages/core/src/sessionHandlers/respClient.ts +16 -143
- package/packages/core/src/sessionHandlers/sqlClient.ts +290 -0
- package/packages/core/src/sessionHandlers/syncBridge.ts +190 -0
- package/packages/core/src/sessionHandlers/syncSocket.ts +236 -0
- package/packages/core/src/testClient.ts +18 -5
- package/packages/core/src/trustedProxy.ts +249 -0
- package/packages/core/src/types.ts +29 -5
- package/packages/core/src/websocket.ts +66 -0
- package/packages/frond/dist/index.js +74 -31
- package/packages/frond/src/engine.ts +99 -33
- package/packages/orm/dist/index.js +26554 -23400
- package/packages/orm/src/adapters/firebird.ts +183 -56
- package/packages/orm/src/adapters/mongodb.ts +25 -4
- package/packages/orm/src/adapters/mssql.ts +114 -29
- package/packages/orm/src/adapters/mysql.ts +103 -40
- package/packages/orm/src/adapters/odbc.ts +44 -21
- package/packages/orm/src/adapters/postgres.ts +118 -26
- package/packages/orm/src/adapters/sqlDialect.ts +120 -0
- package/packages/orm/src/adapters/sqlite.ts +64 -25
- package/packages/orm/src/baseModel.ts +135 -40
- package/packages/orm/src/cachedDatabase.ts +43 -19
- package/packages/orm/src/connectTimeout.ts +265 -0
- package/packages/orm/src/database.ts +338 -198
- package/packages/orm/src/databaseResult.ts +65 -13
- package/packages/orm/src/databaseUrl.ts +484 -0
- package/packages/orm/src/docstore.ts +386 -145
- package/packages/orm/src/index.ts +13 -3
- package/packages/orm/src/migration.ts +18 -3
- package/packages/orm/src/queryBuilder.ts +38 -4
- package/packages/orm/src/sqlTranslator.ts +310 -4
- package/packages/orm/src/types.ts +15 -4
- package/types/cli/src/bin.d.ts +92 -0
- package/types/cli/src/commands/build.d.ts +2 -0
- package/types/cli/src/commands/generate.d.ts +47 -0
- package/types/cli/src/commands/init.d.ts +1 -0
- package/types/cli/src/commands/metrics.d.ts +6 -0
- package/types/cli/src/commands/migrate.d.ts +1 -0
- package/types/cli/src/commands/migrateCreate.d.ts +1 -0
- package/types/cli/src/commands/migrateRollback.d.ts +1 -0
- package/types/cli/src/commands/migrateStatus.d.ts +1 -0
- package/types/cli/src/commands/queue.d.ts +20 -0
- package/types/cli/src/commands/routes.d.ts +1 -0
- package/types/cli/src/commands/seed.d.ts +1 -0
- package/types/cli/src/commands/serve.d.ts +6 -0
- package/types/cli/src/commands/test.d.ts +1 -0
- package/types/core/src/ai.d.ts +64 -0
- package/types/core/src/api.d.ts +262 -0
- package/types/core/src/auth.d.ts +177 -0
- package/types/core/src/authGate.d.ts +20 -0
- package/types/core/src/background.d.ts +34 -0
- package/types/core/src/cache.d.ts +163 -0
- package/types/core/src/constants.d.ts +38 -0
- package/types/core/src/container.d.ts +44 -0
- package/types/core/src/context/chunker.d.ts +31 -0
- package/types/core/src/context/index.d.ts +93 -0
- package/types/core/src/devAdmin.d.ts +179 -0
- package/types/core/src/devMailbox.d.ts +54 -0
- package/types/core/src/dispatchPipeline.d.ts +117 -0
- package/types/core/src/docs.d.ts +141 -0
- package/types/core/src/docsAutoDiscovery.d.ts +6 -0
- package/types/core/src/dotenv.d.ts +87 -0
- package/types/core/src/env.d.ts +28 -0
- package/types/core/src/errorOverlay.d.ts +36 -0
- package/types/core/src/events.d.ts +75 -0
- package/types/core/src/fakeData.d.ts +55 -0
- package/types/core/src/feedback.d.ts +90 -0
- package/types/core/src/graphql.d.ts +207 -0
- package/types/core/src/health.d.ts +22 -0
- package/types/core/src/htmlElement.d.ts +75 -0
- package/types/core/src/i18n.d.ts +37 -0
- package/types/core/src/index.d.ts +92 -0
- package/types/core/src/job.d.ts +39 -0
- package/types/core/src/logger.d.ts +200 -0
- package/types/core/src/mcp.d.ts +248 -0
- package/types/core/src/messenger.d.ts +191 -0
- package/types/core/src/metrics.d.ts +41 -0
- package/types/core/src/middleware.d.ts +330 -0
- package/types/core/src/mqtt.d.ts +257 -0
- package/types/core/src/mqttMessage.d.ts +67 -0
- package/types/core/src/plan.d.ts +96 -0
- package/types/core/src/projectIndex.d.ts +56 -0
- package/types/core/src/queue.d.ts +268 -0
- package/types/core/src/queueBackends/kafkaBackend.d.ts +117 -0
- package/types/core/src/queueBackends/liteBackend.d.ts +128 -0
- package/types/core/src/queueBackends/mongoBackend.d.ts +119 -0
- package/types/core/src/queueBackends/rabbitmqBackend.d.ts +55 -0
- package/types/core/src/rateLimiter.d.ts +49 -0
- package/types/core/src/request.d.ts +25 -0
- package/types/core/src/response.d.ts +28 -0
- package/types/core/src/routeDiscovery.d.ts +12 -0
- package/types/core/src/router.d.ts +366 -0
- package/types/core/src/scss.d.ts +19 -0
- package/types/core/src/server.d.ts +146 -0
- package/types/core/src/service.d.ts +115 -0
- package/types/core/src/session.d.ts +341 -0
- package/types/core/src/sessionHandlers/childError.d.ts +34 -0
- package/types/core/src/sessionHandlers/databaseHandler.d.ts +97 -0
- package/types/core/src/sessionHandlers/memcachedHandler.d.ts +60 -0
- package/types/core/src/sessionHandlers/mongoClient.d.ts +35 -0
- package/types/core/src/sessionHandlers/mongoHandler.d.ts +109 -0
- package/types/core/src/sessionHandlers/respClient.d.ts +22 -0
- package/types/core/src/sessionHandlers/sqlClient.d.ts +39 -0
- package/types/core/src/sessionHandlers/syncBridge.d.ts +91 -0
- package/types/core/src/sessionHandlers/syncSocket.d.ts +49 -0
- package/types/core/src/sessionHandlers/valkeyHandler.d.ts +65 -0
- package/types/core/src/static.d.ts +2 -0
- package/types/core/src/test.d.ts +94 -0
- package/types/core/src/testClient.d.ts +36 -0
- package/types/core/src/testing.d.ts +58 -0
- package/types/core/src/trustedProxy.d.ts +44 -0
- package/types/core/src/types.d.ts +242 -0
- package/types/core/src/validator.d.ts +52 -0
- package/types/core/src/websocket.d.ts +402 -0
- package/types/core/src/websocketBackplane.d.ts +166 -0
- package/types/core/src/websocketConnection.d.ts +54 -0
- package/types/core/src/wsdl.d.ts +101 -0
- package/types/frond/src/engine.d.ts +263 -0
- package/types/frond/src/index.d.ts +2 -0
- package/types/orm/src/adapters/firebird.d.ts +183 -0
- package/types/orm/src/adapters/mongodb.d.ts +81 -0
- package/types/orm/src/adapters/mssql.d.ts +77 -0
- package/types/orm/src/adapters/mysql.d.ts +67 -0
- package/types/orm/src/adapters/odbc.d.ts +94 -0
- package/types/orm/src/adapters/postgres.d.ts +86 -0
- package/types/orm/src/adapters/sqlDialect.d.ts +71 -0
- package/types/orm/src/adapters/sqlite.d.ts +68 -0
- package/types/orm/src/autoCrud.d.ts +73 -0
- package/types/orm/src/baseModel.d.ts +427 -0
- package/types/orm/src/cachedDatabase.d.ts +190 -0
- package/types/orm/src/connectTimeout.d.ts +100 -0
- package/types/orm/src/database.d.ts +655 -0
- package/types/orm/src/databaseResult.d.ts +109 -0
- package/types/orm/src/databaseUrl.d.ts +125 -0
- package/types/orm/src/docstore.d.ts +241 -0
- package/types/orm/src/fakeData.d.ts +22 -0
- package/types/orm/src/index.d.ts +43 -0
- package/types/orm/src/migration.d.ts +275 -0
- package/types/orm/src/model.d.ts +7 -0
- package/types/orm/src/query.d.ts +14 -0
- package/types/orm/src/queryBuilder.d.ts +193 -0
- package/types/orm/src/realtime/index.d.ts +7 -0
- package/types/orm/src/realtime/models/attachment.d.ts +43 -0
- package/types/orm/src/realtime/models/channel.d.ts +32 -0
- package/types/orm/src/realtime/models/channelMember.d.ts +32 -0
- package/types/orm/src/realtime/models/message.d.ts +36 -0
- package/types/orm/src/realtime/models/workspace.d.ts +26 -0
- package/types/orm/src/realtime/realtime.d.ts +24 -0
- package/types/orm/src/realtime/storage.d.ts +61 -0
- package/types/orm/src/seeder.d.ts +118 -0
- package/types/orm/src/sqlTranslator.d.ts +258 -0
- package/types/orm/src/types.d.ts +148 -0
- package/types/orm/src/validation.d.ts +6 -0
- package/types/swagger/src/generator.d.ts +46 -0
- package/types/swagger/src/index.d.ts +2 -0
- package/types/swagger/src/ui.d.ts +11 -0
- 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
|
-
}
|