tina4-nodejs 3.13.92 → 3.13.94

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 (134) hide show
  1. package/CLAUDE.md +16 -3
  2. package/README.md +1 -1
  3. package/package.json +12 -9
  4. package/packages/cli/dist/bin.js +1260 -969
  5. package/packages/core/dist/index.js +1260 -969
  6. package/packages/core/src/devMailbox.ts +20 -44
  7. package/packages/core/src/index.ts +2 -2
  8. package/packages/core/src/messenger.ts +72 -0
  9. package/packages/core/src/queueBackends/kafkaBackend.ts +108 -12
  10. package/packages/core/src/sessionHandlers/childError.ts +72 -0
  11. package/packages/core/src/sessionHandlers/mongoClient.ts +9 -3
  12. package/packages/core/src/sessionHandlers/redisHandler.ts +18 -5
  13. package/packages/core/src/sessionHandlers/respClient.ts +5 -1
  14. package/packages/frond/dist/index.js +74 -31
  15. package/packages/frond/src/engine.ts +99 -33
  16. package/packages/orm/dist/index.js +3055 -2764
  17. package/packages/orm/src/adapters/sqlite.ts +4 -1
  18. package/packages/orm/src/database.ts +108 -8
  19. package/types/cli/src/bin.d.ts +92 -0
  20. package/types/cli/src/commands/build.d.ts +2 -0
  21. package/types/cli/src/commands/generate.d.ts +47 -0
  22. package/types/cli/src/commands/init.d.ts +1 -0
  23. package/types/cli/src/commands/metrics.d.ts +6 -0
  24. package/types/cli/src/commands/migrate.d.ts +1 -0
  25. package/types/cli/src/commands/migrateCreate.d.ts +1 -0
  26. package/types/cli/src/commands/migrateRollback.d.ts +1 -0
  27. package/types/cli/src/commands/migrateStatus.d.ts +1 -0
  28. package/types/cli/src/commands/queue.d.ts +20 -0
  29. package/types/cli/src/commands/routes.d.ts +1 -0
  30. package/types/cli/src/commands/seed.d.ts +1 -0
  31. package/types/cli/src/commands/serve.d.ts +6 -0
  32. package/types/cli/src/commands/test.d.ts +1 -0
  33. package/types/core/src/ai.d.ts +64 -0
  34. package/types/core/src/api.d.ts +262 -0
  35. package/types/core/src/auth.d.ts +154 -0
  36. package/types/core/src/authGate.d.ts +20 -0
  37. package/types/core/src/background.d.ts +34 -0
  38. package/types/core/src/cache.d.ts +160 -0
  39. package/types/core/src/constants.d.ts +38 -0
  40. package/types/core/src/container.d.ts +44 -0
  41. package/types/core/src/context/chunker.d.ts +31 -0
  42. package/types/core/src/context/index.d.ts +93 -0
  43. package/types/core/src/devAdmin.d.ts +179 -0
  44. package/types/core/src/devMailbox.d.ts +54 -0
  45. package/types/core/src/docs.d.ts +141 -0
  46. package/types/core/src/docsAutoDiscovery.d.ts +6 -0
  47. package/types/core/src/dotenv.d.ts +65 -0
  48. package/types/core/src/env.d.ts +28 -0
  49. package/types/core/src/errorOverlay.d.ts +36 -0
  50. package/types/core/src/events.d.ts +75 -0
  51. package/types/core/src/fakeData.d.ts +55 -0
  52. package/types/core/src/feedback.d.ts +90 -0
  53. package/types/core/src/graphql.d.ts +207 -0
  54. package/types/core/src/health.d.ts +22 -0
  55. package/types/core/src/htmlElement.d.ts +75 -0
  56. package/types/core/src/i18n.d.ts +37 -0
  57. package/types/core/src/index.d.ts +93 -0
  58. package/types/core/src/job.d.ts +39 -0
  59. package/types/core/src/logger.d.ts +123 -0
  60. package/types/core/src/mcp.d.ts +248 -0
  61. package/types/core/src/messenger.d.ts +191 -0
  62. package/types/core/src/metrics.d.ts +77 -0
  63. package/types/core/src/middleware.d.ts +207 -0
  64. package/types/core/src/mqtt.d.ts +257 -0
  65. package/types/core/src/mqttMessage.d.ts +67 -0
  66. package/types/core/src/plan.d.ts +96 -0
  67. package/types/core/src/projectIndex.d.ts +56 -0
  68. package/types/core/src/queue.d.ts +219 -0
  69. package/types/core/src/queueBackends/kafkaBackend.d.ts +117 -0
  70. package/types/core/src/queueBackends/liteBackend.d.ts +119 -0
  71. package/types/core/src/queueBackends/mongoBackend.d.ts +97 -0
  72. package/types/core/src/queueBackends/rabbitmqBackend.d.ts +55 -0
  73. package/types/core/src/rateLimiter.d.ts +49 -0
  74. package/types/core/src/request.d.ts +25 -0
  75. package/types/core/src/response.d.ts +28 -0
  76. package/types/core/src/routeDiscovery.d.ts +12 -0
  77. package/types/core/src/router.d.ts +355 -0
  78. package/types/core/src/scss.d.ts +19 -0
  79. package/types/core/src/server.d.ts +131 -0
  80. package/types/core/src/service.d.ts +115 -0
  81. package/types/core/src/session.d.ts +256 -0
  82. package/types/core/src/sessionHandlers/childError.d.ts +34 -0
  83. package/types/core/src/sessionHandlers/databaseHandler.d.ts +42 -0
  84. package/types/core/src/sessionHandlers/mongoClient.d.ts +24 -0
  85. package/types/core/src/sessionHandlers/mongoHandler.d.ts +61 -0
  86. package/types/core/src/sessionHandlers/redisHandler.d.ts +60 -0
  87. package/types/core/src/sessionHandlers/respClient.d.ts +22 -0
  88. package/types/core/src/sessionHandlers/valkeyHandler.d.ts +65 -0
  89. package/types/core/src/static.d.ts +2 -0
  90. package/types/core/src/test.d.ts +94 -0
  91. package/types/core/src/testClient.d.ts +36 -0
  92. package/types/core/src/testing.d.ts +58 -0
  93. package/types/core/src/types.d.ts +219 -0
  94. package/types/core/src/validator.d.ts +52 -0
  95. package/types/core/src/websocket.d.ts +376 -0
  96. package/types/core/src/websocketBackplane.d.ts +166 -0
  97. package/types/core/src/websocketConnection.d.ts +54 -0
  98. package/types/core/src/wsdl.d.ts +101 -0
  99. package/types/frond/src/engine.d.ts +263 -0
  100. package/types/frond/src/index.d.ts +2 -0
  101. package/types/orm/src/adapters/firebird.d.ts +138 -0
  102. package/types/orm/src/adapters/mongodb.d.ts +81 -0
  103. package/types/orm/src/adapters/mssql.d.ts +70 -0
  104. package/types/orm/src/adapters/mysql.d.ts +66 -0
  105. package/types/orm/src/adapters/odbc.d.ts +97 -0
  106. package/types/orm/src/adapters/postgres.d.ts +85 -0
  107. package/types/orm/src/adapters/sqlite.d.ts +56 -0
  108. package/types/orm/src/autoCrud.d.ts +73 -0
  109. package/types/orm/src/baseModel.d.ts +391 -0
  110. package/types/orm/src/cachedDatabase.d.ts +177 -0
  111. package/types/orm/src/database.d.ts +609 -0
  112. package/types/orm/src/databaseResult.d.ts +85 -0
  113. package/types/orm/src/docstore.d.ts +182 -0
  114. package/types/orm/src/fakeData.d.ts +22 -0
  115. package/types/orm/src/index.d.ts +40 -0
  116. package/types/orm/src/migration.d.ts +275 -0
  117. package/types/orm/src/model.d.ts +7 -0
  118. package/types/orm/src/query.d.ts +14 -0
  119. package/types/orm/src/queryBuilder.d.ts +173 -0
  120. package/types/orm/src/realtime/index.d.ts +7 -0
  121. package/types/orm/src/realtime/models/attachment.d.ts +43 -0
  122. package/types/orm/src/realtime/models/channel.d.ts +32 -0
  123. package/types/orm/src/realtime/models/channelMember.d.ts +32 -0
  124. package/types/orm/src/realtime/models/message.d.ts +36 -0
  125. package/types/orm/src/realtime/models/workspace.d.ts +26 -0
  126. package/types/orm/src/realtime/realtime.d.ts +24 -0
  127. package/types/orm/src/realtime/storage.d.ts +61 -0
  128. package/types/orm/src/seeder.d.ts +118 -0
  129. package/types/orm/src/sqlTranslator.d.ts +134 -0
  130. package/types/orm/src/types.d.ts +138 -0
  131. package/types/orm/src/validation.d.ts +6 -0
  132. package/types/swagger/src/generator.d.ts +46 -0
  133. package/types/swagger/src/index.d.ts +2 -0
  134. package/types/swagger/src/ui.d.ts +11 -0
@@ -0,0 +1,134 @@
1
+ /**
2
+ * Tina4 SQL Translation — Cross-engine SQL translator.
3
+ *
4
+ * Translates SQL dialect differences between engines so that application
5
+ * code can use a single SQL style and have it adapted at runtime.
6
+ *
7
+ * import { SQLTranslator } from "@tina4/orm";
8
+ *
9
+ * // Firebird: LIMIT/OFFSET → ROWS X TO Y
10
+ * SQLTranslator.limitToRows("SELECT * FROM users LIMIT 10 OFFSET 5");
11
+ * // → "SELECT * FROM users ROWS 6 TO 15"
12
+ *
13
+ * // MSSQL: LIMIT → TOP N
14
+ * SQLTranslator.limitToTop("SELECT * FROM users LIMIT 10");
15
+ * // → "SELECT TOP 10 * FROM users"
16
+ *
17
+ * Also includes a query cache with TTL support.
18
+ */
19
+ export declare class SQLTranslator {
20
+ /**
21
+ * Convert LIMIT/OFFSET to Firebird ROWS...TO syntax.
22
+ *
23
+ * LIMIT 10 OFFSET 5 → ROWS 6 TO 15
24
+ * LIMIT 10 → ROWS 1 TO 10
25
+ */
26
+ static limitToRows(sql: string): string;
27
+ /**
28
+ * Convert LIMIT to MSSQL TOP syntax.
29
+ *
30
+ * SELECT ... LIMIT 10 → SELECT TOP 10 ...
31
+ * Does NOT convert if OFFSET is present (TOP doesn't support it).
32
+ */
33
+ static limitToTop(sql: string): string;
34
+ /**
35
+ * Convert || concatenation to CONCAT() for MySQL/MSSQL.
36
+ *
37
+ * 'a' || 'b' || 'c' → CONCAT('a', 'b', 'c')
38
+ */
39
+ static concatPipesToFunc(sql: string): string;
40
+ /**
41
+ * Convert TRUE/FALSE to 1/0 for engines without boolean type (Firebird).
42
+ */
43
+ static booleanToInt(sql: string): string;
44
+ /**
45
+ * Convert ILIKE to LOWER() LIKE LOWER() for engines without ILIKE.
46
+ */
47
+ static ilikeToLike(sql: string): string;
48
+ /**
49
+ * Translate AUTOINCREMENT across engines in DDL.
50
+ */
51
+ static autoIncrementSyntax(sql: string, engine: string): string;
52
+ /**
53
+ * Convert ? placeholders to engine-specific style.
54
+ *
55
+ * ? → %s (MySQL, PostgreSQL)
56
+ * ? → :1, :2, :3 (Oracle, Firebird)
57
+ */
58
+ static placeholderStyle(sql: string, style: string): string;
59
+ /**
60
+ * Detect and strip RETURNING clause from INSERT/UPDATE statements.
61
+ * Returns the cleaned SQL and the list of RETURNING columns.
62
+ *
63
+ * "INSERT INTO t (x) VALUES (1) RETURNING id, name"
64
+ * → { sql: "INSERT INTO t (x) VALUES (1)", columns: ["id", "name"] }
65
+ */
66
+ static parseReturning(sql: string): {
67
+ sql: string;
68
+ columns: string[];
69
+ };
70
+ /**
71
+ * v3.13.14 (#48): split a possibly-qualified table name into [schema, table].
72
+ *
73
+ * A model whose table name is qualified — PostgreSQL "gift_cards.gift_card",
74
+ * MSSQL "dbo.widget", MySQL "otherdb.table", SQLite "attached.table" — lives
75
+ * in that schema/catalog, not the default. Adapters use this so tableExists /
76
+ * getColumns query the right namespace instead of matching the whole dotted
77
+ * string as one flat name. Returns [null, name] for a bare name. Splits on the
78
+ * first dot. Firebird has no schemas, so its adapter ignores this.
79
+ */
80
+ static splitSchema(name: string): [string | null, string];
81
+ }
82
+ /**
83
+ * Simple in-memory query cache with TTL support.
84
+ */
85
+ export declare class QueryCache {
86
+ private store;
87
+ private defaultTtl;
88
+ private maxSize;
89
+ constructor(options?: {
90
+ defaultTtl?: number;
91
+ maxSize?: number;
92
+ });
93
+ /**
94
+ * Generate a cache key from a SQL query and params.
95
+ */
96
+ static queryKey(sql: string, params?: unknown[]): string;
97
+ /**
98
+ * Get a cached value. Returns undefined if expired or missing.
99
+ */
100
+ get<T>(key: string): T | undefined;
101
+ /**
102
+ * Set a cached value with optional TTL (seconds) and tags for grouped
103
+ * invalidation via clearTag().
104
+ */
105
+ set<T>(key: string, value: T, ttl?: number, tags?: string[]): void;
106
+ /**
107
+ * Remove all entries that carry the given tag. Returns the number removed.
108
+ */
109
+ clearTag(tag: string): number;
110
+ /**
111
+ * Check if a key exists and is not expired.
112
+ */
113
+ has(key: string): boolean;
114
+ /**
115
+ * Delete a specific key.
116
+ */
117
+ delete(key: string): boolean;
118
+ /**
119
+ * Remove all expired entries.
120
+ */
121
+ sweep(): number;
122
+ /**
123
+ * Clear all cached entries.
124
+ */
125
+ clear(): void;
126
+ /**
127
+ * Get the number of cached entries.
128
+ */
129
+ size(): number;
130
+ /**
131
+ * Get or set a value using a factory function.
132
+ */
133
+ remember<T>(key: string, ttl: number, factory: () => T): T;
134
+ }
@@ -0,0 +1,138 @@
1
+ export type FieldType = "string" | "integer" | "number" | "numeric" | "boolean" | "datetime" | "text" | "json" | "foreignKey";
2
+ export interface FieldDefinition {
3
+ type: FieldType;
4
+ primaryKey?: boolean;
5
+ autoIncrement?: boolean;
6
+ required?: boolean;
7
+ default?: unknown;
8
+ minLength?: number;
9
+ maxLength?: number;
10
+ min?: number;
11
+ max?: number;
12
+ pattern?: string;
13
+ /** For type "foreignKey": the referenced model name (string) */
14
+ references?: string;
15
+ /** For type "foreignKey": override the has-many property name on the referenced model */
16
+ relatedName?: string;
17
+ }
18
+ export interface RelationshipDefinition {
19
+ model: string;
20
+ foreignKey: string;
21
+ /**
22
+ * The relationship accessor/include name on the OWNING model. For an
23
+ * FK-auto-wired has-many this is the declaring class name lowercased + "s"
24
+ * (Python master rule) or the `relatedName` override. Used by eager-load
25
+ * include resolution so an `include: ["posts"]` matches the wired relation.
26
+ */
27
+ relatedName?: string;
28
+ }
29
+ export interface ModelDefinition {
30
+ tableName: string;
31
+ fields: Record<string, FieldDefinition>;
32
+ fieldMapping?: Record<string, string>;
33
+ softDelete?: boolean;
34
+ tableFilter?: string;
35
+ hasOne?: RelationshipDefinition[];
36
+ hasMany?: RelationshipDefinition[];
37
+ belongsTo?: RelationshipDefinition[];
38
+ dbName?: string;
39
+ }
40
+ export interface ColumnInfo {
41
+ name: string;
42
+ type: string;
43
+ nullable?: boolean;
44
+ default?: unknown;
45
+ primaryKey?: boolean;
46
+ }
47
+ export interface DatabaseResult {
48
+ success: boolean;
49
+ affectedRows: number;
50
+ lastId?: number | bigint | string;
51
+ error?: string;
52
+ }
53
+ export interface DatabaseAdapter {
54
+ /** Execute a statement (INSERT, UPDATE, DELETE, DDL). */
55
+ execute(sql: string, params?: unknown[]): unknown;
56
+ /** Execute a single SQL statement with multiple parameter sets (batch). */
57
+ executeMany(sql: string, paramsList: unknown[][]): {
58
+ totalAffected: number;
59
+ lastId?: number | bigint;
60
+ };
61
+ /** Query rows. */
62
+ query<T = Record<string, unknown>>(sql: string, params?: unknown[]): T[];
63
+ /** Fetch rows with optional pagination (limit/skip). */
64
+ fetch<T = Record<string, unknown>>(sql: string, params?: unknown[], limit?: number, skip?: number): T[];
65
+ /** Fetch a single row or null. */
66
+ fetchOne<T = Record<string, unknown>>(sql: string, params?: unknown[]): T | null;
67
+ /** Insert one or more rows into a table, returns result with lastId. */
68
+ 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>, params?: unknown[]): DatabaseResult;
71
+ /** Delete rows from a table matching filter (object, string WHERE, or array of objects). */
72
+ delete(table: string, filter: Record<string, unknown> | string | Record<string, unknown>[], params?: unknown[]): DatabaseResult;
73
+ /** Start a transaction. */
74
+ startTransaction(): void;
75
+ /** Commit the current transaction. */
76
+ commit(): void;
77
+ /** Rollback the current transaction. */
78
+ rollback(): void;
79
+ /** List all tables in the database. */
80
+ tables(): string[];
81
+ /** List columns with types for a table. */
82
+ columns(table: string): ColumnInfo[];
83
+ /** Get the last inserted id (auto-increment integer, or a UUID/string PK). */
84
+ lastInsertId(): number | bigint | string | null;
85
+ /** Close the connection. */
86
+ close(): void;
87
+ /** Check if a table exists. */
88
+ tableExists(name: string): boolean;
89
+ /** Create a table from field definitions. */
90
+ createTable(name: string, columns: Record<string, FieldDefinition>): void;
91
+ /** Get raw column info (legacy, used by migration). */
92
+ getTableColumns?(name: string): Array<{
93
+ name: string;
94
+ type: string;
95
+ }>;
96
+ /** Add a column to an existing table (legacy, used by migration). */
97
+ addColumn?(table: string, colName: string, def: FieldDefinition): void;
98
+ }
99
+ export interface PaginatedResult<T = Record<string, unknown>> {
100
+ data: T[];
101
+ page: number;
102
+ perPage: number;
103
+ total: number;
104
+ totalPages: number;
105
+ hasNext: boolean;
106
+ hasPrev: boolean;
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>;
132
+ }
133
+ export interface QueryOptions {
134
+ filter?: Record<string, unknown>;
135
+ sort?: string;
136
+ page?: number;
137
+ limit?: number;
138
+ }
@@ -0,0 +1,6 @@
1
+ import type { FieldDefinition } from "./types.js";
2
+ export interface ValidationError {
3
+ field: string;
4
+ message: string;
5
+ }
6
+ export declare function validate(data: Record<string, unknown>, fields: Record<string, FieldDefinition>, isUpdate?: boolean): ValidationError[];
@@ -0,0 +1,46 @@
1
+ import type { RouteDefinition } from "../../core/src/index.js";
2
+ import type { ModelDefinition } from "../../orm/src/index.js";
3
+ interface OpenAPISpecInfo {
4
+ title: string;
5
+ version: string;
6
+ description?: string;
7
+ contact?: {
8
+ name?: string;
9
+ url?: string;
10
+ email?: string;
11
+ };
12
+ license?: {
13
+ name: string;
14
+ url?: string;
15
+ };
16
+ }
17
+ interface OpenAPISpec {
18
+ openapi: string;
19
+ info: OpenAPISpecInfo;
20
+ servers?: {
21
+ url: string;
22
+ }[];
23
+ paths: Record<string, Record<string, unknown>>;
24
+ components?: {
25
+ schemas?: Record<string, unknown>;
26
+ securitySchemes?: Record<string, unknown>;
27
+ };
28
+ tags?: {
29
+ name: string;
30
+ }[];
31
+ }
32
+ /**
33
+ * Register a named OpenAPI security scheme (e.g. an oauth2 scheme with scopes,
34
+ * or a custom apiKey). Call at app bootstrap, before generate(). A registered
35
+ * scheme may override the built-in bearerAuth.
36
+ */
37
+ export declare function addSecurityScheme(name: string, definition: Record<string, unknown>): void;
38
+ /**
39
+ * Register a reusable component schema, referenceable via meta.requestSchema /
40
+ * meta.responseSchemas or a raw $ref.
41
+ */
42
+ export declare function addSchema(name: string, schema: Record<string, unknown>): void;
43
+ /** Clear the security-scheme and schema registries (test helper). */
44
+ export declare function resetRegistry(): void;
45
+ export declare function generate(routes: RouteDefinition[], models?: ModelDefinition[]): OpenAPISpec;
46
+ export {};
@@ -0,0 +1,2 @@
1
+ export { generate, addSecurityScheme, addSchema, resetRegistry } from "./generator.js";
2
+ export { createSwaggerRoutes, swaggerEnabled } from "./ui.js";
@@ -0,0 +1,11 @@
1
+ import type { RouteDefinition } from "../../core/src/index.js";
2
+ /**
3
+ * Whether the Swagger UI + spec routes should be registered at boot.
4
+ *
5
+ * Default: enabled when `TINA4_DEBUG=true`, disabled otherwise. Operators
6
+ * can force either state with `TINA4_SWAGGER_ENABLED=true|false`. Matches
7
+ * Python parity: dev-only by default to keep production attack surface
8
+ * minimal, but easy to expose intentionally for public APIs.
9
+ */
10
+ export declare function swaggerEnabled(): boolean;
11
+ export declare function createSwaggerRoutes(getSpec: () => unknown): RouteDefinition[];