tina4-nodejs 3.13.151 → 3.13.152
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 +281 -68
- package/packages/cli/src/bin.ts +179 -7
- package/packages/cli/src/commands/generate.ts +36 -17
- package/packages/cli/src/commands/migrateCreate.ts +15 -3
- package/packages/cli/src/commands/queue.ts +8 -0
- package/packages/cli/src/util.ts +25 -15
- package/packages/core/dist/index.js +130 -61
- package/packages/core/src/authGate.ts +3 -4
- package/packages/core/src/devAdmin.ts +4 -0
- package/packages/core/src/server.ts +4 -2
- package/packages/orm/dist/index.js +130 -61
- package/packages/orm/src/adapters/postgres.ts +79 -19
- package/packages/orm/src/docstore.ts +24 -8
- package/types/cli/src/bin.d.ts +16 -0
- package/types/cli/src/commands/generate.d.ts +11 -0
- package/types/cli/src/commands/migrateCreate.d.ts +2 -0
- package/types/cli/src/commands/queue.d.ts +2 -0
- package/types/cli/src/util.d.ts +2 -1
- package/types/core/src/authGate.d.ts +3 -3
- package/types/orm/src/adapters/postgres.d.ts +6 -0
|
@@ -4268,6 +4268,9 @@ var init_postgres = __esm({
|
|
|
4268
4268
|
await withConnectTimeout(
|
|
4269
4269
|
() => {
|
|
4270
4270
|
this.client = typeof this.config === "string" ? new Client({ connectionString: this.config, ...timeoutOption }) : new Client({ ...this.config, ...timeoutOption });
|
|
4271
|
+
this.client.on("error", () => {
|
|
4272
|
+
this.connectionIsDead = true;
|
|
4273
|
+
});
|
|
4271
4274
|
return this.client.connect();
|
|
4272
4275
|
},
|
|
4273
4276
|
budgetMs,
|
|
@@ -4291,6 +4294,52 @@ var init_postgres = __esm({
|
|
|
4291
4294
|
throw new Error("PostgreSQL adapter not connected. Call connect() first.");
|
|
4292
4295
|
}
|
|
4293
4296
|
}
|
|
4297
|
+
// ── Reconnect after a dropped link (parity with the Python master, #236/#242) ──
|
|
4298
|
+
// pg's Client does not reconnect itself: once the server drops the link it must
|
|
4299
|
+
// be rebuilt. A statement that hits a dropped link reconnects and retries once
|
|
4300
|
+
// when nothing uncommitted went down with it; inside an explicit transaction the
|
|
4301
|
+
// error surfaces. A reconnect that itself fails leaves the link dead (not null-
|
|
4302
|
+
// guarded away), so the NEXT statement retries and recovers once a server returns.
|
|
4303
|
+
connectionIsDead = false;
|
|
4304
|
+
isConnectionError(e) {
|
|
4305
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
4306
|
+
return /connection terminated|terminating connection|server closed the connection|encountered a connection error|connection closed|not queryable|ECONNRESET|EPIPE|socket hang up/i.test(msg);
|
|
4307
|
+
}
|
|
4308
|
+
async reconnect() {
|
|
4309
|
+
void Promise.resolve(this.client?.end()).catch(() => {
|
|
4310
|
+
});
|
|
4311
|
+
this.client = null;
|
|
4312
|
+
this.connectionIsDead = false;
|
|
4313
|
+
await this.connect();
|
|
4314
|
+
}
|
|
4315
|
+
async ensureLiveConnection() {
|
|
4316
|
+
if (!this._inTransaction && (this.client === null || this.connectionIsDead)) {
|
|
4317
|
+
await this.reconnect();
|
|
4318
|
+
}
|
|
4319
|
+
}
|
|
4320
|
+
async runQuery(sql, params) {
|
|
4321
|
+
await this.ensureLiveConnection();
|
|
4322
|
+
this.ensureConnected();
|
|
4323
|
+
try {
|
|
4324
|
+
return await this.client.query(sql, params);
|
|
4325
|
+
} catch (e) {
|
|
4326
|
+
if (!this.isConnectionError(e)) throw e;
|
|
4327
|
+
this.connectionIsDead = true;
|
|
4328
|
+
if (this._inTransaction) throw e;
|
|
4329
|
+
await this.reconnect();
|
|
4330
|
+
return await this.client.query(sql, params);
|
|
4331
|
+
}
|
|
4332
|
+
}
|
|
4333
|
+
// Transaction control (BEGIN/COMMIT/ROLLBACK) runs RAW - no reconnect, no
|
|
4334
|
+
// pre-heal. A failed BEGIN/COMMIT/ROLLBACK must surface so the connection-pool
|
|
4335
|
+
// layer can discard the connection and restore capacity; reconnecting or
|
|
4336
|
+
// retrying here would mask that failure (databasePoolIsolation contract).
|
|
4337
|
+
// Dropped-link recovery stays on the DATA path (runQuery): the next data
|
|
4338
|
+
// statement heals the link.
|
|
4339
|
+
async rawQuery(sql) {
|
|
4340
|
+
this.ensureConnected();
|
|
4341
|
+
await this.client.query(sql);
|
|
4342
|
+
}
|
|
4294
4343
|
/** Convert ? placeholders to $1, $2, ... for pg. */
|
|
4295
4344
|
/** Ensure bytea columns are Buffer (already the case with pg). No-op guard. */
|
|
4296
4345
|
decodeBlobs(row) {
|
|
@@ -4340,7 +4389,6 @@ var init_postgres = __esm({
|
|
|
4340
4389
|
return null;
|
|
4341
4390
|
}
|
|
4342
4391
|
execute(sql, params) {
|
|
4343
|
-
this.ensureConnected();
|
|
4344
4392
|
const convertedSql = this.convertPlaceholders(sql);
|
|
4345
4393
|
throw new Error("Use executeAsync() for PostgreSQL \u2014 async adapter requires async methods.");
|
|
4346
4394
|
}
|
|
@@ -4375,9 +4423,8 @@ var init_postgres = __esm({
|
|
|
4375
4423
|
}
|
|
4376
4424
|
/** Async execute for real usage. */
|
|
4377
4425
|
async executeAsync(sql, params) {
|
|
4378
|
-
this.ensureConnected();
|
|
4379
4426
|
const convertedSql = this.bindable(sql, params);
|
|
4380
|
-
const result = await this.
|
|
4427
|
+
const result = await this.runQuery(convertedSql, params);
|
|
4381
4428
|
if (result.rows?.[0]?.id !== void 0) {
|
|
4382
4429
|
this._lastInsertId = this.normalizeId(result.rows[0].id);
|
|
4383
4430
|
}
|
|
@@ -4388,9 +4435,8 @@ var init_postgres = __esm({
|
|
|
4388
4435
|
}
|
|
4389
4436
|
/** Async query for real usage. */
|
|
4390
4437
|
async queryAsync(sql, params) {
|
|
4391
|
-
this.ensureConnected();
|
|
4392
4438
|
const convertedSql = this.bindable(sql, params);
|
|
4393
|
-
const result = await this.
|
|
4439
|
+
const result = await this.runQuery(convertedSql, params);
|
|
4394
4440
|
return result.rows.map((row) => this.decodeBlobs(row));
|
|
4395
4441
|
}
|
|
4396
4442
|
fetch(sql, params, limit, skip) {
|
|
@@ -4418,7 +4464,6 @@ var init_postgres = __esm({
|
|
|
4418
4464
|
throw new Error("Use insertAsync() for PostgreSQL.");
|
|
4419
4465
|
}
|
|
4420
4466
|
async insertAsync(table2, data) {
|
|
4421
|
-
this.ensureConnected();
|
|
4422
4467
|
if (Array.isArray(data)) {
|
|
4423
4468
|
const batch = buildInsertRows(ANSI_DIALECT, table2, data);
|
|
4424
4469
|
if (!batch) return { success: true, affectedRows: 0 };
|
|
@@ -4432,7 +4477,7 @@ var init_postgres = __esm({
|
|
|
4432
4477
|
}
|
|
4433
4478
|
const { sql, values } = buildInsertRow(POSTGRES_DIALECT, table2, data, " RETURNING *");
|
|
4434
4479
|
try {
|
|
4435
|
-
const result = await this.
|
|
4480
|
+
const result = await this.runQuery(sql, values);
|
|
4436
4481
|
const insertedRow = result.rows[0];
|
|
4437
4482
|
const id = this.normalizeId(insertedRow?.id);
|
|
4438
4483
|
if (id !== null) this._lastInsertId = id;
|
|
@@ -4449,13 +4494,12 @@ var init_postgres = __esm({
|
|
|
4449
4494
|
throw new Error("Use updateAsync() for PostgreSQL.");
|
|
4450
4495
|
}
|
|
4451
4496
|
async updateAsync(table2, data, filter, params) {
|
|
4452
|
-
this.ensureConnected();
|
|
4453
4497
|
const { sql, values } = buildUpdate(POSTGRES_DIALECT, table2, data, filter, params, {
|
|
4454
4498
|
startAt: 1,
|
|
4455
4499
|
convertFragment: (fragment, startAt) => this.convertPlaceholders(fragment, startAt)
|
|
4456
4500
|
});
|
|
4457
4501
|
try {
|
|
4458
|
-
const result = await this.
|
|
4502
|
+
const result = await this.runQuery(sql, values);
|
|
4459
4503
|
return { success: true, affectedRows: result.rowCount ?? 0 };
|
|
4460
4504
|
} catch (e) {
|
|
4461
4505
|
return { success: false, affectedRows: 0, error: e.message };
|
|
@@ -4465,13 +4509,12 @@ var init_postgres = __esm({
|
|
|
4465
4509
|
throw new Error("Use deleteAsync() for PostgreSQL.");
|
|
4466
4510
|
}
|
|
4467
4511
|
async deleteAsync(table2, filter, params) {
|
|
4468
|
-
this.ensureConnected();
|
|
4469
4512
|
const { sql, values } = buildDelete(POSTGRES_DIALECT, table2, filter, params, {
|
|
4470
4513
|
startAt: 1,
|
|
4471
4514
|
convertFragment: (fragment) => this.bindable(fragment, params)
|
|
4472
4515
|
});
|
|
4473
4516
|
try {
|
|
4474
|
-
const result = await this.
|
|
4517
|
+
const result = await this.runQuery(sql, values);
|
|
4475
4518
|
return { success: true, affectedRows: result.rowCount ?? 0 };
|
|
4476
4519
|
} catch (e) {
|
|
4477
4520
|
return { success: false, affectedRows: 0, error: e.message };
|
|
@@ -4481,22 +4524,28 @@ var init_postgres = __esm({
|
|
|
4481
4524
|
throw new Error("Use startTransactionAsync() for PostgreSQL.");
|
|
4482
4525
|
}
|
|
4483
4526
|
async startTransactionAsync() {
|
|
4484
|
-
await this.
|
|
4527
|
+
await this.rawQuery("BEGIN");
|
|
4485
4528
|
this._inTransaction = true;
|
|
4486
4529
|
}
|
|
4487
4530
|
commit() {
|
|
4488
4531
|
throw new Error("Use commitAsync() for PostgreSQL.");
|
|
4489
4532
|
}
|
|
4490
4533
|
async commitAsync() {
|
|
4491
|
-
|
|
4492
|
-
|
|
4534
|
+
try {
|
|
4535
|
+
await this.rawQuery("COMMIT");
|
|
4536
|
+
} finally {
|
|
4537
|
+
this._inTransaction = false;
|
|
4538
|
+
}
|
|
4493
4539
|
}
|
|
4494
4540
|
rollback() {
|
|
4495
4541
|
throw new Error("Use rollbackAsync() for PostgreSQL.");
|
|
4496
4542
|
}
|
|
4497
4543
|
async rollbackAsync() {
|
|
4498
|
-
|
|
4499
|
-
|
|
4544
|
+
try {
|
|
4545
|
+
await this.rawQuery("ROLLBACK");
|
|
4546
|
+
} finally {
|
|
4547
|
+
this._inTransaction = false;
|
|
4548
|
+
}
|
|
4500
4549
|
}
|
|
4501
4550
|
getTables() {
|
|
4502
4551
|
throw new Error("Use tablesAsync() for PostgreSQL.");
|
|
@@ -16767,6 +16816,12 @@ import { dirname as dirname5, isAbsolute as isAbsolute4, join as join9 } from "n
|
|
|
16767
16816
|
function iso(d) {
|
|
16768
16817
|
return d.toISOString();
|
|
16769
16818
|
}
|
|
16819
|
+
function setOwn(obj, key, value) {
|
|
16820
|
+
Object.defineProperty(obj, key, { value, writable: true, enumerable: true, configurable: true });
|
|
16821
|
+
}
|
|
16822
|
+
function getOwn(obj, key) {
|
|
16823
|
+
return Object.hasOwn(obj, key) ? obj[key] : void 0;
|
|
16824
|
+
}
|
|
16770
16825
|
function encodeValue(value) {
|
|
16771
16826
|
if (value instanceof ObjectId) return value.toString();
|
|
16772
16827
|
if (value instanceof Date) return iso(value);
|
|
@@ -16774,7 +16829,7 @@ function encodeValue(value) {
|
|
|
16774
16829
|
if (value !== null && typeof value === "object") {
|
|
16775
16830
|
const out = {};
|
|
16776
16831
|
for (const [k, v] of Object.entries(value)) {
|
|
16777
|
-
out
|
|
16832
|
+
setOwn(out, k, encodeValue(v));
|
|
16778
16833
|
}
|
|
16779
16834
|
return out;
|
|
16780
16835
|
}
|
|
@@ -16793,7 +16848,7 @@ function decodeValue(value) {
|
|
|
16793
16848
|
if (value !== null && typeof value === "object") {
|
|
16794
16849
|
const out = {};
|
|
16795
16850
|
for (const [k, v] of Object.entries(value)) {
|
|
16796
|
-
out
|
|
16851
|
+
setOwn(out, k, decodeValue(v));
|
|
16797
16852
|
}
|
|
16798
16853
|
return out;
|
|
16799
16854
|
}
|
|
@@ -16939,31 +16994,32 @@ function project(doc, projection) {
|
|
|
16939
16994
|
const exclude = new Set(Object.entries(projection).filter(([, v]) => !v).map(([k]) => k));
|
|
16940
16995
|
if (include.size > 0) {
|
|
16941
16996
|
const out2 = {};
|
|
16942
|
-
for (const k of include) if (k
|
|
16997
|
+
for (const k of include) if (Object.hasOwn(doc, k)) setOwn(out2, k, doc[k]);
|
|
16943
16998
|
const idVal = projection._id;
|
|
16944
16999
|
if ((idVal === void 0 || idVal) && "_id" in doc) out2._id = doc._id;
|
|
16945
17000
|
return out2;
|
|
16946
17001
|
}
|
|
16947
17002
|
const out = {};
|
|
16948
|
-
for (const [k, v] of Object.entries(doc)) if (!exclude.has(k)) out
|
|
17003
|
+
for (const [k, v] of Object.entries(doc)) if (!exclude.has(k)) setOwn(out, k, v);
|
|
16949
17004
|
return out;
|
|
16950
17005
|
}
|
|
16951
17006
|
function setPath(doc, dotted, value) {
|
|
16952
17007
|
const parts = dotted.split(".");
|
|
16953
17008
|
let node = doc;
|
|
16954
17009
|
for (const p of parts.slice(0, -1)) {
|
|
16955
|
-
|
|
16956
|
-
|
|
17010
|
+
const child = getOwn(node, p);
|
|
17011
|
+
if (child === void 0 || child === null || typeof child !== "object") {
|
|
17012
|
+
setOwn(node, p, {});
|
|
16957
17013
|
}
|
|
16958
17014
|
node = node[p];
|
|
16959
17015
|
}
|
|
16960
|
-
node
|
|
17016
|
+
setOwn(node, parts[parts.length - 1], value);
|
|
16961
17017
|
}
|
|
16962
17018
|
function unsetPath(doc, dotted) {
|
|
16963
17019
|
const parts = dotted.split(".");
|
|
16964
17020
|
let node = doc;
|
|
16965
17021
|
for (const p of parts.slice(0, -1)) {
|
|
16966
|
-
const next = node
|
|
17022
|
+
const next = getOwn(node, p);
|
|
16967
17023
|
if (next === null || typeof next !== "object") return;
|
|
16968
17024
|
node = next;
|
|
16969
17025
|
}
|
|
@@ -23383,8 +23439,8 @@ var init_ssoIdentity = __esm({
|
|
|
23383
23439
|
});
|
|
23384
23440
|
|
|
23385
23441
|
// src/authGate.ts
|
|
23386
|
-
function enforceRouteAuth(req2, res, match
|
|
23387
|
-
if (!(match.secure === true && match.noAuth !== true
|
|
23442
|
+
function enforceRouteAuth(req2, res, match) {
|
|
23443
|
+
if (!(match.secure === true && match.noAuth !== true)) {
|
|
23388
23444
|
return false;
|
|
23389
23445
|
}
|
|
23390
23446
|
const authHeader = req2.headers.authorization ?? "";
|
|
@@ -27122,26 +27178,31 @@ function parseFlags(args, booleanFlags) {
|
|
|
27122
27178
|
const positional = [];
|
|
27123
27179
|
let i = 0;
|
|
27124
27180
|
while (i < args.length) {
|
|
27125
|
-
|
|
27126
|
-
|
|
27127
|
-
const key = arg.slice(2);
|
|
27128
|
-
if (booleanFlags?.has(key)) {
|
|
27129
|
-
flags[key] = true;
|
|
27130
|
-
i += 1;
|
|
27131
|
-
} else if (i + 1 < args.length && !args[i + 1].startsWith("--")) {
|
|
27132
|
-
flags[key] = args[i + 1];
|
|
27133
|
-
i += 2;
|
|
27134
|
-
} else {
|
|
27135
|
-
flags[key] = true;
|
|
27136
|
-
i += 1;
|
|
27137
|
-
}
|
|
27181
|
+
if (args[i].startsWith("--")) {
|
|
27182
|
+
i += readFlag(args, i, flags, booleanFlags);
|
|
27138
27183
|
} else {
|
|
27139
|
-
positional.push(
|
|
27184
|
+
positional.push(args[i]);
|
|
27140
27185
|
i += 1;
|
|
27141
27186
|
}
|
|
27142
27187
|
}
|
|
27143
27188
|
return { flags, positional };
|
|
27144
27189
|
}
|
|
27190
|
+
function readFlag(args, i, flags, booleanFlags) {
|
|
27191
|
+
const arg = args[i];
|
|
27192
|
+
const eq = arg.indexOf("=");
|
|
27193
|
+
if (eq !== -1) {
|
|
27194
|
+
flags[arg.slice(2, eq)] = arg.slice(eq + 1);
|
|
27195
|
+
return 1;
|
|
27196
|
+
}
|
|
27197
|
+
const key = arg.slice(2);
|
|
27198
|
+
const next = args[i + 1];
|
|
27199
|
+
if (!booleanFlags?.has(key) && next !== void 0 && !next.startsWith("--")) {
|
|
27200
|
+
flags[key] = next;
|
|
27201
|
+
return 2;
|
|
27202
|
+
}
|
|
27203
|
+
flags[key] = true;
|
|
27204
|
+
return 1;
|
|
27205
|
+
}
|
|
27145
27206
|
var init_util = __esm({
|
|
27146
27207
|
"../cli/src/util.ts"() {
|
|
27147
27208
|
"use strict";
|
|
@@ -27154,6 +27215,7 @@ __export(generate_exports, {
|
|
|
27154
27215
|
DEFAULT_FIELDS: () => DEFAULT_FIELDS,
|
|
27155
27216
|
GENERATORS: () => GENERATORS,
|
|
27156
27217
|
RESOLUTION_ENVELOPE_VERSION: () => RESOLUTION_ENVELOPE_VERSION,
|
|
27218
|
+
RESOLUTION_FLAGS: () => RESOLUTION_FLAGS,
|
|
27157
27219
|
SQL_RESERVED_TABLE_NAMES: () => SQL_RESERVED_TABLE_NAMES,
|
|
27158
27220
|
aiFill: () => aiFill,
|
|
27159
27221
|
currentResolution: () => currentResolution,
|
|
@@ -27470,6 +27532,10 @@ async function generate(what, name, extraArgs = []) {
|
|
|
27470
27532
|
extraArgs = [name, ...extraArgs];
|
|
27471
27533
|
name = "";
|
|
27472
27534
|
}
|
|
27535
|
+
if (GENERATORS[what] && !noNameGenerators.has(what) && name.startsWith("-")) {
|
|
27536
|
+
console.log(`Invalid ${what} name: '${name}' - names can't start with '-'.`);
|
|
27537
|
+
process.exit(1);
|
|
27538
|
+
}
|
|
27473
27539
|
if (!noNameGenerators.has(what) && !name) {
|
|
27474
27540
|
console.error(` Usage: tina4nodejs generate ${what} <name> [options]`);
|
|
27475
27541
|
process.exit(1);
|
|
@@ -27786,7 +27852,7 @@ function generateCrud(name, flags) {
|
|
|
27786
27852
|
if (!__resolution.jsonMode) console.log(`
|
|
27787
27853
|
Generating CRUD for ${name}...
|
|
27788
27854
|
`);
|
|
27789
|
-
generateModel(name, flags, false);
|
|
27855
|
+
if (!flags["skip-model"]) generateModel(name, flags, false);
|
|
27790
27856
|
generateCrudAdminRoute(name, table2, isPublic);
|
|
27791
27857
|
if (!flags["no-templates"]) copyCrudTemplates();
|
|
27792
27858
|
generateCrudGateTest(name, table2, isPublic);
|
|
@@ -29096,7 +29162,7 @@ for (const stmt of statements(downSql)) db.execute(stmt);
|
|
|
29096
29162
|
assert("DOWN drops the ${table2} table", db.tableExists("${table2}") === false);`;
|
|
29097
29163
|
writeTest(`${table2}_migration`, standaloneTest(doc, body));
|
|
29098
29164
|
}
|
|
29099
|
-
var FIELD_TYPE_MAP, SQL_RESERVED_TABLE_NAMES, RESOLUTION_ENVELOPE_VERSION, __resolution, TINA4_EDIT_MARKER, DEFAULT_FIELDS, GENERATORS, GENERATOR_LIST, NEXT_STEPS;
|
|
29165
|
+
var FIELD_TYPE_MAP, SQL_RESERVED_TABLE_NAMES, RESOLUTION_ENVELOPE_VERSION, __resolution, TINA4_EDIT_MARKER, DEFAULT_FIELDS, GENERATORS, RESOLUTION_FLAGS, GENERATOR_LIST, NEXT_STEPS;
|
|
29100
29166
|
var init_generate = __esm({
|
|
29101
29167
|
"../cli/src/commands/generate.ts"() {
|
|
29102
29168
|
"use strict";
|
|
@@ -29209,22 +29275,23 @@ var init_generate = __esm({
|
|
|
29209
29275
|
TINA4_EDIT_MARKER = /^\s*(?:\/\/|--|\{#|#)\s*tina4:edit\s+(.+?)(?:\s*#\})?\s*$/;
|
|
29210
29276
|
DEFAULT_FIELDS = [["name", "string"]];
|
|
29211
29277
|
GENERATORS = {
|
|
29212
|
-
model: { handler: generateModel, usage: '<Name> [--fields "name:string,price:float"] [--table-name <name>]', summary: "ORM model + matching migration" },
|
|
29213
|
-
route: { handler: generateRoute, usage: "<name> [--model Name] [--public]", summary: "CRUD route file, secure by default (--public opens writes)" },
|
|
29214
|
-
crud: { handler: generateCrud, usage: '<Name> [--fields "..."] [--public] [--no-templates]', summary: "Model + migration + AutoCrud-backed admin page (toCrud) + editable crud/ templates + gate test" },
|
|
29215
|
-
migration: { handler: (n, f) => generateMigration(n, f, void 0, void 0, !f["no-test"]), usage: "<description>", summary: "Timestamped migration file (UP/DOWN)" },
|
|
29216
|
-
middleware: { handler: generateMiddleware, usage: "<Name>", summary: "Middleware with before/after hooks" },
|
|
29217
|
-
test: { handler: generateTest, usage: "<name> [--model Name]", summary: "Test file" },
|
|
29218
|
-
form: { handler: generateForm2, usage: '<Name> [--fields "..."]', summary: "Form template with inputs matching model fields" },
|
|
29219
|
-
view: { handler: generateView, usage: '<Name> [--fields "..."]', summary: "List + detail view templates" },
|
|
29220
|
-
auth: { handler: (_n, f) => generateAuth(f), usage: "", summary: "Login/register routes (public) + User model + templates" },
|
|
29221
|
-
service: { handler: generateService, usage: '<Name> [--every 5m | --cron "..."]', summary: "Scheduled ServiceRunner task (src/services/)" },
|
|
29222
|
-
queue: { handler: generateQueue, usage: "<topic>", summary: "Producer + consumer daemon worker (src/services/)" },
|
|
29223
|
-
validator: { handler: generateValidator, usage: "<Name>", summary: "Request-body Validator (src/validators/)" },
|
|
29224
|
-
seeder: { handler: generateSeeder, usage: "<Model>", summary: "FakeData + seedOrm seeder (src/seeds/)" },
|
|
29225
|
-
websocket: { handler: generateWebsocket, usage: "<path>", summary: "websocket() handler (src/routes/)" },
|
|
29226
|
-
listener: { handler: generateListener, usage: "<event>", summary: "Events.on(event) listener (src/listeners/)" }
|
|
29227
|
-
};
|
|
29278
|
+
model: { handler: generateModel, flags: { fields: true, "table-name": true, "no-migration": false }, usage: '<Name> [--fields "name:string,price:float"] [--table-name <name>]', summary: "ORM model + matching migration" },
|
|
29279
|
+
route: { handler: generateRoute, flags: { model: true, public: false, "table-name": true }, usage: "<name> [--model Name] [--public]", summary: "CRUD route file, secure by default (--public opens writes)" },
|
|
29280
|
+
crud: { handler: generateCrud, flags: { fields: true, "table-name": true, public: false, "no-templates": false, "no-migration": false, "skip-model": false }, usage: '<Name> [--fields "..."] [--public] [--no-templates] [--skip-model]', summary: "Model + migration + AutoCrud-backed admin page (toCrud) + editable crud/ templates + gate test" },
|
|
29281
|
+
migration: { handler: (n, f) => generateMigration(n, f, void 0, void 0, !f["no-test"]), flags: { fields: true, "table-name": true, "no-test": false }, usage: "<description>", summary: "Timestamped migration file (UP/DOWN)" },
|
|
29282
|
+
middleware: { handler: generateMiddleware, flags: {}, usage: "<Name>", summary: "Middleware with before/after hooks" },
|
|
29283
|
+
test: { handler: generateTest, flags: { model: true, public: false, "secure-writes": false }, usage: "<name> [--model Name]", summary: "Test file" },
|
|
29284
|
+
form: { handler: generateForm2, flags: { fields: true, "table-name": true }, usage: '<Name> [--fields "..."]', summary: "Form template with inputs matching model fields" },
|
|
29285
|
+
view: { handler: generateView, flags: { fields: true, "table-name": true }, usage: '<Name> [--fields "..."]', summary: "List + detail view templates" },
|
|
29286
|
+
auth: { handler: (_n, f) => generateAuth(f), flags: {}, usage: "", summary: "Login/register routes (public) + User model + templates" },
|
|
29287
|
+
service: { handler: generateService, flags: { every: true, cron: true }, usage: '<Name> [--every 5m | --cron "..."]', summary: "Scheduled ServiceRunner task (src/services/)" },
|
|
29288
|
+
queue: { handler: generateQueue, flags: {}, usage: "<topic>", summary: "Producer + consumer daemon worker (src/services/)" },
|
|
29289
|
+
validator: { handler: generateValidator, flags: {}, usage: "<Name>", summary: "Request-body Validator (src/validators/)" },
|
|
29290
|
+
seeder: { handler: generateSeeder, flags: { "table-name": true }, usage: "<Model>", summary: "FakeData + seedOrm seeder (src/seeds/)" },
|
|
29291
|
+
websocket: { handler: generateWebsocket, flags: {}, usage: "<path>", summary: "websocket() handler (src/routes/)" },
|
|
29292
|
+
listener: { handler: generateListener, flags: {}, usage: "<event>", summary: "Events.on(event) listener (src/listeners/)" }
|
|
29293
|
+
};
|
|
29294
|
+
RESOLUTION_FLAGS = { json: false, "dry-run": false };
|
|
29228
29295
|
GENERATOR_LIST = Object.keys(GENERATORS).join(", ");
|
|
29229
29296
|
NEXT_STEPS = {
|
|
29230
29297
|
model: ({ name, table: table2 }) => [
|
|
@@ -39039,7 +39106,8 @@ var init_devAdmin = __esm({
|
|
|
39039
39106
|
router.addRoute({
|
|
39040
39107
|
method: route.method,
|
|
39041
39108
|
pattern: route.pattern,
|
|
39042
|
-
handler: route.handler
|
|
39109
|
+
handler: route.handler,
|
|
39110
|
+
noAuth: true
|
|
39043
39111
|
});
|
|
39044
39112
|
}
|
|
39045
39113
|
if (mcpEnabled()) {
|
|
@@ -39063,7 +39131,8 @@ var init_devAdmin = __esm({
|
|
|
39063
39131
|
router.addRoute({
|
|
39064
39132
|
method: route.method,
|
|
39065
39133
|
pattern: route.pattern,
|
|
39066
|
-
handler: route.handler
|
|
39134
|
+
handler: route.handler,
|
|
39135
|
+
noAuth: true
|
|
39067
39136
|
});
|
|
39068
39137
|
}
|
|
39069
39138
|
getDefaultDevServer();
|
|
@@ -42330,7 +42399,7 @@ async function runMatchedRoute(ctx) {
|
|
|
42330
42399
|
const { req: req2, res, match, postMatchMiddleware } = ctx;
|
|
42331
42400
|
req2.params = match.params;
|
|
42332
42401
|
if (await runGlobalMiddlewarePass(postMatchMiddleware, req2, res)) return;
|
|
42333
|
-
if (enforceRouteAuth(req2, res, match
|
|
42402
|
+
if (enforceRouteAuth(req2, res, match)) return;
|
|
42334
42403
|
const routeMiddlewareClasses = (match.middlewares ?? []).filter(isMiddlewareClass);
|
|
42335
42404
|
let handlerSkipped = false;
|
|
42336
42405
|
if (match.middlewares && match.middlewares.length > 0) {
|
|
@@ -37,8 +37,8 @@ export interface AuthGateRoute {
|
|
|
37
37
|
* to `res.raw` and the caller must stop (not run the handler). Returns `false`
|
|
38
38
|
* when the route is public OR a valid token was presented (in which case
|
|
39
39
|
* `req.user` is populated and, for a body formToken, a `FreshToken` header is
|
|
40
|
-
* set). Auth is enforced only for a route that is `secure` and not `noAuth
|
|
41
|
-
*
|
|
40
|
+
* set). Auth is enforced only for a route that is `secure` and not `noAuth`
|
|
41
|
+
* (the dev dashboard registers its own routes `noAuth`).
|
|
42
42
|
*
|
|
43
43
|
* Token sources, in priority order: `Authorization: Bearer` header, a
|
|
44
44
|
* `formToken` in the parsed body, then a session token.
|
|
@@ -47,9 +47,8 @@ export function enforceRouteAuth(
|
|
|
47
47
|
req: Tina4Request,
|
|
48
48
|
res: Tina4Response,
|
|
49
49
|
match: AuthGateRoute,
|
|
50
|
-
isDevAdmin: boolean,
|
|
51
50
|
): boolean {
|
|
52
|
-
if (!(match.secure === true && match.noAuth !== true
|
|
51
|
+
if (!(match.secure === true && match.noAuth !== true)) {
|
|
53
52
|
return false;
|
|
54
53
|
}
|
|
55
54
|
|
|
@@ -839,11 +839,14 @@ export class DevAdmin {
|
|
|
839
839
|
{ method: "GET", pattern: "/__dev/toolbar.js", handler: handleToolbarJs },
|
|
840
840
|
];
|
|
841
841
|
|
|
842
|
+
// noAuth: the dashboard's own routes skip the auth gate. Only these do; a
|
|
843
|
+
// route of the application's own keeps the normal rules, whatever its path.
|
|
842
844
|
for (const route of routes) {
|
|
843
845
|
router.addRoute({
|
|
844
846
|
method: route.method,
|
|
845
847
|
pattern: route.pattern,
|
|
846
848
|
handler: route.handler,
|
|
849
|
+
noAuth: true,
|
|
847
850
|
});
|
|
848
851
|
}
|
|
849
852
|
|
|
@@ -877,6 +880,7 @@ export class DevAdmin {
|
|
|
877
880
|
method: route.method,
|
|
878
881
|
pattern: route.pattern,
|
|
879
882
|
handler: route.handler,
|
|
883
|
+
noAuth: true,
|
|
880
884
|
});
|
|
881
885
|
}
|
|
882
886
|
|
|
@@ -1182,8 +1182,10 @@ async function runMatchedRoute(ctx: MatchedRouteContext): Promise<void> {
|
|
|
1182
1182
|
// Auth enforcement lives in enforceRouteAuth (authGate.ts) so the in-process
|
|
1183
1183
|
// TestClient enforces the EXACT same gate - parity with Python #PY2, where a
|
|
1184
1184
|
// tokenless write must 401 in tests too, or a green test hides a live 401.
|
|
1185
|
-
//
|
|
1186
|
-
|
|
1185
|
+
// The dev dashboard's own routes are public because DevAdmin registers them
|
|
1186
|
+
// noAuth, not because of their path: a "/__dev" prefix test also opened any
|
|
1187
|
+
// write route of the application's own named /__developer or /__dev/anything.
|
|
1188
|
+
if (enforceRouteAuth(req, res, match as never)) return;
|
|
1187
1189
|
|
|
1188
1190
|
// The route's OWN class middleware: its beforeX hooks run inside
|
|
1189
1191
|
// runRouteMiddlewares, its afterX hooks join the after pass below - one
|