tina4-nodejs 3.13.157 → 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 +4 -3
- package/package.json +3 -3
- package/packages/cli/dist/bin.js +1384 -639
- package/packages/cli/src/commands/generate.ts +72 -23
- package/packages/core/dist/index.js +1393 -639
- package/packages/core/public/bundled-component-provenance.json +2 -2
- package/packages/core/public/js/frond.js +26 -7
- package/packages/core/public/js/frond.min.js +1 -1
- package/packages/core/src/index.ts +18 -0
- package/packages/core/src/middleware.ts +10 -4
- package/packages/core/src/queue.ts +42 -32
- package/packages/core/src/queueBackends/kafkaBackend.ts +687 -544
- package/packages/core/src/server.ts +41 -4
- package/packages/core/src/tcp.ts +484 -0
- package/packages/frond/dist/index.js +118 -4
- package/packages/frond/src/engine.ts +87 -8
- package/packages/frond/src/index.ts +1 -1
- package/packages/orm/dist/index.js +1386 -641
- package/packages/orm/src/migration.ts +34 -0
- package/packages/orm/src/queryBuilder.ts +38 -0
- package/types/core/src/index.d.ts +2 -0
- package/types/core/src/queue.d.ts +1 -1
- package/types/core/src/queueBackends/kafkaBackend.d.ts +48 -54
- package/types/core/src/tcp.d.ts +165 -0
- package/types/frond/src/engine.d.ts +9 -0
- package/types/frond/src/index.d.ts +1 -1
- package/types/orm/src/migration.d.ts +0 -24
- package/types/orm/src/queryBuilder.d.ts +28 -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
|
|