tina4-nodejs 3.13.158 → 3.13.159
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 +2 -2
- package/package.json +1 -1
- package/packages/cli/dist/bin.js +80 -23
- package/packages/cli/src/commands/generate.ts +72 -23
- package/packages/core/dist/index.js +80 -23
- package/packages/core/src/server.ts +22 -1
- package/packages/orm/dist/index.js +80 -23
- package/packages/orm/src/migration.ts +34 -0
- package/types/orm/src/migration.d.ts +0 -24
package/CLAUDE.md
CHANGED
|
@@ -14,13 +14,13 @@ Even if the skill text is not currently loaded, these are non-negotiable:
|
|
|
14
14
|
|
|
15
15
|
The full discipline lives in `.claude/skills/tina4-maintainer/SKILL.md`; this block is the always-on floor.
|
|
16
16
|
|
|
17
|
-
# CLAUDE.md - AI Developer Guide for tina4-nodejs (v3.13.
|
|
17
|
+
# CLAUDE.md - AI Developer Guide for tina4-nodejs (v3.13.159)
|
|
18
18
|
|
|
19
19
|
> This file helps AI assistants (Claude, Copilot, Cursor, etc.) understand and work on this codebase effectively.
|
|
20
20
|
|
|
21
21
|
## What This Project Is
|
|
22
22
|
|
|
23
|
-
Tina4 for Node.js/TypeScript v3.13.
|
|
23
|
+
Tina4 for Node.js/TypeScript v3.13.159 - The Intelligent Native Application 4ramework. A convention-over-configuration structural paradigm. The developer writes TypeScript; Tina4 is invisible infrastructure.
|
|
24
24
|
|
|
25
25
|
The philosophy: zero ceremony, batteries included, file system as source of truth.
|
|
26
26
|
|
package/package.json
CHANGED
package/packages/cli/dist/bin.js
CHANGED
|
@@ -9326,6 +9326,13 @@ function consumeSqlDelimiter(state) {
|
|
|
9326
9326
|
}
|
|
9327
9327
|
return true;
|
|
9328
9328
|
}
|
|
9329
|
+
function hasExecutableSql(sql) {
|
|
9330
|
+
const body = sql.replace(/\/\*[\s\S]*?\*\//g, "").replace(/--[^\n]*/g, "");
|
|
9331
|
+
return body.replace(/[;\s]/g, "") !== "";
|
|
9332
|
+
}
|
|
9333
|
+
function isUnappliedScaffold(sql) {
|
|
9334
|
+
return TINA4_EDIT_MARKER_RE.test(sql) && !hasExecutableSql(sql);
|
|
9335
|
+
}
|
|
9329
9336
|
function splitStatements(sql, delimiter4 = ";") {
|
|
9330
9337
|
const state = {
|
|
9331
9338
|
sql: normalizeQuotes(sql),
|
|
@@ -9510,6 +9517,12 @@ async function runPendingMigrations(db, dir, delimiter4) {
|
|
|
9510
9517
|
result.skipped.push(file);
|
|
9511
9518
|
continue;
|
|
9512
9519
|
}
|
|
9520
|
+
if (isUnappliedScaffold(sqlContent)) {
|
|
9521
|
+
console.warn(
|
|
9522
|
+
` Migration ${file} is still an unedited scaffold (a 'tina4:edit' placeholder with no SQL yet) \u2014 skipped and kept pending. Write the migration and remove the tina4:edit line(s), then run migrate again.`
|
|
9523
|
+
);
|
|
9524
|
+
continue;
|
|
9525
|
+
}
|
|
9513
9526
|
const statements = splitStatements(sqlContent, delimiter4);
|
|
9514
9527
|
try {
|
|
9515
9528
|
await adapterStartTransaction(db);
|
|
@@ -9654,7 +9667,7 @@ export class ${className} {
|
|
|
9654
9667
|
writeFileSync2(filePath, content, "utf-8");
|
|
9655
9668
|
return filePath;
|
|
9656
9669
|
}
|
|
9657
|
-
var ALTER_ADD_RE, CREATE_TABLE_RE, MIGRATION_TABLE, SMART_QUOTES, SMART_QUOTE_RE, SET_TERM_RE, MIGRATION_LOCK_NAME, PG_ADVISORY_KEY, delay, Migration;
|
|
9670
|
+
var ALTER_ADD_RE, CREATE_TABLE_RE, MIGRATION_TABLE, SMART_QUOTES, SMART_QUOTE_RE, SET_TERM_RE, TINA4_EDIT_MARKER_RE, MIGRATION_LOCK_NAME, PG_ADVISORY_KEY, delay, Migration;
|
|
9658
9671
|
var init_migration = __esm({
|
|
9659
9672
|
"../orm/src/migration.ts"() {
|
|
9660
9673
|
"use strict";
|
|
@@ -9679,6 +9692,7 @@ var init_migration = __esm({
|
|
|
9679
9692
|
};
|
|
9680
9693
|
SMART_QUOTE_RE = new RegExp(`[${Object.keys(SMART_QUOTES).join("")}]`, "g");
|
|
9681
9694
|
SET_TERM_RE = /^SET\s+TERM\s+(\S+)$/i;
|
|
9695
|
+
TINA4_EDIT_MARKER_RE = /(?:#|\/\/|--|\/\*|\{#)\s*tina4:edit\b/i;
|
|
9682
9696
|
MIGRATION_LOCK_NAME = "tina4_migration_lock";
|
|
9683
9697
|
PG_ADVISORY_KEY = BigInt.asIntN(
|
|
9684
9698
|
64,
|
|
@@ -28222,6 +28236,7 @@ function generateMigration(name, flags, fieldsOverride, tableOverride, emitTest
|
|
|
28222
28236
|
}
|
|
28223
28237
|
const fields = fieldsOverride || parseFields(flags.fields || "");
|
|
28224
28238
|
const isCreate = name.startsWith("create_") || fieldsOverride !== void 0;
|
|
28239
|
+
const isView = isCreate && fieldsOverride === void 0 && table2.endsWith("_view");
|
|
28225
28240
|
const fileName = `${ts}_${name}.sql`;
|
|
28226
28241
|
const path10 = join22(dir, fileName);
|
|
28227
28242
|
setResolutionField("migration_path", `migrations/${fileName}`);
|
|
@@ -28231,7 +28246,13 @@ function generateMigration(name, flags, fieldsOverride, tableOverride, emitTest
|
|
|
28231
28246
|
}
|
|
28232
28247
|
let upSql;
|
|
28233
28248
|
let downSql;
|
|
28234
|
-
if (
|
|
28249
|
+
if (isView) {
|
|
28250
|
+
upSql = `-- tina4:edit write the CREATE VIEW statement, then remove the
|
|
28251
|
+
-- tina4:edit lines. For example:
|
|
28252
|
+
-- CREATE VIEW ${table2} AS
|
|
28253
|
+
-- SELECT id, /* columns */ FROM source_table WHERE /* ... */;`;
|
|
28254
|
+
downSql = `DROP VIEW IF EXISTS ${table2};`;
|
|
28255
|
+
} else if (isCreate) {
|
|
28235
28256
|
const colLines = [" id INTEGER PRIMARY KEY AUTOINCREMENT"];
|
|
28236
28257
|
for (const [fname, ftype] of fields) {
|
|
28237
28258
|
const info = FIELD_TYPE_MAP[ftype] || FIELD_TYPE_MAP.string;
|
|
@@ -28257,9 +28278,6 @@ DROP TABLE IF EXISTS ${table2};`;
|
|
|
28257
28278
|
|
|
28258
28279
|
-- UP
|
|
28259
28280
|
${upSql}
|
|
28260
|
-
|
|
28261
|
-
-- DOWN
|
|
28262
|
-
${downSql}
|
|
28263
28281
|
`;
|
|
28264
28282
|
writeFileSafe(path10, content);
|
|
28265
28283
|
const downPath = join22(dir, `${ts}_${name}.down.sql`);
|
|
@@ -28269,7 +28287,7 @@ ${downSql}
|
|
|
28269
28287
|
${downSql}
|
|
28270
28288
|
`;
|
|
28271
28289
|
writeFileSafe(downPath, downContent);
|
|
28272
|
-
if (emitTest && isCreate) emitMigrationTest(name, table2);
|
|
28290
|
+
if (emitTest && isCreate && !isView) emitMigrationTest(name, table2);
|
|
28273
28291
|
}
|
|
28274
28292
|
function generateMiddleware(name, _flags) {
|
|
28275
28293
|
const snake = toSnake(name);
|
|
@@ -29080,9 +29098,11 @@ function emitRouteStubTest(route) {
|
|
|
29080
29098
|
* Routing test for ${route} \u2014 no mocks, real Router + route discovery.
|
|
29081
29099
|
*
|
|
29082
29100
|
* Generated with src/routes/api/${route}/ by \`tina4nodejs generate route
|
|
29083
|
-
* ${route}\` (no --model). The handlers
|
|
29084
|
-
* implement them
|
|
29085
|
-
* register on the REAL Router, and the list handler
|
|
29101
|
+
* ${route}\` (no --model). The handlers start as AI-FILL stubs that throw until
|
|
29102
|
+
* you implement them. This tests what is live on generation: all five routes
|
|
29103
|
+
* register on the REAL Router, and the list handler is wired and callable. It
|
|
29104
|
+
* stays GREEN whether the stub still throws OR you have filled it in \u2014
|
|
29105
|
+
* implementing the handler never turns this test red.
|
|
29086
29106
|
* Run with: npx tsx tests/${route}.test.ts
|
|
29087
29107
|
*/
|
|
29088
29108
|
import { dirname, resolve } from "node:path";
|
|
@@ -29099,9 +29119,15 @@ for (const sig of ["GET /api/${route}", "POST /api/${route}", "GET /api/${route}
|
|
|
29099
29119
|
assert(\`route registered: \${sig}\`, sigs.includes(sig));
|
|
29100
29120
|
}
|
|
29101
29121
|
|
|
29102
|
-
// The
|
|
29103
|
-
|
|
29104
|
-
|
|
29122
|
+
// The list handler is WIRED: a loud AI-FILL stub (throws) on generation. This
|
|
29123
|
+
// stays green whether it still throws OR you have filled it in, so doing the
|
|
29124
|
+
// work never turns the suite red.
|
|
29125
|
+
assert("list handler is callable", typeof listHandler === "function");
|
|
29126
|
+
try {
|
|
29127
|
+
await listHandler({} as never, {} as never);
|
|
29128
|
+
} catch {
|
|
29129
|
+
// still the scaffold stub (throws until filled) \u2014 expected
|
|
29130
|
+
}`;
|
|
29105
29131
|
writeTest(route, standaloneTest(doc, body));
|
|
29106
29132
|
}
|
|
29107
29133
|
function emitMiddlewareTest(name, snake) {
|
|
@@ -29185,8 +29211,14 @@ ServiceRunner.register(service.name, service.handler, { interval: (service as {
|
|
|
29185
29211
|
assert("registers on a real ServiceRunner", ServiceRunner.list().some((s) => s.name === "${snake}"));
|
|
29186
29212
|
ServiceRunner.remove("${snake}");
|
|
29187
29213
|
|
|
29188
|
-
// The
|
|
29189
|
-
|
|
29214
|
+
// The task is WIRED: a loud AI-FILL stub (throws) on generation. This stays
|
|
29215
|
+
// green whether it still throws OR you have filled it in.
|
|
29216
|
+
assert("task is callable", typeof ${camel}Task === "function");
|
|
29217
|
+
try {
|
|
29218
|
+
await ${camel}Task({} as never);
|
|
29219
|
+
} catch {
|
|
29220
|
+
// still the scaffold stub (throws until filled) \u2014 expected
|
|
29221
|
+
}`;
|
|
29190
29222
|
writeTest(snake, standaloneTest(doc, body));
|
|
29191
29223
|
}
|
|
29192
29224
|
function emitQueueTest(topic, slug, pascal) {
|
|
@@ -29208,8 +29240,14 @@ assert("the job is really on the queue", new Queue({ topic: "${topic}" }).size()
|
|
|
29208
29240
|
assert("consumer default export is a daemon", worker.daemon === true);
|
|
29209
29241
|
assert("consumer handler is wired", typeof worker.handler === "function");
|
|
29210
29242
|
|
|
29211
|
-
// The per-job handler is
|
|
29212
|
-
|
|
29243
|
+
// The per-job handler is WIRED: a loud AI-FILL stub (throws) on generation.
|
|
29244
|
+
// This stays green whether it still throws OR you have filled it in.
|
|
29245
|
+
assert("handle is callable", typeof handle${pascal} === "function");
|
|
29246
|
+
try {
|
|
29247
|
+
await handle${pascal}({});
|
|
29248
|
+
} catch {
|
|
29249
|
+
// still the scaffold stub (throws until filled) \u2014 expected
|
|
29250
|
+
}`;
|
|
29213
29251
|
writeTest(slug, standaloneTest(doc, body));
|
|
29214
29252
|
}
|
|
29215
29253
|
function emitValidatorTest(name, snake, pascal) {
|
|
@@ -29271,9 +29309,14 @@ import { ${handler} } from "../src/routes/ws_${base}.js"; // importing register
|
|
|
29271
29309
|
const closed = await ${handler}(null as never, "close", "");
|
|
29272
29310
|
assert("close event handled cleanly", closed === undefined);
|
|
29273
29311
|
|
|
29274
|
-
// The "message" branch is
|
|
29275
|
-
|
|
29276
|
-
|
|
29312
|
+
// The "message" branch is WIRED: a loud AI-FILL stub (throws) on generation.
|
|
29313
|
+
// This stays green whether it still throws OR you have filled it in.
|
|
29314
|
+
try {
|
|
29315
|
+
await ${handler}(null as never, "message", "hi");
|
|
29316
|
+
assert("message branch is callable", true);
|
|
29317
|
+
} catch {
|
|
29318
|
+
assert("message branch is callable", true); // still the scaffold stub
|
|
29319
|
+
}`;
|
|
29277
29320
|
writeTest(`ws_${base}`, standaloneTest(doc, body));
|
|
29278
29321
|
}
|
|
29279
29322
|
function emitListenerTest(event, slug) {
|
|
@@ -29290,9 +29333,15 @@ import { Events } from "tina4-nodejs";
|
|
|
29290
29333
|
import "../src/listeners/${slug}.js"; // importing registers the listener via Events.on()`;
|
|
29291
29334
|
const body = `assert("listener registered on the real event bus", Events.listeners("${event}").length >= 1);
|
|
29292
29335
|
|
|
29293
|
-
//
|
|
29294
|
-
|
|
29295
|
-
|
|
29336
|
+
// Emitting reaches the listener. It starts as a loud AI-FILL stub (a strict emit
|
|
29337
|
+
// re-raises); once you implement it this test STILL passes, so doing the work
|
|
29338
|
+
// never turns the suite red.
|
|
29339
|
+
try {
|
|
29340
|
+
await Events.emit("${event}", { strict: true }, { id: 1 });
|
|
29341
|
+
assert("emitting reaches the listener", true);
|
|
29342
|
+
} catch {
|
|
29343
|
+
assert("emitting reaches the listener", true); // still the scaffold stub
|
|
29344
|
+
}`;
|
|
29296
29345
|
writeTest(slug, standaloneTest(doc, body));
|
|
29297
29346
|
}
|
|
29298
29347
|
function emitAuthTest() {
|
|
@@ -43723,6 +43772,12 @@ async function invokeRouteHandler(match, req2, res) {
|
|
|
43723
43772
|
if (args.length === 0) return await match.handler();
|
|
43724
43773
|
return await match.handler(...args);
|
|
43725
43774
|
}
|
|
43775
|
+
function coerceHandlerResult(res, result) {
|
|
43776
|
+
if (res.raw.writableEnded || res.raw.headersSent) return;
|
|
43777
|
+
if (result === void 0 || result === null) return;
|
|
43778
|
+
if (result === res) return;
|
|
43779
|
+
res(result);
|
|
43780
|
+
}
|
|
43726
43781
|
async function renderIfTemplateRoute(match, res, result) {
|
|
43727
43782
|
if (res.raw.writableEnded) return;
|
|
43728
43783
|
if (!match.template) return;
|
|
@@ -43742,7 +43797,9 @@ async function runMatchedRoute(ctx) {
|
|
|
43742
43797
|
handlerSkipped = !proceed || res.raw.writableEnded;
|
|
43743
43798
|
}
|
|
43744
43799
|
if (!handlerSkipped) {
|
|
43745
|
-
|
|
43800
|
+
const result = await invokeRouteHandler(match, req2, res);
|
|
43801
|
+
await renderIfTemplateRoute(match, res, result);
|
|
43802
|
+
coerceHandlerResult(res, result);
|
|
43746
43803
|
}
|
|
43747
43804
|
const afterMiddleware = [...ctx.allGlobalMiddleware, ...routeMiddlewareClasses];
|
|
43748
43805
|
if (afterMiddleware.length > 0) {
|
|
@@ -1482,6 +1482,12 @@ export function generateMigration(
|
|
|
1482
1482
|
// Build SQL columns from fields
|
|
1483
1483
|
const fields = fieldsOverride || parseFields((flags.fields as string) || "");
|
|
1484
1484
|
const isCreate = name.startsWith("create_") || fieldsOverride !== undefined;
|
|
1485
|
+
// A `create_*_view` name is a VIEW, not a table. Emitting a runnable
|
|
1486
|
+
// `CREATE TABLE <name>_view` made migrate build a table and never the view,
|
|
1487
|
+
// silently (#297). A view needs a SELECT, so scaffold commented guidance with
|
|
1488
|
+
// tina4:edit markers and no executable SQL, so the runner keeps it pending
|
|
1489
|
+
// until it is written (#288).
|
|
1490
|
+
const isView = isCreate && fieldsOverride === undefined && table.endsWith("_view");
|
|
1485
1491
|
|
|
1486
1492
|
const fileName = `${ts}_${name}.sql`;
|
|
1487
1493
|
const path = join(dir, fileName);
|
|
@@ -1507,7 +1513,14 @@ export function generateMigration(
|
|
|
1507
1513
|
// parsed label (the migration runner's splitStatements strips `--` line
|
|
1508
1514
|
// comments, so a comma-less marker line inside a DDL body is still
|
|
1509
1515
|
// syntactically inert on every engine).
|
|
1510
|
-
if (
|
|
1516
|
+
if (isView) {
|
|
1517
|
+
upSql =
|
|
1518
|
+
`-- tina4:edit write the CREATE VIEW statement, then remove the\n` +
|
|
1519
|
+
`-- tina4:edit lines. For example:\n` +
|
|
1520
|
+
`-- CREATE VIEW ${table} AS\n` +
|
|
1521
|
+
`-- SELECT id, /* columns */ FROM source_table WHERE /* ... */;`;
|
|
1522
|
+
downSql = `DROP VIEW IF EXISTS ${table};`;
|
|
1523
|
+
} else if (isCreate) {
|
|
1511
1524
|
const colLines = [" id INTEGER PRIMARY KEY AUTOINCREMENT"];
|
|
1512
1525
|
for (const [fname, ftype] of fields) {
|
|
1513
1526
|
const info = FIELD_TYPE_MAP[ftype] || FIELD_TYPE_MAP.string;
|
|
@@ -1533,11 +1546,15 @@ export function generateMigration(
|
|
|
1533
1546
|
}
|
|
1534
1547
|
|
|
1535
1548
|
const now = isoNow();
|
|
1549
|
+
// The main .sql holds ONLY the UP migration. The runner executes the WHOLE
|
|
1550
|
+
// file (comments stripped), so embedding the DOWN here made it CREATE then
|
|
1551
|
+
// immediately DROP the table — a generated migration silently undid itself.
|
|
1552
|
+
// Rollback reads the sibling .down.sql, never this file's DOWN. Keep DOWN out
|
|
1553
|
+
// of the main file (parity with the Python/PHP/Ruby masters).
|
|
1536
1554
|
const content =
|
|
1537
1555
|
`-- Migration: ${name}\n` +
|
|
1538
1556
|
`-- Created: ${now}\n\n` +
|
|
1539
|
-
`-- UP\n${upSql}\n
|
|
1540
|
-
`-- DOWN\n${downSql}\n`;
|
|
1557
|
+
`-- UP\n${upSql}\n`;
|
|
1541
1558
|
|
|
1542
1559
|
writeFileSafe(path, content);
|
|
1543
1560
|
|
|
@@ -1550,10 +1567,11 @@ export function generateMigration(
|
|
|
1550
1567
|
|
|
1551
1568
|
writeFileSafe(downPath, downContent);
|
|
1552
1569
|
|
|
1553
|
-
// Co-emit a real up/down migration test — only for CREATE migrations (a
|
|
1554
|
-
// placeholder ALTER
|
|
1555
|
-
//
|
|
1556
|
-
|
|
1570
|
+
// Co-emit a real up/down migration test — only for CREATE TABLE migrations (a
|
|
1571
|
+
// placeholder ALTER, or a VIEW stub that still needs its SELECT, has no
|
|
1572
|
+
// asserted schema yet). Suppressed when a model generates its matching
|
|
1573
|
+
// migration (the model's own test covers schema).
|
|
1574
|
+
if (emitTest && isCreate && !isView) emitMigrationTest(name, table);
|
|
1557
1575
|
}
|
|
1558
1576
|
|
|
1559
1577
|
// ── Middleware ───────────────────────────────────────────────────────
|
|
@@ -2541,9 +2559,11 @@ function emitRouteStubTest(route: string): void {
|
|
|
2541
2559
|
* Routing test for ${route} — no mocks, real Router + route discovery.
|
|
2542
2560
|
*
|
|
2543
2561
|
* Generated with src/routes/api/${route}/ by \`tina4nodejs generate route
|
|
2544
|
-
* ${route}\` (no --model). The handlers
|
|
2545
|
-
* implement them
|
|
2546
|
-
* register on the REAL Router, and the list handler
|
|
2562
|
+
* ${route}\` (no --model). The handlers start as AI-FILL stubs that throw until
|
|
2563
|
+
* you implement them. This tests what is live on generation: all five routes
|
|
2564
|
+
* register on the REAL Router, and the list handler is wired and callable. It
|
|
2565
|
+
* stays GREEN whether the stub still throws OR you have filled it in —
|
|
2566
|
+
* implementing the handler never turns this test red.
|
|
2547
2567
|
* Run with: npx tsx tests/${route}.test.ts
|
|
2548
2568
|
*/
|
|
2549
2569
|
import { dirname, resolve } from "node:path";
|
|
@@ -2560,9 +2580,15 @@ for (const sig of ["GET /api/${route}", "POST /api/${route}", "GET /api/${route}
|
|
|
2560
2580
|
assert(\`route registered: \${sig}\`, sigs.includes(sig));
|
|
2561
2581
|
}
|
|
2562
2582
|
|
|
2563
|
-
// The
|
|
2564
|
-
|
|
2565
|
-
|
|
2583
|
+
// The list handler is WIRED: a loud AI-FILL stub (throws) on generation. This
|
|
2584
|
+
// stays green whether it still throws OR you have filled it in, so doing the
|
|
2585
|
+
// work never turns the suite red.
|
|
2586
|
+
assert("list handler is callable", typeof listHandler === "function");
|
|
2587
|
+
try {
|
|
2588
|
+
await listHandler({} as never, {} as never);
|
|
2589
|
+
} catch {
|
|
2590
|
+
// still the scaffold stub (throws until filled) — expected
|
|
2591
|
+
}`;
|
|
2566
2592
|
writeTest(route, standaloneTest(doc, body));
|
|
2567
2593
|
}
|
|
2568
2594
|
|
|
@@ -2651,8 +2677,14 @@ ServiceRunner.register(service.name, service.handler, { interval: (service as {
|
|
|
2651
2677
|
assert("registers on a real ServiceRunner", ServiceRunner.list().some((s) => s.name === "${snake}"));
|
|
2652
2678
|
ServiceRunner.remove("${snake}");
|
|
2653
2679
|
|
|
2654
|
-
// The
|
|
2655
|
-
|
|
2680
|
+
// The task is WIRED: a loud AI-FILL stub (throws) on generation. This stays
|
|
2681
|
+
// green whether it still throws OR you have filled it in.
|
|
2682
|
+
assert("task is callable", typeof ${camel}Task === "function");
|
|
2683
|
+
try {
|
|
2684
|
+
await ${camel}Task({} as never);
|
|
2685
|
+
} catch {
|
|
2686
|
+
// still the scaffold stub (throws until filled) — expected
|
|
2687
|
+
}`;
|
|
2656
2688
|
writeTest(snake, standaloneTest(doc, body));
|
|
2657
2689
|
}
|
|
2658
2690
|
|
|
@@ -2676,8 +2708,14 @@ assert("the job is really on the queue", new Queue({ topic: "${topic}" }).size()
|
|
|
2676
2708
|
assert("consumer default export is a daemon", worker.daemon === true);
|
|
2677
2709
|
assert("consumer handler is wired", typeof worker.handler === "function");
|
|
2678
2710
|
|
|
2679
|
-
// The per-job handler is
|
|
2680
|
-
|
|
2711
|
+
// The per-job handler is WIRED: a loud AI-FILL stub (throws) on generation.
|
|
2712
|
+
// This stays green whether it still throws OR you have filled it in.
|
|
2713
|
+
assert("handle is callable", typeof handle${pascal} === "function");
|
|
2714
|
+
try {
|
|
2715
|
+
await handle${pascal}({});
|
|
2716
|
+
} catch {
|
|
2717
|
+
// still the scaffold stub (throws until filled) — expected
|
|
2718
|
+
}`;
|
|
2681
2719
|
writeTest(slug, standaloneTest(doc, body));
|
|
2682
2720
|
}
|
|
2683
2721
|
|
|
@@ -2748,9 +2786,14 @@ import { ${handler} } from "../src/routes/ws_${base}.js"; // importing register
|
|
|
2748
2786
|
const closed = await ${handler}(null as never, "close", "");
|
|
2749
2787
|
assert("close event handled cleanly", closed === undefined);
|
|
2750
2788
|
|
|
2751
|
-
// The "message" branch is
|
|
2752
|
-
|
|
2753
|
-
|
|
2789
|
+
// The "message" branch is WIRED: a loud AI-FILL stub (throws) on generation.
|
|
2790
|
+
// This stays green whether it still throws OR you have filled it in.
|
|
2791
|
+
try {
|
|
2792
|
+
await ${handler}(null as never, "message", "hi");
|
|
2793
|
+
assert("message branch is callable", true);
|
|
2794
|
+
} catch {
|
|
2795
|
+
assert("message branch is callable", true); // still the scaffold stub
|
|
2796
|
+
}`;
|
|
2754
2797
|
writeTest(`ws_${base}`, standaloneTest(doc, body));
|
|
2755
2798
|
}
|
|
2756
2799
|
|
|
@@ -2769,9 +2812,15 @@ import { Events } from "tina4-nodejs";
|
|
|
2769
2812
|
import "../src/listeners/${slug}.js"; // importing registers the listener via Events.on()`;
|
|
2770
2813
|
const body = `assert("listener registered on the real event bus", Events.listeners("${event}").length >= 1);
|
|
2771
2814
|
|
|
2772
|
-
//
|
|
2773
|
-
|
|
2774
|
-
|
|
2815
|
+
// Emitting reaches the listener. It starts as a loud AI-FILL stub (a strict emit
|
|
2816
|
+
// re-raises); once you implement it this test STILL passes, so doing the work
|
|
2817
|
+
// never turns the suite red.
|
|
2818
|
+
try {
|
|
2819
|
+
await Events.emit("${event}", { strict: true }, { id: 1 });
|
|
2820
|
+
assert("emitting reaches the listener", true);
|
|
2821
|
+
} catch {
|
|
2822
|
+
assert("emitting reaches the listener", true); // still the scaffold stub
|
|
2823
|
+
}`;
|
|
2775
2824
|
writeTest(slug, standaloneTest(doc, body));
|
|
2776
2825
|
}
|
|
2777
2826
|
|
|
@@ -9325,6 +9325,13 @@ function consumeSqlDelimiter(state) {
|
|
|
9325
9325
|
}
|
|
9326
9326
|
return true;
|
|
9327
9327
|
}
|
|
9328
|
+
function hasExecutableSql(sql) {
|
|
9329
|
+
const body = sql.replace(/\/\*[\s\S]*?\*\//g, "").replace(/--[^\n]*/g, "");
|
|
9330
|
+
return body.replace(/[;\s]/g, "") !== "";
|
|
9331
|
+
}
|
|
9332
|
+
function isUnappliedScaffold(sql) {
|
|
9333
|
+
return TINA4_EDIT_MARKER_RE.test(sql) && !hasExecutableSql(sql);
|
|
9334
|
+
}
|
|
9328
9335
|
function splitStatements(sql, delimiter2 = ";") {
|
|
9329
9336
|
const state = {
|
|
9330
9337
|
sql: normalizeQuotes(sql),
|
|
@@ -9509,6 +9516,12 @@ async function runPendingMigrations(db, dir, delimiter2) {
|
|
|
9509
9516
|
result.skipped.push(file);
|
|
9510
9517
|
continue;
|
|
9511
9518
|
}
|
|
9519
|
+
if (isUnappliedScaffold(sqlContent)) {
|
|
9520
|
+
console.warn(
|
|
9521
|
+
` Migration ${file} is still an unedited scaffold (a 'tina4:edit' placeholder with no SQL yet) \u2014 skipped and kept pending. Write the migration and remove the tina4:edit line(s), then run migrate again.`
|
|
9522
|
+
);
|
|
9523
|
+
continue;
|
|
9524
|
+
}
|
|
9512
9525
|
const statements = splitStatements(sqlContent, delimiter2);
|
|
9513
9526
|
try {
|
|
9514
9527
|
await adapterStartTransaction(db);
|
|
@@ -9653,7 +9666,7 @@ export class ${className} {
|
|
|
9653
9666
|
writeFileSync(filePath, content, "utf-8");
|
|
9654
9667
|
return filePath;
|
|
9655
9668
|
}
|
|
9656
|
-
var ALTER_ADD_RE, CREATE_TABLE_RE, MIGRATION_TABLE, SMART_QUOTES, SMART_QUOTE_RE, SET_TERM_RE, MIGRATION_LOCK_NAME, PG_ADVISORY_KEY, delay, Migration;
|
|
9669
|
+
var ALTER_ADD_RE, CREATE_TABLE_RE, MIGRATION_TABLE, SMART_QUOTES, SMART_QUOTE_RE, SET_TERM_RE, TINA4_EDIT_MARKER_RE, MIGRATION_LOCK_NAME, PG_ADVISORY_KEY, delay, Migration;
|
|
9657
9670
|
var init_migration = __esm({
|
|
9658
9671
|
"../orm/src/migration.ts"() {
|
|
9659
9672
|
"use strict";
|
|
@@ -9678,6 +9691,7 @@ var init_migration = __esm({
|
|
|
9678
9691
|
};
|
|
9679
9692
|
SMART_QUOTE_RE = new RegExp(`[${Object.keys(SMART_QUOTES).join("")}]`, "g");
|
|
9680
9693
|
SET_TERM_RE = /^SET\s+TERM\s+(\S+)$/i;
|
|
9694
|
+
TINA4_EDIT_MARKER_RE = /(?:#|\/\/|--|\/\*|\{#)\s*tina4:edit\b/i;
|
|
9681
9695
|
MIGRATION_LOCK_NAME = "tina4_migration_lock";
|
|
9682
9696
|
PG_ADVISORY_KEY = BigInt.asIntN(
|
|
9683
9697
|
64,
|
|
@@ -28178,6 +28192,7 @@ function generateMigration(name, flags, fieldsOverride, tableOverride, emitTest
|
|
|
28178
28192
|
}
|
|
28179
28193
|
const fields = fieldsOverride || parseFields(flags.fields || "");
|
|
28180
28194
|
const isCreate = name.startsWith("create_") || fieldsOverride !== void 0;
|
|
28195
|
+
const isView = isCreate && fieldsOverride === void 0 && table2.endsWith("_view");
|
|
28181
28196
|
const fileName = `${ts}_${name}.sql`;
|
|
28182
28197
|
const path10 = join20(dir, fileName);
|
|
28183
28198
|
setResolutionField("migration_path", `migrations/${fileName}`);
|
|
@@ -28187,7 +28202,13 @@ function generateMigration(name, flags, fieldsOverride, tableOverride, emitTest
|
|
|
28187
28202
|
}
|
|
28188
28203
|
let upSql;
|
|
28189
28204
|
let downSql;
|
|
28190
|
-
if (
|
|
28205
|
+
if (isView) {
|
|
28206
|
+
upSql = `-- tina4:edit write the CREATE VIEW statement, then remove the
|
|
28207
|
+
-- tina4:edit lines. For example:
|
|
28208
|
+
-- CREATE VIEW ${table2} AS
|
|
28209
|
+
-- SELECT id, /* columns */ FROM source_table WHERE /* ... */;`;
|
|
28210
|
+
downSql = `DROP VIEW IF EXISTS ${table2};`;
|
|
28211
|
+
} else if (isCreate) {
|
|
28191
28212
|
const colLines = [" id INTEGER PRIMARY KEY AUTOINCREMENT"];
|
|
28192
28213
|
for (const [fname, ftype] of fields) {
|
|
28193
28214
|
const info = FIELD_TYPE_MAP[ftype] || FIELD_TYPE_MAP.string;
|
|
@@ -28213,9 +28234,6 @@ DROP TABLE IF EXISTS ${table2};`;
|
|
|
28213
28234
|
|
|
28214
28235
|
-- UP
|
|
28215
28236
|
${upSql}
|
|
28216
|
-
|
|
28217
|
-
-- DOWN
|
|
28218
|
-
${downSql}
|
|
28219
28237
|
`;
|
|
28220
28238
|
writeFileSafe(path10, content);
|
|
28221
28239
|
const downPath = join20(dir, `${ts}_${name}.down.sql`);
|
|
@@ -28225,7 +28243,7 @@ ${downSql}
|
|
|
28225
28243
|
${downSql}
|
|
28226
28244
|
`;
|
|
28227
28245
|
writeFileSafe(downPath, downContent);
|
|
28228
|
-
if (emitTest && isCreate) emitMigrationTest(name, table2);
|
|
28246
|
+
if (emitTest && isCreate && !isView) emitMigrationTest(name, table2);
|
|
28229
28247
|
}
|
|
28230
28248
|
function generateMiddleware(name, _flags) {
|
|
28231
28249
|
const snake = toSnake(name);
|
|
@@ -29036,9 +29054,11 @@ function emitRouteStubTest(route) {
|
|
|
29036
29054
|
* Routing test for ${route} \u2014 no mocks, real Router + route discovery.
|
|
29037
29055
|
*
|
|
29038
29056
|
* Generated with src/routes/api/${route}/ by \`tina4nodejs generate route
|
|
29039
|
-
* ${route}\` (no --model). The handlers
|
|
29040
|
-
* implement them
|
|
29041
|
-
* register on the REAL Router, and the list handler
|
|
29057
|
+
* ${route}\` (no --model). The handlers start as AI-FILL stubs that throw until
|
|
29058
|
+
* you implement them. This tests what is live on generation: all five routes
|
|
29059
|
+
* register on the REAL Router, and the list handler is wired and callable. It
|
|
29060
|
+
* stays GREEN whether the stub still throws OR you have filled it in \u2014
|
|
29061
|
+
* implementing the handler never turns this test red.
|
|
29042
29062
|
* Run with: npx tsx tests/${route}.test.ts
|
|
29043
29063
|
*/
|
|
29044
29064
|
import { dirname, resolve } from "node:path";
|
|
@@ -29055,9 +29075,15 @@ for (const sig of ["GET /api/${route}", "POST /api/${route}", "GET /api/${route}
|
|
|
29055
29075
|
assert(\`route registered: \${sig}\`, sigs.includes(sig));
|
|
29056
29076
|
}
|
|
29057
29077
|
|
|
29058
|
-
// The
|
|
29059
|
-
|
|
29060
|
-
|
|
29078
|
+
// The list handler is WIRED: a loud AI-FILL stub (throws) on generation. This
|
|
29079
|
+
// stays green whether it still throws OR you have filled it in, so doing the
|
|
29080
|
+
// work never turns the suite red.
|
|
29081
|
+
assert("list handler is callable", typeof listHandler === "function");
|
|
29082
|
+
try {
|
|
29083
|
+
await listHandler({} as never, {} as never);
|
|
29084
|
+
} catch {
|
|
29085
|
+
// still the scaffold stub (throws until filled) \u2014 expected
|
|
29086
|
+
}`;
|
|
29061
29087
|
writeTest(route, standaloneTest(doc, body));
|
|
29062
29088
|
}
|
|
29063
29089
|
function emitMiddlewareTest(name, snake) {
|
|
@@ -29141,8 +29167,14 @@ ServiceRunner.register(service.name, service.handler, { interval: (service as {
|
|
|
29141
29167
|
assert("registers on a real ServiceRunner", ServiceRunner.list().some((s) => s.name === "${snake}"));
|
|
29142
29168
|
ServiceRunner.remove("${snake}");
|
|
29143
29169
|
|
|
29144
|
-
// The
|
|
29145
|
-
|
|
29170
|
+
// The task is WIRED: a loud AI-FILL stub (throws) on generation. This stays
|
|
29171
|
+
// green whether it still throws OR you have filled it in.
|
|
29172
|
+
assert("task is callable", typeof ${camel}Task === "function");
|
|
29173
|
+
try {
|
|
29174
|
+
await ${camel}Task({} as never);
|
|
29175
|
+
} catch {
|
|
29176
|
+
// still the scaffold stub (throws until filled) \u2014 expected
|
|
29177
|
+
}`;
|
|
29146
29178
|
writeTest(snake, standaloneTest(doc, body));
|
|
29147
29179
|
}
|
|
29148
29180
|
function emitQueueTest(topic, slug, pascal) {
|
|
@@ -29164,8 +29196,14 @@ assert("the job is really on the queue", new Queue({ topic: "${topic}" }).size()
|
|
|
29164
29196
|
assert("consumer default export is a daemon", worker.daemon === true);
|
|
29165
29197
|
assert("consumer handler is wired", typeof worker.handler === "function");
|
|
29166
29198
|
|
|
29167
|
-
// The per-job handler is
|
|
29168
|
-
|
|
29199
|
+
// The per-job handler is WIRED: a loud AI-FILL stub (throws) on generation.
|
|
29200
|
+
// This stays green whether it still throws OR you have filled it in.
|
|
29201
|
+
assert("handle is callable", typeof handle${pascal} === "function");
|
|
29202
|
+
try {
|
|
29203
|
+
await handle${pascal}({});
|
|
29204
|
+
} catch {
|
|
29205
|
+
// still the scaffold stub (throws until filled) \u2014 expected
|
|
29206
|
+
}`;
|
|
29169
29207
|
writeTest(slug, standaloneTest(doc, body));
|
|
29170
29208
|
}
|
|
29171
29209
|
function emitValidatorTest(name, snake, pascal) {
|
|
@@ -29227,9 +29265,14 @@ import { ${handler} } from "../src/routes/ws_${base}.js"; // importing register
|
|
|
29227
29265
|
const closed = await ${handler}(null as never, "close", "");
|
|
29228
29266
|
assert("close event handled cleanly", closed === undefined);
|
|
29229
29267
|
|
|
29230
|
-
// The "message" branch is
|
|
29231
|
-
|
|
29232
|
-
|
|
29268
|
+
// The "message" branch is WIRED: a loud AI-FILL stub (throws) on generation.
|
|
29269
|
+
// This stays green whether it still throws OR you have filled it in.
|
|
29270
|
+
try {
|
|
29271
|
+
await ${handler}(null as never, "message", "hi");
|
|
29272
|
+
assert("message branch is callable", true);
|
|
29273
|
+
} catch {
|
|
29274
|
+
assert("message branch is callable", true); // still the scaffold stub
|
|
29275
|
+
}`;
|
|
29233
29276
|
writeTest(`ws_${base}`, standaloneTest(doc, body));
|
|
29234
29277
|
}
|
|
29235
29278
|
function emitListenerTest(event, slug) {
|
|
@@ -29246,9 +29289,15 @@ import { Events } from "tina4-nodejs";
|
|
|
29246
29289
|
import "../src/listeners/${slug}.js"; // importing registers the listener via Events.on()`;
|
|
29247
29290
|
const body = `assert("listener registered on the real event bus", Events.listeners("${event}").length >= 1);
|
|
29248
29291
|
|
|
29249
|
-
//
|
|
29250
|
-
|
|
29251
|
-
|
|
29292
|
+
// Emitting reaches the listener. It starts as a loud AI-FILL stub (a strict emit
|
|
29293
|
+
// re-raises); once you implement it this test STILL passes, so doing the work
|
|
29294
|
+
// never turns the suite red.
|
|
29295
|
+
try {
|
|
29296
|
+
await Events.emit("${event}", { strict: true }, { id: 1 });
|
|
29297
|
+
assert("emitting reaches the listener", true);
|
|
29298
|
+
} catch {
|
|
29299
|
+
assert("emitting reaches the listener", true); // still the scaffold stub
|
|
29300
|
+
}`;
|
|
29252
29301
|
writeTest(slug, standaloneTest(doc, body));
|
|
29253
29302
|
}
|
|
29254
29303
|
function emitAuthTest() {
|
|
@@ -43679,6 +43728,12 @@ async function invokeRouteHandler(match, req2, res) {
|
|
|
43679
43728
|
if (args.length === 0) return await match.handler();
|
|
43680
43729
|
return await match.handler(...args);
|
|
43681
43730
|
}
|
|
43731
|
+
function coerceHandlerResult(res, result) {
|
|
43732
|
+
if (res.raw.writableEnded || res.raw.headersSent) return;
|
|
43733
|
+
if (result === void 0 || result === null) return;
|
|
43734
|
+
if (result === res) return;
|
|
43735
|
+
res(result);
|
|
43736
|
+
}
|
|
43682
43737
|
async function renderIfTemplateRoute(match, res, result) {
|
|
43683
43738
|
if (res.raw.writableEnded) return;
|
|
43684
43739
|
if (!match.template) return;
|
|
@@ -43698,7 +43753,9 @@ async function runMatchedRoute(ctx) {
|
|
|
43698
43753
|
handlerSkipped = !proceed || res.raw.writableEnded;
|
|
43699
43754
|
}
|
|
43700
43755
|
if (!handlerSkipped) {
|
|
43701
|
-
|
|
43756
|
+
const result = await invokeRouteHandler(match, req2, res);
|
|
43757
|
+
await renderIfTemplateRoute(match, res, result);
|
|
43758
|
+
coerceHandlerResult(res, result);
|
|
43702
43759
|
}
|
|
43703
43760
|
const afterMiddleware = [...ctx.allGlobalMiddleware, ...routeMiddlewareClasses];
|
|
43704
43761
|
if (afterMiddleware.length > 0) {
|
|
@@ -1130,6 +1130,25 @@ async function invokeRouteHandler(
|
|
|
1130
1130
|
* other shape - a handler that already wrote, no template, null/undefined, a
|
|
1131
1131
|
* string, a Buffer - is left exactly as it was.
|
|
1132
1132
|
*/
|
|
1133
|
+
/**
|
|
1134
|
+
* Coerce a handler's RETURN value into a response (#289).
|
|
1135
|
+
*
|
|
1136
|
+
* Node's idiom is `res.json()` / `res.send()`, but a handler that `return`s a
|
|
1137
|
+
* dict / array / string without writing used to answer an empty 200 with no
|
|
1138
|
+
* error and no log line — the value was dropped. This mirrors the Python, PHP
|
|
1139
|
+
* and Ruby masters, which coerce a bare return: a non-null, non-undefined
|
|
1140
|
+
* return is run through the auto-detecting `response()` callable (`res` itself),
|
|
1141
|
+
* so `return { open: 3 }` serialises to JSON. It is skipped when the handler
|
|
1142
|
+
* already sent (a template render, `res.json()`, a stream) or returned nothing,
|
|
1143
|
+
* so an explicit `res.json(...)` is never double-sent.
|
|
1144
|
+
*/
|
|
1145
|
+
function coerceHandlerResult(res: Tina4Response, result: unknown): void {
|
|
1146
|
+
if (res.raw.writableEnded || res.raw.headersSent) return;
|
|
1147
|
+
if (result === undefined || result === null) return;
|
|
1148
|
+
if (result === (res as unknown)) return; // handler returned the response itself
|
|
1149
|
+
(res as unknown as (data: unknown) => void)(result);
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1133
1152
|
async function renderIfTemplateRoute(
|
|
1134
1153
|
match: { template?: string },
|
|
1135
1154
|
res: Tina4Response,
|
|
@@ -1201,7 +1220,9 @@ async function runMatchedRoute(ctx: MatchedRouteContext): Promise<void> {
|
|
|
1201
1220
|
}
|
|
1202
1221
|
|
|
1203
1222
|
if (!handlerSkipped) {
|
|
1204
|
-
|
|
1223
|
+
const result = await invokeRouteHandler(match, req, res);
|
|
1224
|
+
await renderIfTemplateRoute(match, res, result);
|
|
1225
|
+
coerceHandlerResult(res, result);
|
|
1205
1226
|
}
|
|
1206
1227
|
|
|
1207
1228
|
// Global afterX hooks (logging / post-processing), over EVERY global
|
|
@@ -15075,6 +15075,7 @@ function generateMigration(name, flags, fieldsOverride, tableOverride, emitTest
|
|
|
15075
15075
|
}
|
|
15076
15076
|
const fields = fieldsOverride || parseFields(flags.fields || "");
|
|
15077
15077
|
const isCreate = name.startsWith("create_") || fieldsOverride !== void 0;
|
|
15078
|
+
const isView = isCreate && fieldsOverride === void 0 && table2.endsWith("_view");
|
|
15078
15079
|
const fileName = `${ts}_${name}.sql`;
|
|
15079
15080
|
const path10 = join15(dir, fileName);
|
|
15080
15081
|
setResolutionField("migration_path", `migrations/${fileName}`);
|
|
@@ -15084,7 +15085,13 @@ function generateMigration(name, flags, fieldsOverride, tableOverride, emitTest
|
|
|
15084
15085
|
}
|
|
15085
15086
|
let upSql;
|
|
15086
15087
|
let downSql;
|
|
15087
|
-
if (
|
|
15088
|
+
if (isView) {
|
|
15089
|
+
upSql = `-- tina4:edit write the CREATE VIEW statement, then remove the
|
|
15090
|
+
-- tina4:edit lines. For example:
|
|
15091
|
+
-- CREATE VIEW ${table2} AS
|
|
15092
|
+
-- SELECT id, /* columns */ FROM source_table WHERE /* ... */;`;
|
|
15093
|
+
downSql = `DROP VIEW IF EXISTS ${table2};`;
|
|
15094
|
+
} else if (isCreate) {
|
|
15088
15095
|
const colLines = [" id INTEGER PRIMARY KEY AUTOINCREMENT"];
|
|
15089
15096
|
for (const [fname, ftype] of fields) {
|
|
15090
15097
|
const info = FIELD_TYPE_MAP[ftype] || FIELD_TYPE_MAP.string;
|
|
@@ -15110,9 +15117,6 @@ DROP TABLE IF EXISTS ${table2};`;
|
|
|
15110
15117
|
|
|
15111
15118
|
-- UP
|
|
15112
15119
|
${upSql}
|
|
15113
|
-
|
|
15114
|
-
-- DOWN
|
|
15115
|
-
${downSql}
|
|
15116
15120
|
`;
|
|
15117
15121
|
writeFileSafe(path10, content);
|
|
15118
15122
|
const downPath = join15(dir, `${ts}_${name}.down.sql`);
|
|
@@ -15122,7 +15126,7 @@ ${downSql}
|
|
|
15122
15126
|
${downSql}
|
|
15123
15127
|
`;
|
|
15124
15128
|
writeFileSafe(downPath, downContent);
|
|
15125
|
-
if (emitTest && isCreate) emitMigrationTest(name, table2);
|
|
15129
|
+
if (emitTest && isCreate && !isView) emitMigrationTest(name, table2);
|
|
15126
15130
|
}
|
|
15127
15131
|
function generateMiddleware(name, _flags) {
|
|
15128
15132
|
const snake = toSnake(name);
|
|
@@ -15933,9 +15937,11 @@ function emitRouteStubTest(route) {
|
|
|
15933
15937
|
* Routing test for ${route} \u2014 no mocks, real Router + route discovery.
|
|
15934
15938
|
*
|
|
15935
15939
|
* Generated with src/routes/api/${route}/ by \`tina4nodejs generate route
|
|
15936
|
-
* ${route}\` (no --model). The handlers
|
|
15937
|
-
* implement them
|
|
15938
|
-
* register on the REAL Router, and the list handler
|
|
15940
|
+
* ${route}\` (no --model). The handlers start as AI-FILL stubs that throw until
|
|
15941
|
+
* you implement them. This tests what is live on generation: all five routes
|
|
15942
|
+
* register on the REAL Router, and the list handler is wired and callable. It
|
|
15943
|
+
* stays GREEN whether the stub still throws OR you have filled it in \u2014
|
|
15944
|
+
* implementing the handler never turns this test red.
|
|
15939
15945
|
* Run with: npx tsx tests/${route}.test.ts
|
|
15940
15946
|
*/
|
|
15941
15947
|
import { dirname, resolve } from "node:path";
|
|
@@ -15952,9 +15958,15 @@ for (const sig of ["GET /api/${route}", "POST /api/${route}", "GET /api/${route}
|
|
|
15952
15958
|
assert(\`route registered: \${sig}\`, sigs.includes(sig));
|
|
15953
15959
|
}
|
|
15954
15960
|
|
|
15955
|
-
// The
|
|
15956
|
-
|
|
15957
|
-
|
|
15961
|
+
// The list handler is WIRED: a loud AI-FILL stub (throws) on generation. This
|
|
15962
|
+
// stays green whether it still throws OR you have filled it in, so doing the
|
|
15963
|
+
// work never turns the suite red.
|
|
15964
|
+
assert("list handler is callable", typeof listHandler === "function");
|
|
15965
|
+
try {
|
|
15966
|
+
await listHandler({} as never, {} as never);
|
|
15967
|
+
} catch {
|
|
15968
|
+
// still the scaffold stub (throws until filled) \u2014 expected
|
|
15969
|
+
}`;
|
|
15958
15970
|
writeTest(route, standaloneTest(doc, body));
|
|
15959
15971
|
}
|
|
15960
15972
|
function emitMiddlewareTest(name, snake) {
|
|
@@ -16038,8 +16050,14 @@ ServiceRunner.register(service.name, service.handler, { interval: (service as {
|
|
|
16038
16050
|
assert("registers on a real ServiceRunner", ServiceRunner.list().some((s) => s.name === "${snake}"));
|
|
16039
16051
|
ServiceRunner.remove("${snake}");
|
|
16040
16052
|
|
|
16041
|
-
// The
|
|
16042
|
-
|
|
16053
|
+
// The task is WIRED: a loud AI-FILL stub (throws) on generation. This stays
|
|
16054
|
+
// green whether it still throws OR you have filled it in.
|
|
16055
|
+
assert("task is callable", typeof ${camel}Task === "function");
|
|
16056
|
+
try {
|
|
16057
|
+
await ${camel}Task({} as never);
|
|
16058
|
+
} catch {
|
|
16059
|
+
// still the scaffold stub (throws until filled) \u2014 expected
|
|
16060
|
+
}`;
|
|
16043
16061
|
writeTest(snake, standaloneTest(doc, body));
|
|
16044
16062
|
}
|
|
16045
16063
|
function emitQueueTest(topic, slug, pascal) {
|
|
@@ -16061,8 +16079,14 @@ assert("the job is really on the queue", new Queue({ topic: "${topic}" }).size()
|
|
|
16061
16079
|
assert("consumer default export is a daemon", worker.daemon === true);
|
|
16062
16080
|
assert("consumer handler is wired", typeof worker.handler === "function");
|
|
16063
16081
|
|
|
16064
|
-
// The per-job handler is
|
|
16065
|
-
|
|
16082
|
+
// The per-job handler is WIRED: a loud AI-FILL stub (throws) on generation.
|
|
16083
|
+
// This stays green whether it still throws OR you have filled it in.
|
|
16084
|
+
assert("handle is callable", typeof handle${pascal} === "function");
|
|
16085
|
+
try {
|
|
16086
|
+
await handle${pascal}({});
|
|
16087
|
+
} catch {
|
|
16088
|
+
// still the scaffold stub (throws until filled) \u2014 expected
|
|
16089
|
+
}`;
|
|
16066
16090
|
writeTest(slug, standaloneTest(doc, body));
|
|
16067
16091
|
}
|
|
16068
16092
|
function emitValidatorTest(name, snake, pascal) {
|
|
@@ -16124,9 +16148,14 @@ import { ${handler} } from "../src/routes/ws_${base}.js"; // importing register
|
|
|
16124
16148
|
const closed = await ${handler}(null as never, "close", "");
|
|
16125
16149
|
assert("close event handled cleanly", closed === undefined);
|
|
16126
16150
|
|
|
16127
|
-
// The "message" branch is
|
|
16128
|
-
|
|
16129
|
-
|
|
16151
|
+
// The "message" branch is WIRED: a loud AI-FILL stub (throws) on generation.
|
|
16152
|
+
// This stays green whether it still throws OR you have filled it in.
|
|
16153
|
+
try {
|
|
16154
|
+
await ${handler}(null as never, "message", "hi");
|
|
16155
|
+
assert("message branch is callable", true);
|
|
16156
|
+
} catch {
|
|
16157
|
+
assert("message branch is callable", true); // still the scaffold stub
|
|
16158
|
+
}`;
|
|
16130
16159
|
writeTest(`ws_${base}`, standaloneTest(doc, body));
|
|
16131
16160
|
}
|
|
16132
16161
|
function emitListenerTest(event, slug) {
|
|
@@ -16143,9 +16172,15 @@ import { Events } from "tina4-nodejs";
|
|
|
16143
16172
|
import "../src/listeners/${slug}.js"; // importing registers the listener via Events.on()`;
|
|
16144
16173
|
const body = `assert("listener registered on the real event bus", Events.listeners("${event}").length >= 1);
|
|
16145
16174
|
|
|
16146
|
-
//
|
|
16147
|
-
|
|
16148
|
-
|
|
16175
|
+
// Emitting reaches the listener. It starts as a loud AI-FILL stub (a strict emit
|
|
16176
|
+
// re-raises); once you implement it this test STILL passes, so doing the work
|
|
16177
|
+
// never turns the suite red.
|
|
16178
|
+
try {
|
|
16179
|
+
await Events.emit("${event}", { strict: true }, { id: 1 });
|
|
16180
|
+
assert("emitting reaches the listener", true);
|
|
16181
|
+
} catch {
|
|
16182
|
+
assert("emitting reaches the listener", true); // still the scaffold stub
|
|
16183
|
+
}`;
|
|
16149
16184
|
writeTest(slug, standaloneTest(doc, body));
|
|
16150
16185
|
}
|
|
16151
16186
|
function emitAuthTest() {
|
|
@@ -30576,6 +30611,12 @@ async function invokeRouteHandler(match, req2, res) {
|
|
|
30576
30611
|
if (args.length === 0) return await match.handler();
|
|
30577
30612
|
return await match.handler(...args);
|
|
30578
30613
|
}
|
|
30614
|
+
function coerceHandlerResult(res, result) {
|
|
30615
|
+
if (res.raw.writableEnded || res.raw.headersSent) return;
|
|
30616
|
+
if (result === void 0 || result === null) return;
|
|
30617
|
+
if (result === res) return;
|
|
30618
|
+
res(result);
|
|
30619
|
+
}
|
|
30579
30620
|
async function renderIfTemplateRoute(match, res, result) {
|
|
30580
30621
|
if (res.raw.writableEnded) return;
|
|
30581
30622
|
if (!match.template) return;
|
|
@@ -30595,7 +30636,9 @@ async function runMatchedRoute(ctx) {
|
|
|
30595
30636
|
handlerSkipped = !proceed || res.raw.writableEnded;
|
|
30596
30637
|
}
|
|
30597
30638
|
if (!handlerSkipped) {
|
|
30598
|
-
|
|
30639
|
+
const result = await invokeRouteHandler(match, req2, res);
|
|
30640
|
+
await renderIfTemplateRoute(match, res, result);
|
|
30641
|
+
coerceHandlerResult(res, result);
|
|
30599
30642
|
}
|
|
30600
30643
|
const afterMiddleware = [...ctx.allGlobalMiddleware, ...routeMiddlewareClasses];
|
|
30601
30644
|
if (afterMiddleware.length > 0) {
|
|
@@ -45587,6 +45630,13 @@ function consumeSqlDelimiter(state) {
|
|
|
45587
45630
|
}
|
|
45588
45631
|
return true;
|
|
45589
45632
|
}
|
|
45633
|
+
function hasExecutableSql(sql) {
|
|
45634
|
+
const body = sql.replace(/\/\*[\s\S]*?\*\//g, "").replace(/--[^\n]*/g, "");
|
|
45635
|
+
return body.replace(/[;\s]/g, "") !== "";
|
|
45636
|
+
}
|
|
45637
|
+
function isUnappliedScaffold(sql) {
|
|
45638
|
+
return TINA4_EDIT_MARKER_RE.test(sql) && !hasExecutableSql(sql);
|
|
45639
|
+
}
|
|
45590
45640
|
function splitStatements(sql, delimiter2 = ";") {
|
|
45591
45641
|
const state = {
|
|
45592
45642
|
sql: normalizeQuotes(sql),
|
|
@@ -45771,6 +45821,12 @@ async function runPendingMigrations(db, dir, delimiter2) {
|
|
|
45771
45821
|
result.skipped.push(file);
|
|
45772
45822
|
continue;
|
|
45773
45823
|
}
|
|
45824
|
+
if (isUnappliedScaffold(sqlContent)) {
|
|
45825
|
+
console.warn(
|
|
45826
|
+
` Migration ${file} is still an unedited scaffold (a 'tina4:edit' placeholder with no SQL yet) \u2014 skipped and kept pending. Write the migration and remove the tina4:edit line(s), then run migrate again.`
|
|
45827
|
+
);
|
|
45828
|
+
continue;
|
|
45829
|
+
}
|
|
45774
45830
|
const statements = splitStatements(sqlContent, delimiter2);
|
|
45775
45831
|
try {
|
|
45776
45832
|
await adapterStartTransaction(db);
|
|
@@ -45915,7 +45971,7 @@ export class ${className} {
|
|
|
45915
45971
|
writeFileSync17(filePath, content, "utf-8");
|
|
45916
45972
|
return filePath;
|
|
45917
45973
|
}
|
|
45918
|
-
var ALTER_ADD_RE, CREATE_TABLE_RE, MIGRATION_TABLE, SMART_QUOTES, SMART_QUOTE_RE, SET_TERM_RE, MIGRATION_LOCK_NAME, PG_ADVISORY_KEY, delay, Migration;
|
|
45974
|
+
var ALTER_ADD_RE, CREATE_TABLE_RE, MIGRATION_TABLE, SMART_QUOTES, SMART_QUOTE_RE, SET_TERM_RE, TINA4_EDIT_MARKER_RE, MIGRATION_LOCK_NAME, PG_ADVISORY_KEY, delay, Migration;
|
|
45919
45975
|
var init_migration = __esm({
|
|
45920
45976
|
"src/migration.ts"() {
|
|
45921
45977
|
"use strict";
|
|
@@ -45940,6 +45996,7 @@ var init_migration = __esm({
|
|
|
45940
45996
|
};
|
|
45941
45997
|
SMART_QUOTE_RE = new RegExp(`[${Object.keys(SMART_QUOTES).join("")}]`, "g");
|
|
45942
45998
|
SET_TERM_RE = /^SET\s+TERM\s+(\S+)$/i;
|
|
45999
|
+
TINA4_EDIT_MARKER_RE = /(?:#|\/\/|--|\/\*|\{#)\s*tina4:edit\b/i;
|
|
45943
46000
|
MIGRATION_LOCK_NAME = "tina4_migration_lock";
|
|
45944
46001
|
PG_ADVISORY_KEY = BigInt.asIntN(
|
|
45945
46002
|
64,
|
|
@@ -937,6 +937,23 @@ function consumeSqlDelimiter(state: SplitState): boolean {
|
|
|
937
937
|
* survives as one. Multi-character terminators (e.g. `!!`) are supported.
|
|
938
938
|
* Mirrors the tina4-python `_split_statements` / tina4-php / tina4-ruby scanner (parity).
|
|
939
939
|
*/
|
|
940
|
+
const TINA4_EDIT_MARKER_RE = /(?:#|\/\/|--|\/\*|\{#)\s*tina4:edit\b/i;
|
|
941
|
+
|
|
942
|
+
/** True if any executable statement remains once SQL comments are stripped. */
|
|
943
|
+
function hasExecutableSql(sql: string): boolean {
|
|
944
|
+
const body = sql.replace(/\/\*[\s\S]*?\*\//g, "").replace(/--[^\n]*/g, "");
|
|
945
|
+
return body.replace(/[;\s]/g, "") !== "";
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
/**
|
|
949
|
+
* True if a migration is still the unedited scaffold placeholder: it bears a
|
|
950
|
+
* tina4:edit marker AND has no executable statement. Used to keep an empty
|
|
951
|
+
* placeholder pending rather than apply it as a silent no-op (#288/#297).
|
|
952
|
+
*/
|
|
953
|
+
function isUnappliedScaffold(sql: string): boolean {
|
|
954
|
+
return TINA4_EDIT_MARKER_RE.test(sql) && !hasExecutableSql(sql);
|
|
955
|
+
}
|
|
956
|
+
|
|
940
957
|
export function splitStatements(sql: string, delimiter = ";"): string[] {
|
|
941
958
|
const state: SplitState = {
|
|
942
959
|
sql: normalizeQuotes(sql),
|
|
@@ -1248,6 +1265,23 @@ async function runPendingMigrations(
|
|
|
1248
1265
|
continue;
|
|
1249
1266
|
}
|
|
1250
1267
|
|
|
1268
|
+
// An empty, unedited scaffold migration — one that still bears a tina4:edit
|
|
1269
|
+
// marker AND has no executable statement (the comment-only ALTER stub from a
|
|
1270
|
+
// non-create migrate:create, or the view stub) — is unfinished. Applying it
|
|
1271
|
+
// (and recording it passed) runs nothing and leaves the real SQL, written
|
|
1272
|
+
// later under the same filename, never applied, with migrate reporting
|
|
1273
|
+
// nothing pending (#288, #297). Keep it pending until it is written. A
|
|
1274
|
+
// scaffolded CREATE TABLE carries the same hint but IS real DDL, so it
|
|
1275
|
+
// applies — generate-model → migrate is untouched.
|
|
1276
|
+
if (isUnappliedScaffold(sqlContent)) {
|
|
1277
|
+
console.warn(
|
|
1278
|
+
` Migration ${file} is still an unedited scaffold (a 'tina4:edit' ` +
|
|
1279
|
+
`placeholder with no SQL yet) — skipped and kept pending. Write the ` +
|
|
1280
|
+
`migration and remove the tina4:edit line(s), then run migrate again.`,
|
|
1281
|
+
);
|
|
1282
|
+
continue; // neither applied nor failed — it stays pending for next run
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1251
1285
|
const statements = splitStatements(sqlContent, delimiter);
|
|
1252
1286
|
|
|
1253
1287
|
try {
|
|
@@ -145,30 +145,6 @@ export declare function normalizeQuotes(sql: string): string;
|
|
|
145
145
|
* directive.
|
|
146
146
|
*/
|
|
147
147
|
export declare function parseSetTerm(statement: string): string | null;
|
|
148
|
-
/**
|
|
149
|
-
* Split SQL text into individual statements with a single-pass, quote- and
|
|
150
|
-
* comment-aware scanner. The split decision is made character by character so
|
|
151
|
-
* the delimiter only ever fires in real statement position.
|
|
152
|
-
*
|
|
153
|
-
* This is the fix for issue #54: the old implementation split on `delimiter`
|
|
154
|
-
* BEFORE stripping `-- …` line comments, so a `;` inside a line comment
|
|
155
|
-
* fragmented one statement into several broken pieces. A scanner that knows
|
|
156
|
-
* where it is (code / comment / string) cannot make that mistake.
|
|
157
|
-
*
|
|
158
|
-
* Handled, in priority order, only when NOT already inside a stored-proc block:
|
|
159
|
-
* - `$$ … $$` and `// … //` stored-proc blocks are kept intact (inner `;` never
|
|
160
|
-
* splits). A `//` preceded by `:` is a URL scheme (`https://…`), not a delimiter.
|
|
161
|
-
* - `/* … */` block comments are stripped.
|
|
162
|
-
* - `-- …` line comments are stripped to end of line (the newline is kept).
|
|
163
|
-
* - `'…'` single-quoted strings and `"…"` double-quoted identifiers are copied
|
|
164
|
-
* verbatim, honouring the SQL doubled-quote escape (`''` / `""`); a `;`, `--`
|
|
165
|
-
* or `/*` inside a literal is data, not a delimiter or comment.
|
|
166
|
-
* - A `SET TERM <new> <current>` directive switches the active terminator and is
|
|
167
|
-
* consumed (never emitted), so a statement whose own body contains the default
|
|
168
|
-
* terminator — a Firebird trigger, stored procedure or `EXECUTE BLOCK` —
|
|
169
|
-
* survives as one. Multi-character terminators (e.g. `!!`) are supported.
|
|
170
|
-
* Mirrors the tina4-python `_split_statements` / tina4-php / tina4-ruby scanner (parity).
|
|
171
|
-
*/
|
|
172
148
|
export declare function splitStatements(sql: string, delimiter?: string): string[];
|
|
173
149
|
/**
|
|
174
150
|
* Sort migration filenames supporting both naming patterns:
|