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.
- package/CLAUDE.md +158 -30
- package/README.md +1 -1
- package/package.json +3 -1
- package/packages/cli/dist/bin.js +30911 -28444
- package/packages/cli/src/commands/metrics.ts +17 -11
- package/packages/cli/src/commands/serve.ts +10 -9
- package/packages/core/dist/index.js +30810 -28261
- package/packages/core/public/css/tina4.min.css +1 -1
- 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/dispatchPipeline.ts +285 -0
- package/packages/core/src/dotenv.ts +185 -40
- package/packages/core/src/index.ts +6 -7
- package/packages/core/src/logger.ts +257 -36
- package/packages/core/src/mcp.ts +1 -1
- package/packages/core/src/messenger.ts +294 -106
- 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 +1 -1
- 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 +34 -16
- package/packages/core/src/response.ts +46 -1
- package/packages/core/src/router.ts +29 -4
- package/packages/core/src/server.ts +886 -421
- package/packages/core/src/session.ts +244 -27
- 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 -208
- package/packages/core/src/sessionHandlers/mongoHandler.ts +88 -8
- package/packages/core/src/sessionHandlers/respClient.ts +16 -147
- 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/orm/dist/index.js +22717 -20168
- 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 +60 -24
- package/packages/orm/src/autoCrud.ts +12 -10
- 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 +241 -197
- package/packages/orm/src/databaseResult.ts +51 -28
- package/packages/orm/src/databaseUrl.ts +484 -0
- package/packages/orm/src/docstore.ts +386 -145
- package/packages/orm/src/index.ts +13 -6
- package/packages/orm/src/migration.ts +44 -11
- package/packages/orm/src/model.ts +4 -0
- package/packages/orm/src/queryBuilder.ts +47 -6
- package/packages/orm/src/sqlTranslator.ts +310 -4
- package/packages/orm/src/types.ts +21 -77
- package/packages/swagger/dist/index.js +78 -20
- package/packages/swagger/src/generator.ts +172 -29
- package/types/core/src/ai.d.ts +1 -1
- package/types/core/src/auth.d.ts +28 -5
- package/types/core/src/background.d.ts +3 -3
- package/types/core/src/cache.d.ts +15 -12
- package/types/core/src/dispatchPipeline.d.ts +117 -0
- package/types/core/src/dotenv.d.ts +38 -16
- package/types/core/src/index.d.ts +6 -9
- package/types/core/src/logger.d.ts +93 -16
- package/types/core/src/messenger.d.ts +47 -6
- package/types/core/src/metrics.d.ts +25 -61
- package/types/core/src/middleware.d.ts +134 -11
- package/types/core/src/queue.d.ts +54 -5
- package/types/core/src/queueBackends/kafkaBackend.d.ts +1 -1
- package/types/core/src/queueBackends/liteBackend.d.ts +9 -0
- package/types/core/src/queueBackends/mongoBackend.d.ts +24 -2
- package/types/core/src/queueBackends/rabbitmqBackend.d.ts +3 -3
- package/types/core/src/router.d.ts +14 -3
- package/types/core/src/server.d.ts +15 -4
- package/types/core/src/session.d.ts +87 -2
- package/types/core/src/sessionHandlers/databaseHandler.d.ts +60 -5
- package/types/core/src/sessionHandlers/memcachedHandler.d.ts +60 -0
- package/types/core/src/sessionHandlers/mongoClient.d.ts +16 -5
- package/types/core/src/sessionHandlers/mongoHandler.d.ts +51 -3
- package/types/core/src/sessionHandlers/respClient.d.ts +2 -2
- 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/trustedProxy.d.ts +44 -0
- package/types/core/src/types.d.ts +28 -5
- package/types/core/src/websocket.d.ts +26 -0
- package/types/orm/src/adapters/firebird.d.ts +55 -10
- package/types/orm/src/adapters/mongodb.d.ts +2 -2
- package/types/orm/src/adapters/mssql.d.ts +18 -11
- package/types/orm/src/adapters/mysql.d.ts +11 -10
- package/types/orm/src/adapters/odbc.d.ts +9 -12
- package/types/orm/src/adapters/postgres.d.ts +11 -10
- package/types/orm/src/adapters/sqlDialect.d.ts +71 -0
- package/types/orm/src/adapters/sqlite.d.ts +15 -3
- package/types/orm/src/baseModel.d.ts +45 -9
- package/types/orm/src/cachedDatabase.d.ts +18 -5
- package/types/orm/src/connectTimeout.d.ts +100 -0
- package/types/orm/src/database.d.ts +78 -28
- package/types/orm/src/databaseResult.d.ts +29 -15
- package/types/orm/src/databaseUrl.d.ts +125 -0
- package/types/orm/src/docstore.d.ts +102 -43
- package/types/orm/src/index.d.ts +6 -4
- package/types/orm/src/migration.d.ts +4 -3
- package/types/orm/src/queryBuilder.d.ts +23 -3
- package/types/orm/src/sqlTranslator.d.ts +126 -2
- package/types/orm/src/types.d.ts +21 -38
- package/packages/core/src/scss.ts +0 -623
- package/packages/core/src/sessionHandlers/redisHandler.ts +0 -219
- package/types/core/src/scss.d.ts +0 -19
- package/types/core/src/sessionHandlers/redisHandler.d.ts +0 -60
|
@@ -78,6 +78,102 @@ export declare class SQLTranslator {
|
|
|
78
78
|
* first dot. Firebird has no schemas, so its adapter ignores this.
|
|
79
79
|
*/
|
|
80
80
|
static splitSchema(name: string): [string | null, string];
|
|
81
|
+
/**
|
|
82
|
+
* Hard per-statement bind-parameter ceiling per engine. 0 = never collapse.
|
|
83
|
+
* Sourced from test/fixtures/batch_write_contract.json, byte-identical in all
|
|
84
|
+
* four frameworks.
|
|
85
|
+
*/
|
|
86
|
+
static readonly MAX_BIND_PARAMS: Record<string, number>;
|
|
87
|
+
/**
|
|
88
|
+
* The four frameworks do not agree on what an engine calls itself — Python
|
|
89
|
+
* and PHP report "postgresql", Ruby and Node report "postgres". Without
|
|
90
|
+
* normalising, the cap lookup misses and the collapse silently does nothing
|
|
91
|
+
* on the engine with the largest win.
|
|
92
|
+
*/
|
|
93
|
+
static readonly ENGINE_ALIASES: Record<string, string>;
|
|
94
|
+
private static readonly INSERT_VALUES;
|
|
95
|
+
/**
|
|
96
|
+
* Engines whose lastInsertId reports the FIRST generated id of a multi-row
|
|
97
|
+
* INSERT rather than the last. Verified live, not assumed: a 3-row insert
|
|
98
|
+
* into a fresh MySQL table reports 1 while MAX(id) is 3. SQLite, PostgreSQL
|
|
99
|
+
* and MSSQL already report the last, so collapsing does not change them.
|
|
100
|
+
*/
|
|
101
|
+
static readonly FIRST_ID_ENGINES: readonly string[];
|
|
102
|
+
/**
|
|
103
|
+
* Normalise a collapsed batch's last id to the LAST row's id.
|
|
104
|
+
*
|
|
105
|
+
* A row-at-a-time batch reports the last row's id simply because the last
|
|
106
|
+
* statement inserted the last row. Collapsing rows into one statement changes
|
|
107
|
+
* that on any engine that reports the FIRST generated id, so this restores
|
|
108
|
+
* the contract instead of quietly redefining it. The ids in one statement are
|
|
109
|
+
* consecutive, so the last is `first + rows - 1`.
|
|
110
|
+
*/
|
|
111
|
+
static batchLastId(reportedId: unknown, rowsInChunk: number, engine: string): unknown;
|
|
112
|
+
/**
|
|
113
|
+
* Collapse a row-at-a-time INSERT batch into chunked multi-row VALUES.
|
|
114
|
+
*
|
|
115
|
+
* A batch that loops one INSERT per row pays a full network round-trip per
|
|
116
|
+
* row, and the round-trip — not SQL building — is the entire cost of a batch
|
|
117
|
+
* write. Measured over 500 rows: PostgreSQL 9848ms row-at-a-time against
|
|
118
|
+
* 15.8ms as a single multi-row statement (625x), MySQL 216x, MSSQL 121x.
|
|
119
|
+
*
|
|
120
|
+
* PURE: no I/O and no engine contact, so the chunking rules are checkable
|
|
121
|
+
* without a database. The live-engine runners prove the rows land.
|
|
122
|
+
*
|
|
123
|
+
* @returns Statements to run INSTEAD of the loop, or an EMPTY array meaning
|
|
124
|
+
* "not collapsible — keep looping", which is always correct.
|
|
125
|
+
*/
|
|
126
|
+
static buildBatchInserts(sql: string, paramSets: unknown[][], engine: string): Array<[string, unknown[]]>;
|
|
127
|
+
/**
|
|
128
|
+
* Blank out string literals, quoted identifiers and comments, so a keyword
|
|
129
|
+
* search sees only real SQL. Blanks are spaces of the SAME LENGTH (newlines
|
|
130
|
+
* preserved), so offsets and line structure still line up with the original.
|
|
131
|
+
*
|
|
132
|
+
* This exists because "does the caller's SQL already have a LIMIT?" used to be
|
|
133
|
+
* `sql.toUpperCase().split("--")[0].includes("LIMIT")`, and MEASURED on a real
|
|
134
|
+
* 150-row table with the 100-row cap in force, every one of these returned
|
|
135
|
+
* ALL 150 ROWS instead of 100:
|
|
136
|
+
*
|
|
137
|
+
* SELECT * FROM t WHERE label != 'LIMIT' ORDER BY id -- literal
|
|
138
|
+
* SELECT * FROM t ORDER BY id -- LIMIT 5 -- line comment
|
|
139
|
+
* SELECT * FROM t ORDER BY id /* LIMIT 5 *\/ -- block comment
|
|
140
|
+
*
|
|
141
|
+
* A column named `rate_limit` does it too. That is a silently UNCAPPED read of
|
|
142
|
+
* a whole table, which is the exact production incident the row cap exists to
|
|
143
|
+
* prevent, reachable through an ordinary column name.
|
|
144
|
+
*
|
|
145
|
+
* @param sql Raw SQL, exactly as the caller wrote it.
|
|
146
|
+
* @returns The same string with literals and comments replaced by spaces.
|
|
147
|
+
*/
|
|
148
|
+
static scrubSqlText(sql: string): string;
|
|
149
|
+
/**
|
|
150
|
+
* True when the statement ENDS with its own LIMIT clause, so appending another
|
|
151
|
+
* would be wrong (and on SQLite, a syntax error).
|
|
152
|
+
*
|
|
153
|
+
* Anchored to the END on purpose. A bare "contains LIMIT" test also matches a
|
|
154
|
+
* LIMIT inside a subquery, where the OUTER statement still needs its cap. This
|
|
155
|
+
* is tina4-php's `SqlNormalizerTrait::hasTrailingLimit` regex, ported verbatim
|
|
156
|
+
* so all four frameworks answer identically: it accepts a numeric value, `?`,
|
|
157
|
+
* `$1` and `:name` placeholders, MySQL's `LIMIT a, b`, and a trailing OFFSET.
|
|
158
|
+
*
|
|
159
|
+
* @param sql Raw SQL; literals and comments are scrubbed before matching.
|
|
160
|
+
*/
|
|
161
|
+
static hasTrailingLimit(sql: string): boolean;
|
|
162
|
+
/**
|
|
163
|
+
* Append `LIMIT`/`OFFSET` to a statement unless it already carries its own.
|
|
164
|
+
*
|
|
165
|
+
* The clause goes on a NEW LINE. Appending it inline is the second half of the
|
|
166
|
+
* same bug: `SELECT * FROM t -- note` + ` LIMIT 100` puts the clause INSIDE the
|
|
167
|
+
* trailing comment, where SQLite silently ignores it and the whole table comes
|
|
168
|
+
* back. A newline cannot be commented out by a `--` that started on the line
|
|
169
|
+
* above. Trailing semicolons are stripped first for the same reason
|
|
170
|
+
* (`SELECT * FROM t;` + `LIMIT 100` is a syntax error).
|
|
171
|
+
*
|
|
172
|
+
* @param sql The caller's statement.
|
|
173
|
+
* @param limit Row cap to apply; a non-positive value means "no cap".
|
|
174
|
+
* @param offset Rows to skip; omitted or 0 emits no OFFSET.
|
|
175
|
+
*/
|
|
176
|
+
static appendLimit(sql: string, limit?: number, offset?: number): string;
|
|
81
177
|
}
|
|
82
178
|
/**
|
|
83
179
|
* Simple in-memory query cache with TTL support.
|
|
@@ -91,9 +187,37 @@ export declare class QueryCache {
|
|
|
91
187
|
maxSize?: number;
|
|
92
188
|
});
|
|
93
189
|
/**
|
|
94
|
-
*
|
|
190
|
+
* Stable identity of the DATABASE a cache entry came from.
|
|
191
|
+
*
|
|
192
|
+
* `engine://host:port/database` - and deliberately NOTHING else.
|
|
193
|
+
*
|
|
194
|
+
* WHY IT EXISTS: the key used to be `query:${sql}:${params}` with nothing
|
|
195
|
+
* naming the connection, so on any SHARED backend two databases cross-served
|
|
196
|
+
* each other's rows. Two apps pointed at one Redis, or one app with a primary
|
|
197
|
+
* and an analytics connection, silently read each other's data. Identical SQL
|
|
198
|
+
* text across tenants is the COMMON case, not an edge case, so the collision
|
|
199
|
+
* was the normal outcome.
|
|
200
|
+
*
|
|
201
|
+
* WHY NO CREDENTIALS: a password in the key means every rotation silently
|
|
202
|
+
* cold-starts the cache, and a shared backend's key namespace is visible to
|
|
203
|
+
* every tenant of that backend - a secret must never be folded into it. The
|
|
204
|
+
* username is out for the same reason plus a second: two connections
|
|
205
|
+
* differing only by role read the SAME rows and should share the entry.
|
|
206
|
+
*
|
|
207
|
+
* WHY NOTHING PER-PROCESS: no pid, no object id, no salt. Those would isolate
|
|
208
|
+
* the databases by ACCIDENT and destroy the point of a shared cache, because
|
|
209
|
+
* no instance would ever hit another instance's entry.
|
|
210
|
+
*/
|
|
211
|
+
static cacheIdentity(url: string): string;
|
|
212
|
+
/**
|
|
213
|
+
* Generate a cache key from DATABASE IDENTITY + SQL + params.
|
|
214
|
+
*
|
|
215
|
+
* The NUL separators keep the three parts from running together, so a table
|
|
216
|
+
* named after the tail of a database name cannot forge another database's
|
|
217
|
+
* key. The key is not hashed here: the only backend with a key-length limit
|
|
218
|
+
* is memcached, and its backend already SHA-256-hashes whatever it is given.
|
|
95
219
|
*/
|
|
96
|
-
static queryKey(sql: string, params?: unknown[]): string;
|
|
220
|
+
static queryKey(sql: string, params?: unknown[], identity?: string): string;
|
|
97
221
|
/**
|
|
98
222
|
* Get a cached value. Returns undefined if expired or missing.
|
|
99
223
|
*/
|
package/types/orm/src/types.d.ts
CHANGED
|
@@ -28,6 +28,13 @@ export interface RelationshipDefinition {
|
|
|
28
28
|
}
|
|
29
29
|
export interface ModelDefinition {
|
|
30
30
|
tableName: string;
|
|
31
|
+
/**
|
|
32
|
+
* The model CLASS name (e.g. `Item` for tableName `items`), carried from
|
|
33
|
+
* `ModelClass.name` at discovery. Swagger keys `components.schemas` by this —
|
|
34
|
+
* the type name a generated client wants — falling back to a singular
|
|
35
|
+
* PascalCase derivation of tableName when a raw definition carries none.
|
|
36
|
+
*/
|
|
37
|
+
className?: string;
|
|
31
38
|
fields: Record<string, FieldDefinition>;
|
|
32
39
|
fieldMapping?: Record<string, string>;
|
|
33
40
|
softDelete?: boolean;
|
|
@@ -66,8 +73,8 @@ export interface DatabaseAdapter {
|
|
|
66
73
|
fetchOne<T = Record<string, unknown>>(sql: string, params?: unknown[]): T | null;
|
|
67
74
|
/** Insert one or more rows into a table, returns result with lastId. */
|
|
68
75
|
insert(table: string, data: Record<string, unknown> | Record<string, unknown>[]): DatabaseResult;
|
|
69
|
-
/** Update rows in a table matching filter, returns affected row count. */
|
|
70
|
-
update(table: string, data: Record<string, unknown>, filter: Record<string, unknown
|
|
76
|
+
/** Update rows in a table matching filter (object or string WHERE), returns affected row count. */
|
|
77
|
+
update(table: string, data: Record<string, unknown>, filter: Record<string, unknown> | string, params?: unknown[]): DatabaseResult;
|
|
71
78
|
/** Delete rows from a table matching filter (object, string WHERE, or array of objects). */
|
|
72
79
|
delete(table: string, filter: Record<string, unknown> | string | Record<string, unknown>[], params?: unknown[]): DatabaseResult;
|
|
73
80
|
/** Start a transaction. */
|
|
@@ -77,9 +84,9 @@ export interface DatabaseAdapter {
|
|
|
77
84
|
/** Rollback the current transaction. */
|
|
78
85
|
rollback(): void;
|
|
79
86
|
/** List all tables in the database. */
|
|
80
|
-
|
|
87
|
+
getTables(): string[];
|
|
81
88
|
/** List columns with types for a table. */
|
|
82
|
-
|
|
89
|
+
getColumns(table: string): ColumnInfo[];
|
|
83
90
|
/** Get the last inserted id (auto-increment integer, or a UUID/string PK). */
|
|
84
91
|
lastInsertId(): number | bigint | string | null;
|
|
85
92
|
/** Close the connection. */
|
|
@@ -95,40 +102,16 @@ export interface DatabaseAdapter {
|
|
|
95
102
|
}>;
|
|
96
103
|
/** Add a column to an existing table (legacy, used by migration). */
|
|
97
104
|
addColumn?(table: string, colName: string, def: FieldDefinition): void;
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Wraps an array of fetched rows with convenience methods.
|
|
110
|
-
*
|
|
111
|
-
* Mirrors Python's `DatabaseResult` and Ruby's `Tina4::DatabaseResult`.
|
|
112
|
-
*/
|
|
113
|
-
export declare class FetchResult<T = Record<string, unknown>> {
|
|
114
|
-
readonly records: T[];
|
|
115
|
-
readonly count: number;
|
|
116
|
-
readonly sql: string;
|
|
117
|
-
constructor(records: T[], sql?: string);
|
|
118
|
-
/** Paginate the in-memory result set. */
|
|
119
|
-
toPaginate(page?: number, perPage?: number): PaginatedResult<T>;
|
|
120
|
-
/** Return the first record or null. */
|
|
121
|
-
first(): T | null;
|
|
122
|
-
/** Return the last record or null. */
|
|
123
|
-
last(): T | null;
|
|
124
|
-
/** Check if result is empty. */
|
|
125
|
-
isEmpty(): boolean;
|
|
126
|
-
/** Convert to plain array. */
|
|
127
|
-
toArray(): T[];
|
|
128
|
-
/** Convert to JSON string. */
|
|
129
|
-
toJSON(): string;
|
|
130
|
-
/** Iterate over records. */
|
|
131
|
-
[Symbol.iterator](): Iterator<T>;
|
|
105
|
+
/**
|
|
106
|
+
* Stable identity of the DATABASE this adapter is connected to, as
|
|
107
|
+
* `engine://host:port/database` with NO credentials - set by whoever built
|
|
108
|
+
* the adapter from a URL or config.
|
|
109
|
+
*
|
|
110
|
+
* The query cache folds this into every key. Without it two databases sharing
|
|
111
|
+
* one cache backend cross-serve each other's rows, because identical SQL text
|
|
112
|
+
* across tenants is the common case.
|
|
113
|
+
*/
|
|
114
|
+
cacheIdentity?: string;
|
|
132
115
|
}
|
|
133
116
|
export interface QueryOptions {
|
|
134
117
|
filter?: Record<string, unknown>;
|