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
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tina4 GraphQL — Zero-dependency GraphQL engine.
|
|
3
|
+
*
|
|
4
|
+
* Recursive-descent parser, schema builder, and query executor.
|
|
5
|
+
*
|
|
6
|
+
* import { GraphQL } from "@tina4/core";
|
|
7
|
+
*
|
|
8
|
+
* const gql = new GraphQL();
|
|
9
|
+
* gql.addType("User", { id: { type: "ID" }, name: { type: "String" } });
|
|
10
|
+
* gql.addQuery("user", { id: "ID!" }, "User", (root, args) => getUser(args.id));
|
|
11
|
+
* const result = gql.execute('{ user(id: "1") { name } }');
|
|
12
|
+
*
|
|
13
|
+
* Supported:
|
|
14
|
+
* - Queries, mutations
|
|
15
|
+
* - Variables, default values
|
|
16
|
+
* - Aliases
|
|
17
|
+
* - Nested selections
|
|
18
|
+
* - List types ([Type])
|
|
19
|
+
* - Non-null types (Type!)
|
|
20
|
+
* - Error capture (resolver exceptions become GraphQL errors)
|
|
21
|
+
*/
|
|
22
|
+
export interface GraphQLField {
|
|
23
|
+
type: string;
|
|
24
|
+
description?: string;
|
|
25
|
+
}
|
|
26
|
+
export type ResolverFn = (root: unknown, args: Record<string, unknown>, context?: Record<string, unknown>) => unknown;
|
|
27
|
+
export interface GraphQLResult {
|
|
28
|
+
data: Record<string, unknown> | null;
|
|
29
|
+
errors?: Array<{
|
|
30
|
+
message: string;
|
|
31
|
+
path?: string[];
|
|
32
|
+
}>;
|
|
33
|
+
}
|
|
34
|
+
interface Token {
|
|
35
|
+
type: string;
|
|
36
|
+
value: string;
|
|
37
|
+
pos: number;
|
|
38
|
+
}
|
|
39
|
+
export declare function tokenize(source: string): Token[];
|
|
40
|
+
export declare class ParseError extends Error {
|
|
41
|
+
constructor(message: string);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* URL the GraphQL handler should be mounted at.
|
|
45
|
+
* `TINA4_GRAPHQL_ENDPOINT` overrides the default `/graphql`.
|
|
46
|
+
*/
|
|
47
|
+
export declare function graphqlEndpoint(): string;
|
|
48
|
+
/**
|
|
49
|
+
* Whether to auto-generate the schema from registered ORM models.
|
|
50
|
+
* `TINA4_GRAPHQL_AUTO_SCHEMA=true` (default) lets the dev server build a
|
|
51
|
+
* usable schema with no manual wiring; set to `false` to require explicit
|
|
52
|
+
* `addType` / `addQuery` calls.
|
|
53
|
+
*/
|
|
54
|
+
export declare function graphqlAutoSchemaEnabled(): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Maximum selection-set nesting depth. A deeply nested query (or a circular
|
|
57
|
+
* fragment) would otherwise recurse without bound — a classic GraphQL DoS /
|
|
58
|
+
* stack-overflow vector. `TINA4_GRAPHQL_MAX_DEPTH` overrides the default (50);
|
|
59
|
+
* set `<= 0` to disable the guard. A non-numeric value falls back to 50.
|
|
60
|
+
*/
|
|
61
|
+
export declare function graphqlMaxDepth(): number;
|
|
62
|
+
export declare class GraphQL {
|
|
63
|
+
private types;
|
|
64
|
+
private queries;
|
|
65
|
+
private mutations;
|
|
66
|
+
/** Object-type field resolvers indexed by `[typeName][fieldName]`. */
|
|
67
|
+
private fieldResolvers;
|
|
68
|
+
private static classResolvers;
|
|
69
|
+
private static defaultInstance;
|
|
70
|
+
/**
|
|
71
|
+
* Maximum selection-set nesting depth (read from `TINA4_GRAPHQL_MAX_DEPTH`,
|
|
72
|
+
* default 50; `<= 0` disables the guard). Public so tests can set it and the
|
|
73
|
+
* dev app can introspect it. Counted per selection level AND per fragment
|
|
74
|
+
* spread / inline fragment, so circular fragments are caught too.
|
|
75
|
+
*/
|
|
76
|
+
maxDepth: number;
|
|
77
|
+
/**
|
|
78
|
+
* Decorator-style resolver registration.
|
|
79
|
+
*
|
|
80
|
+
* Resolvers may be synchronous OR async (return a Promise) — `execute()`
|
|
81
|
+
* awaits every resolver, so an `async` resolver's value is resolved before
|
|
82
|
+
* the field is serialized. Return a value directly, or `await` your data
|
|
83
|
+
* (e.g. an async DB driver) and the executor will await it for you.
|
|
84
|
+
*
|
|
85
|
+
* GraphQL.resolve("Query", "products", async (root, args) =>
|
|
86
|
+
* (await db.fetch("SELECT * FROM products")).records);
|
|
87
|
+
*
|
|
88
|
+
* GraphQL.resolve("Mutation", "createProduct", async (root, args) => {
|
|
89
|
+
* const p = new Product(args.input);
|
|
90
|
+
* await p.save();
|
|
91
|
+
* return p.toDict();
|
|
92
|
+
* });
|
|
93
|
+
*
|
|
94
|
+
* GraphQL.resolve("Product", "reviews", async (product, args) =>
|
|
95
|
+
* (await db.fetch("SELECT * FROM reviews WHERE product_id = ?", [product.id])).records);
|
|
96
|
+
*
|
|
97
|
+
* Resolvers registered before any GraphQL instance exists accumulate
|
|
98
|
+
* in the class-level registry. `new GraphQL()` drains them into its
|
|
99
|
+
* schema. Resolvers registered after `setDefault(gql)` wire into the
|
|
100
|
+
* live schema immediately.
|
|
101
|
+
*/
|
|
102
|
+
static resolve(typeName: string, fieldName: string, resolver: ResolverFn): void;
|
|
103
|
+
/**
|
|
104
|
+
* Designate `instance` as the default singleton. Post-startup
|
|
105
|
+
* `GraphQL.resolve()` calls wire into this instance's live schema.
|
|
106
|
+
*/
|
|
107
|
+
static setDefault(instance: GraphQL): void;
|
|
108
|
+
/** Test-only — clear the class-level registry. */
|
|
109
|
+
static _clearClassResolvers(): void;
|
|
110
|
+
constructor();
|
|
111
|
+
/** Wire a single resolver into the live schema. */
|
|
112
|
+
private attachResolver;
|
|
113
|
+
/**
|
|
114
|
+
* Get the field resolver registered for an object type, if any.
|
|
115
|
+
* Used by the executor during nested field resolution.
|
|
116
|
+
*/
|
|
117
|
+
getFieldResolver(typeName: string, fieldName: string): ResolverFn | undefined;
|
|
118
|
+
/**
|
|
119
|
+
* Return schema metadata for debugging.
|
|
120
|
+
*/
|
|
121
|
+
introspect(): Record<string, unknown>;
|
|
122
|
+
/**
|
|
123
|
+
* Register a named type with its fields.
|
|
124
|
+
*/
|
|
125
|
+
addType(name: string, fields: Record<string, GraphQLField>): GraphQL;
|
|
126
|
+
/**
|
|
127
|
+
* Register a query resolver.
|
|
128
|
+
*/
|
|
129
|
+
addQuery(name: string, args: Record<string, string>, returnType: string, resolver: ResolverFn): GraphQL;
|
|
130
|
+
/**
|
|
131
|
+
* Register a mutation resolver.
|
|
132
|
+
*/
|
|
133
|
+
addMutation(name: string, args: Record<string, string>, returnType: string, resolver: ResolverFn): GraphQL;
|
|
134
|
+
/**
|
|
135
|
+
* Execute a GraphQL query string.
|
|
136
|
+
*/
|
|
137
|
+
execute(query: string, variables?: Record<string, unknown>, context?: Record<string, unknown>): Promise<GraphQLResult>;
|
|
138
|
+
/**
|
|
139
|
+
* Resolve a list of selections and merge results into the `target` dict.
|
|
140
|
+
* Fragment spreads and inline fragments are merged (not nested).
|
|
141
|
+
*
|
|
142
|
+
* `depth` is incremented on every recursive entry (field sub-selections,
|
|
143
|
+
* fragment spreads, inline fragments) and checked against `maxDepth` so an
|
|
144
|
+
* over-deep query or a circular fragment fails with a structured error
|
|
145
|
+
* instead of recursing until the interpreter stack overflows. Top-level
|
|
146
|
+
* starts at depth 1; `maxDepth <= 0` disables the guard.
|
|
147
|
+
*/
|
|
148
|
+
private resolveSelectionsInto;
|
|
149
|
+
/**
|
|
150
|
+
* Generate SDL schema string.
|
|
151
|
+
*/
|
|
152
|
+
schemaSdl(): string;
|
|
153
|
+
/**
|
|
154
|
+
* Auto-generate type, queries, and CRUD mutations from an ORM model class.
|
|
155
|
+
*
|
|
156
|
+
* The model class must have static `tableName` (string) and `fields`
|
|
157
|
+
* (Record<string, { type: string; primaryKey?: boolean }>).
|
|
158
|
+
*
|
|
159
|
+
* Creates:
|
|
160
|
+
* - A GraphQL type from the model's fields
|
|
161
|
+
* - Queries: {modelName}(id: ID!): Type, {modelNames}(limit: Int, offset: Int): [Type]
|
|
162
|
+
* - Mutations: create{ModelName}, update{ModelName}, delete{ModelName}
|
|
163
|
+
*
|
|
164
|
+
* @param modelClass - The model class with static tableName and fields
|
|
165
|
+
* @param adapter - Optional database adapter; if omitted, resolvers will
|
|
166
|
+
* import getAdapter from @tina4/orm at call time
|
|
167
|
+
*/
|
|
168
|
+
fromOrm(modelClass: {
|
|
169
|
+
tableName: string;
|
|
170
|
+
fields: Record<string, {
|
|
171
|
+
type: string;
|
|
172
|
+
primaryKey?: boolean;
|
|
173
|
+
}>;
|
|
174
|
+
name?: string;
|
|
175
|
+
}, adapter?: {
|
|
176
|
+
query: <T = Record<string, unknown>>(sql: string, params?: unknown[]) => T[];
|
|
177
|
+
execute: (sql: string, params?: unknown[]) => unknown;
|
|
178
|
+
}): GraphQL;
|
|
179
|
+
private formatArgs;
|
|
180
|
+
private resolveField;
|
|
181
|
+
private resolveArgs;
|
|
182
|
+
/**
|
|
183
|
+
* Check directives: @skip, @include, @auth, @role, @guest.
|
|
184
|
+
* Returns true if the field should be included, false to skip.
|
|
185
|
+
*/
|
|
186
|
+
private checkDirectives;
|
|
187
|
+
/**
|
|
188
|
+
* Validate resolved args against declared types.
|
|
189
|
+
*/
|
|
190
|
+
private validateArgs;
|
|
191
|
+
private coerceValue;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Lightweight GraphQL type wrapper matching Ruby's GraphQLType.
|
|
195
|
+
*/
|
|
196
|
+
export declare class GraphQLType {
|
|
197
|
+
static readonly SCALARS: string[];
|
|
198
|
+
name: string;
|
|
199
|
+
kind: string;
|
|
200
|
+
ofType: GraphQLType | null;
|
|
201
|
+
constructor(name: string, kind?: string, ofType?: GraphQLType | null);
|
|
202
|
+
/**
|
|
203
|
+
* Parse a GraphQL type string like "String", "String!", "[Int!]!".
|
|
204
|
+
*/
|
|
205
|
+
static parse(typeStr: string): GraphQLType;
|
|
206
|
+
}
|
|
207
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { RouteDefinition } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Resolve the health route path. Priority:
|
|
4
|
+
* 1. `TINA4_HEALTH_PATH` env var
|
|
5
|
+
* 2. Default `/__health` (matches Python parity — under-prefix avoids
|
|
6
|
+
* colliding with app routes named /health)
|
|
7
|
+
*/
|
|
8
|
+
export declare function healthPath(): string;
|
|
9
|
+
/**
|
|
10
|
+
* Create the primary health route definition.
|
|
11
|
+
*
|
|
12
|
+
* Tests use this directly. Server bootstrap goes through createHealthRoutes()
|
|
13
|
+
* to also register the legacy `/health` alias when TINA4_HEALTH_PATH points
|
|
14
|
+
* elsewhere — matching Python behaviour so existing probes don't break.
|
|
15
|
+
*/
|
|
16
|
+
export declare function createHealthRoute(version?: string): RouteDefinition;
|
|
17
|
+
/**
|
|
18
|
+
* Create one or two health routes — the env-defined path always, plus a
|
|
19
|
+
* legacy `/health` alias when the env path differs. Mirrors
|
|
20
|
+
* tina4-python's two-line registration in `core/server.py`.
|
|
21
|
+
*/
|
|
22
|
+
export declare function createHealthRoutes(version?: string): RouteDefinition[];
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Programmatic HTML builder — avoids string concatenation.
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
* const el = new HtmlElement("div", { class: "card" }, ["Hello"]);
|
|
6
|
+
* el.toString(); // '<div class="card">Hello</div>'
|
|
7
|
+
*
|
|
8
|
+
* // Builder pattern
|
|
9
|
+
* const el = htmlElement("div")(htmlElement("p")("Text"));
|
|
10
|
+
*
|
|
11
|
+
* // Helper functions
|
|
12
|
+
* const h: Record<string, any> = {};
|
|
13
|
+
* addHtmlHelpers(h);
|
|
14
|
+
* const html = h._div({ class: "card" }, h._p("Hello"));
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Raw — marker for trusted, pre-sanitised HTML that must render UNESCAPED.
|
|
18
|
+
*
|
|
19
|
+
* String/scalar children of an HtmlElement are HTML-escaped by default to
|
|
20
|
+
* prevent stored/reflected XSS. Wrap a value in Raw to opt out of escaping
|
|
21
|
+
* when (and only when) you have already sanitised it yourself.
|
|
22
|
+
*
|
|
23
|
+
* new HtmlElement("div", {}, ["<b>x</b>"]).toString() // <b>x</b> (escaped)
|
|
24
|
+
* new HtmlElement("div", {}, [new Raw("<b>x</b>")]).toString() // <b>x</b> (raw)
|
|
25
|
+
*
|
|
26
|
+
* Alias: SafeString.
|
|
27
|
+
*/
|
|
28
|
+
export declare class Raw {
|
|
29
|
+
readonly value: string;
|
|
30
|
+
constructor(value: string);
|
|
31
|
+
toString(): string;
|
|
32
|
+
}
|
|
33
|
+
export declare const SafeString: typeof Raw;
|
|
34
|
+
type Attrs = Record<string, string | number | boolean | null | undefined>;
|
|
35
|
+
type Child = string | number | HtmlElement | Raw;
|
|
36
|
+
/**
|
|
37
|
+
* HtmlElement — a single HTML tag with attributes and children.
|
|
38
|
+
*/
|
|
39
|
+
export declare class HtmlElement {
|
|
40
|
+
readonly tag: string;
|
|
41
|
+
readonly attrs: Attrs;
|
|
42
|
+
readonly children: Child[];
|
|
43
|
+
constructor(tag: string, attrs?: Attrs, children?: Child[]);
|
|
44
|
+
/**
|
|
45
|
+
* Render to HTML string.
|
|
46
|
+
*/
|
|
47
|
+
toString(): string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Create a callable HTML element builder.
|
|
51
|
+
* Returns a function that, when called with children/attrs, produces a new HtmlElement.
|
|
52
|
+
*
|
|
53
|
+
* Usage:
|
|
54
|
+
* const div = htmlElement("div");
|
|
55
|
+
* const el = div({ class: "card" }, "Hello");
|
|
56
|
+
* console.log(el.toString()); // '<div class="card">Hello</div>'
|
|
57
|
+
*/
|
|
58
|
+
export declare function htmlElement(tag: string, attrs?: Attrs, children?: Child[]): {
|
|
59
|
+
(...args: (Child | Attrs | Child[])[]): /*elided*/ any;
|
|
60
|
+
tag: string;
|
|
61
|
+
attrs: Attrs;
|
|
62
|
+
children: Child[];
|
|
63
|
+
toString(): string;
|
|
64
|
+
_isHtmlElement: boolean;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Injects helper functions (_div, _p, _a, _span, etc.) into the target object.
|
|
68
|
+
*
|
|
69
|
+
* Usage:
|
|
70
|
+
* const h: Record<string, any> = {};
|
|
71
|
+
* addHtmlHelpers(h);
|
|
72
|
+
* const html = h._div({ class: "card" }, h._p("Hello"));
|
|
73
|
+
*/
|
|
74
|
+
export declare function addHtmlHelpers(target: Record<string, unknown>): void;
|
|
75
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export declare class I18n {
|
|
2
|
+
private _localeDir;
|
|
3
|
+
private _defaultLocale;
|
|
4
|
+
private _currentLocale;
|
|
5
|
+
private _translations;
|
|
6
|
+
/**
|
|
7
|
+
* @param locale Default locale code (e.g. "en"). Falls back to
|
|
8
|
+
* TINA4_LOCALE, then "en".
|
|
9
|
+
* @param path Directory holding the JSON/YAML locale files. Falls back to
|
|
10
|
+
* TINA4_LOCALE_DIR, then "src/locales".
|
|
11
|
+
*
|
|
12
|
+
* Arg order is (locale, path) to match the Python master `I18n(locale, path)`
|
|
13
|
+
* (BUG-7, BREAKING in 3.13.x — was previously (localeDir, defaultLocale)).
|
|
14
|
+
*/
|
|
15
|
+
constructor(locale?: string, path?: string);
|
|
16
|
+
setLocale(locale: string): void;
|
|
17
|
+
getLocale(): string;
|
|
18
|
+
/**
|
|
19
|
+
* Translate a key. Supports {placeholder} interpolation.
|
|
20
|
+
* Falls back to default locale, then returns the key itself.
|
|
21
|
+
*/
|
|
22
|
+
t(key: string, params?: Record<string, string>, locale?: string): string;
|
|
23
|
+
/** Alias for t() */
|
|
24
|
+
translate(key: string, params?: Record<string, string>, locale?: string): string;
|
|
25
|
+
/** Load and return translations for a locale. */
|
|
26
|
+
loadTranslations(locale: string): Record<string, string>;
|
|
27
|
+
/** Add a single translation key/value to a locale (in-memory only). */
|
|
28
|
+
addTranslation(locale: string, key: string, value: string): void;
|
|
29
|
+
/** List available locale codes based on JSON files in the locale directory. */
|
|
30
|
+
availableLocales(): string[];
|
|
31
|
+
/** Load a locale file if not already loaded. */
|
|
32
|
+
private _loadLocale;
|
|
33
|
+
/** Flatten nested objects: {"a": {"b": "c"}} → {"a.b": "c"} */
|
|
34
|
+
/** Zero-dep YAML parser for simple key: value locale files. */
|
|
35
|
+
private static _parseSimpleYaml;
|
|
36
|
+
private static _flatten;
|
|
37
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
export type { Tina4Request, Tina4Response, RouteHandler, RouteDefinition, RouteMeta, Tina4Config, Middleware, MiddlewareClass, MiddlewareSpec, UploadedFile, CookieOptions, WebSocketRouteHandler, WebSocketRouteDefinition, } from "./types.js";
|
|
2
|
+
export { startServer, resolvePortAndHost, handle, start, stop, httpReason, resolveTemplate, resetTemplateCache, templateAutoRoutingEnabled, isBannerSuppressed } from "./server.js";
|
|
3
|
+
export { background, stopAllBackgroundTasks, backgroundTaskCount } from "./background.js";
|
|
4
|
+
export { Router, RouteGroup, RouteRef, WsRouteRef, defaultRouter, runRouteMiddlewares, resolveStringMiddleware, isTrailingSlashRedirectEnabled } from "./router.js";
|
|
5
|
+
export { get, post, put, patch, del, any, websocket, del as delete } from "./router.js";
|
|
6
|
+
export type { RouteInfo } from "./router.js";
|
|
7
|
+
export { discoverRoutes } from "./routeDiscovery.js";
|
|
8
|
+
export { MiddlewareChain, MiddlewareRunner, cors, requestLogger, CorsMiddleware, RateLimiterMiddleware, RequestLogger, SecurityHeadersMiddleware, CsrfMiddleware } from "./middleware.js";
|
|
9
|
+
export type { CorsConfig } from "./middleware.js";
|
|
10
|
+
export { createRequest, makeCaseInsensitiveHeaders } from "./request.js";
|
|
11
|
+
export { createResponse, errorResponse, setDefaultTemplatesDir, getFrond, setFrond, getFrameworkFrond } from "./response.js";
|
|
12
|
+
export { tryServeStatic } from "./static.js";
|
|
13
|
+
export { loadEnv, getEnv, requireEnv, hasEnv, allEnv, resetEnv, isTruthy } from "./dotenv.js";
|
|
14
|
+
export { Env } from "./env.js";
|
|
15
|
+
export { Log } from "./logger.js";
|
|
16
|
+
export { createHealthRoute, createHealthRoutes, healthPath } from "./health.js";
|
|
17
|
+
export { rateLimiter } from "./rateLimiter.js";
|
|
18
|
+
export { isTrustedProxy, trustedProxyNetworks, resolveClientIp, resetTrustedProxyCache } from "./trustedProxy.js";
|
|
19
|
+
export type { RateLimiterConfig } from "./rateLimiter.js";
|
|
20
|
+
export { HTTP_OK, HTTP_CREATED, HTTP_ACCEPTED, HTTP_NO_CONTENT, HTTP_MOVED, HTTP_REDIRECT, HTTP_NOT_MODIFIED, HTTP_BAD_REQUEST, HTTP_UNAUTHORIZED, HTTP_FORBIDDEN, HTTP_NOT_FOUND, HTTP_METHOD_NOT_ALLOWED, HTTP_CONFLICT, HTTP_GONE, HTTP_UNPROCESSABLE, HTTP_TOO_MANY, HTTP_SERVER_ERROR, HTTP_BAD_GATEWAY, HTTP_UNAVAILABLE, APPLICATION_JSON, APPLICATION_XML, APPLICATION_FORM, APPLICATION_OCTET, TEXT_HTML, TEXT_PLAIN, TEXT_CSV, TEXT_XML, } from "./constants.js";
|
|
21
|
+
export { getToken, validToken, getPayload, hashPassword, checkPassword, authMiddleware, refreshToken, authenticateRequest, validateApiKey, ensureDevSecret, resolveAlgorithm, algorithmAvailable, availableAlgorithms, Auth, } from "./auth.js";
|
|
22
|
+
export { Session, FileSessionHandler, RedisSessionHandler, buildSessionCookie, isSecureScheme, isValidSessionId, sessionCookieName, VALID_SESSION_BACKENDS, CANONICAL_SESSION_BACKENDS } from "./session.js";
|
|
23
|
+
export type { SessionConfig, SessionHandler } from "./session.js";
|
|
24
|
+
export { I18n } from "./i18n.js";
|
|
25
|
+
export { FakeData } from "./fakeData.js";
|
|
26
|
+
export { ScssCompiler } from "./scss.js";
|
|
27
|
+
export type { ScssConfig } from "./scss.js";
|
|
28
|
+
export { Queue } from "./queue.js";
|
|
29
|
+
export type { QueueConfig, QueueJob, ProcessOptions } from "./queue.js";
|
|
30
|
+
export { createJob } from "./job.js";
|
|
31
|
+
export type { JobData, JobQueueBridge } from "./job.js";
|
|
32
|
+
export { Mqtt, MqttError, MqttTimeoutError } from "./mqtt.js";
|
|
33
|
+
export type { MqttOptions, ParsedMqttUrl } from "./mqtt.js";
|
|
34
|
+
export { MqttMessage } from "./mqttMessage.js";
|
|
35
|
+
export type { MqttAcknowledger } from "./mqttMessage.js";
|
|
36
|
+
export { GraphQL, ParseError, graphqlEndpoint, graphqlAutoSchemaEnabled, graphqlMaxDepth } from "./graphql.js";
|
|
37
|
+
export type { GraphQLField, ResolverFn, GraphQLResult } from "./graphql.js";
|
|
38
|
+
export { WebSocketServer, devReloadWs, computeAcceptKey, parseUpgradeHeaders, buildFrame, parseFrame, originAllowed, wsToken, wsAuthorized, offeredBearerSubprotocol, serveWebSocketRoute, wsRouteManager, OP_TEXT, OP_BINARY, OP_CLOSE, OP_PING, OP_PONG, CLOSE_NORMAL, CLOSE_GOING_AWAY, CLOSE_PROTOCOL_ERROR, CLOSE_POLICY_VIOLATION, } from "./websocket.js";
|
|
39
|
+
export type { WebSocketClient } from "./websocket.js";
|
|
40
|
+
export { ServiceRunner, Tina4Service, matchCronField, matchesCron } from "./service.js";
|
|
41
|
+
export type { ServiceOptions, ServiceContext, ServiceHandler, ServiceInfo } from "./service.js";
|
|
42
|
+
export { responseCache, clearCache, cacheStats, cacheGet, cacheSet, cacheDelete, cacheClear, cacheBackendStats, sweep, createBackend, _resetBackend } from "./cache.js";
|
|
43
|
+
export type { ResponseCacheConfig, CacheBackend } from "./cache.js";
|
|
44
|
+
export { Api } from "./api.js";
|
|
45
|
+
export type { ApiResult, ApiOptions, ApiTransport, DownloadResult, UploadOptions } from "./api.js";
|
|
46
|
+
export { Context, defaultContext, existingContext, fts5Supported, _sharedContexts } from "./context/index.js";
|
|
47
|
+
export type { SearchHit } from "./context/index.js";
|
|
48
|
+
export { Events } from "./events.js";
|
|
49
|
+
export { DevAdmin, MessageLog, RequestInspector, ErrorTracker, DevMailboxStore, DevQueue, WsTracker, supervisorBaseUrl, devAdminLanguage } from "./devAdmin.js";
|
|
50
|
+
export { feedbackEnabled, feedbackWhitelist, feedbackIdentifyUser, feedbackIsWhitelisted, feedbackRateLimitOk, injectFeedbackWidget, handleFeedbackTurn, handleFeedbackWidgetJs, registerFeedbackRoutes, } from "./feedback.js";
|
|
51
|
+
export { Messenger, MessengerConnectionError, createMessenger } from "./messenger.js";
|
|
52
|
+
export type { SendResult, EmailMessage } from "./messenger.js";
|
|
53
|
+
export { DevMailbox } from "./devMailbox.js";
|
|
54
|
+
export { WSDLService, WSDLOperation } from "./wsdl.js";
|
|
55
|
+
export type { WSDLOperationMeta } from "./wsdl.js";
|
|
56
|
+
export { HtmlElement, htmlElement, addHtmlHelpers, Raw, SafeString } from "./htmlElement.js";
|
|
57
|
+
export { renderErrorOverlay, renderProductionError, isDebugMode } from "./errorOverlay.js";
|
|
58
|
+
export { AI_TOOLS, isInstalled, showMenu, installSelected, installAll, generateContext } from "./ai.js";
|
|
59
|
+
export type { AiTool } from "./ai.js";
|
|
60
|
+
export type { ImapMessage, ImapFullMessage } from "./messenger.js";
|
|
61
|
+
export { LiteBackend } from "./queueBackends/liteBackend.js";
|
|
62
|
+
export { RabbitMQBackend, parseAmqpUrl } from "./queueBackends/rabbitmqBackend.js";
|
|
63
|
+
export type { RabbitMQConfig } from "./queueBackends/rabbitmqBackend.js";
|
|
64
|
+
export { KafkaBackend, kafkaSecurityConfig } from "./queueBackends/kafkaBackend.js";
|
|
65
|
+
export type { KafkaConfig, KafkaSecurityConfig, KafkaClientConfig, } from "./queueBackends/kafkaBackend.js";
|
|
66
|
+
export { MongoBackend } from "./queueBackends/mongoBackend.js";
|
|
67
|
+
export type { MongoConfig as MongoQueueConfig } from "./queueBackends/mongoBackend.js";
|
|
68
|
+
export { DatabaseSessionHandler } from "./sessionHandlers/databaseHandler.js";
|
|
69
|
+
export type { DatabaseSessionConfig } from "./sessionHandlers/databaseHandler.js";
|
|
70
|
+
export { MongoSessionHandler } from "./sessionHandlers/mongoHandler.js";
|
|
71
|
+
export type { MongoSessionConfig } from "./sessionHandlers/mongoHandler.js";
|
|
72
|
+
export { ValkeySessionHandler } from "./sessionHandlers/valkeyHandler.js";
|
|
73
|
+
export type { ValkeySessionConfig } from "./sessionHandlers/valkeyHandler.js";
|
|
74
|
+
export { tests, assertEqual, assertRaises, assertTrue, assertFalse, runAll, reset } from "./testing.js";
|
|
75
|
+
export { TestClient, TestResponse } from "./testClient.js";
|
|
76
|
+
export { Tina4Test, AssertionError as Tina4AssertionError } from "./test.js";
|
|
77
|
+
export type { TestRunResults } from "./test.js";
|
|
78
|
+
export { Container, container } from "./container.js";
|
|
79
|
+
export { Validator } from "./validator.js";
|
|
80
|
+
export type { ValidationError } from "./validator.js";
|
|
81
|
+
export type { WebSocketConnection } from "./websocketConnection.js";
|
|
82
|
+
export { RedisBackplane, NATSBackplane, createBackplane, WsBackplaneManager, buildEnvelope, WS_BACKPLANE_CHANNEL, } from "./websocketBackplane.js";
|
|
83
|
+
export type { WebSocketBackplane, WsEnvelope, WsEnvelopeKind, WsBackplaneLogger, } from "./websocketBackplane.js";
|
|
84
|
+
export { McpServer, mcpTool, mcpResource, registerDevTools, getDefaultDevServer, encodeResponse, encodeError, encodeNotification, decodeRequest, schemaFromParams, isLocalhost, isLoopback, mcpEnabled, isRequestAllowed, mcpPort, PARSE_ERROR, INVALID_REQUEST, METHOD_NOT_FOUND, INVALID_PARAMS, INTERNAL_ERROR, } from "./mcp.js";
|
|
85
|
+
export type { JsonRpcMessage, McpToolDefinition, McpResourceDefinition, JsonSchema, McpToolParam } from "./mcp.js";
|
|
86
|
+
export { Plan } from "./plan.js";
|
|
87
|
+
export type { PlanStep, ParsedPlan, PlanSummary, ExecutionSummary, CurrentPlan } from "./plan.js";
|
|
88
|
+
export { ProjectIndex } from "./projectIndex.js";
|
|
89
|
+
export type { FileEntry, FileRoute } from "./projectIndex.js";
|
|
90
|
+
export { Docs } from "./docs.js";
|
|
91
|
+
export type { DocsHit, ClassSpec, MethodSpec, IndexEntry, DriftHit } from "./docs.js";
|
|
92
|
+
export { writeMcpDiscovery } from "./docsAutoDiscovery.js";
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tina4 Queue Job — a single queue job with lifecycle methods.
|
|
3
|
+
*/
|
|
4
|
+
export interface JobData {
|
|
5
|
+
id: string;
|
|
6
|
+
payload: unknown;
|
|
7
|
+
status: "pending" | "reserved" | "failed" | "dead" | "completed";
|
|
8
|
+
createdAt: string;
|
|
9
|
+
attempts: number;
|
|
10
|
+
delayUntil: string | null;
|
|
11
|
+
priority: number;
|
|
12
|
+
topic: string;
|
|
13
|
+
error?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface JobLifecycle {
|
|
16
|
+
/** Mark this job as completed. */
|
|
17
|
+
complete(): void;
|
|
18
|
+
/** Mark this job as failed with a reason. */
|
|
19
|
+
fail(reason?: string): void;
|
|
20
|
+
/** Reject this job with a reason. Alias for fail(). */
|
|
21
|
+
reject(reason?: string): void;
|
|
22
|
+
/** Re-queue this job with incremented attempts and optional delay. */
|
|
23
|
+
retry(delaySeconds?: number): void;
|
|
24
|
+
/** Return job fields as a flat array of values. */
|
|
25
|
+
toArray(): unknown[];
|
|
26
|
+
/** Return job as a plain object. */
|
|
27
|
+
toHash(): Record<string, unknown>;
|
|
28
|
+
/** Return job as a JSON string. */
|
|
29
|
+
toJson(): string;
|
|
30
|
+
}
|
|
31
|
+
export type QueueJob = JobData & JobLifecycle;
|
|
32
|
+
export interface JobQueueBridge {
|
|
33
|
+
_failJob(topic: string, job: QueueJob, reason: string, maxRetries: number): void;
|
|
34
|
+
_retryJob(topic: string, job: QueueJob, delaySeconds?: number): void;
|
|
35
|
+
_completeJob(topic: string, job: QueueJob): void;
|
|
36
|
+
getMaxRetries(): number;
|
|
37
|
+
}
|
|
38
|
+
/** Create a QueueJob with lifecycle methods bound to a Queue instance. */
|
|
39
|
+
export declare function createJob(data: JobData, queue: JobQueueBridge): QueueJob;
|