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,66 @@
1
+ /**
2
+ * Tina4 MySQL Adapter — uses the `mysql2` package (optional peer dependency).
3
+ *
4
+ * Install: npm install mysql2
5
+ * URL format: mysql://user:pass@host:port/database
6
+ */
7
+ import type { DatabaseAdapter, DatabaseResult, ColumnInfo, FieldDefinition } from "../types.js";
8
+ export interface MysqlConfig {
9
+ host?: string;
10
+ port?: number;
11
+ user?: string;
12
+ password?: string;
13
+ database?: string;
14
+ connectionString?: string;
15
+ }
16
+ export declare class MysqlAdapter implements DatabaseAdapter {
17
+ private config;
18
+ private connection;
19
+ private _lastInsertId;
20
+ private _inTransaction;
21
+ constructor(config: MysqlConfig | string);
22
+ /** Connect to MySQL. Must be called before using the adapter. */
23
+ connect(): Promise<void>;
24
+ private ensureConnected;
25
+ private queryPromise;
26
+ /** Translate SQL for MySQL dialect. */
27
+ translateSql(sql: string): string;
28
+ execute(sql: string, params?: unknown[]): unknown;
29
+ executeMany(sql: string, paramsList: unknown[][]): {
30
+ totalAffected: number;
31
+ lastId?: number | bigint;
32
+ };
33
+ executeManyAsync(sql: string, paramsList: unknown[][]): Promise<{
34
+ totalAffected: number;
35
+ lastId?: number | bigint;
36
+ }>;
37
+ executeAsync(sql: string, params?: unknown[]): Promise<unknown>;
38
+ query<T = Record<string, unknown>>(sql: string, params?: unknown[]): T[];
39
+ queryAsync<T = Record<string, unknown>>(sql: string, params?: unknown[]): Promise<T[]>;
40
+ fetch<T = Record<string, unknown>>(sql: string, params?: unknown[], limit?: number, skip?: number): T[];
41
+ fetchAsync<T = Record<string, unknown>>(sql: string, params?: unknown[], limit?: number, skip?: number): Promise<T[]>;
42
+ fetchOne<T = Record<string, unknown>>(sql: string, params?: unknown[]): T | null;
43
+ fetchOneAsync<T = Record<string, unknown>>(sql: string, params?: unknown[]): Promise<T | null>;
44
+ insert(table: string, data: Record<string, unknown> | Record<string, unknown>[]): DatabaseResult;
45
+ insertAsync(table: string, data: Record<string, unknown> | Record<string, unknown>[]): Promise<DatabaseResult>;
46
+ update(table: string, data: Record<string, unknown>, filter: Record<string, unknown>, params?: unknown[]): DatabaseResult;
47
+ updateAsync(table: string, data: Record<string, unknown>, filter: Record<string, unknown>): Promise<DatabaseResult>;
48
+ delete(table: string, filter: Record<string, unknown>, params?: unknown[]): DatabaseResult;
49
+ deleteAsync(table: string, filter: Record<string, unknown>): Promise<DatabaseResult>;
50
+ startTransaction(): void;
51
+ startTransactionAsync(): Promise<void>;
52
+ commit(): void;
53
+ commitAsync(): Promise<void>;
54
+ rollback(): void;
55
+ rollbackAsync(): Promise<void>;
56
+ tables(): string[];
57
+ tablesAsync(): Promise<string[]>;
58
+ columns(table: string): ColumnInfo[];
59
+ columnsAsync(table: string): Promise<ColumnInfo[]>;
60
+ lastInsertId(): number | bigint | null;
61
+ close(): void;
62
+ tableExists(name: string): boolean;
63
+ tableExistsAsync(name: string): Promise<boolean>;
64
+ createTable(name: string, columns: Record<string, FieldDefinition>): void;
65
+ createTableAsync(name: string, columns: Record<string, FieldDefinition>): Promise<void>;
66
+ }
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Tina4 ODBC Adapter — uses the `odbc` package (optional peer dependency).
3
+ *
4
+ * Install: npm install odbc
5
+ * URL format: odbc:///DSN=MyDSN
6
+ * odbc:///DRIVER={driver};SERVER=host;DATABASE=db
7
+ *
8
+ * The connection string after stripping the "odbc:///" prefix is passed
9
+ * directly to odbc.connect(), so any valid ODBC connection string works.
10
+ */
11
+ import type { DatabaseAdapter, DatabaseResult, ColumnInfo, FieldDefinition } from "../types.js";
12
+ export interface OdbcConfig {
13
+ /** Full ODBC connection string, e.g. "DSN=MyDSN" or "DRIVER={SQL Server};SERVER=host;DATABASE=db" */
14
+ connectionString: string;
15
+ }
16
+ export declare class OdbcAdapter implements DatabaseAdapter {
17
+ private config;
18
+ private connection;
19
+ private _lastInsertId;
20
+ private _inTransaction;
21
+ /**
22
+ * Accepts either an OdbcConfig object or a raw connection string.
23
+ * When created via Database.create("odbc:///DSN=MyDSN"), the "odbc:///"
24
+ * prefix is stripped by parseDatabaseUrl and the remainder is passed here.
25
+ */
26
+ constructor(config: OdbcConfig | string);
27
+ /** Extract the raw ODBC connection string from config. */
28
+ private getConnectionString;
29
+ /** Connect to the ODBC data source. Must be called before using the adapter. */
30
+ connect(): Promise<void>;
31
+ private ensureConnected;
32
+ execute(sql: string, params?: unknown[]): unknown;
33
+ executeMany(sql: string, paramsList: unknown[][]): {
34
+ totalAffected: number;
35
+ lastId?: number | bigint;
36
+ };
37
+ query<T = Record<string, unknown>>(sql: string, params?: unknown[]): T[];
38
+ fetch<T = Record<string, unknown>>(sql: string, params?: unknown[], limit?: number, skip?: number): T[];
39
+ fetchOne<T = Record<string, unknown>>(sql: string, params?: unknown[]): T | null;
40
+ insert(table: string, data: Record<string, unknown>): DatabaseResult;
41
+ update(table: string, data: Record<string, unknown>, filter: Record<string, unknown>): DatabaseResult;
42
+ delete(table: string, filter: Record<string, unknown> | string | Record<string, unknown>[]): DatabaseResult;
43
+ startTransaction(): void;
44
+ commit(): void;
45
+ rollback(): void;
46
+ tables(): string[];
47
+ columns(table: string): ColumnInfo[];
48
+ tableExists(name: string): boolean;
49
+ createTable(name: string, columns: Record<string, FieldDefinition>): void;
50
+ getTableColumns(name: string): Array<{
51
+ name: string;
52
+ type: string;
53
+ }>;
54
+ addColumn(table: string, colName: string, def: FieldDefinition): void;
55
+ /** Execute a write statement (INSERT, UPDATE, DELETE, DDL). */
56
+ executeAsync(sql: string, params?: unknown[]): Promise<unknown>;
57
+ /** Execute a statement with multiple parameter sets inside a single transaction. */
58
+ executeManyAsync(sql: string, paramsList: unknown[][]): Promise<{
59
+ totalAffected: number;
60
+ lastId?: number | bigint;
61
+ }>;
62
+ /** Run a SELECT and return all matching rows. */
63
+ queryAsync<T = Record<string, unknown>>(sql: string, params?: unknown[]): Promise<T[]>;
64
+ /** Run a SELECT with optional LIMIT/OFFSET pagination. */
65
+ fetchAsync<T = Record<string, unknown>>(sql: string, params?: unknown[], limit?: number, skip?: number): Promise<T[]>;
66
+ /** Run a SELECT and return the first row or null. */
67
+ fetchOneAsync<T = Record<string, unknown>>(sql: string, params?: unknown[]): Promise<T | null>;
68
+ /** Insert a single row into a table. */
69
+ insertAsync(table: string, data: Record<string, unknown>): Promise<DatabaseResult>;
70
+ /** Update rows in a table matching filter. */
71
+ updateAsync(table: string, data: Record<string, unknown>, filter: Record<string, unknown>): Promise<DatabaseResult>;
72
+ /** Delete rows from a table. */
73
+ deleteAsync(table: string, filter: Record<string, unknown> | string | Record<string, unknown>[]): Promise<DatabaseResult>;
74
+ /** Begin a transaction. */
75
+ startTransactionAsync(): Promise<void>;
76
+ /** Commit the current transaction. */
77
+ commitAsync(): Promise<void>;
78
+ /** Rollback the current transaction. */
79
+ rollbackAsync(): Promise<void>;
80
+ /** List all user tables using ODBC catalog functions. */
81
+ tablesAsync(): Promise<string[]>;
82
+ /** Get column metadata for a table using ODBC catalog functions. */
83
+ columnsAsync(table: string): Promise<ColumnInfo[]>;
84
+ /** Check whether a table exists. */
85
+ tableExistsAsync(name: string): Promise<boolean>;
86
+ /** Create a table from a FieldDefinition map. Uses generic SQL — works with most ODBC sources. */
87
+ createTableAsync(name: string, columns: Record<string, FieldDefinition>): Promise<void>;
88
+ /** Get raw column name+type list for a table. */
89
+ getTableColumnsAsync(name: string): Promise<Array<{
90
+ name: string;
91
+ type: string;
92
+ }>>;
93
+ /** Add a column to an existing table. */
94
+ addColumnAsync(table: string, colName: string, def: FieldDefinition): Promise<void>;
95
+ lastInsertId(): number | bigint | null;
96
+ close(): void;
97
+ }
@@ -0,0 +1,85 @@
1
+ /**
2
+ * Tina4 PostgreSQL Adapter — uses the `pg` package (optional peer dependency).
3
+ *
4
+ * Install: npm install pg @types/pg
5
+ * URL format: postgresql://user:pass@host:port/database
6
+ */
7
+ import type { DatabaseAdapter, DatabaseResult, ColumnInfo, FieldDefinition } from "../types.js";
8
+ export interface PostgresConfig {
9
+ host?: string;
10
+ port?: number;
11
+ user?: string;
12
+ password?: string;
13
+ database?: string;
14
+ connectionString?: string;
15
+ }
16
+ export declare class PostgresAdapter implements DatabaseAdapter {
17
+ private config;
18
+ private client;
19
+ private _lastInsertId;
20
+ private _inTransaction;
21
+ constructor(config: PostgresConfig | string);
22
+ /** Connect to PostgreSQL. Must be called before using the adapter. */
23
+ connect(): Promise<void>;
24
+ private ensureConnected;
25
+ /** Convert ? placeholders to $1, $2, ... for pg. */
26
+ /** Ensure bytea columns are Buffer (already the case with pg). No-op guard. */
27
+ private decodeBlobs;
28
+ private convertPlaceholders;
29
+ /**
30
+ * Normalise an `id` column value (typed `unknown` because pg row values are
31
+ * `unknown`) into the shape `_lastInsertId` / `DatabaseResult.lastId`
32
+ * expect. At runtime PG returns numeric PKs as number/bigint (the int8/numeric
33
+ * type parsers above coerce them to Number); a numeric string is coerced to a
34
+ * number so the SERIAL path always returns the integer id.
35
+ *
36
+ * A non-numeric string id — the UUID PK case (`id uuid PRIMARY KEY DEFAULT
37
+ * gen_random_uuid()`) returned via RETURNING — is preserved as-is so the
38
+ * insert surfaces the actual id instead of null (#256). null/undefined/empty
39
+ * still become null.
40
+ */
41
+ private normalizeId;
42
+ execute(sql: string, params?: unknown[]): unknown;
43
+ executeMany(sql: string, paramsList: unknown[][]): {
44
+ totalAffected: number;
45
+ lastId?: number | bigint;
46
+ };
47
+ /** Async executeMany for real usage. */
48
+ executeManyAsync(sql: string, paramsList: unknown[][]): Promise<{
49
+ totalAffected: number;
50
+ lastId?: number | bigint;
51
+ }>;
52
+ /** Async execute for real usage. */
53
+ executeAsync(sql: string, params?: unknown[]): Promise<unknown>;
54
+ query<T = Record<string, unknown>>(sql: string, params?: unknown[]): T[];
55
+ /** Async query for real usage. */
56
+ queryAsync<T = Record<string, unknown>>(sql: string, params?: unknown[]): Promise<T[]>;
57
+ fetch<T = Record<string, unknown>>(sql: string, params?: unknown[], limit?: number, skip?: number): T[];
58
+ fetchAsync<T = Record<string, unknown>>(sql: string, params?: unknown[], limit?: number, skip?: number): Promise<T[]>;
59
+ fetchOne<T = Record<string, unknown>>(sql: string, params?: unknown[]): T | null;
60
+ fetchOneAsync<T = Record<string, unknown>>(sql: string, params?: unknown[]): Promise<T | null>;
61
+ insert(table: string, data: Record<string, unknown> | Record<string, unknown>[]): DatabaseResult;
62
+ insertAsync(table: string, data: Record<string, unknown> | Record<string, unknown>[]): Promise<DatabaseResult>;
63
+ update(table: string, data: Record<string, unknown>, filter: Record<string, unknown>, params?: unknown[]): DatabaseResult;
64
+ updateAsync(table: string, data: Record<string, unknown>, filter: Record<string, unknown>): Promise<DatabaseResult>;
65
+ delete(table: string, filter: Record<string, unknown>, params?: unknown[]): DatabaseResult;
66
+ deleteAsync(table: string, filter: Record<string, unknown>): Promise<DatabaseResult>;
67
+ startTransaction(): void;
68
+ startTransactionAsync(): Promise<void>;
69
+ commit(): void;
70
+ commitAsync(): Promise<void>;
71
+ rollback(): void;
72
+ rollbackAsync(): Promise<void>;
73
+ tables(): string[];
74
+ tablesAsync(): Promise<string[]>;
75
+ columns(table: string): ColumnInfo[];
76
+ columnsAsync(table: string): Promise<ColumnInfo[]>;
77
+ lastInsertId(): number | bigint | string | null;
78
+ close(): void;
79
+ tableExists(name: string): boolean;
80
+ tableExistsAsync(name: string): Promise<boolean>;
81
+ createTable(name: string, columns: Record<string, FieldDefinition>): void;
82
+ createTableAsync(name: string, columns: Record<string, FieldDefinition>): Promise<void>;
83
+ /** Translate SQL for PostgreSQL dialect. */
84
+ translateSql(sql: string): string;
85
+ }
@@ -0,0 +1,56 @@
1
+ import type { DatabaseAdapter, DatabaseResult, ColumnInfo, FieldDefinition } from "../types.js";
2
+ export declare class SQLiteAdapter implements DatabaseAdapter {
3
+ private db;
4
+ private _lastInsertId;
5
+ constructor(dbPath: string);
6
+ execute(sql: string, params?: unknown[]): unknown;
7
+ executeMany(sql: string, paramsList: unknown[][]): {
8
+ totalAffected: number;
9
+ lastId?: number | bigint;
10
+ };
11
+ query<T = Record<string, unknown>>(sql: string, params?: unknown[]): T[];
12
+ fetch<T = Record<string, unknown>>(sql: string, params?: unknown[], limit?: number, skip?: number): T[];
13
+ fetchOne<T = Record<string, unknown>>(sql: string, params?: unknown[]): T | null;
14
+ insert(table: string, data: Record<string, unknown> | Record<string, unknown>[]): DatabaseResult;
15
+ update(table: string, data: Record<string, unknown>, filter: Record<string, unknown>, params?: unknown[]): DatabaseResult;
16
+ delete(table: string, filter: Record<string, unknown> | string | Record<string, unknown>[], params?: unknown[]): DatabaseResult;
17
+ private _inTransaction;
18
+ startTransaction(): void;
19
+ commit(): void;
20
+ rollback(): void;
21
+ tables(): string[];
22
+ columns(table: string): ColumnInfo[];
23
+ lastInsertId(): number | bigint | null;
24
+ close(): void;
25
+ /**
26
+ * Atomically increment and return the next value of a tina4_sequences row.
27
+ *
28
+ * DB-contract B (no duplicate primary keys under concurrency): the old
29
+ * read-increment-read path in Database.sequenceNext() yields at every `await`
30
+ * between the read and the write, so two concurrent async callers can read the
31
+ * same `current_value` and return the same id. This method runs the WHOLE
32
+ * operation — ensure-table, seed-if-absent, and the increment-and-return — as
33
+ * ONE synchronous burst on the single shared `node:sqlite` connection. Because
34
+ * `node:sqlite` is synchronous and JavaScript is single-threaded, no other
35
+ * async task can interleave between the statements (there is no `await`
36
+ * inside), so the increment is atomic and every caller gets a distinct id.
37
+ * This is the Node analog of the Python master holding SQLiteAdapter._write_lock
38
+ * across the whole op.
39
+ *
40
+ * On SQLite >= 3.35 a single `UPDATE ... SET current_value = current_value + 1
41
+ * ... RETURNING current_value` is itself atomic and returns the new value in
42
+ * one statement (read via prepare().all() — stmt.run() does not surface
43
+ * RETURNING rows). Older SQLite does `UPDATE ... + 1` then `SELECT`, still
44
+ * race-safe because both run in the same synchronous burst.
45
+ *
46
+ * @throws if the sequence row vanishes mid-increment (never silently returns 1).
47
+ */
48
+ sequenceNextSqlite(seqName: string, seedValue: number): number;
49
+ tableExists(name: string): boolean;
50
+ createTable(name: string, columns: Record<string, FieldDefinition>): void;
51
+ getTableColumns(name: string): Array<{
52
+ name: string;
53
+ type: string;
54
+ }>;
55
+ addColumn(table: string, colName: string, def: FieldDefinition): void;
56
+ }
@@ -0,0 +1,73 @@
1
+ import type { RouteDefinition } from "../../core/src/index.js";
2
+ import type { DiscoveredModel } from "./model.js";
3
+ /**
4
+ * Auto-CRUD — discovers ORM models and auto-generates REST endpoints.
5
+ *
6
+ * Generated endpoints per model:
7
+ * GET /api/{table} — list with pagination, filtering, sorting
8
+ * GET /api/{table}/{id} — get single record
9
+ * POST /api/{table} — create record
10
+ * PUT /api/{table}/{id} — update record
11
+ * DELETE /api/{table}/{id} — delete record
12
+ */
13
+ /**
14
+ * Options accepted by the AutoCrud registration API.
15
+ *
16
+ * `public` is the cross-backend escape hatch (parity with python's `public=True`
17
+ * and php's `bool $public`). Write routes (POST/PUT/DELETE) are secure-by-default
18
+ * — the router gates them unless a def sets `secure: false`. Set `public: true`
19
+ * to open the generated write routes explicitly. Reads (GET) are always public.
20
+ */
21
+ export interface AutoCrudOptions {
22
+ /** When true, the generated write routes (POST/PUT/DELETE) are OPEN (secure:false). Default false → secure. */
23
+ public?: boolean;
24
+ }
25
+ export declare class AutoCrud {
26
+ private static registered;
27
+ /** tableName -> public-writes flag (default secure); mirrors php's `$this->public`. */
28
+ private static publicWrites;
29
+ /**
30
+ * Register a model for auto-CRUD.
31
+ *
32
+ * @param options.public If true, the generated write routes are OPEN (no auth).
33
+ * Default (false) keeps them secure-by-default, matching the framework's write gate.
34
+ */
35
+ static register(model: DiscoveredModel, prefix?: string, options?: AutoCrudOptions): void;
36
+ /**
37
+ * Discover models from the provided array and register them.
38
+ * (In Node.js, models are discovered by the server and passed in.)
39
+ */
40
+ static discover(discoveredModels: DiscoveredModel[], prefix?: string, options?: AutoCrudOptions): string[];
41
+ /**
42
+ * Return all registered models.
43
+ */
44
+ static models(): Map<string, DiscoveredModel>;
45
+ /**
46
+ * Clear all registered models (useful for testing).
47
+ */
48
+ static clear(): void;
49
+ /**
50
+ * Generate route definitions for all registered models, honouring each
51
+ * model's per-table `public` flag (set at register/discover time).
52
+ */
53
+ static generateRoutes(): RouteDefinition[];
54
+ }
55
+ /**
56
+ * Filter discovered models down to those that explicitly opted into auto-CRUD via
57
+ * `static autoCrud = true` (the documented opt-in gate; default false). The server
58
+ * passes only these to generateCrudRoutes, so a model without the flag gets no CRUD
59
+ * endpoints. Exported so the opt-in gate is locked in by a test rather than
60
+ * re-implemented at each call site.
61
+ */
62
+ export declare function crudEligibleModels(models: DiscoveredModel[]): DiscoveredModel[];
63
+ /**
64
+ * Generate CRUD route definitions for the given models.
65
+ * (Standalone function for backward compatibility.)
66
+ *
67
+ * @param options.public When true, the generated write routes (POST/PUT/DELETE)
68
+ * opt OUT of the router's secure-by-default write gate (`secure: false`) — the
69
+ * cross-backend escape hatch (parity with python `public=True` / php `$public`).
70
+ * Default (false) leaves `secure` unset so the router gates writes (secure:true).
71
+ * GET routes are unaffected (reads are already public).
72
+ */
73
+ export declare function generateCrudRoutes(models: DiscoveredModel[], options?: AutoCrudOptions): RouteDefinition[];