tina4-nodejs 3.13.163 → 3.13.165

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.
@@ -368,8 +368,8 @@ var init_modelCollection = __esm({
368
368
 
369
369
  // src/databaseUrl.ts
370
370
  import { inspect } from "node:util";
371
- function stripOneSlash(path10) {
372
- return path10.startsWith("/") ? path10.slice(1) : path10;
371
+ function stripOneSlash(path9) {
372
+ return path9.startsWith("/") ? path9.slice(1) : path9;
373
373
  }
374
374
  function decode(value) {
375
375
  if (value === void 0 || value === "") return null;
@@ -1839,16 +1839,16 @@ function parseEnvContent(content) {
1839
1839
  }
1840
1840
  return result;
1841
1841
  }
1842
- function loadEnv(path10, override = false) {
1842
+ function loadEnv(path9, override = false) {
1843
1843
  const fromEnv = (process.env.TINA4_ENV_FILE ?? "").trim();
1844
- if (path10 === void 0 && fromEnv.length > 0) {
1844
+ if (path9 === void 0 && fromEnv.length > 0) {
1845
1845
  const named = resolve(fromEnv);
1846
1846
  return mergeFirstWins(
1847
1847
  loadEnvFile(join(dirname(named), ".env.local"), override),
1848
1848
  loadEnvFile(named, override)
1849
1849
  );
1850
1850
  }
1851
- const target = resolve(path10 ?? ".");
1851
+ const target = resolve(path9 ?? ".");
1852
1852
  if (existsSync(target) && statSync(target).isDirectory()) {
1853
1853
  return mergeFirstWins(
1854
1854
  loadEnvFile(join(target, ".env.local"), override),
@@ -2085,12 +2085,12 @@ function resolveCallerName() {
2085
2085
  return void 0;
2086
2086
  }
2087
2087
  }
2088
- function targetIsFile(path10) {
2088
+ function targetIsFile(path9) {
2089
2089
  try {
2090
- if (existsSync2(path10) && statSync2(path10).isDirectory()) return false;
2090
+ if (existsSync2(path9) && statSync2(path9).isDirectory()) return false;
2091
2091
  } catch {
2092
2092
  }
2093
- const base = basename(path10);
2093
+ const base = basename(path9);
2094
2094
  return base.includes(".") && !base.startsWith(".");
2095
2095
  }
2096
2096
  function resolveBool(explicit, envName, fallback) {
@@ -2414,8 +2414,8 @@ var init_logger = __esm({
2414
2414
  rotateSize;
2415
2415
  rotateKeep;
2416
2416
  lock;
2417
- constructor(path10, rotateSize, rotateKeep, lockBuffer) {
2418
- this.path = path10;
2417
+ constructor(path9, rotateSize, rotateKeep, lockBuffer) {
2418
+ this.path = path9;
2419
2419
  this.rotateSize = rotateSize;
2420
2420
  this.rotateKeep = rotateKeep;
2421
2421
  this.lock = new SinkLock(lockBuffer);
@@ -2936,8 +2936,8 @@ function hashPassword(password, salt, iterations = 26e4) {
2936
2936
  }
2937
2937
  function checkPassword(password, hash) {
2938
2938
  try {
2939
- const delimiter2 = hash.includes("$") ? "$" : ":";
2940
- const parts = hash.split(delimiter2);
2939
+ const delimiter3 = hash.includes("$") ? "$" : ":";
2940
+ const parts = hash.split(delimiter3);
2941
2941
  if (parts.length !== 4 || parts[0] !== "pbkdf2_sha256") return false;
2942
2942
  const iterations = parseInt(parts[1], 10);
2943
2943
  const salt = parts[2];
@@ -4585,8 +4585,8 @@ function coerceParam(raw, type2) {
4585
4585
  return raw;
4586
4586
  }
4587
4587
  }
4588
- function joinGroupPath(prefix, path10) {
4589
- const full = `${prefix}/${path10.replace(/^\/+/, "")}`;
4588
+ function joinGroupPath(prefix, path9) {
4589
+ const full = `${prefix}/${path9.replace(/^\/+/, "")}`;
4590
4590
  const trimmed = `/${trimSlashes(full)}`;
4591
4591
  return trimmed.replace(/\/+/g, "/");
4592
4592
  }
@@ -4627,26 +4627,26 @@ async function runRouteMiddlewares(middlewares, req2, res) {
4627
4627
  }
4628
4628
  return true;
4629
4629
  }
4630
- function get(path10, handler, middlewares, meta) {
4631
- return defaultRouter.get(path10, handler, middlewares, meta);
4630
+ function get(path9, handler, middlewares, meta) {
4631
+ return defaultRouter.get(path9, handler, middlewares, meta);
4632
4632
  }
4633
- function post(path10, handler, middlewares, meta) {
4634
- return defaultRouter.post(path10, handler, middlewares, meta);
4633
+ function post(path9, handler, middlewares, meta) {
4634
+ return defaultRouter.post(path9, handler, middlewares, meta);
4635
4635
  }
4636
- function put(path10, handler, middlewares, meta) {
4637
- return defaultRouter.put(path10, handler, middlewares, meta);
4636
+ function put(path9, handler, middlewares, meta) {
4637
+ return defaultRouter.put(path9, handler, middlewares, meta);
4638
4638
  }
4639
- function patch(path10, handler, middlewares, meta) {
4640
- return defaultRouter.patch(path10, handler, middlewares, meta);
4639
+ function patch(path9, handler, middlewares, meta) {
4640
+ return defaultRouter.patch(path9, handler, middlewares, meta);
4641
4641
  }
4642
- function del(path10, handler, middlewares, meta) {
4643
- return defaultRouter.delete(path10, handler, middlewares, meta);
4642
+ function del(path9, handler, middlewares, meta) {
4643
+ return defaultRouter.delete(path9, handler, middlewares, meta);
4644
4644
  }
4645
- function any(path10, handler, middlewares, meta) {
4646
- return defaultRouter.any(path10, handler, middlewares, meta);
4645
+ function any(path9, handler, middlewares, meta) {
4646
+ return defaultRouter.any(path9, handler, middlewares, meta);
4647
4647
  }
4648
- function websocket(path10, handler, options) {
4649
- return defaultRouter.websocket(path10, handler, options);
4648
+ function websocket(path9, handler, options) {
4649
+ return defaultRouter.websocket(path9, handler, options);
4650
4650
  }
4651
4651
  var WsRouteRef, RouteRef, Router, RouteGroup, TINA4_DEFAULT_ROUTER, globalRouterHost, defaultRouter;
4652
4652
  var init_router = __esm({
@@ -4794,32 +4794,32 @@ var init_router = __esm({
4794
4794
  /**
4795
4795
  * Register a GET route programmatically.
4796
4796
  */
4797
- get(path10, handler, middlewares, meta) {
4798
- return this.addRoute({ method: "GET", pattern: path10, handler, middlewares, meta });
4797
+ get(path9, handler, middlewares, meta) {
4798
+ return this.addRoute({ method: "GET", pattern: path9, handler, middlewares, meta });
4799
4799
  }
4800
4800
  /**
4801
4801
  * Register a POST route programmatically.
4802
4802
  */
4803
- post(path10, handler, middlewares, meta) {
4804
- return this.addRoute({ method: "POST", pattern: path10, handler, middlewares, meta });
4803
+ post(path9, handler, middlewares, meta) {
4804
+ return this.addRoute({ method: "POST", pattern: path9, handler, middlewares, meta });
4805
4805
  }
4806
4806
  /**
4807
4807
  * Register a PUT route programmatically.
4808
4808
  */
4809
- put(path10, handler, middlewares, meta) {
4810
- return this.addRoute({ method: "PUT", pattern: path10, handler, middlewares, meta });
4809
+ put(path9, handler, middlewares, meta) {
4810
+ return this.addRoute({ method: "PUT", pattern: path9, handler, middlewares, meta });
4811
4811
  }
4812
4812
  /**
4813
4813
  * Register a PATCH route programmatically.
4814
4814
  */
4815
- patch(path10, handler, middlewares, meta) {
4816
- return this.addRoute({ method: "PATCH", pattern: path10, handler, middlewares, meta });
4815
+ patch(path9, handler, middlewares, meta) {
4816
+ return this.addRoute({ method: "PATCH", pattern: path9, handler, middlewares, meta });
4817
4817
  }
4818
4818
  /**
4819
4819
  * Register a DELETE route programmatically.
4820
4820
  */
4821
- delete(path10, handler, middlewares, meta) {
4822
- return this.addRoute({ method: "DELETE", pattern: path10, handler, middlewares, meta });
4821
+ delete(path9, handler, middlewares, meta) {
4822
+ return this.addRoute({ method: "DELETE", pattern: path9, handler, middlewares, meta });
4823
4823
  }
4824
4824
  /**
4825
4825
  * Register an explicit HEAD route. By default the framework auto-handles
@@ -4829,8 +4829,8 @@ var init_router = __esm({
4829
4829
  * logic, custom validator headers without the cost of building the body.
4830
4830
  * The framework still strips the response body for you on the way out.
4831
4831
  */
4832
- head(path10, handler, middlewares, meta) {
4833
- return this.addRoute({ method: "HEAD", pattern: path10, handler, middlewares, meta });
4832
+ head(path9, handler, middlewares, meta) {
4833
+ return this.addRoute({ method: "HEAD", pattern: path9, handler, middlewares, meta });
4834
4834
  }
4835
4835
  /**
4836
4836
  * Register an explicit OPTIONS route. By default the framework auto-
@@ -4838,16 +4838,16 @@ var init_router = __esm({
4838
4838
  * registered for the path and returning 204 (RFC 9110 §9.3.7). Use
4839
4839
  * this to take over that behaviour.
4840
4840
  */
4841
- options(path10, handler, middlewares, meta) {
4842
- return this.addRoute({ method: "OPTIONS", pattern: path10, handler, middlewares, meta });
4841
+ options(path9, handler, middlewares, meta) {
4842
+ return this.addRoute({ method: "OPTIONS", pattern: path9, handler, middlewares, meta });
4843
4843
  }
4844
4844
  /**
4845
4845
  * Register a route that matches ANY HTTP method.
4846
4846
  */
4847
- any(path10, handler, middlewares, meta) {
4847
+ any(path9, handler, middlewares, meta) {
4848
4848
  let lastRef;
4849
4849
  for (const method of ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "HEAD"]) {
4850
- lastRef = this.addRoute({ method, pattern: path10, handler, middlewares, meta });
4850
+ lastRef = this.addRoute({ method, pattern: path9, handler, middlewares, meta });
4851
4851
  }
4852
4852
  return lastRef;
4853
4853
  }
@@ -4866,14 +4866,14 @@ var init_router = __esm({
4866
4866
  * the trailing slash. Returning the de-slashed pattern lets callers issue
4867
4867
  * a 308 redirect instead of a hard 404 — Python parity.
4868
4868
  */
4869
- match(method, path10) {
4869
+ match(method, path9) {
4870
4870
  const upperMethod = method.toUpperCase();
4871
4871
  const routes = this.routes.get(upperMethod);
4872
4872
  if (routes) {
4873
- const direct = this.matchRoute(routes, path10);
4873
+ const direct = this.matchRoute(routes, path9);
4874
4874
  if (direct) return direct;
4875
- if (isTrailingSlashRedirectEnabled() && path10.length > 1 && path10.endsWith("/")) {
4876
- const stripped = rtrimSlashes(path10);
4875
+ if (isTrailingSlashRedirectEnabled() && path9.length > 1 && path9.endsWith("/")) {
4876
+ const stripped = rtrimSlashes(path9);
4877
4877
  if (stripped.length > 0) {
4878
4878
  const retry = this.matchRoute(routes, stripped);
4879
4879
  if (retry) return retry;
@@ -4883,7 +4883,7 @@ var init_router = __esm({
4883
4883
  if (upperMethod === "HEAD") {
4884
4884
  const getRoutes = this.routes.get("GET");
4885
4885
  if (getRoutes) {
4886
- return this.matchRoute(getRoutes, path10);
4886
+ return this.matchRoute(getRoutes, path9);
4887
4887
  }
4888
4888
  }
4889
4889
  return null;
@@ -4898,13 +4898,13 @@ var init_router = __esm({
4898
4898
  * OPTIONS is appended whenever any method exists for the path (the
4899
4899
  * framework auto-handles OPTIONS).
4900
4900
  */
4901
- methodsAllowedForPath(path10) {
4901
+ methodsAllowedForPath(path9) {
4902
4902
  const order = ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"];
4903
4903
  const seen = /* @__PURE__ */ new Set();
4904
4904
  for (const m of order) {
4905
4905
  const routes = this.routes.get(m);
4906
4906
  if (!routes) continue;
4907
- if (this.matchRoute(routes, path10)) {
4907
+ if (this.matchRoute(routes, path9)) {
4908
4908
  seen.add(m);
4909
4909
  }
4910
4910
  }
@@ -4915,9 +4915,9 @@ var init_router = __esm({
4915
4915
  return order.filter((m) => seen.has(m));
4916
4916
  }
4917
4917
  /** Inner match against a list of compiled routes, no trailing-slash logic. */
4918
- matchRoute(routes, path10) {
4918
+ matchRoute(routes, path9) {
4919
4919
  for (const route of routes) {
4920
- const match = route.regex.exec(path10);
4920
+ const match = route.regex.exec(path9);
4921
4921
  if (match) {
4922
4922
  const params = {};
4923
4923
  for (let i = 0; i < route.paramNames.length; i++) {
@@ -5005,10 +5005,10 @@ var init_router = __esm({
5005
5005
  * When secured, the upgrade handshake requires a valid JWT (Authorization
5006
5006
  * header / `bearer` subprotocol / `?token=`) or the upgrade is rejected.
5007
5007
  */
5008
- websocket(path10, handler, options) {
5009
- this.wsRoutes = this.wsRoutes.filter((r) => r.pattern !== path10);
5008
+ websocket(path9, handler, options) {
5009
+ this.wsRoutes = this.wsRoutes.filter((r) => r.pattern !== path9);
5010
5010
  const route = {
5011
- pattern: path10,
5011
+ pattern: path9,
5012
5012
  handler,
5013
5013
  // Public unless explicitly secured via options OR a handler `_secured` flag.
5014
5014
  authRequired: Boolean(options?.secured ?? handler._secured ?? false)
@@ -5065,54 +5065,54 @@ var init_router = __esm({
5065
5065
  * Register a route for a specific HTTP method.
5066
5066
  * Core registration method — all convenience methods delegate here.
5067
5067
  */
5068
- static add(method, path10, handler, middleware, swaggerMeta, template) {
5068
+ static add(method, path9, handler, middleware, swaggerMeta, template) {
5069
5069
  const m = method.toUpperCase();
5070
5070
  if (m === "ANY") {
5071
- return defaultRouter.any(path10, handler, middleware, swaggerMeta);
5071
+ return defaultRouter.any(path9, handler, middleware, swaggerMeta);
5072
5072
  }
5073
- return defaultRouter.addRoute({ method: m, pattern: path10, handler, middlewares: middleware, meta: swaggerMeta, template });
5073
+ return defaultRouter.addRoute({ method: m, pattern: path9, handler, middlewares: middleware, meta: swaggerMeta, template });
5074
5074
  }
5075
5075
  /**
5076
5076
  * Register a GET route on the default global router.
5077
5077
  */
5078
- static get(path10, handler, middleware, swaggerMeta, template) {
5079
- return defaultRouter.get(path10, handler, middleware, swaggerMeta);
5078
+ static get(path9, handler, middleware, swaggerMeta, template) {
5079
+ return defaultRouter.get(path9, handler, middleware, swaggerMeta);
5080
5080
  }
5081
5081
  /**
5082
5082
  * Register a POST route on the default global router.
5083
5083
  */
5084
- static post(path10, handler, middleware, swaggerMeta, template) {
5085
- return defaultRouter.post(path10, handler, middleware, swaggerMeta);
5084
+ static post(path9, handler, middleware, swaggerMeta, template) {
5085
+ return defaultRouter.post(path9, handler, middleware, swaggerMeta);
5086
5086
  }
5087
5087
  /**
5088
5088
  * Register a PUT route on the default global router.
5089
5089
  */
5090
- static put(path10, handler, middleware, swaggerMeta, template) {
5091
- return defaultRouter.put(path10, handler, middleware, swaggerMeta);
5090
+ static put(path9, handler, middleware, swaggerMeta, template) {
5091
+ return defaultRouter.put(path9, handler, middleware, swaggerMeta);
5092
5092
  }
5093
5093
  /**
5094
5094
  * Register a PATCH route on the default global router.
5095
5095
  */
5096
- static patch(path10, handler, middleware, swaggerMeta, template) {
5097
- return defaultRouter.patch(path10, handler, middleware, swaggerMeta);
5096
+ static patch(path9, handler, middleware, swaggerMeta, template) {
5097
+ return defaultRouter.patch(path9, handler, middleware, swaggerMeta);
5098
5098
  }
5099
5099
  /**
5100
5100
  * Register a DELETE route on the default global router.
5101
5101
  */
5102
- static delete(path10, handler, middleware, swaggerMeta, template) {
5103
- return defaultRouter.delete(path10, handler, middleware, swaggerMeta);
5102
+ static delete(path9, handler, middleware, swaggerMeta, template) {
5103
+ return defaultRouter.delete(path9, handler, middleware, swaggerMeta);
5104
5104
  }
5105
5105
  /**
5106
5106
  * Register a route that matches ANY HTTP method on the default global router.
5107
5107
  */
5108
- static any(path10, handler, middleware, swaggerMeta, template) {
5109
- return defaultRouter.any(path10, handler, middleware, swaggerMeta);
5108
+ static any(path9, handler, middleware, swaggerMeta, template) {
5109
+ return defaultRouter.any(path9, handler, middleware, swaggerMeta);
5110
5110
  }
5111
5111
  /**
5112
5112
  * Register a WebSocket route on the default global router.
5113
5113
  */
5114
- static websocket(path10, handler, options) {
5115
- return defaultRouter.websocket(path10, handler, options);
5114
+ static websocket(path9, handler, options) {
5115
+ return defaultRouter.websocket(path9, handler, options);
5116
5116
  }
5117
5117
  /**
5118
5118
  * Match a WebSocket upgrade path against routes on the default global router.
@@ -5228,57 +5228,57 @@ var init_router = __esm({
5228
5228
  const merged = [...group, ...route];
5229
5229
  return merged.length > 0 ? merged : void 0;
5230
5230
  }
5231
- get(path10, handler, middlewares, meta) {
5231
+ get(path9, handler, middlewares, meta) {
5232
5232
  return this.router.addRoute({
5233
5233
  method: "GET",
5234
- pattern: joinGroupPath(this.prefix, path10),
5234
+ pattern: joinGroupPath(this.prefix, path9),
5235
5235
  handler,
5236
5236
  middlewares: this.mergeMiddlewares(middlewares),
5237
5237
  meta
5238
5238
  });
5239
5239
  }
5240
- post(path10, handler, middlewares, meta) {
5240
+ post(path9, handler, middlewares, meta) {
5241
5241
  return this.router.addRoute({
5242
5242
  method: "POST",
5243
- pattern: joinGroupPath(this.prefix, path10),
5243
+ pattern: joinGroupPath(this.prefix, path9),
5244
5244
  handler,
5245
5245
  middlewares: this.mergeMiddlewares(middlewares),
5246
5246
  meta
5247
5247
  });
5248
5248
  }
5249
- put(path10, handler, middlewares, meta) {
5249
+ put(path9, handler, middlewares, meta) {
5250
5250
  return this.router.addRoute({
5251
5251
  method: "PUT",
5252
- pattern: joinGroupPath(this.prefix, path10),
5252
+ pattern: joinGroupPath(this.prefix, path9),
5253
5253
  handler,
5254
5254
  middlewares: this.mergeMiddlewares(middlewares),
5255
5255
  meta
5256
5256
  });
5257
5257
  }
5258
- patch(path10, handler, middlewares, meta) {
5258
+ patch(path9, handler, middlewares, meta) {
5259
5259
  return this.router.addRoute({
5260
5260
  method: "PATCH",
5261
- pattern: joinGroupPath(this.prefix, path10),
5261
+ pattern: joinGroupPath(this.prefix, path9),
5262
5262
  handler,
5263
5263
  middlewares: this.mergeMiddlewares(middlewares),
5264
5264
  meta
5265
5265
  });
5266
5266
  }
5267
- delete(path10, handler, middlewares, meta) {
5267
+ delete(path9, handler, middlewares, meta) {
5268
5268
  return this.router.addRoute({
5269
5269
  method: "DELETE",
5270
- pattern: joinGroupPath(this.prefix, path10),
5270
+ pattern: joinGroupPath(this.prefix, path9),
5271
5271
  handler,
5272
5272
  middlewares: this.mergeMiddlewares(middlewares),
5273
5273
  meta
5274
5274
  });
5275
5275
  }
5276
- any(path10, handler, middlewares, meta) {
5276
+ any(path9, handler, middlewares, meta) {
5277
5277
  let lastRef;
5278
5278
  for (const method of ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "HEAD"]) {
5279
5279
  lastRef = this.router.addRoute({
5280
5280
  method,
5281
- pattern: joinGroupPath(this.prefix, path10),
5281
+ pattern: joinGroupPath(this.prefix, path9),
5282
5282
  handler,
5283
5283
  middlewares: this.mergeMiddlewares(middlewares),
5284
5284
  meta
@@ -5937,15 +5937,15 @@ function findOutsideQuotes(expr, needle) {
5937
5937
  }
5938
5938
  return -1;
5939
5939
  }
5940
- function splitOutsideQuotes(expr, sep9) {
5941
- if (!expr.includes(sep9)) return [expr];
5940
+ function splitOutsideQuotes(expr, sep10) {
5941
+ if (!expr.includes(sep10)) return [expr];
5942
5942
  const parts = [];
5943
5943
  let currentStart = 0;
5944
5944
  let inQuote = null;
5945
5945
  let depth = 0;
5946
5946
  let bracketDepth = 0;
5947
5947
  let i = 0;
5948
- const sepLen = sep9.length;
5948
+ const sepLen = sep10.length;
5949
5949
  const lastStart = expr.length - sepLen;
5950
5950
  while (i <= lastStart) {
5951
5951
  const ch = expr[i];
@@ -5966,7 +5966,7 @@ function splitOutsideQuotes(expr, sep9) {
5966
5966
  else if (ch === ")") depth--;
5967
5967
  else if (ch === "[") bracketDepth++;
5968
5968
  else if (ch === "]") bracketDepth--;
5969
- if (depth === 0 && bracketDepth === 0 && expr.startsWith(sep9, i)) {
5969
+ if (depth === 0 && bracketDepth === 0 && expr.startsWith(sep10, i)) {
5970
5970
  parts.push(expr.slice(currentStart, i));
5971
5971
  i += sepLen;
5972
5972
  currentStart = i;
@@ -7144,8 +7144,8 @@ var init_engine = __esm({
7144
7144
  },
7145
7145
  first: (v) => Array.isArray(v) ? v[0] ?? null : null,
7146
7146
  last: (v) => Array.isArray(v) ? v[v.length - 1] ?? null : null,
7147
- join: (v, sep9) => Array.isArray(v) ? v.map(String).join(sep9 !== void 0 ? String(sep9) : ", ") : String(v),
7148
- split: (v, sep9) => String(v).split(sep9 !== void 0 ? String(sep9) : " "),
7147
+ join: (v, sep10) => Array.isArray(v) ? v.map(String).join(sep10 !== void 0 ? String(sep10) : ", ") : String(v),
7148
+ split: (v, sep10) => String(v).split(sep10 !== void 0 ? String(sep10) : " "),
7149
7149
  replace: (v, from, to) => {
7150
7150
  const s = String(v);
7151
7151
  if (from !== void 0 && typeof from === "object" && from !== null && !Array.isArray(from)) {
@@ -7288,8 +7288,14 @@ var init_engine = __esm({
7288
7288
  // and every future ``new Frond()`` inherits it automatically.
7289
7289
  // Mirrors Python's _class_globals / _class_filters / _class_tests.
7290
7290
  static classFilters = /* @__PURE__ */ new Map();
7291
- static classGlobals = /* @__PURE__ */ new Map();
7291
+ // Globals are read LIVE at render time (not copied at construction), so a
7292
+ // Frond.addGlobal() made after an engine exists still reaches it. A plain
7293
+ // object rather than a Map so render() can spread it in one step.
7294
+ static classGlobals = {};
7292
7295
  static classTests = /* @__PURE__ */ new Map();
7296
+ // Bumped on every class-level filter/test change, so an engine knows when
7297
+ // to rebuild its merged filter/test maps (see syncRegistries).
7298
+ static classRegistryVersion = 0;
7293
7299
  // ── Live-block registries (server-rendered {% live %} regions) ──
7294
7300
  // A {% live %} block registers three things when its page first renders:
7295
7301
  // liveFragments[name] -> the raw body source, re-rendered on every
@@ -7309,20 +7315,27 @@ var init_engine = __esm({
7309
7315
  static liveBroadcaster = null;
7310
7316
  /**
7311
7317
  * Register a custom filter at the class level — available to every
7312
- * future ``new Frond()`` instance. Callable as ``Frond.addFilter()``
7318
+ * instance, existing ones included: an engine merges the class filters
7319
+ * again at its next render (ADR-0107). Callable as ``Frond.addFilter()``
7313
7320
  * (static) or ``frond.addFilter()`` (instance). See instance method
7314
7321
  * below for the dual-call semantics.
7315
7322
  */
7316
7323
  static addFilter(name, fn) {
7317
7324
  _Frond.classFilters.set(name, fn);
7325
+ _Frond.classRegistryVersion++;
7318
7326
  }
7319
7327
  /**
7320
7328
  * Register a global variable available in all templates of every
7321
- * future instance. Callable as ``Frond.addGlobal()`` (static) or
7329
+ * instance, existing ones included: class globals are read at render time
7330
+ * (ADR-0106). Callable as ``Frond.addGlobal()`` (static) or
7322
7331
  * ``frond.addGlobal()`` (instance).
7323
7332
  */
7324
7333
  static addGlobal(name, value) {
7325
- _Frond.classGlobals.set(name, value);
7334
+ _Frond.classGlobals[name] = value;
7335
+ }
7336
+ /** True when a class-level global with this name is registered. */
7337
+ static hasGlobal(name) {
7338
+ return Object.prototype.hasOwnProperty.call(_Frond.classGlobals, name);
7326
7339
  }
7327
7340
  /**
7328
7341
  * Register a custom test (``{% if x is positive %}``) at the class
@@ -7331,6 +7344,7 @@ var init_engine = __esm({
7331
7344
  */
7332
7345
  static addTest(name, fn) {
7333
7346
  _Frond.classTests.set(name, fn);
7347
+ _Frond.classRegistryVersion++;
7334
7348
  }
7335
7349
  /**
7336
7350
  * Clear the class-level globals/filters/tests registries.
@@ -7340,15 +7354,25 @@ var init_engine = __esm({
7340
7354
  */
7341
7355
  static clearRegistry() {
7342
7356
  _Frond.classFilters.clear();
7343
- _Frond.classGlobals.clear();
7357
+ _Frond.classGlobals = {};
7344
7358
  _Frond.classTests.clear();
7359
+ _Frond.classRegistryVersion++;
7345
7360
  _Frond.liveFragments.clear();
7346
7361
  _Frond.liveSources.clear();
7347
7362
  _Frond.liveWsPaths.clear();
7348
7363
  }
7349
7364
  templateDir;
7350
- filters;
7365
+ /** Effective filters: built-in < class < instance (see syncRegistries). */
7366
+ filters = {};
7367
+ /** Filters / tests registered on THIS instance only (ADR-0052). */
7368
+ localFilters = {};
7369
+ localTests = {};
7370
+ /** The class-registry version `filters` / `tests` were last merged at. */
7371
+ registryVersion = -1;
7372
+ /** Globals registered on THIS instance only (ADR-0052). */
7351
7373
  globals;
7374
+ /** Built-in globals (formToken, range, dump, csp_nonce, ...). */
7375
+ builtinGlobals;
7352
7376
  tests;
7353
7377
  _sandbox;
7354
7378
  _allowedFilters;
@@ -7378,9 +7402,10 @@ var init_engine = __esm({
7378
7402
  }
7379
7403
  constructor(templateDir = "src/templates") {
7380
7404
  this.templateDir = resolve2(templateDir);
7381
- this.filters = { ...BUILTIN_FILTERS };
7382
7405
  this.globals = {};
7406
+ this.builtinGlobals = {};
7383
7407
  this.tests = {};
7408
+ this.syncRegistries();
7384
7409
  this._sandbox = false;
7385
7410
  this._allowedFilters = null;
7386
7411
  this._allowedTags = null;
@@ -7428,16 +7453,25 @@ var init_engine = __esm({
7428
7453
  return { output, next };
7429
7454
  }
7430
7455
  };
7431
- this.globals.formToken = (descriptor) => _generateFormToken(descriptor || "");
7432
- this.globals.form_token = (descriptor) => _generateFormToken(descriptor || "");
7433
- this.globals.formTokenValue = (descriptor) => _generateFormTokenValue(descriptor || "");
7434
- this.globals.form_token_value = (descriptor) => _generateFormTokenValue(descriptor || "");
7435
- this.globals.range = frondRange;
7436
- this.globals.dump = (value) => renderDump(value);
7437
- this.globals.csp_nonce = () => _cspNonceProvider();
7438
- for (const [k, v] of _Frond.classFilters) this.filters[k] = v;
7439
- for (const [k, v] of _Frond.classGlobals) this.globals[k] = v;
7440
- for (const [k, v] of _Frond.classTests) this.tests[k] = v;
7456
+ this.builtinGlobals.formToken = (descriptor) => _generateFormToken(descriptor || "");
7457
+ this.builtinGlobals.form_token = (descriptor) => _generateFormToken(descriptor || "");
7458
+ this.builtinGlobals.formTokenValue = (descriptor) => _generateFormTokenValue(descriptor || "");
7459
+ this.builtinGlobals.form_token_value = (descriptor) => _generateFormTokenValue(descriptor || "");
7460
+ this.builtinGlobals.range = frondRange;
7461
+ this.builtinGlobals.dump = (value) => renderDump(value);
7462
+ this.builtinGlobals.csp_nonce = () => _cspNonceProvider();
7463
+ }
7464
+ /**
7465
+ * Rebuild the merged filter/test maps when the class registry changed.
7466
+ * Same layering as globals -- built-ins < class < this instance. Filter
7467
+ * lookup is on the hot path, so the merge is a plain object rebuilt only
7468
+ * when the class-registry version moves, never a per-lookup chain.
7469
+ */
7470
+ syncRegistries() {
7471
+ if (this.registryVersion === _Frond.classRegistryVersion) return;
7472
+ this.filters = { ...BUILTIN_FILTERS, ...Object.fromEntries(_Frond.classFilters), ...this.localFilters };
7473
+ this.tests = { ...Object.fromEntries(_Frond.classTests), ...this.localTests };
7474
+ this.registryVersion = _Frond.classRegistryVersion;
7441
7475
  }
7442
7476
  sandbox(filters, tags, vars) {
7443
7477
  this._sandbox = true;
@@ -7458,6 +7492,7 @@ var init_engine = __esm({
7458
7492
  * for process-global registration. tina4: ADR-0052.
7459
7493
  */
7460
7494
  addFilter(name, fn) {
7495
+ this.localFilters[name] = fn;
7461
7496
  this.filters[name] = fn;
7462
7497
  }
7463
7498
  /**
@@ -7470,6 +7505,7 @@ var init_engine = __esm({
7470
7505
  * Register a custom test on this instance only.
7471
7506
  */
7472
7507
  addTest(name, fn) {
7508
+ this.localTests[name] = fn;
7473
7509
  this.tests[name] = fn;
7474
7510
  }
7475
7511
  /**
@@ -7485,8 +7521,19 @@ var init_engine = __esm({
7485
7521
  const n = parseInt(raw, 10);
7486
7522
  return isNaN(n) || n < 0 ? 0 : n;
7487
7523
  }
7524
+ /**
7525
+ * Layer the globals under the render data: built-ins < class globals (read
7526
+ * live, so registration order never matters) < this instance's own globals
7527
+ * < the data passed to render(). Every render starts here, so this is also
7528
+ * where the filter/test maps catch up with any class registration made
7529
+ * since the last render.
7530
+ */
7531
+ withGlobals(data) {
7532
+ this.syncRegistries();
7533
+ return { ...this.builtinGlobals, ..._Frond.classGlobals, ...this.globals, ...data || {} };
7534
+ }
7488
7535
  render(template, data) {
7489
- const context = { ...this.globals, ...data || {} };
7536
+ const context = this.withGlobals(data);
7490
7537
  const filePath = join5(this.templateDir, template);
7491
7538
  if (!existsSync5(filePath)) {
7492
7539
  throw new Error(`Template not found: ${filePath}`);
@@ -7509,7 +7556,7 @@ var init_engine = __esm({
7509
7556
  return this.executeWithSource(source, tokens, context);
7510
7557
  }
7511
7558
  renderString(source, data) {
7512
- const context = { ...this.globals, ...data || {} };
7559
+ const context = this.withGlobals(data);
7513
7560
  const key = createHash3("md5").update(source).digest("hex");
7514
7561
  const ttlMs = this.cacheTtlSeconds() * 1e3;
7515
7562
  const cached = this.compiledStrings.get(key);
@@ -8667,6 +8714,7 @@ var init_engine = __esm({
8667
8714
  // ../core/src/response.ts
8668
8715
  import fs2 from "node:fs";
8669
8716
  import nodePath from "node:path";
8717
+ import { fileURLToPath } from "node:url";
8670
8718
  import { once } from "node:events";
8671
8719
  async function closeSource(source) {
8672
8720
  const s = source;
@@ -8709,7 +8757,7 @@ async function getFrond() {
8709
8757
  return engine;
8710
8758
  }
8711
8759
  async function getFrameworkFrond() {
8712
- const frameworkDir = nodePath.resolve(nodePath.dirname(import.meta.url.replace("file://", "")), "..", "templates");
8760
+ const frameworkDir = nodePath.resolve(nodePath.dirname(fileURLToPath(import.meta.url)), "..", "templates");
8713
8761
  if (!_frameworkFrond && fs2.existsSync(frameworkDir)) {
8714
8762
  try {
8715
8763
  const { Frond: Frond2, setCspNonceProvider: setCspNonceProvider2 } = await Promise.resolve().then(() => (init_engine(), engine_exports));
@@ -9744,9 +9792,9 @@ var init_middleware = __esm({
9744
9792
  const duration = Date.now() - (req2.startTime ?? Date.now());
9745
9793
  const status2 = res.raw.statusCode;
9746
9794
  const method = req2.method ?? "?";
9747
- const path10 = logPath(req2);
9795
+ const path9 = logPath(req2);
9748
9796
  const color = status2 >= 400 ? "\x1B[31m" : status2 >= 300 ? "\x1B[33m" : "\x1B[32m";
9749
- console.log(` ${color}${status2}\x1B[0m ${method} ${path10} \x1B[90m${duration}ms\x1B[0m`);
9797
+ console.log(` ${color}${status2}\x1B[0m ${method} ${path9} \x1B[90m${duration}ms\x1B[0m`);
9750
9798
  return [req2, res];
9751
9799
  }
9752
9800
  };
@@ -9911,7 +9959,7 @@ function createRequest(req2) {
9911
9959
  const xfHost = trustedPeer ? req2.headers["x-forwarded-host"] : void 0;
9912
9960
  const host = (Array.isArray(xfHost) ? xfHost[0] : xfHost) ?? (req2.headers.host ?? "localhost");
9913
9961
  const query = {};
9914
- let path10;
9962
+ let path9;
9915
9963
  let queryString;
9916
9964
  let fullUrl;
9917
9965
  try {
@@ -9920,13 +9968,13 @@ function createRequest(req2) {
9920
9968
  if (isUnsafeFieldName(key)) continue;
9921
9969
  Reflect.set(query, key, value);
9922
9970
  }
9923
- path10 = url.pathname;
9971
+ path9 = url.pathname;
9924
9972
  queryString = url.search.replace(/^\?/, "");
9925
9973
  fullUrl = url.toString();
9926
9974
  } catch {
9927
9975
  const rawTarget = req2.url ?? "/";
9928
9976
  const questionIdx = rawTarget.indexOf("?");
9929
- path10 = questionIdx >= 0 ? rawTarget.slice(0, questionIdx) : rawTarget;
9977
+ path9 = questionIdx >= 0 ? rawTarget.slice(0, questionIdx) : rawTarget;
9930
9978
  queryString = questionIdx >= 0 ? rawTarget.slice(questionIdx + 1) : "";
9931
9979
  try {
9932
9980
  for (const [key, value] of new URLSearchParams(queryString)) {
@@ -9939,7 +9987,7 @@ function createRequest(req2) {
9939
9987
  }
9940
9988
  tReq.params = {};
9941
9989
  w.query = query;
9942
- w.path = path10;
9990
+ w.path = path9;
9943
9991
  w.queryString = queryString;
9944
9992
  w.url = fullUrl;
9945
9993
  tReq.body = void 0;
@@ -10054,14 +10102,14 @@ function extractBoundary(contentType) {
10054
10102
  function parseMultipart(body, boundary) {
10055
10103
  const pairs = [];
10056
10104
  const files = {};
10057
- const delimiter2 = Buffer.from(`--${boundary}`);
10105
+ const delimiter3 = Buffer.from(`--${boundary}`);
10058
10106
  const closeDelimiter = Buffer.from(`--${boundary}--`);
10059
10107
  const crlf = Buffer.from("\r\n");
10060
10108
  const doubleCrlf = Buffer.from("\r\n\r\n");
10061
10109
  let offset = 0;
10062
- const firstIdx = bufferIndexOf(body, delimiter2, offset);
10110
+ const firstIdx = bufferIndexOf(body, delimiter3, offset);
10063
10111
  if (firstIdx === -1) return { fields: {}, files };
10064
- offset = firstIdx + delimiter2.length;
10112
+ offset = firstIdx + delimiter3.length;
10065
10113
  if (body[offset] === 13 && body[offset + 1] === 10) {
10066
10114
  offset += 2;
10067
10115
  }
@@ -10070,7 +10118,7 @@ function parseMultipart(body, boundary) {
10070
10118
  if (headersEnd === -1) break;
10071
10119
  const headersStr = body.subarray(offset, headersEnd).toString("utf-8");
10072
10120
  offset = headersEnd + doubleCrlf.length;
10073
- const nextDelimIdx = bufferIndexOf(body, delimiter2, offset);
10121
+ const nextDelimIdx = bufferIndexOf(body, delimiter3, offset);
10074
10122
  if (nextDelimIdx === -1) break;
10075
10123
  const contentEnd = nextDelimIdx - crlf.length;
10076
10124
  const content = body.subarray(offset, contentEnd);
@@ -10094,7 +10142,7 @@ function parseMultipart(body, boundary) {
10094
10142
  } else if (disposition.name) {
10095
10143
  pairs.push([disposition.name, content.toString("utf-8")]);
10096
10144
  }
10097
- offset = nextDelimIdx + delimiter2.length;
10145
+ offset = nextDelimIdx + delimiter3.length;
10098
10146
  if (body[offset] === 45 && body[offset + 1] === 45) {
10099
10147
  break;
10100
10148
  }
@@ -10654,6 +10702,7 @@ __export(routeDiscovery_exports, {
10654
10702
  });
10655
10703
  import { readdirSync as readdirSync2, statSync as statSync5, mkdirSync as mkdirSync4, writeFileSync as writeFileSync3, existsSync as existsSync6 } from "node:fs";
10656
10704
  import { join as join7, relative, basename as basename2, extname } from "node:path";
10705
+ import { pathToFileURL } from "node:url";
10657
10706
  function boolExport(value) {
10658
10707
  return typeof value === "boolean" ? value : void 0;
10659
10708
  }
@@ -10675,7 +10724,7 @@ async function discoverRoutes(routesDir) {
10675
10724
  const relativePath2 = relative(routesDir, filePath);
10676
10725
  const pattern = filePathToPattern(relativePath2);
10677
10726
  try {
10678
- const moduleUrl = `file://${filePath}?t=${currentMtime}`;
10727
+ const moduleUrl = `${pathToFileURL(filePath).href}?t=${currentMtime}`;
10679
10728
  const mod = await import(moduleUrl);
10680
10729
  const handler = mod.default ?? mod.handler;
10681
10730
  if (typeof handler !== "function") {
@@ -10716,7 +10765,7 @@ function recordBrokenImport(filePath, error2) {
10716
10765
  try {
10717
10766
  const brokenDir = join7(process.cwd(), "data", ".broken");
10718
10767
  if (!existsSync6(brokenDir)) mkdirSync4(brokenDir, { recursive: true });
10719
- const slug = filePath.replace(/[/\\]/g, "_");
10768
+ const slug = filePath.replace(/[/\\:]/g, "_");
10720
10769
  const payload = JSON.stringify({
10721
10770
  type: "auto_discover_failure",
10722
10771
  file: filePath,
@@ -10856,27 +10905,33 @@ function sleepSync(ms) {
10856
10905
  if (ms <= 0) return;
10857
10906
  Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
10858
10907
  }
10859
- function takeOverPort(port, dev, noTakeover, baseDir, grace = 500) {
10908
+ function probeBind(host, port, timeout = 5e3) {
10909
+ try {
10910
+ execFileSync(process.execPath, ["-e", BIND_PROBE, host, String(port)], { stdio: "ignore", timeout });
10911
+ return "free";
10912
+ } catch (err) {
10913
+ return err.status === PROBE_HELD ? "held" : "unknown";
10914
+ }
10915
+ }
10916
+ function refusal(port, dev, noTakeover, host) {
10917
+ if (dev && !noTakeover) return null;
10918
+ if (host !== void 0 && probeBind(host, port) !== "held") {
10919
+ return { status: TAKEOVER_NOTHING, port, killed: [], message: "" };
10920
+ }
10921
+ if (noTakeover) {
10922
+ return { status: TAKEOVER_REFUSED_OPTOUT, port, killed: [], message: `Port ${port} is in use and takeover is disabled (TINA4_NO_TAKEOVER/--no-kill) -- free it or choose another port.` };
10923
+ }
10924
+ return { status: TAKEOVER_REFUSED_PROD, port, killed: [], message: `Port ${port} is in use; takeover is disabled outside dev mode -- free it or choose another port.` };
10925
+ }
10926
+ function takeOverPort(port, dev, noTakeover, baseDir, grace = 500, host) {
10860
10927
  const make = (status2, killed2 = [], message = "") => ({
10861
10928
  status: status2,
10862
10929
  port,
10863
10930
  killed: killed2,
10864
10931
  message
10865
10932
  });
10866
- if (noTakeover) {
10867
- return make(
10868
- TAKEOVER_REFUSED_OPTOUT,
10869
- [],
10870
- `Port ${port} is in use and takeover is disabled (TINA4_NO_TAKEOVER/--no-kill) -- free it or choose another port.`
10871
- );
10872
- }
10873
- if (!dev) {
10874
- return make(
10875
- TAKEOVER_REFUSED_PROD,
10876
- [],
10877
- `Port ${port} is in use; takeover is disabled outside dev mode -- free it or choose another port.`
10878
- );
10879
- }
10933
+ const early = refusal(port, dev, noTakeover, host);
10934
+ if (early !== null) return early;
10880
10935
  if (inContainer()) return make(TAKEOVER_SKIPPED_CONTAINER);
10881
10936
  const tokens = portHolders(port);
10882
10937
  if (tokens.length === 0) return make(TAKEOVER_NOTHING);
@@ -10908,7 +10963,7 @@ function takeOverPort(port, dev, noTakeover, baseDir, grace = 500) {
10908
10963
  `Reclaimed port ${port} from Tina4 dev server (PID: ${killed.join(", ")}).`
10909
10964
  );
10910
10965
  }
10911
- var TAKEOVER_NOTHING, TAKEOVER_KILLED, TAKEOVER_REFUSED_FOREIGN, TAKEOVER_REFUSED_OPTOUT, TAKEOVER_REFUSED_PROD, TAKEOVER_SKIPPED_CONTAINER, TAKEOVER_REFUSALS;
10966
+ var TAKEOVER_NOTHING, TAKEOVER_KILLED, TAKEOVER_REFUSED_FOREIGN, TAKEOVER_REFUSED_OPTOUT, TAKEOVER_REFUSED_PROD, TAKEOVER_SKIPPED_CONTAINER, TAKEOVER_REFUSALS, PROBE_HELD, PROBE_OTHER, BIND_PROBE;
10912
10967
  var init_portTakeover = __esm({
10913
10968
  "../core/src/portTakeover.ts"() {
10914
10969
  "use strict";
@@ -10923,6 +10978,9 @@ var init_portTakeover = __esm({
10923
10978
  TAKEOVER_REFUSED_OPTOUT,
10924
10979
  TAKEOVER_REFUSED_PROD
10925
10980
  ];
10981
+ PROBE_HELD = 3;
10982
+ PROBE_OTHER = 4;
10983
+ BIND_PROBE = `const s = require("node:net").createServer();s.on("error", (e) => process.exit(e && e.code === "EADDRINUSE" ? ${PROBE_HELD} : ${PROBE_OTHER}));s.listen({ host: process.argv[1], port: Number(process.argv[2]) }, () => s.close(() => process.exit(0)));`;
10926
10984
  }
10927
10985
  });
10928
10986
 
@@ -12100,6 +12158,21 @@ var init_databaseHandler = __esm({
12100
12158
  }
12101
12159
  return this.sqliteHandle;
12102
12160
  }
12161
+ /**
12162
+ * Release the SQLite connection this handler opened, so its file (and the
12163
+ * WAL's -wal / -shm side files) is no longer held open: on Windows an open
12164
+ * file cannot be deleted or replaced. Idempotent, and the next read or write
12165
+ * reopens the connection. A server engine needs nothing here - each call goes
12166
+ * through the sync bridge, which holds no connection between calls.
12167
+ */
12168
+ close() {
12169
+ if (this.sqliteHandle === null) return;
12170
+ try {
12171
+ this.sqliteHandle.close();
12172
+ } finally {
12173
+ this.sqliteHandle = null;
12174
+ }
12175
+ }
12103
12176
  get engine() {
12104
12177
  return this.target === null ? "sqlite" : this.target.engine;
12105
12178
  }
@@ -13300,8 +13373,8 @@ function tryServeStatic(staticDir, req2, res) {
13300
13373
  }
13301
13374
  return false;
13302
13375
  }
13303
- function hasHiddenSegment(path10, separator = "/") {
13304
- return path10.split(separator).some((segment) => segment.length > 0 && segment.startsWith("."));
13376
+ function hasHiddenSegment(path9, separator = "/") {
13377
+ return path9.split(separator).some((segment) => segment.length > 0 && segment.startsWith("."));
13305
13378
  }
13306
13379
  function conditionalHeader(req2, name) {
13307
13380
  const headers = req2.headers;
@@ -13625,10 +13698,10 @@ function createHealthRoute(version = "3.0.0") {
13625
13698
  function createHealthRoutes(version = "3.0.0") {
13626
13699
  startTime = Date.now();
13627
13700
  const routes = [];
13628
- const path10 = healthPath();
13701
+ const path9 = healthPath();
13629
13702
  routes.push({
13630
13703
  method: "GET",
13631
- pattern: path10,
13704
+ pattern: path9,
13632
13705
  handler: buildHandler(version),
13633
13706
  meta: {
13634
13707
  summary: "Health check",
@@ -13636,7 +13709,7 @@ function createHealthRoutes(version = "3.0.0") {
13636
13709
  tags: ["System"]
13637
13710
  }
13638
13711
  });
13639
- if (path10 !== "/health") {
13712
+ if (path9 !== "/health") {
13640
13713
  routes.push({
13641
13714
  method: "GET",
13642
13715
  pattern: "/health",
@@ -13714,9 +13787,72 @@ var init_rateLimiter = __esm({
13714
13787
  }
13715
13788
  });
13716
13789
 
13790
+ // ../core/src/batchSpawn.ts
13791
+ import { spawnSync } from "node:child_process";
13792
+ import { existsSync as existsSync9, statSync as statSync8 } from "node:fs";
13793
+ import { delimiter, extname as extname3, join as join11 } from "node:path";
13794
+ function isBatchFile(file, platform = process.platform) {
13795
+ return platform === "win32" && /\.(cmd|bat)$/i.test(file);
13796
+ }
13797
+ function escapeBatchArgument(arg) {
13798
+ let quoted = String(arg).replace(/(\\*)"/g, '$1$1\\"').replace(/(\\*)$/, "$1$1");
13799
+ quoted = `"${quoted}"`;
13800
+ return quoted.replace(CMD_META, "^$1").replace(CMD_META, "^$1");
13801
+ }
13802
+ function escapeBatchCommand(file) {
13803
+ return file.replace(CMD_META, "^$1");
13804
+ }
13805
+ function findExecutable(name, platform = process.platform) {
13806
+ if (platform !== "win32" || /[\\/]/.test(name) || extname3(name) !== "") return name;
13807
+ const exts = (process.env.PATHEXT || ".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean);
13808
+ const dirs = (process.env.PATH || "").split(delimiter).filter(Boolean);
13809
+ const candidates = dirs.flatMap((dir) => exts.map((ext) => join11(dir, name + ext.toLowerCase())));
13810
+ return candidates.find(isRegularFile) ?? name;
13811
+ }
13812
+ function isRegularFile(path9) {
13813
+ try {
13814
+ return existsSync9(path9) && statSync8(path9).isFile();
13815
+ } catch {
13816
+ return false;
13817
+ }
13818
+ }
13819
+ function spawnSyncAllowingBatch(file, args, options = {}) {
13820
+ if (!isBatchFile(file)) return spawnSync(file, args, options);
13821
+ const line = [escapeBatchCommand(file), ...args.map(escapeBatchArgument)].join(" ");
13822
+ const shell = process.env.comspec || "cmd.exe";
13823
+ return spawnSync(shell, ["/d", "/s", "/c", `"${line}"`], {
13824
+ ...options,
13825
+ windowsVerbatimArguments: true
13826
+ });
13827
+ }
13828
+ function execFileSyncAllowingBatch(name, args, options = {}) {
13829
+ const result = spawnSyncAllowingBatch(findExecutable(name), args, { encoding: "utf-8", ...options });
13830
+ if (result.error) throw result.error;
13831
+ const stdout = String(result.stdout ?? "");
13832
+ const stderr = String(result.stderr ?? "");
13833
+ if (result.status !== 0) {
13834
+ const err = new Error(
13835
+ `Command failed: ${name} ${args.join(" ")} (exit ${result.status ?? result.signal})
13836
+ ${stderr}`.trim()
13837
+ );
13838
+ err.status = result.status;
13839
+ err.stdout = stdout;
13840
+ err.stderr = stderr;
13841
+ throw err;
13842
+ }
13843
+ return stdout;
13844
+ }
13845
+ var CMD_META;
13846
+ var init_batchSpawn = __esm({
13847
+ "../core/src/batchSpawn.ts"() {
13848
+ "use strict";
13849
+ CMD_META = /([()\][%!^"`<>&|;, *?])/g;
13850
+ }
13851
+ });
13852
+
13717
13853
  // ../core/src/devMailbox.ts
13718
- import { mkdirSync as mkdirSync7, readdirSync as readdirSync4, readFileSync as readFileSync9, writeFileSync as writeFileSync6, unlinkSync as unlinkSync6, existsSync as existsSync9 } from "node:fs";
13719
- import { join as join11 } from "node:path";
13854
+ import { mkdirSync as mkdirSync7, readdirSync as readdirSync4, readFileSync as readFileSync9, writeFileSync as writeFileSync6, unlinkSync as unlinkSync6, existsSync as existsSync10 } from "node:fs";
13855
+ import { join as join12 } from "node:path";
13720
13856
  import { randomUUID } from "node:crypto";
13721
13857
  var DevMailbox;
13722
13858
  var init_devMailbox = __esm({
@@ -13731,7 +13867,7 @@ var init_devMailbox = __esm({
13731
13867
  * Ensure a folder directory exists.
13732
13868
  */
13733
13869
  ensureFolder(folder) {
13734
- const dir = join11(this.mailboxDir, folder);
13870
+ const dir = join12(this.mailboxDir, folder);
13735
13871
  mkdirSync7(dir, { recursive: true });
13736
13872
  return dir;
13737
13873
  }
@@ -13770,10 +13906,10 @@ var init_devMailbox = __esm({
13770
13906
  read: false
13771
13907
  };
13772
13908
  const outboxDir = this.ensureFolder("outbox");
13773
- writeFileSync6(join11(outboxDir, `${id}.json`), JSON.stringify(message, null, 2));
13909
+ writeFileSync6(join12(outboxDir, `${id}.json`), JSON.stringify(message, null, 2));
13774
13910
  const inboxDir = this.ensureFolder("inbox");
13775
13911
  const inboxMessage = { ...message, type: "inbox" };
13776
- writeFileSync6(join11(inboxDir, `${id}.json`), JSON.stringify(inboxMessage, null, 2));
13912
+ writeFileSync6(join12(inboxDir, `${id}.json`), JSON.stringify(inboxMessage, null, 2));
13777
13913
  return { success: true, message: "Email captured to dev mailbox", id };
13778
13914
  }
13779
13915
  /**
@@ -13791,7 +13927,7 @@ var init_devMailbox = __esm({
13791
13927
  const sliced = files.slice(offset, offset + limit);
13792
13928
  for (const file of sliced) {
13793
13929
  try {
13794
- const msg = JSON.parse(readFileSync9(join11(dir, file), "utf-8"));
13930
+ const msg = JSON.parse(readFileSync9(join12(dir, file), "utf-8"));
13795
13931
  results.push(msg);
13796
13932
  } catch {
13797
13933
  }
@@ -13804,8 +13940,8 @@ var init_devMailbox = __esm({
13804
13940
  read(msgId) {
13805
13941
  const folders = ["inbox", "outbox"];
13806
13942
  for (const folder of folders) {
13807
- const filePath = join11(this.mailboxDir, folder, `${msgId}.json`);
13808
- if (existsSync9(filePath)) {
13943
+ const filePath = join12(this.mailboxDir, folder, `${msgId}.json`);
13944
+ if (existsSync10(filePath)) {
13809
13945
  try {
13810
13946
  const msg = JSON.parse(readFileSync9(filePath, "utf-8"));
13811
13947
  msg.read = true;
@@ -13828,7 +13964,7 @@ var init_devMailbox = __esm({
13828
13964
  const files = readdirSync4(dir).filter((f) => f.endsWith(".json"));
13829
13965
  for (const file of files) {
13830
13966
  try {
13831
- const msg = JSON.parse(readFileSync9(join11(dir, file), "utf-8"));
13967
+ const msg = JSON.parse(readFileSync9(join12(dir, file), "utf-8"));
13832
13968
  if (!msg.read) count++;
13833
13969
  } catch {
13834
13970
  }
@@ -13844,8 +13980,8 @@ var init_devMailbox = __esm({
13844
13980
  let deleted = false;
13845
13981
  const folders = ["inbox", "outbox"];
13846
13982
  for (const folder of folders) {
13847
- const filePath = join11(this.mailboxDir, folder, `${msgId}.json`);
13848
- if (existsSync9(filePath)) {
13983
+ const filePath = join12(this.mailboxDir, folder, `${msgId}.json`);
13984
+ if (existsSync10(filePath)) {
13849
13985
  try {
13850
13986
  unlinkSync6(filePath);
13851
13987
  deleted = true;
@@ -13861,12 +13997,12 @@ var init_devMailbox = __esm({
13861
13997
  clear(folder) {
13862
13998
  const folders = folder ? [folder] : ["inbox", "outbox"];
13863
13999
  for (const f of folders) {
13864
- const dir = join11(this.mailboxDir, f);
14000
+ const dir = join12(this.mailboxDir, f);
13865
14001
  try {
13866
- if (existsSync9(dir)) {
14002
+ if (existsSync10(dir)) {
13867
14003
  const files = readdirSync4(dir).filter((file) => file.endsWith(".json"));
13868
14004
  for (const file of files) {
13869
- unlinkSync6(join11(dir, file));
14005
+ unlinkSync6(join12(dir, file));
13870
14006
  }
13871
14007
  }
13872
14008
  } catch {
@@ -13919,7 +14055,7 @@ Generated by DevMailbox.seed() for development purposes.`,
13919
14055
  // first two are unread
13920
14056
  };
13921
14057
  const dir = this.ensureFolder("inbox");
13922
- writeFileSync6(join11(dir, `${id}.json`), JSON.stringify(message, null, 2));
14058
+ writeFileSync6(join12(dir, `${id}.json`), JSON.stringify(message, null, 2));
13923
14059
  }
13924
14060
  }
13925
14061
  /**
@@ -13927,9 +14063,9 @@ Generated by DevMailbox.seed() for development purposes.`,
13927
14063
  */
13928
14064
  count(folder) {
13929
14065
  const countDir = (f) => {
13930
- const dir = join11(this.mailboxDir, f);
14066
+ const dir = join12(this.mailboxDir, f);
13931
14067
  try {
13932
- if (existsSync9(dir)) {
14068
+ if (existsSync10(dir)) {
13933
14069
  return readdirSync4(dir).filter((file) => file.endsWith(".json")).length;
13934
14070
  }
13935
14071
  } catch {
@@ -13970,8 +14106,8 @@ var init_upstreamResponse = __esm({
13970
14106
  // ../core/src/metrics.ts
13971
14107
  import * as fs3 from "node:fs";
13972
14108
  import * as path2 from "node:path";
13973
- import { spawnSync } from "node:child_process";
13974
- import { fileURLToPath } from "node:url";
14109
+ import { spawnSync as spawnSync2 } from "node:child_process";
14110
+ import { fileURLToPath as fileURLToPath2 } from "node:url";
13975
14111
  function containsTypeScript(directory) {
13976
14112
  if (!fs3.existsSync(directory) || !fs3.statSync(directory).isDirectory()) return false;
13977
14113
  for (const entry of fs3.readdirSync(directory, { withFileTypes: true })) {
@@ -13982,7 +14118,7 @@ function containsTypeScript(directory) {
13982
14118
  return false;
13983
14119
  }
13984
14120
  function resolveTarget(root = "src") {
13985
- const resolved = containsTypeScript(root) ? path2.resolve(root) : path2.dirname(fileURLToPath(import.meta.url));
14121
+ const resolved = containsTypeScript(root) ? path2.resolve(root) : path2.dirname(fileURLToPath2(import.meta.url));
13986
14122
  const mode = containsTypeScript(root) ? "project" : "framework";
13987
14123
  lastScanRoot = resolved;
13988
14124
  return [resolved, mode];
@@ -14010,7 +14146,7 @@ function enginePath() {
14010
14146
  function runEngine(target) {
14011
14147
  const binary = enginePath();
14012
14148
  if (!binary) throw new MetricsEngineError(`tina4 not found on PATH - ${INSTALL_HINT}`);
14013
- const processResult = spawnSync(binary, ["metrics", "--path", target, "--json", "--no-history"], {
14149
+ const processResult = spawnSync2(binary, ["metrics", "--path", target, "--json", "--no-history"], {
14014
14150
  encoding: "utf8",
14015
14151
  timeout: 6e4,
14016
14152
  maxBuffer: 64 * 1024 * 1024
@@ -14103,9 +14239,9 @@ var init_metrics = __esm({
14103
14239
  });
14104
14240
 
14105
14241
  // ../core/src/feedback.ts
14106
- import { readFileSync as readFileSync10, existsSync as existsSync11 } from "node:fs";
14107
- import { dirname as dirname5, join as join13, resolve as resolve5 } from "node:path";
14108
- import { fileURLToPath as fileURLToPath2 } from "node:url";
14242
+ import { readFileSync as readFileSync10, existsSync as existsSync12 } from "node:fs";
14243
+ import { dirname as dirname5, join as join14, resolve as resolve5 } from "node:path";
14244
+ import { fileURLToPath as fileURLToPath3 } from "node:url";
14109
14245
  function feedbackEnabled() {
14110
14246
  const raw = (process.env.TINA4_ENABLE_FEEDBACK ?? "").trim().toLowerCase();
14111
14247
  return raw === "1" || raw === "true" || raw === "yes" || raw === "on";
@@ -14154,8 +14290,8 @@ function feedbackRateLimitOk(user) {
14154
14290
  }
14155
14291
  function injectFeedbackWidget(request, html) {
14156
14292
  if (!html) return html;
14157
- const path10 = (request.path ?? "") || "";
14158
- if (path10.startsWith("/__dev") || path10.startsWith("/__feedback")) return html;
14293
+ const path9 = (request.path ?? "") || "";
14294
+ if (path9.startsWith("/__dev") || path9.startsWith("/__feedback")) return html;
14159
14295
  if (html.includes("data-tina4-feedback")) return html;
14160
14296
  const [allowed] = feedbackIsWhitelisted(request);
14161
14297
  if (!allowed) return html;
@@ -14231,11 +14367,11 @@ var init_feedback = __esm({
14231
14367
  clearTimeout(timer);
14232
14368
  await relayUpstreamResponse(res, upstream);
14233
14369
  };
14234
- __feedbackDirname = dirname5(fileURLToPath2(import.meta.url));
14370
+ __feedbackDirname = dirname5(fileURLToPath3(import.meta.url));
14235
14371
  WIDGET_BUNDLE_PATH = resolve5(__feedbackDirname, "__feedback", "widget.js");
14236
14372
  handleFeedbackWidgetJs = (_req, res) => {
14237
14373
  let body;
14238
- if (existsSync11(WIDGET_BUNDLE_PATH)) {
14374
+ if (existsSync12(WIDGET_BUNDLE_PATH)) {
14239
14375
  body = readFileSync10(WIDGET_BUNDLE_PATH);
14240
14376
  } else {
14241
14377
  body = "console.warn('tina4-feedback-widget bundle not built yet');";
@@ -14251,14 +14387,14 @@ var init_feedback = __esm({
14251
14387
  });
14252
14388
 
14253
14389
  // ../core/src/version.ts
14254
- import { existsSync as existsSync12, readFileSync as readFileSync11 } from "node:fs";
14255
- import { dirname as dirname6, join as join14 } from "node:path";
14256
- import { fileURLToPath as fileURLToPath3 } from "node:url";
14390
+ import { existsSync as existsSync13, readFileSync as readFileSync11 } from "node:fs";
14391
+ import { dirname as dirname6, join as join15 } from "node:path";
14392
+ import { fileURLToPath as fileURLToPath4 } from "node:url";
14257
14393
  function resolveFrameworkVersion() {
14258
- let dir = dirname6(fileURLToPath3(import.meta.url));
14394
+ let dir = dirname6(fileURLToPath4(import.meta.url));
14259
14395
  for (let i = 0; i < 6; i++) {
14260
- const pkgPath = join14(dir, "package.json");
14261
- if (existsSync12(pkgPath)) {
14396
+ const pkgPath = join15(dir, "package.json");
14397
+ if (existsSync13(pkgPath)) {
14262
14398
  try {
14263
14399
  const pkg = JSON.parse(readFileSync11(pkgPath, "utf-8"));
14264
14400
  if (typeof pkg.version === "string" && pkg.version) return pkg.version;
@@ -14340,27 +14476,27 @@ __export(generate_exports, {
14340
14476
  toSnake: () => toSnake,
14341
14477
  toTableName: () => toTableName
14342
14478
  });
14343
- import { existsSync as existsSync13, mkdirSync as mkdirSync8, writeFileSync as writeFileSync7, readdirSync as readdirSync6, copyFileSync } from "node:fs";
14344
- import { join as join15, relative as relative2, resolve as resolve6, sep as sep3, dirname as dirname7 } from "node:path";
14345
- import { fileURLToPath as fileURLToPath4 } from "node:url";
14479
+ import { existsSync as existsSync14, mkdirSync as mkdirSync8, writeFileSync as writeFileSync7, readdirSync as readdirSync6, copyFileSync } from "node:fs";
14480
+ import { join as join16, relative as relative2, resolve as resolve6, sep as sep3, dirname as dirname7 } from "node:path";
14481
+ import { fileURLToPath as fileURLToPath5 } from "node:url";
14346
14482
  function ensureDir(dir) {
14347
14483
  if (__resolution.dryRun) return;
14348
- if (!existsSync13(dir)) {
14484
+ if (!existsSync14(dir)) {
14349
14485
  mkdirSync8(dir, { recursive: true });
14350
14486
  }
14351
14487
  }
14352
- function writeFileSafe(path10, content) {
14353
- captureEditHints(path10, content);
14488
+ function writeFileSafe(path9, content) {
14489
+ captureEditHints(path9, content);
14354
14490
  if (__resolution.dryRun) {
14355
14491
  return;
14356
14492
  }
14357
- if (existsSync13(path10)) {
14358
- if (!__resolution.jsonMode) console.log(` File already exists: ${path10}`);
14493
+ if (existsSync14(path9)) {
14494
+ if (!__resolution.jsonMode) console.log(` File already exists: ${path9}`);
14359
14495
  return;
14360
14496
  }
14361
- writeFileSync7(path10, content, "utf-8");
14362
- __resolution.actionsTaken.push(`wrote ${path10}`);
14363
- if (!__resolution.jsonMode) console.log(` Created ${path10}`);
14497
+ writeFileSync7(path9, content, "utf-8");
14498
+ __resolution.actionsTaken.push(`wrote ${path9}`);
14499
+ if (!__resolution.jsonMode) console.log(` Created ${path9}`);
14364
14500
  }
14365
14501
  function toSnake(name) {
14366
14502
  return name.replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2").replace(/([a-z0-9])([A-Z])/g, "$1_$2").toLowerCase();
@@ -14452,9 +14588,9 @@ function pushRoute(routePattern) {
14452
14588
  if (!__resolution.body.routes) __resolution.body.routes = [];
14453
14589
  __resolution.body.routes.push(routePattern);
14454
14590
  }
14455
- function pushTestPath(path10) {
14591
+ function pushTestPath(path9) {
14456
14592
  if (!__resolution.body.test_paths) __resolution.body.test_paths = [];
14457
- __resolution.body.test_paths.push(path10);
14593
+ __resolution.body.test_paths.push(path9);
14458
14594
  }
14459
14595
  function pushEditHint(hint) {
14460
14596
  if (!__resolution.body.edit_hints) __resolution.body.edit_hints = [];
@@ -14685,7 +14821,7 @@ function generateModel(name, flags, emitTest = true) {
14685
14821
  const table2 = resolveTable(name, flags, { announce: true });
14686
14822
  const dir = resolve6("src/models");
14687
14823
  ensureDir(dir);
14688
- const path10 = join15(dir, `${name}.ts`);
14824
+ const path9 = join16(dir, `${name}.ts`);
14689
14825
  setResolutionField("class_name", name);
14690
14826
  setResolutionField("table_name", table2);
14691
14827
  setResolutionField("file_path", `src/models/${name}.ts`);
@@ -14708,7 +14844,7 @@ ${fieldLines.join("\n")}
14708
14844
  };
14709
14845
  }
14710
14846
  `;
14711
- writeFileSafe(path10, content);
14847
+ writeFileSafe(path9, content);
14712
14848
  if (!flags["no-migration"]) {
14713
14849
  generateMigration(`create_${table2}`, flags, fields, table2, false);
14714
14850
  }
@@ -14725,7 +14861,7 @@ function generateRoute(name, flags, emitTest = true) {
14725
14861
  const model = flags.model;
14726
14862
  const isPublic = Boolean(flags.public);
14727
14863
  const base = resolve6("src/routes/api", routePath);
14728
- const idDir = join15(base, "[id]");
14864
+ const idDir = join16(base, "[id]");
14729
14865
  ensureDir(base);
14730
14866
  ensureDir(idDir);
14731
14867
  pushRoute(`/api/${routePath}`);
@@ -14741,7 +14877,7 @@ function generateRoute(name, flags, emitTest = true) {
14741
14877
  const writeDoc = isPublic ? "Public (--public): no token required." : "Secure by default: requires a Bearer token (use --public to open).";
14742
14878
  if (model) {
14743
14879
  writeFileSafe(
14744
- join15(base, "get.ts"),
14880
+ join16(base, "get.ts"),
14745
14881
  `import type { Tina4Request, Tina4Response } from "tina4-nodejs";
14746
14882
  ${modelImportBase}
14747
14883
  export const meta = { summary: "List all ${routePath}", tags: ["${routePath}"] };
@@ -14758,7 +14894,7 @@ export default async function (req: Tina4Request, res: Tina4Response) {
14758
14894
  );
14759
14895
  } else {
14760
14896
  writeFileSafe(
14761
- join15(base, "get.ts"),
14897
+ join16(base, "get.ts"),
14762
14898
  `import type { Tina4Request, Tina4Response } from "tina4-nodejs";
14763
14899
 
14764
14900
  export const meta = { summary: "List all ${routePath}", tags: ["${routePath}"] };
@@ -14777,7 +14913,7 @@ ${aiFill(`list_${routePath}`, {
14777
14913
  }
14778
14914
  if (model) {
14779
14915
  writeFileSafe(
14780
- join15(base, "post.ts"),
14916
+ join16(base, "post.ts"),
14781
14917
  `import type { Tina4Request, Tina4Response } from "tina4-nodejs";
14782
14918
  ${modelImportBase}${secureOptOut(isPublic)}export const meta = { summary: "Create a new ${singular}", tags: ["${routePath}"] };
14783
14919
 
@@ -14800,7 +14936,7 @@ ${extend(
14800
14936
  );
14801
14937
  } else {
14802
14938
  writeFileSafe(
14803
- join15(base, "post.ts"),
14939
+ join16(base, "post.ts"),
14804
14940
  `import type { Tina4Request, Tina4Response } from "tina4-nodejs";
14805
14941
 
14806
14942
  ${secureOptOut(isPublic)}export const meta = { summary: "Create a new ${singular}", tags: ["${routePath}"] };
@@ -14821,7 +14957,7 @@ ${aiFill(`create_${singular}`, {
14821
14957
  }
14822
14958
  if (model) {
14823
14959
  writeFileSafe(
14824
- join15(idDir, "get.ts"),
14960
+ join16(idDir, "get.ts"),
14825
14961
  `import type { Tina4Request, Tina4Response } from "tina4-nodejs";
14826
14962
  ${modelImportId}
14827
14963
  export const meta = { summary: "Get a ${singular} by ID", tags: ["${routePath}"] };
@@ -14839,7 +14975,7 @@ export default async function (req: Tina4Request, res: Tina4Response) {
14839
14975
  );
14840
14976
  } else {
14841
14977
  writeFileSafe(
14842
- join15(idDir, "get.ts"),
14978
+ join16(idDir, "get.ts"),
14843
14979
  `import type { Tina4Request, Tina4Response } from "tina4-nodejs";
14844
14980
 
14845
14981
  export const meta = { summary: "Get a ${singular} by ID", tags: ["${routePath}"] };
@@ -14858,7 +14994,7 @@ ${aiFill(`get_${singular}`, {
14858
14994
  }
14859
14995
  if (model) {
14860
14996
  writeFileSafe(
14861
- join15(idDir, "put.ts"),
14997
+ join16(idDir, "put.ts"),
14862
14998
  `import type { Tina4Request, Tina4Response } from "tina4-nodejs";
14863
14999
  ${modelImportId}${secureOptOut(isPublic)}export const meta = { summary: "Update a ${singular} by ID", tags: ["${routePath}"] };
14864
15000
 
@@ -14887,7 +15023,7 @@ ${extend(
14887
15023
  );
14888
15024
  } else {
14889
15025
  writeFileSafe(
14890
- join15(idDir, "put.ts"),
15026
+ join16(idDir, "put.ts"),
14891
15027
  `import type { Tina4Request, Tina4Response } from "tina4-nodejs";
14892
15028
 
14893
15029
  ${secureOptOut(isPublic)}export const meta = { summary: "Update a ${singular} by ID", tags: ["${routePath}"] };
@@ -14908,7 +15044,7 @@ ${aiFill(`update_${singular}`, {
14908
15044
  }
14909
15045
  if (model) {
14910
15046
  writeFileSafe(
14911
- join15(idDir, "delete.ts"),
15047
+ join16(idDir, "delete.ts"),
14912
15048
  `import type { Tina4Request, Tina4Response } from "tina4-nodejs";
14913
15049
  ${modelImportId}${secureOptOut(isPublic)}export const meta = { summary: "Delete a ${singular} by ID", tags: ["${routePath}"] };
14914
15050
 
@@ -14927,7 +15063,7 @@ export default async function (req: Tina4Request, res: Tina4Response) {
14927
15063
  );
14928
15064
  } else {
14929
15065
  writeFileSafe(
14930
- join15(idDir, "delete.ts"),
15066
+ join16(idDir, "delete.ts"),
14931
15067
  `import type { Tina4Request, Tina4Response } from "tina4-nodejs";
14932
15068
 
14933
15069
  ${secureOptOut(isPublic)}export const meta = { summary: "Delete a ${singular} by ID", tags: ["${routePath}"] };
@@ -15004,10 +15140,10 @@ export default async function (req: Tina4Request, res: Tina4Response) {
15004
15140
  return res.html(await Crud.toCrud(req, { model: ${model}, title: "${model} Admin"${publicOpt} }));
15005
15141
  }
15006
15142
  `;
15007
- writeFileSafe(join15(dir, "get.ts"), content);
15143
+ writeFileSafe(join16(dir, "get.ts"), content);
15008
15144
  }
15009
15145
  function frameworkCrudTemplatesDir() {
15010
- const here = dirname7(fileURLToPath4(import.meta.url));
15146
+ const here = dirname7(fileURLToPath5(import.meta.url));
15011
15147
  const candidates = [
15012
15148
  resolve6(here, "../../../core/templates/crud"),
15013
15149
  // monorepo: packages/cli/src/commands -> packages/core/templates/crud
@@ -15016,7 +15152,7 @@ function frameworkCrudTemplatesDir() {
15016
15152
  resolve6(here, "../templates/crud")
15017
15153
  // flattened publish fallback
15018
15154
  ];
15019
- return candidates.find((c) => existsSync13(c)) ?? null;
15155
+ return candidates.find((c) => existsSync14(c)) ?? null;
15020
15156
  }
15021
15157
  function copyCrudTemplates() {
15022
15158
  const sourceDir = frameworkCrudTemplatesDir();
@@ -15027,13 +15163,13 @@ function copyCrudTemplates() {
15027
15163
  const targetDir = resolve6("src/templates/crud");
15028
15164
  ensureDir(targetDir);
15029
15165
  for (const file of readdirSync6(sourceDir).filter((f) => f.endsWith(".twig")).sort()) {
15030
- const dest = join15(targetDir, file);
15031
- if (existsSync13(dest)) {
15166
+ const dest = join16(targetDir, file);
15167
+ if (existsSync14(dest)) {
15032
15168
  if (!__resolution.jsonMode) console.log(` File already exists: ${dest}`);
15033
15169
  continue;
15034
15170
  }
15035
15171
  if (__resolution.dryRun) continue;
15036
- copyFileSync(join15(sourceDir, file), dest);
15172
+ copyFileSync(join16(sourceDir, file), dest);
15037
15173
  __resolution.actionsTaken.push(`wrote ${dest}`);
15038
15174
  if (!__resolution.jsonMode) console.log(` Created ${dest}`);
15039
15175
  }
@@ -15091,7 +15227,7 @@ ${writeCase}
15091
15227
  console.log(\`\\nResults: \${pass} passed, \${fail} failed\`);
15092
15228
  process.exit(fail > 0 ? 1 : 0);
15093
15229
  `;
15094
- writeFileSafe(join15(dir, `${table2}.test.ts`), content);
15230
+ writeFileSafe(join16(dir, `${table2}.test.ts`), content);
15095
15231
  }
15096
15232
  function generateMigration(name, flags, fieldsOverride, tableOverride, emitTest = true) {
15097
15233
  const ts = timestamp();
@@ -15111,7 +15247,7 @@ function generateMigration(name, flags, fieldsOverride, tableOverride, emitTest
15111
15247
  const isCreate = name.startsWith("create_") || fieldsOverride !== void 0;
15112
15248
  const isView = isCreate && fieldsOverride === void 0 && table2.endsWith("_view");
15113
15249
  const fileName = `${ts}_${name}.sql`;
15114
- const path10 = join15(dir, fileName);
15250
+ const path9 = join16(dir, fileName);
15115
15251
  setResolutionField("migration_path", `migrations/${fileName}`);
15116
15252
  if (__resolution.target === "migration") {
15117
15253
  setResolutionField("file_path", `migrations/${fileName}`);
@@ -15152,8 +15288,8 @@ DROP TABLE IF EXISTS ${table2};`;
15152
15288
  -- UP
15153
15289
  ${upSql}
15154
15290
  `;
15155
- writeFileSafe(path10, content);
15156
- const downPath = join15(dir, `${ts}_${name}.down.sql`);
15291
+ writeFileSafe(path9, content);
15292
+ const downPath = join16(dir, `${ts}_${name}.down.sql`);
15157
15293
  const downContent = `-- Rollback: ${name}
15158
15294
  -- Created: ${now}
15159
15295
 
@@ -15166,7 +15302,7 @@ function generateMiddleware(name, _flags) {
15166
15302
  const snake = toSnake(name);
15167
15303
  const dir = resolve6("src/middleware");
15168
15304
  ensureDir(dir);
15169
- const path10 = join15(dir, `${snake}.ts`);
15305
+ const path9 = join16(dir, `${snake}.ts`);
15170
15306
  if (__resolution.target === "middleware") {
15171
15307
  setResolutionField("class_name", name);
15172
15308
  setResolutionField("file_path", `src/middleware/${snake}.ts`);
@@ -15204,7 +15340,7 @@ export async function after${name}(
15204
15340
  await next();
15205
15341
  }
15206
15342
  `;
15207
- writeFileSafe(path10, content);
15343
+ writeFileSafe(path9, content);
15208
15344
  emitMiddlewareTest(name, snake);
15209
15345
  }
15210
15346
  function generateTest(name, flags) {
@@ -15213,7 +15349,7 @@ function generateTest(name, flags) {
15213
15349
  const model = flags.model;
15214
15350
  const dir = resolve6("tests");
15215
15351
  ensureDir(dir);
15216
- const path10 = join15(dir, `${snake}.test.ts`);
15352
+ const path9 = join16(dir, `${snake}.test.ts`);
15217
15353
  if (model && flags["secure-writes"]) {
15218
15354
  const isPublic = Boolean(flags.public);
15219
15355
  const posture = isPublic ? "open (--public)" : "gated";
@@ -15262,7 +15398,7 @@ ${writeCase}
15262
15398
  console.log(\`\\nResults: \${pass} passed, \${fail} failed\`);
15263
15399
  process.exit(fail > 0 ? 1 : 0);
15264
15400
  `;
15265
- writeFileSafe(path10, content2);
15401
+ writeFileSafe(path9, content2);
15266
15402
  return;
15267
15403
  }
15268
15404
  let content;
@@ -15328,7 +15464,7 @@ const test${titleName} = tests(
15328
15464
  void test${titleName};
15329
15465
  `;
15330
15466
  }
15331
- writeFileSafe(path10, content);
15467
+ writeFileSafe(path9, content);
15332
15468
  void singular;
15333
15469
  }
15334
15470
  function generateForm(name, flags) {
@@ -15351,7 +15487,7 @@ function generateForm(name, flags) {
15351
15487
  };
15352
15488
  const dir = resolve6("src/templates/forms");
15353
15489
  ensureDir(dir);
15354
- const path10 = join15(dir, `${table2}.twig`);
15490
+ const path9 = join16(dir, `${table2}.twig`);
15355
15491
  let fieldHtml = "";
15356
15492
  for (const [fname, ftype] of fields) {
15357
15493
  const itype = inputTypes[ftype] || "text";
@@ -15395,7 +15531,7 @@ function generateForm(name, flags) {
15395
15531
  </div>
15396
15532
  {% endblock %}
15397
15533
  `;
15398
- writeFileSafe(path10, content);
15534
+ writeFileSafe(path9, content);
15399
15535
  }
15400
15536
  function generateView(name, flags) {
15401
15537
  const fields = fieldsOrDefault(flags.fields || "");
@@ -15404,7 +15540,7 @@ function generateView(name, flags) {
15404
15540
  const cols = fields.map(([f]) => f);
15405
15541
  const dir = resolve6("src/templates/pages");
15406
15542
  ensureDir(dir);
15407
- const listPath = join15(dir, `${routeName}.twig`);
15543
+ const listPath = join16(dir, `${routeName}.twig`);
15408
15544
  const th = cols.map((c) => ` <th>${c.replace(/_/g, " ").replace(/\b\w/g, (ch) => ch.toUpperCase())}</th>`).join("\n");
15409
15545
  const td = cols.map((c) => ` <td>{{ item.${c} }}</td>`).join("\n");
15410
15546
  const listContent = `{% extends "base.twig" %}
@@ -15441,7 +15577,7 @@ ${td}
15441
15577
  {% endblock %}
15442
15578
  `;
15443
15579
  writeFileSafe(listPath, listContent);
15444
- const detailPath = join15(dir, `${table2}.twig`);
15580
+ const detailPath = join16(dir, `${table2}.twig`);
15445
15581
  const detailFields = cols.map((c) => ` <div class="mb-3"><strong>${c.replace(/_/g, " ").replace(/\b\w/g, (ch) => ch.toUpperCase())}:</strong> {{ item.${c} }}</div>`).join("\n");
15446
15582
  const detailContent = `{% extends "base.twig" %}
15447
15583
  {% block title %}${name} Detail{% endblock %}
@@ -15471,7 +15607,7 @@ function generateAuth(_flags) {
15471
15607
  ensureDir(loginDir);
15472
15608
  ensureDir(meDir);
15473
15609
  writeFileSafe(
15474
- join15(registerDir, "post.ts"),
15610
+ join16(registerDir, "post.ts"),
15475
15611
  `import type { Tina4Request, Tina4Response } from "tina4-nodejs";
15476
15612
  import { hashPassword } from "tina4-nodejs";
15477
15613
  import User from "../../../../models/User.js";
@@ -15503,7 +15639,7 @@ export default async function (req: Tina4Request, res: Tina4Response) {
15503
15639
  `
15504
15640
  );
15505
15641
  writeFileSafe(
15506
- join15(loginDir, "post.ts"),
15642
+ join16(loginDir, "post.ts"),
15507
15643
  `import type { Tina4Request, Tina4Response } from "tina4-nodejs";
15508
15644
  import { checkPassword, getToken } from "tina4-nodejs";
15509
15645
  import User from "../../../../models/User.js";
@@ -15536,7 +15672,7 @@ export default async function (req: Tina4Request, res: Tina4Response) {
15536
15672
  `
15537
15673
  );
15538
15674
  writeFileSafe(
15539
- join15(meDir, "get.ts"),
15675
+ join16(meDir, "get.ts"),
15540
15676
  `import type { Tina4Request, Tina4Response } from "tina4-nodejs";
15541
15677
  import { authenticateRequest } from "tina4-nodejs";
15542
15678
 
@@ -15555,7 +15691,7 @@ export default async function (req: Tina4Request, res: Tina4Response) {
15555
15691
  const formsDir = resolve6("src/templates/forms");
15556
15692
  ensureDir(formsDir);
15557
15693
  writeFileSafe(
15558
- join15(formsDir, "login.twig"),
15694
+ join16(formsDir, "login.twig"),
15559
15695
  `{% extends "base.twig" %}
15560
15696
  {% block title %}Login{% endblock %}
15561
15697
  {% block content %}
@@ -15583,7 +15719,7 @@ export default async function (req: Tina4Request, res: Tina4Response) {
15583
15719
  `
15584
15720
  );
15585
15721
  writeFileSafe(
15586
- join15(formsDir, "register.twig"),
15722
+ join16(formsDir, "register.twig"),
15587
15723
  `{% extends "base.twig" %}
15588
15724
  {% block title %}Register{% endblock %}
15589
15725
  {% block content %}
@@ -15622,7 +15758,7 @@ function generateService(name, flags) {
15622
15758
  const cron = flags.cron;
15623
15759
  const dir = resolve6("src/services");
15624
15760
  ensureDir(dir);
15625
- const path10 = join15(dir, `${snake}.ts`);
15761
+ const path9 = join16(dir, `${snake}.ts`);
15626
15762
  let scheduleField;
15627
15763
  let note;
15628
15764
  if (cron && cron !== true) {
@@ -15665,7 +15801,7 @@ export default {
15665
15801
  ${scheduleField}
15666
15802
  };
15667
15803
  `;
15668
- writeFileSafe(path10, content);
15804
+ writeFileSafe(path9, content);
15669
15805
  emitServiceTest(name, snake, camel);
15670
15806
  }
15671
15807
  function generateQueue(name, _flags) {
@@ -15674,7 +15810,7 @@ function generateQueue(name, _flags) {
15674
15810
  const pascal = toPascal(topic) || "Topic";
15675
15811
  const dir = resolve6("src/services");
15676
15812
  ensureDir(dir);
15677
- const path10 = join15(dir, `${slug}_consumer.ts`);
15813
+ const path9 = join16(dir, `${slug}_consumer.ts`);
15678
15814
  const body = aiFill(`handle${pascal}`, {
15679
15815
  intent: `process ONE ${topic} job payload`,
15680
15816
  given: "payload -> the produced job data (job.payload)",
@@ -15729,13 +15865,13 @@ export default {
15729
15865
  daemon: true,
15730
15866
  };
15731
15867
  `;
15732
- writeFileSafe(path10, content);
15868
+ writeFileSafe(path9, content);
15733
15869
  emitQueueTest(topic, slug, pascal);
15734
15870
  }
15735
15871
  function generateValidator(name, _flags) {
15736
15872
  const dir = resolve6("src/validators");
15737
15873
  ensureDir(dir);
15738
- const path10 = join15(dir, `${toSnake(name)}.ts`);
15874
+ const path9 = join16(dir, `${toSnake(name)}.ts`);
15739
15875
  const rules = extend(
15740
15876
  "add / adjust the validation rules for this payload",
15741
15877
  `e.g. .email("email").minLength("name", 2).integer("age"); ground: tina4_context("validate request body with Validator", "nodejs")`
@@ -15756,14 +15892,14 @@ ${rules} validator.required("name"); // starter rule (matches the model's def
15756
15892
  return validator;
15757
15893
  }
15758
15894
  `;
15759
- writeFileSafe(path10, content);
15895
+ writeFileSafe(path9, content);
15760
15896
  emitValidatorTest(name, toSnake(name), toPascal(name));
15761
15897
  }
15762
15898
  function generateSeeder(name, flags) {
15763
15899
  const table2 = resolveTable(name, flags, { announce: false });
15764
15900
  const dir = resolve6("src/seeds");
15765
15901
  ensureDir(dir);
15766
- const path10 = join15(dir, `${table2}_seeder.ts`);
15902
+ const path9 = join16(dir, `${table2}_seeder.ts`);
15767
15903
  const overrides = extend(
15768
15904
  "override fields that need a specific shape (seedOrm auto-fills the rest)",
15769
15905
  `e.g. return { email: (f) => f.email(), status: "active" }; ground: tina4_context("seed ORM model with FakeData", "nodejs")`
@@ -15797,7 +15933,7 @@ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href)
15797
15933
  await run();
15798
15934
  }
15799
15935
  `;
15800
- writeFileSafe(path10, content);
15936
+ writeFileSafe(path9, content);
15801
15937
  emitSeederTest(name, table2);
15802
15938
  }
15803
15939
  function generateWebsocket(name, _flags) {
@@ -15808,7 +15944,7 @@ function generateWebsocket(name, _flags) {
15808
15944
  const handlerName = `${toCamel(toPascal(base))}Ws`;
15809
15945
  const dir = resolve6("src/routes");
15810
15946
  ensureDir(dir);
15811
- const path10 = join15(dir, `ws_${base}.ts`);
15947
+ const path9 = join16(dir, `ws_${base}.ts`);
15812
15948
  const body = aiFill(handlerName, {
15813
15949
  intent: `handle an inbound "message" frame on ${wsPath}`,
15814
15950
  given: "data -> the message payload (string); connection -> WebSocketConnection",
@@ -15850,7 +15986,7 @@ ${body}}
15850
15986
 
15851
15987
  websocket("${wsPath}", ${handlerName});
15852
15988
  `;
15853
- writeFileSafe(path10, content);
15989
+ writeFileSafe(path9, content);
15854
15990
  emitWebsocketTest(wsPath, base, handlerName);
15855
15991
  }
15856
15992
  function generateListener(name, _flags) {
@@ -15859,7 +15995,7 @@ function generateListener(name, _flags) {
15859
15995
  const handlerName = `on${toPascal(slug)}`;
15860
15996
  const dir = resolve6("src/listeners");
15861
15997
  ensureDir(dir);
15862
- const path10 = join15(dir, `${slug}.ts`);
15998
+ const path9 = join16(dir, `${slug}.ts`);
15863
15999
  const body = aiFill(handlerName, {
15864
16000
  intent: `react to the '${event}' event`,
15865
16001
  given: `args -> whatever Events.emit("${event}", ...args) passed`,
@@ -15885,13 +16021,13 @@ ${body}}
15885
16021
 
15886
16022
  Events.on("${event}", ${handlerName});
15887
16023
  `;
15888
- writeFileSafe(path10, content);
16024
+ writeFileSafe(path9, content);
15889
16025
  emitListenerTest(event, slug);
15890
16026
  }
15891
16027
  function writeTest(testName, content) {
15892
16028
  const dir = resolve6("tests");
15893
16029
  ensureDir(dir);
15894
- writeFileSafe(join15(dir, `${testName}.test.ts`), content);
16030
+ writeFileSafe(join16(dir, `${testName}.test.ts`), content);
15895
16031
  }
15896
16032
  function standaloneTest(doc, body) {
15897
16033
  return `${doc}
@@ -16557,7 +16693,6 @@ __export(mcp_exports, {
16557
16693
  import * as fs4 from "node:fs";
16558
16694
  import * as path3 from "node:path";
16559
16695
  import * as os from "node:os";
16560
- import { spawnSync as spawnSync2 } from "node:child_process";
16561
16696
  import { createRequire as createRequire2 } from "node:module";
16562
16697
  import { randomBytes as randomBytes5 } from "node:crypto";
16563
16698
  function reqSibling(pkg) {
@@ -16886,7 +17021,7 @@ function verifyNodeSyntax(absPath, relPath) {
16886
17021
  if (!target) return null;
16887
17022
  const { cmd, args } = syntaxCheckCommand(absPath, target.ext);
16888
17023
  try {
16889
- const proc = spawnSync2(cmd, args, {
17024
+ const proc = spawnSyncAllowingBatch(findExecutable(cmd), args, {
16890
17025
  encoding: "utf-8",
16891
17026
  timeout: 5e3,
16892
17027
  cwd: path3.dirname(path3.dirname(absPath))
@@ -17767,13 +17902,13 @@ function registerDevTools(server) {
17767
17902
  "git_status",
17768
17903
  () => {
17769
17904
  try {
17770
- const { execFileSync: execFileSync6 } = req("node:child_process");
17905
+ const { execFileSync: execFileSync5 } = req("node:child_process");
17771
17906
  const cwd = path3.resolve(process.cwd());
17772
17907
  const run = (args) => {
17773
- return execFileSync6("git", args, { cwd, timeout: 3e3, encoding: "utf-8" }).toString().trim();
17908
+ return execFileSync5("git", args, { cwd, timeout: 3e3, encoding: "utf-8" }).toString().trim();
17774
17909
  };
17775
17910
  try {
17776
- execFileSync6("git", ["rev-parse", "--is-inside-work-tree"], { cwd, timeout: 3e3 });
17911
+ execFileSync5("git", ["rev-parse", "--is-inside-work-tree"], { cwd, timeout: 3e3 });
17777
17912
  } catch {
17778
17913
  return { error: "Not a git repository" };
17779
17914
  }
@@ -17901,6 +18036,7 @@ var init_mcp = __esm({
17901
18036
  "../core/src/mcp.ts"() {
17902
18037
  "use strict";
17903
18038
  init_slashTrim();
18039
+ init_batchSpawn();
17904
18040
  init_version();
17905
18041
  req = createRequire2(import.meta.url);
17906
18042
  PARSE_ERROR = -32700;
@@ -19362,7 +19498,7 @@ function pack(segments, maxLines) {
19362
19498
  }
19363
19499
  return chunks;
19364
19500
  }
19365
- function chunkCode(text, path10 = "", maxLines = 60) {
19501
+ function chunkCode(text, path9 = "", maxLines = 60) {
19366
19502
  const lines = splitLines(text);
19367
19503
  let bounds = [];
19368
19504
  for (let i = 0; i < lines.length; i++) {
@@ -19376,7 +19512,7 @@ function chunkCode(text, path10 = "", maxLines = 60) {
19376
19512
  for (let k = 0; k < bounds.length; k++) {
19377
19513
  segments.push(lines.slice(bounds[k], ends[k]));
19378
19514
  }
19379
- const header = path10 ? `# file: ${path10}` : null;
19515
+ const header = path9 ? `# file: ${path9}` : null;
19380
19516
  const packed = pack(segments, maxLines);
19381
19517
  const out = [];
19382
19518
  for (let i = 0; i < packed.length; i++) {
@@ -19427,8 +19563,8 @@ __export(context_exports, {
19427
19563
  fts5Supported: () => fts5Supported
19428
19564
  });
19429
19565
  import { DatabaseSync as DatabaseSync2 } from "node:sqlite";
19430
- import { existsSync as existsSync15, mkdirSync as mkdirSync10, readFileSync as readFileSync13, readdirSync as readdirSync8, realpathSync as realpathSync5 } from "node:fs";
19431
- import { basename as basename4, dirname as dirname9, extname as extname4, isAbsolute as isAbsolute4, join as join17, relative as relative4, resolve as resolve8 } from "node:path";
19566
+ import { existsSync as existsSync16, mkdirSync as mkdirSync10, readFileSync as readFileSync13, readdirSync as readdirSync8, realpathSync as realpathSync5 } from "node:fs";
19567
+ import { basename as basename4, dirname as dirname9, extname as extname5, isAbsolute as isAbsolute4, join as join18, relative as relative4, resolve as resolve8 } from "node:path";
19432
19568
  function fts5Supported() {
19433
19569
  try {
19434
19570
  const conn = new DatabaseSync2(":memory:");
@@ -19451,13 +19587,13 @@ function realResolve(abs) {
19451
19587
  } catch {
19452
19588
  }
19453
19589
  try {
19454
- return join17(realpathSync5(dirname9(abs)), basename4(abs));
19590
+ return join18(realpathSync5(dirname9(abs)), basename4(abs));
19455
19591
  } catch {
19456
19592
  return abs;
19457
19593
  }
19458
19594
  }
19459
19595
  function dbKey(db) {
19460
- return resolve8(db ? String(db) : join17(process.cwd(), ".tina4", "context.db"));
19596
+ return resolve8(db ? String(db) : join18(process.cwd(), ".tina4", "context.db"));
19461
19597
  }
19462
19598
  function defaultContext(root, db) {
19463
19599
  const key = dbKey(db);
@@ -19563,7 +19699,7 @@ var init_context = __esm({
19563
19699
  }
19564
19700
  // ── indexing ───────────────────────────────────────────────
19565
19701
  static chunksFor(label, text) {
19566
- const ext = extname4(label).toLowerCase();
19702
+ const ext = extname5(label).toLowerCase();
19567
19703
  const special = SPECIAL_FILES.has(basename4(label).toLowerCase());
19568
19704
  if (CODE_EXTS.has(ext) || CONFIG_EXTS.has(ext) || special) {
19569
19705
  return chunkCode(text, label);
@@ -19602,7 +19738,7 @@ var init_context = __esm({
19602
19738
  static eligible(filename) {
19603
19739
  const fn = filename.toLowerCase();
19604
19740
  if (fn.endsWith(".min.js")) return false;
19605
- const ext = extname4(fn);
19741
+ const ext = extname5(fn);
19606
19742
  return CODE_EXTS.has(ext) || DOC_EXTS.has(ext) || CONFIG_EXTS.has(ext) || SPECIAL_FILES.has(fn);
19607
19743
  }
19608
19744
  /**
@@ -19630,11 +19766,11 @@ var init_context = __esm({
19630
19766
  files.sort();
19631
19767
  for (const fn of files) {
19632
19768
  if (!_Context.eligible(fn)) continue;
19633
- const full = join17(dir, fn);
19769
+ const full = join18(dir, fn);
19634
19770
  const rel = relative4(rootAbs, full);
19635
19771
  total += this.indexPath(full, rel);
19636
19772
  }
19637
- for (const d of subdirs) walk2(join17(dir, d));
19773
+ for (const d of subdirs) walk2(join18(dir, d));
19638
19774
  };
19639
19775
  walk2(rootAbs);
19640
19776
  return total;
@@ -19650,7 +19786,7 @@ var init_context = __esm({
19650
19786
  reindexFile(changedPath) {
19651
19787
  if (!this.available || this.root === null) return -1;
19652
19788
  const raw = String(changedPath);
19653
- const abs = isAbsolute4(raw) ? raw : join17(process.cwd(), raw);
19789
+ const abs = isAbsolute4(raw) ? raw : join18(process.cwd(), raw);
19654
19790
  const resolved = realResolve(resolve8(abs));
19655
19791
  const rel = relative4(this.root, resolved);
19656
19792
  if (rel === "" || rel.startsWith("..") || isAbsolute4(rel)) {
@@ -19663,7 +19799,7 @@ var init_context = __esm({
19663
19799
  }
19664
19800
  if (!_Context.eligible(basename4(rel))) return -1;
19665
19801
  const stored = rel;
19666
- if (!existsSync15(abs)) {
19802
+ if (!existsSync16(abs)) {
19667
19803
  this.conn.prepare("DELETE FROM chunks WHERE path = ?").run(stored);
19668
19804
  return 0;
19669
19805
  }
@@ -19681,8 +19817,8 @@ var init_context = __esm({
19681
19817
  const expr = [...toks].sort().map((t) => `"${t}"`).join(" OR ");
19682
19818
  return { expr, toks };
19683
19819
  }
19684
- static isTestlike(path10) {
19685
- const s = (path10 || "").toLowerCase();
19820
+ static isTestlike(path9) {
19821
+ const s = (path9 || "").toLowerCase();
19686
19822
  return ["/test", "test/", "test_", "_test.", ".test.", "/example", "example/"].some((p) => s.includes(p));
19687
19823
  }
19688
19824
  static defines(foldedBody, symbols) {
@@ -20146,7 +20282,7 @@ function parseFrame(data) {
20146
20282
  const payload = data.subarray(offset, offset + payloadLen);
20147
20283
  return { fin: !!fin, opcode, payload: Buffer.from(payload), bytesConsumed: offset + payloadLen };
20148
20284
  }
20149
- function createRouteConnection(socket, path10, headers, params, auth) {
20285
+ function createRouteConnection(socket, path9, headers, params, auth) {
20150
20286
  const id = randomUUID3().slice(0, 8);
20151
20287
  const send = (message) => {
20152
20288
  try {
@@ -20156,14 +20292,14 @@ function createRouteConnection(socket, path10, headers, params, auth) {
20156
20292
  };
20157
20293
  const conn = {
20158
20294
  id,
20159
- path: path10,
20295
+ path: path9,
20160
20296
  ip: socket.remoteAddress ?? "unknown",
20161
20297
  headers,
20162
20298
  params,
20163
20299
  auth,
20164
20300
  send,
20165
20301
  sendJson: (data) => send(JSON.stringify(data)),
20166
- broadcast: (message) => wsRouteManager.broadcastPath(path10, message),
20302
+ broadcast: (message) => wsRouteManager.broadcastPath(path9, message),
20167
20303
  broadcastToRoom: (room, message, excludeSelf = false) => wsRouteManager.broadcastToRoom(room, message, excludeSelf ? id : void 0),
20168
20304
  getRoomConnections: (room) => wsRouteManager.getRoomConnections(room),
20169
20305
  joinRoom: (room) => wsRouteManager.joinRoom(id, room),
@@ -20372,8 +20508,8 @@ var init_websocket = __esm({
20372
20508
  * to the Router's `(conn, event, data)` style and registers it via
20373
20509
  * `Router.websocket()`.
20374
20510
  */
20375
- route(path10, handler, options) {
20376
- this._routeHandlers.set(path10, handler);
20511
+ route(path9, handler, options) {
20512
+ this._routeHandlers.set(path9, handler);
20377
20513
  const adapter = async (conn, event, data) => {
20378
20514
  if (event === "open") {
20379
20515
  const result = handler(conn);
@@ -20396,7 +20532,7 @@ var init_websocket = __esm({
20396
20532
  }
20397
20533
  }
20398
20534
  };
20399
- Router.websocket(path10, adapter, options);
20535
+ Router.websocket(path9, adapter, options);
20400
20536
  }
20401
20537
  /**
20402
20538
  * Broadcast a message to all connected clients.
@@ -20406,18 +20542,18 @@ var init_websocket = __esm({
20406
20542
  * When `path` is omitted/undefined, all clients receive the message
20407
20543
  * (backward compatible).
20408
20544
  */
20409
- broadcast(message, excludeIds, path10) {
20545
+ broadcast(message, excludeIds, path9) {
20410
20546
  this.ensureBackplane();
20411
20547
  const exclude = new Set(excludeIds ?? []);
20412
20548
  for (const [id, client] of Array.from(this.clients)) {
20413
20549
  if (exclude.has(id)) continue;
20414
- if (path10 !== void 0 && client.path !== path10) continue;
20550
+ if (path9 !== void 0 && client.path !== path9) continue;
20415
20551
  this.safeSend(client, message);
20416
20552
  }
20417
20553
  this.backplane.publish(
20418
- path10 !== void 0 ? "path" : "all",
20554
+ path9 !== void 0 ? "path" : "all",
20419
20555
  message,
20420
- { path: path10 ?? null, exclude: excludeIds?.[0] ?? null },
20556
+ { path: path9 ?? null, exclude: excludeIds?.[0] ?? null },
20421
20557
  Log
20422
20558
  );
20423
20559
  }
@@ -20893,10 +21029,10 @@ var init_websocket = __esm({
20893
21029
  }
20894
21030
  }
20895
21031
  /** Broadcast a text frame to every connection on the same path. */
20896
- broadcastPath(path10, message) {
21032
+ broadcastPath(path9, message) {
20897
21033
  const frame = buildFrame(OP_TEXT, Buffer.from(message, "utf-8"));
20898
21034
  for (const state of this.connections.values()) {
20899
- if (state.path !== path10 || state.closed) continue;
21035
+ if (state.path !== path9 || state.closed) continue;
20900
21036
  try {
20901
21037
  state.socket.write(frame);
20902
21038
  } catch {
@@ -22509,8 +22645,8 @@ var init_job = __esm({
22509
22645
  });
22510
22646
 
22511
22647
  // ../core/src/queueBackends/liteBackend.ts
22512
- import { mkdirSync as mkdirSync11, readdirSync as readdirSync9, readFileSync as readFileSync14, writeFileSync as writeFileSync9, unlinkSync as unlinkSync7, existsSync as existsSync16 } from "node:fs";
22513
- import { join as join18 } from "node:path";
22648
+ import { mkdirSync as mkdirSync11, readdirSync as readdirSync9, readFileSync as readFileSync14, writeFileSync as writeFileSync9, unlinkSync as unlinkSync7, existsSync as existsSync17 } from "node:fs";
22649
+ import { join as join19 } from "node:path";
22514
22650
  import { randomUUID as randomUUID6 } from "node:crypto";
22515
22651
  var LiteBackend;
22516
22652
  var init_liteBackend = __esm({
@@ -22534,22 +22670,22 @@ var init_liteBackend = __esm({
22534
22670
  this.visibilityTimeout = visibilityTimeout;
22535
22671
  }
22536
22672
  ensureDir(queue) {
22537
- const dir = join18(this.basePath, queue);
22673
+ const dir = join19(this.basePath, queue);
22538
22674
  mkdirSync11(dir, { recursive: true });
22539
22675
  return dir;
22540
22676
  }
22541
22677
  ensureFailedDir(queue) {
22542
- const dir = join18(this.basePath, queue, "failed");
22678
+ const dir = join19(this.basePath, queue, "failed");
22543
22679
  mkdirSync11(dir, { recursive: true });
22544
22680
  return dir;
22545
22681
  }
22546
22682
  ensureReservedDir(queue) {
22547
- const dir = join18(this.basePath, queue, "reserved");
22683
+ const dir = join19(this.basePath, queue, "reserved");
22548
22684
  mkdirSync11(dir, { recursive: true });
22549
22685
  return dir;
22550
22686
  }
22551
22687
  reservedPath(queue, jobId) {
22552
- return join18(this.ensureReservedDir(queue), `${jobId}.queue-data`);
22688
+ return join19(this.ensureReservedDir(queue), `${jobId}.queue-data`);
22553
22689
  }
22554
22690
  nowIso() {
22555
22691
  return (/* @__PURE__ */ new Date()).toISOString();
@@ -22592,7 +22728,7 @@ var init_liteBackend = __esm({
22592
22728
  error: void 0
22593
22729
  };
22594
22730
  const prefix = this.nextPrefix();
22595
- writeFileSync9(join18(dir, `${prefix}_${id}.queue-data`), JSON.stringify(job, null, 2));
22731
+ writeFileSync9(join19(dir, `${prefix}_${id}.queue-data`), JSON.stringify(job, null, 2));
22596
22732
  return id;
22597
22733
  }
22598
22734
  /**
@@ -22611,7 +22747,7 @@ var init_liteBackend = __esm({
22611
22747
  }
22612
22748
  const candidates = [];
22613
22749
  for (const filename of filenames) {
22614
- const filePath = join18(dir, filename);
22750
+ const filePath = join19(dir, filename);
22615
22751
  let job;
22616
22752
  try {
22617
22753
  job = JSON.parse(readFileSync14(filePath, "utf-8"));
@@ -22675,7 +22811,7 @@ var init_liteBackend = __esm({
22675
22811
  return;
22676
22812
  }
22677
22813
  for (const filename of filenames) {
22678
- const filePath = join18(reservedDir, filename);
22814
+ const filePath = join19(reservedDir, filename);
22679
22815
  let record2;
22680
22816
  try {
22681
22817
  record2 = JSON.parse(readFileSync14(filePath, "utf-8"));
@@ -22713,7 +22849,7 @@ var init_liteBackend = __esm({
22713
22849
  this.reclaimExpired(queue, bridge.getMaxRetries(), this.nowIso());
22714
22850
  const now = this.nowIso();
22715
22851
  for (const [filename, job] of this.availableCandidates(queue, now)) {
22716
- const filePath = join18(dir, filename);
22852
+ const filePath = join19(dir, filename);
22717
22853
  job.topic = queue;
22718
22854
  job.priority = job.priority ?? 0;
22719
22855
  this.writeReserved(queue, job);
@@ -22738,7 +22874,7 @@ var init_liteBackend = __esm({
22738
22874
  const results = [];
22739
22875
  for (const [filename, job] of this.availableCandidates(queue, now)) {
22740
22876
  if (results.length >= count) break;
22741
- const filePath = join18(dir, filename);
22877
+ const filePath = join19(dir, filename);
22742
22878
  job.topic = queue;
22743
22879
  job.priority = job.priority ?? 0;
22744
22880
  this.writeReserved(queue, job);
@@ -22791,7 +22927,7 @@ var init_liteBackend = __esm({
22791
22927
  let count = 0;
22792
22928
  for (const file of files) {
22793
22929
  try {
22794
- const job = JSON.parse(readFileSync14(join18(scanDir, file), "utf-8"));
22930
+ const job = JSON.parse(readFileSync14(join19(scanDir, file), "utf-8"));
22795
22931
  if (job.status === status2) count++;
22796
22932
  } catch {
22797
22933
  }
@@ -22804,28 +22940,28 @@ var init_liteBackend = __esm({
22804
22940
  try {
22805
22941
  const files = readdirSync9(dir).filter((f) => f.endsWith(".queue-data"));
22806
22942
  for (const file of files) {
22807
- unlinkSync7(join18(dir, file));
22943
+ unlinkSync7(join19(dir, file));
22808
22944
  count++;
22809
22945
  }
22810
22946
  } catch {
22811
22947
  }
22812
- const failedDir = join18(dir, "failed");
22948
+ const failedDir = join19(dir, "failed");
22813
22949
  try {
22814
- if (existsSync16(failedDir)) {
22950
+ if (existsSync17(failedDir)) {
22815
22951
  const files = readdirSync9(failedDir).filter((f) => f.endsWith(".queue-data"));
22816
22952
  for (const file of files) {
22817
- unlinkSync7(join18(failedDir, file));
22953
+ unlinkSync7(join19(failedDir, file));
22818
22954
  count++;
22819
22955
  }
22820
22956
  }
22821
22957
  } catch {
22822
22958
  }
22823
- const reservedDir = join18(dir, "reserved");
22959
+ const reservedDir = join19(dir, "reserved");
22824
22960
  try {
22825
- if (existsSync16(reservedDir)) {
22961
+ if (existsSync17(reservedDir)) {
22826
22962
  const files = readdirSync9(reservedDir).filter((f) => f.endsWith(".queue-data"));
22827
22963
  for (const file of files) {
22828
- unlinkSync7(join18(reservedDir, file));
22964
+ unlinkSync7(join19(reservedDir, file));
22829
22965
  count++;
22830
22966
  }
22831
22967
  }
@@ -22848,7 +22984,7 @@ var init_liteBackend = __esm({
22848
22984
  const files = readdirSync9(dir).filter((f) => f.endsWith(".queue-data")).sort();
22849
22985
  for (const file of files) {
22850
22986
  try {
22851
- const job = JSON.parse(readFileSync14(join18(dir, file), "utf-8"));
22987
+ const job = JSON.parse(readFileSync14(join19(dir, file), "utf-8"));
22852
22988
  const attempts = job.attempts || 0;
22853
22989
  if (attempts > 0 && attempts < maxRetries) {
22854
22990
  results.push(job);
@@ -22871,9 +23007,9 @@ var init_liteBackend = __esm({
22871
23007
  try {
22872
23008
  const queues = readdirSync9(this.basePath);
22873
23009
  for (const q of queues) {
22874
- const failedDir = join18(this.basePath, q, "failed");
22875
- const filePath = join18(failedDir, `${jobId}.queue-data`);
22876
- if (existsSync16(filePath)) {
23010
+ const failedDir = join19(this.basePath, q, "failed");
23011
+ const filePath = join19(failedDir, `${jobId}.queue-data`);
23012
+ if (existsSync17(filePath)) {
22877
23013
  const job = JSON.parse(readFileSync14(filePath, "utf-8"));
22878
23014
  job.status = "pending";
22879
23015
  job.attempts = (job.attempts || 0) + 1;
@@ -22881,8 +23017,8 @@ var init_liteBackend = __esm({
22881
23017
  job.createdAt = (/* @__PURE__ */ new Date()).toISOString();
22882
23018
  job.delayUntil = delaySeconds ? new Date(Date.now() + delaySeconds * 1e3).toISOString() : null;
22883
23019
  const prefix = this.nextPrefix();
22884
- const queueDir = join18(this.basePath, q);
22885
- writeFileSync9(join18(queueDir, `${prefix}_${jobId}.queue-data`), JSON.stringify(job, null, 2));
23020
+ const queueDir = join19(this.basePath, q);
23021
+ writeFileSync9(join19(queueDir, `${prefix}_${jobId}.queue-data`), JSON.stringify(job, null, 2));
22886
23022
  unlinkSync7(filePath);
22887
23023
  return true;
22888
23024
  }
@@ -22898,7 +23034,7 @@ var init_liteBackend = __esm({
22898
23034
  const files = readdirSync9(failedDir).filter((f) => f.endsWith(".queue-data")).sort();
22899
23035
  for (const file of files) {
22900
23036
  try {
22901
- const job = JSON.parse(readFileSync14(join18(failedDir, file), "utf-8"));
23037
+ const job = JSON.parse(readFileSync14(join19(failedDir, file), "utf-8"));
22902
23038
  if ((job.attempts || 0) >= maxRetries) {
22903
23039
  job.status = "dead";
22904
23040
  results.push(job);
@@ -22919,7 +23055,7 @@ var init_liteBackend = __esm({
22919
23055
  const files = readdirSync9(failedDir).filter((f) => f.endsWith(".queue-data"));
22920
23056
  for (const file of files) {
22921
23057
  try {
22922
- unlinkSync7(join18(failedDir, file));
23058
+ unlinkSync7(join19(failedDir, file));
22923
23059
  count++;
22924
23060
  } catch {
22925
23061
  }
@@ -22932,9 +23068,9 @@ var init_liteBackend = __esm({
22932
23068
  const files = readdirSync9(dir).filter((f) => f.endsWith(".queue-data"));
22933
23069
  for (const file of files) {
22934
23070
  try {
22935
- const job = JSON.parse(readFileSync14(join18(dir, file), "utf-8"));
23071
+ const job = JSON.parse(readFileSync14(join19(dir, file), "utf-8"));
22936
23072
  if (job.status === status2) {
22937
- unlinkSync7(join18(dir, file));
23073
+ unlinkSync7(join19(dir, file));
22938
23074
  count++;
22939
23075
  }
22940
23076
  } catch {
@@ -22958,7 +23094,7 @@ var init_liteBackend = __esm({
22958
23094
  const files = readdirSync9(failedDir).filter((f) => f.endsWith(".queue-data"));
22959
23095
  for (const file of files) {
22960
23096
  try {
22961
- const filePath = join18(failedDir, file);
23097
+ const filePath = join19(failedDir, file);
22962
23098
  const job = JSON.parse(readFileSync14(filePath, "utf-8"));
22963
23099
  if ((job.attempts || 0) >= maxRetries) {
22964
23100
  continue;
@@ -22968,7 +23104,7 @@ var init_liteBackend = __esm({
22968
23104
  job.createdAt = (/* @__PURE__ */ new Date()).toISOString();
22969
23105
  job.delayUntil = null;
22970
23106
  const prefix = this.nextPrefix();
22971
- writeFileSync9(join18(queueDir, `${prefix}_${job.id}.queue-data`), JSON.stringify(job, null, 2));
23107
+ writeFileSync9(join19(queueDir, `${prefix}_${job.id}.queue-data`), JSON.stringify(job, null, 2));
22972
23108
  unlinkSync7(filePath);
22973
23109
  count++;
22974
23110
  } catch {
@@ -22988,7 +23124,7 @@ var init_liteBackend = __esm({
22988
23124
  }
22989
23125
  for (const file of files) {
22990
23126
  if (!file.includes(id)) continue;
22991
- const filePath = join18(dir, file);
23127
+ const filePath = join19(dir, file);
22992
23128
  let job;
22993
23129
  try {
22994
23130
  job = JSON.parse(readFileSync14(filePath, "utf-8"));
@@ -23036,7 +23172,7 @@ var init_liteBackend = __esm({
23036
23172
  error: error2
23037
23173
  };
23038
23174
  const prefix = this.nextPrefix();
23039
- writeFileSync9(join18(dir, `${prefix}_${job.id}.queue-data`), JSON.stringify(jobData, null, 2));
23175
+ writeFileSync9(join19(dir, `${prefix}_${job.id}.queue-data`), JSON.stringify(jobData, null, 2));
23040
23176
  }
23041
23177
  /**
23042
23178
  * Move the job to the dead-letter (failed/) directory. Terminal until a
@@ -23056,7 +23192,7 @@ var init_liteBackend = __esm({
23056
23192
  error: error2,
23057
23193
  failedAt: (/* @__PURE__ */ new Date()).toISOString()
23058
23194
  };
23059
- writeFileSync9(join18(failedDir, `${job.id}.queue-data`), JSON.stringify(jobData, null, 2));
23195
+ writeFileSync9(join19(failedDir, `${job.id}.queue-data`), JSON.stringify(jobData, null, 2));
23060
23196
  }
23061
23197
  /**
23062
23198
  * Record a failed attempt.
@@ -23106,7 +23242,7 @@ var init_liteBackend = __esm({
23106
23242
  retryJob(queue, job, delaySeconds) {
23107
23243
  this.clearReservation(queue, job.id);
23108
23244
  try {
23109
- unlinkSync7(join18(this.ensureFailedDir(queue), `${job.id}.queue-data`));
23245
+ unlinkSync7(join19(this.ensureFailedDir(queue), `${job.id}.queue-data`));
23110
23246
  } catch {
23111
23247
  }
23112
23248
  job.attempts = (job.attempts || 0) + 1;
@@ -24246,6 +24382,9 @@ var init_projectIndexExtractors = __esm({
24246
24382
  import * as fs6 from "node:fs";
24247
24383
  import * as path6 from "node:path";
24248
24384
  import * as crypto2 from "node:crypto";
24385
+ function indexKey(root, fullPath) {
24386
+ return path6.relative(root, fullPath).split(path6.sep).join("/");
24387
+ }
24249
24388
  function projectRoot2() {
24250
24389
  return path6.resolve(process.cwd());
24251
24390
  }
@@ -24280,7 +24419,7 @@ function extract(fullPath) {
24280
24419
  return {};
24281
24420
  }
24282
24421
  const entry = {
24283
- path: path6.relative(projectRoot2(), fullPath),
24422
+ path: indexKey(projectRoot2(), fullPath),
24284
24423
  size: st.size,
24285
24424
  mtime: Math.floor(st.mtimeMs / 1e3),
24286
24425
  language: languageFor(fullPath)
@@ -24387,7 +24526,6 @@ var projectIndex_exports = {};
24387
24526
  __export(projectIndex_exports, {
24388
24527
  ProjectIndex: () => ProjectIndex
24389
24528
  });
24390
- import * as path7 from "node:path";
24391
24529
  import * as fs7 from "node:fs";
24392
24530
  function scoreSearchEntry(query, rel, entry) {
24393
24531
  let score = rel.toLowerCase().includes(query) ? 10 : 0;
@@ -24420,7 +24558,7 @@ var init_projectIndex = __esm({
24420
24558
  const found = [];
24421
24559
  walk(root, found);
24422
24560
  for (const fp of found) {
24423
- const rel = path7.relative(root, fp);
24561
+ const rel = indexKey(root, fp);
24424
24562
  seen.add(rel);
24425
24563
  let mtime;
24426
24564
  try {
@@ -24446,7 +24584,7 @@ var init_projectIndex = __esm({
24446
24584
  updated,
24447
24585
  removed: removed.length,
24448
24586
  total: Object.keys(files).length,
24449
- path: path7.relative(root, indexPath())
24587
+ path: indexKey(root, indexPath())
24450
24588
  };
24451
24589
  },
24452
24590
  search(query, limit = 20) {
@@ -24998,23 +25136,23 @@ __export(docs_exports, {
24998
25136
  returnFromSignature: () => returnFromSignature
24999
25137
  });
25000
25138
  import * as fs8 from "node:fs";
25001
- import * as path8 from "node:path";
25002
- import { fileURLToPath as fileURLToPath5 } from "node:url";
25139
+ import * as path7 from "node:path";
25140
+ import { fileURLToPath as fileURLToPath6 } from "node:url";
25003
25141
  function detectFrameworkRoots() {
25004
- const corePackageRoot = path8.resolve(__DIRNAME, "..");
25005
- const packagesRoot = path8.resolve(corePackageRoot, "..");
25142
+ const corePackageRoot = path7.resolve(__DIRNAME, "..");
25143
+ const packagesRoot = path7.resolve(corePackageRoot, "..");
25006
25144
  const roots = [];
25007
25145
  for (const pkg of ["core", "orm", "swagger", "frond"]) {
25008
- const dir = path8.join(packagesRoot, pkg, "src");
25146
+ const dir = path7.join(packagesRoot, pkg, "src");
25009
25147
  if (fs8.existsSync(dir)) roots.push(dir);
25010
25148
  }
25011
25149
  return roots;
25012
25150
  }
25013
25151
  function detectVersion(projectRoot3) {
25014
25152
  for (const candidate of [
25015
- path8.join(projectRoot3, "package.json"),
25016
- path8.resolve(__DIRNAME, "..", "..", "..", "package.json"),
25017
- path8.resolve(__DIRNAME, "..", "package.json")
25153
+ path7.join(projectRoot3, "package.json"),
25154
+ path7.resolve(__DIRNAME, "..", "..", "..", "package.json"),
25155
+ path7.resolve(__DIRNAME, "..", "package.json")
25018
25156
  ]) {
25019
25157
  try {
25020
25158
  const pkg = JSON.parse(fs8.readFileSync(candidate, "utf-8"));
@@ -25025,16 +25163,16 @@ function detectVersion(projectRoot3) {
25025
25163
  return "0.0.0";
25026
25164
  }
25027
25165
  function relativePath(absPath, projectRoot3, frameworkRoots) {
25028
- const norm = path8.resolve(absPath);
25166
+ const norm = path7.resolve(absPath);
25029
25167
  for (const fw of frameworkRoots) {
25030
- const parent = path8.dirname(fw);
25031
- if (norm.startsWith(parent + path8.sep)) {
25032
- const monorepo = path8.resolve(parent, "..", "..");
25033
- if (norm.startsWith(monorepo + path8.sep)) return path8.relative(monorepo, norm);
25034
- return path8.relative(parent, norm);
25168
+ const parent = path7.dirname(fw);
25169
+ if (norm.startsWith(parent + path7.sep)) {
25170
+ const monorepo = path7.resolve(parent, "..", "..");
25171
+ if (norm.startsWith(monorepo + path7.sep)) return path7.relative(monorepo, norm);
25172
+ return path7.relative(parent, norm);
25035
25173
  }
25036
25174
  }
25037
- if (norm.startsWith(projectRoot3 + path8.sep)) return path8.relative(projectRoot3, norm);
25175
+ if (norm.startsWith(projectRoot3 + path7.sep)) return path7.relative(projectRoot3, norm);
25038
25176
  return norm;
25039
25177
  }
25040
25178
  function tokenise(text) {
@@ -25074,12 +25212,12 @@ function walkTsFiles(root) {
25074
25212
  if (e.name.startsWith(".")) continue;
25075
25213
  if (e.isDirectory()) {
25076
25214
  if (e.name === "node_modules" || e.name === "tests" || e.name === "test" || e.name === "dist" || e.name === "build") continue;
25077
- visit(path8.join(dir, e.name));
25215
+ visit(path7.join(dir, e.name));
25078
25216
  } else if (e.isFile()) {
25079
25217
  if (!e.name.endsWith(".ts") && !e.name.endsWith(".js") && !e.name.endsWith(".mjs")) continue;
25080
25218
  if (e.name.endsWith(".test.ts") || e.name.endsWith(".test.js")) continue;
25081
25219
  if (e.name.endsWith(".d.ts")) continue;
25082
- found.push(path8.join(dir, e.name));
25220
+ found.push(path7.join(dir, e.name));
25083
25221
  }
25084
25222
  }
25085
25223
  }
@@ -25406,8 +25544,8 @@ var init_docs = __esm({
25406
25544
  "hash"
25407
25545
  ]);
25408
25546
  _DOCS_CACHE = /* @__PURE__ */ new Map();
25409
- __FILENAME = fileURLToPath5(import.meta.url);
25410
- __DIRNAME = path8.dirname(__FILENAME);
25547
+ __FILENAME = fileURLToPath6(import.meta.url);
25548
+ __DIRNAME = path7.dirname(__FILENAME);
25411
25549
  USER_DIRS = ["src/orm", "src/routes", "src/app", "src/services", "src/models"];
25412
25550
  FENCE_RE = new RegExp(
25413
25551
  String.fromCharCode(96, 96, 96) + "[a-zA-Z0-9_+-]*\\n([\\s\\S]*?)\\n" + String.fromCharCode(96, 96, 96),
@@ -25425,7 +25563,7 @@ var init_docs = __esm({
25425
25563
  userMtime = 0;
25426
25564
  frameworkMtime = 0;
25427
25565
  constructor(projectRoot3) {
25428
- this.projectRoot = path8.resolve(projectRoot3);
25566
+ this.projectRoot = path7.resolve(projectRoot3);
25429
25567
  this.frameworkRoots = detectFrameworkRoots();
25430
25568
  this.version = detectVersion(this.projectRoot);
25431
25569
  }
@@ -25617,7 +25755,7 @@ var init_docs = __esm({
25617
25755
  // ── Drift detector + sync ────────────────────────────────────────
25618
25756
  static checkDocs(mdPath, projectRoot3) {
25619
25757
  if (!fs8.existsSync(mdPath)) return { drift: [] };
25620
- const docs = _Docs.cached(projectRoot3 ?? path8.dirname(mdPath));
25758
+ const docs = _Docs.cached(projectRoot3 ?? path7.dirname(mdPath));
25621
25759
  const idx = docs.index();
25622
25760
  const known = /* @__PURE__ */ new Set();
25623
25761
  for (const e of idx) known.add(e.name.toLowerCase());
@@ -25644,7 +25782,7 @@ var init_docs = __esm({
25644
25782
  return { drift };
25645
25783
  }
25646
25784
  static syncDocs(mdPath, projectRoot3) {
25647
- const docs = _Docs.cached(projectRoot3 ?? (fs8.existsSync(mdPath) ? path8.dirname(mdPath) : process.cwd()));
25785
+ const docs = _Docs.cached(projectRoot3 ?? (fs8.existsSync(mdPath) ? path7.dirname(mdPath) : process.cwd()));
25648
25786
  const generated = docs.renderGeneratedBlock();
25649
25787
  const begin = "<!-- BEGIN GENERATED API -->";
25650
25788
  const end = "<!-- END GENERATED API -->";
@@ -25668,7 +25806,7 @@ ${end}
25668
25806
  }
25669
25807
  // ── Internals ────────────────────────────────────────────────────
25670
25808
  static cached(projectRoot3) {
25671
- const key = path8.resolve(projectRoot3 ?? process.cwd());
25809
+ const key = path7.resolve(projectRoot3 ?? process.cwd());
25672
25810
  let inst = _DOCS_CACHE.get(key);
25673
25811
  if (!inst) {
25674
25812
  inst = new _Docs(key);
@@ -25695,11 +25833,11 @@ ${end}
25695
25833
  this.frameworkMtime = shared.mtime;
25696
25834
  this.indexCache = null;
25697
25835
  }
25698
- const userMtime = this.maxMtime(USER_DIRS.map((d) => path8.join(this.projectRoot, d)));
25836
+ const userMtime = this.maxMtime(USER_DIRS.map((d) => path7.join(this.projectRoot, d)));
25699
25837
  if (this.indexCache === null || userMtime !== this.userMtime) {
25700
25838
  this.userEntries = /* @__PURE__ */ new Map();
25701
25839
  for (const sub of USER_DIRS) {
25702
- const dir = path8.join(this.projectRoot, sub);
25840
+ const dir = path7.join(this.projectRoot, sub);
25703
25841
  if (!fs8.existsSync(dir)) continue;
25704
25842
  for (const f of walkTsFiles(dir)) {
25705
25843
  buildEntriesForFile(f, "user", this.frameworkRoots, this.projectRoot, this.version, this.userEntries);
@@ -25782,9 +25920,9 @@ ${end}
25782
25920
 
25783
25921
  // ../core/src/devAdmin.ts
25784
25922
  import { cpus as osCpus } from "node:os";
25785
- import { readFileSync as readFileSync18, writeFileSync as writeFileSync13, existsSync as existsSync20, readdirSync as readdirSync13, mkdirSync as mkdirSync14, copyFileSync as copyFileSync2, statSync as statSync15, openSync as openSync5, closeSync as closeSync5, fstatSync as fstatSync3, fchmodSync as fchmodSync2, ftruncateSync as ftruncateSync2, constants as constants4, realpathSync as realpathSync6, lstatSync as lstatSync3 } from "node:fs";
25786
- import { join as join22, dirname as dirname11, resolve as resolve12, relative as relative9, sep as sep6, basename as basename5 } from "node:path";
25787
- import { fileURLToPath as fileURLToPath6 } from "node:url";
25923
+ import { readFileSync as readFileSync18, writeFileSync as writeFileSync13, existsSync as existsSync21, readdirSync as readdirSync13, mkdirSync as mkdirSync14, copyFileSync as copyFileSync2, statSync as statSync16, openSync as openSync5, closeSync as closeSync5, fstatSync as fstatSync3, fchmodSync as fchmodSync2, ftruncateSync as ftruncateSync2, constants as constants4, realpathSync as realpathSync6, lstatSync as lstatSync3 } from "node:fs";
25924
+ import { join as join23, dirname as dirname11, resolve as resolve12, relative as relative8, sep as sep7, basename as basename5 } from "node:path";
25925
+ import { fileURLToPath as fileURLToPath7 } from "node:url";
25788
25926
  import { timingSafeEqual as timingSafeEqual2 } from "node:crypto";
25789
25927
  import net2 from "node:net";
25790
25928
  function escapeHtml2(value) {
@@ -25862,15 +26000,15 @@ function devToolbarAllowed(req2) {
25862
26000
  return devPeerAllowed(peer);
25863
26001
  }
25864
26002
  function devRequestDenial(req2) {
25865
- const path10 = (req2.path ?? "").replace(/\/+/g, "/");
25866
- const isMcp = DEV_MCP_PREFIXES.some((prefix) => path10 === prefix || path10.startsWith(prefix + "/"));
26003
+ const path9 = (req2.path ?? "").replace(/\/+/g, "/");
26004
+ const isMcp = DEV_MCP_PREFIXES.some((prefix) => path9 === prefix || path9.startsWith(prefix + "/"));
25867
26005
  if (!devHostAllowed(req2.header("host"))) {
25868
26006
  return { status: 403, error: "dev-admin: refused (host not allowed)" };
25869
26007
  }
25870
26008
  if (!devSameOriginOk(req2)) {
25871
26009
  return { status: 403, error: "dev-admin: refused (cross-origin request)" };
25872
26010
  }
25873
- if (DEV_PUBLIC_ASSETS.has(path10)) {
26011
+ if (DEV_PUBLIC_ASSETS.has(path9)) {
25874
26012
  return null;
25875
26013
  }
25876
26014
  if (!isMcp) {
@@ -25962,12 +26100,12 @@ function mapQueueJob(job, topic, status2) {
25962
26100
  };
25963
26101
  }
25964
26102
  function readQueueDir(dir, topic, status2) {
25965
- if (!existsSync20(dir)) return [];
26103
+ if (!existsSync21(dir)) return [];
25966
26104
  const jobs = [];
25967
26105
  for (const filename of readdirSync13(dir).sort()) {
25968
26106
  if (!filename.endsWith(".queue-data")) continue;
25969
26107
  try {
25970
- jobs.push(mapQueueJob(JSON.parse(readFileSync18(join22(dir, filename), "utf-8")), topic, status2));
26108
+ jobs.push(mapQueueJob(JSON.parse(readFileSync18(join23(dir, filename), "utf-8")), topic, status2));
25971
26109
  } catch {
25972
26110
  }
25973
26111
  }
@@ -26104,8 +26242,8 @@ async function proxyToSupervisor(req2, res, downstreamPath) {
26104
26242
  function resolveDevEnvVar(key) {
26105
26243
  const live = process.env[key];
26106
26244
  if (live !== void 0 && live !== "") return live;
26107
- const envPath = join22(process.cwd(), ".env");
26108
- if (!existsSync20(envPath)) return "";
26245
+ const envPath = join23(process.cwd(), ".env");
26246
+ if (!existsSync21(envPath)) return "";
26109
26247
  for (const line of readFileSync18(envPath, "utf-8").split("\n")) {
26110
26248
  const t = line.trim();
26111
26249
  if (!t || t.startsWith("#") || !t.includes("=")) continue;
@@ -26115,8 +26253,8 @@ function resolveDevEnvVar(key) {
26115
26253
  return "";
26116
26254
  }
26117
26255
  function upsertDevEnvVar(key, value) {
26118
- const envPath = join22(process.cwd(), ".env");
26119
- const lines = existsSync20(envPath) ? readFileSync18(envPath, "utf-8").split("\n") : [];
26256
+ const envPath = join23(process.cwd(), ".env");
26257
+ const lines = existsSync21(envPath) ? readFileSync18(envPath, "utf-8").split("\n") : [];
26120
26258
  let found = false;
26121
26259
  const out = [];
26122
26260
  for (const line of lines) {
@@ -26146,9 +26284,9 @@ function formatUptime(seconds) {
26146
26284
  return parts.join(" ");
26147
26285
  }
26148
26286
  function parseEnvFile() {
26149
- const envPath = join22(process.cwd(), ".env");
26287
+ const envPath = join23(process.cwd(), ".env");
26150
26288
  const result = {};
26151
- if (!existsSync20(envPath)) return result;
26289
+ if (!existsSync21(envPath)) return result;
26152
26290
  const lines = readFileSync18(envPath, "utf-8").split("\n");
26153
26291
  for (const line of lines) {
26154
26292
  const trimmed = line.trim();
@@ -26160,10 +26298,10 @@ function parseEnvFile() {
26160
26298
  }
26161
26299
  function walkDirRecursive(dir) {
26162
26300
  const results = [];
26163
- if (!existsSync20(dir)) return results;
26301
+ if (!existsSync21(dir)) return results;
26164
26302
  for (const entry of readdirSync13(dir)) {
26165
- const full = join22(dir, entry);
26166
- if (statSync15(full).isDirectory()) {
26303
+ const full = join23(dir, entry);
26304
+ if (statSync16(full).isDirectory()) {
26167
26305
  results.push(...walkDirRecursive(full));
26168
26306
  } else {
26169
26307
  results.push(full);
@@ -26180,8 +26318,8 @@ function handleGalleryDeploy(router) {
26180
26318
  return;
26181
26319
  }
26182
26320
  const galleryDir = resolve12(__devAdminDirname, "..", "gallery");
26183
- const gallerySrc = join22(galleryDir, name, "src");
26184
- if (!existsSync20(gallerySrc)) {
26321
+ const gallerySrc = join23(galleryDir, name, "src");
26322
+ if (!existsSync21(gallerySrc)) {
26185
26323
  res.json({ error: `Gallery item '${name}' not found` }, 404);
26186
26324
  return;
26187
26325
  }
@@ -26189,15 +26327,15 @@ function handleGalleryDeploy(router) {
26189
26327
  const copied = [];
26190
26328
  const allFiles = walkDirRecursive(gallerySrc);
26191
26329
  for (const srcFile of allFiles) {
26192
- const rel = relative9(gallerySrc, srcFile);
26193
- const dest = join22(projectSrc, rel);
26330
+ const rel = relative8(gallerySrc, srcFile);
26331
+ const dest = join23(projectSrc, rel);
26194
26332
  mkdirSync14(dirname11(dest), { recursive: true });
26195
26333
  copyFileSync2(srcFile, dest);
26196
26334
  copied.push(rel);
26197
26335
  }
26198
26336
  try {
26199
26337
  const routesDir = resolve12(process.cwd(), "src", "routes");
26200
- if (existsSync20(routesDir)) {
26338
+ if (existsSync21(routesDir)) {
26201
26339
  const { discoverRoutes: discoverRoutes2 } = await Promise.resolve().then(() => (init_routeDiscovery(), routeDiscovery_exports));
26202
26340
  const routes = await discoverRoutes2(routesDir);
26203
26341
  for (const route of routes) {
@@ -26226,7 +26364,7 @@ function realPathOf2(target) {
26226
26364
  tail.unshift(basename5(existing));
26227
26365
  existing = dirname11(existing);
26228
26366
  }
26229
- return join22(realpathSync6(existing), ...tail);
26367
+ return join23(realpathSync6(existing), ...tail);
26230
26368
  }
26231
26369
  function safeJoin(projectRoot3, rel, extraRoots = []) {
26232
26370
  try {
@@ -26234,14 +26372,14 @@ function safeJoin(projectRoot3, rel, extraRoots = []) {
26234
26372
  const resolved = realPathOf2(resolve12(root, rel));
26235
26373
  const roots = [root, ...extraRoots.filter(Boolean).map((r) => realPathOf2(resolve12(r)))];
26236
26374
  for (const r of roots) {
26237
- if (resolved === r || resolved.startsWith(r.endsWith(sep6) ? r : r + sep6)) return resolved;
26375
+ if (resolved === r || resolved.startsWith(r.endsWith(sep7) ? r : r + sep7)) return resolved;
26238
26376
  }
26239
26377
  } catch {
26240
26378
  }
26241
26379
  return null;
26242
26380
  }
26243
26381
  function resolvedRelative(projectRoot3, resolvedPath) {
26244
- return relative9(realPathOf2(resolve12(projectRoot3)), resolvedPath);
26382
+ return relative8(realPathOf2(resolve12(projectRoot3)), resolvedPath);
26245
26383
  }
26246
26384
  function devFilesHidden(name) {
26247
26385
  if (DEV_FILES_IGNORED.has(name)) return true;
@@ -26257,10 +26395,10 @@ function devGitStatusLabel(code) {
26257
26395
  async function devGitInfo(root) {
26258
26396
  const empty = { branch: "", gitRoot: null, status: /* @__PURE__ */ new Map() };
26259
26397
  try {
26260
- const { execFileSync: execFileSync6 } = await import("node:child_process");
26398
+ const { execFileSync: execFileSync5 } = await import("node:child_process");
26261
26399
  const git = (args) => {
26262
26400
  try {
26263
- return execFileSync6("git", args, { cwd: root, timeout: 3e3, encoding: "utf-8" }).toString();
26401
+ return execFileSync5("git", args, { cwd: root, timeout: 3e3, encoding: "utf-8" }).toString();
26264
26402
  } catch {
26265
26403
  return null;
26266
26404
  }
@@ -26312,7 +26450,7 @@ function buildFileEntry(name, full, entryRel, cwdInGit, gitStatus) {
26312
26450
  let isDir = false;
26313
26451
  let size = null;
26314
26452
  try {
26315
- const st = statSync15(full);
26453
+ const st = statSync16(full);
26316
26454
  isDir = st.isDirectory();
26317
26455
  if (!isDir) size = st.size;
26318
26456
  } catch {
@@ -26387,7 +26525,7 @@ function applyMcpOutcome(res, outcome) {
26387
26525
  function renderToolbarHtml(ctx) {
26388
26526
  const nodeVersion = process.version;
26389
26527
  const method = escapeHtml2(ctx.method);
26390
- const path10 = escapeHtml2(ctx.path);
26528
+ const path9 = escapeHtml2(ctx.path);
26391
26529
  const matchedPattern = escapeHtml2(ctx.matchedPattern);
26392
26530
  const reload = ctx.reload === false ? "0" : "1";
26393
26531
  return `<link rel="stylesheet" href="/__dev/toolbar.css">
@@ -26404,7 +26542,7 @@ function renderToolbarHtml(ctx) {
26404
26542
  </div>
26405
26543
  </div>
26406
26544
  <span class="t4-green">${method}</span>
26407
- <span>${path10}</span>
26545
+ <span>${path9}</span>
26408
26546
  <span class="t4-arrow">&rarr; ${matchedPattern}</span>
26409
26547
  <span class="t4-yellow">req:${ctx.requestId}</span>
26410
26548
  <span class="t4-blue">${ctx.routeCount} routes</span>
@@ -26579,6 +26717,7 @@ var init_devAdmin = __esm({
26579
26717
  "../core/src/devAdmin.ts"() {
26580
26718
  "use strict";
26581
26719
  init_slashTrim();
26720
+ init_batchSpawn();
26582
26721
  init_devMailbox();
26583
26722
  init_upstreamResponse();
26584
26723
  init_dotenv();
@@ -26640,12 +26779,12 @@ var init_devAdmin = __esm({
26640
26779
  RequestInspector = class {
26641
26780
  static requests = [];
26642
26781
  static maxRequests = 200;
26643
- static capture(method, path10, status2, duration) {
26782
+ static capture(method, path9, status2, duration) {
26644
26783
  const entry = {
26645
26784
  id: `${Date.now()}_${this.requests.length}`,
26646
26785
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
26647
26786
  method,
26648
- path: path10,
26787
+ path: path9,
26649
26788
  status: status2,
26650
26789
  durationMs: Math.round(duration * 100) / 100
26651
26790
  };
@@ -26834,12 +26973,12 @@ var init_devAdmin = __esm({
26834
26973
  };
26835
26974
  WsTracker = class {
26836
26975
  static connections = [];
26837
- static add(remoteAddress, path10) {
26976
+ static add(remoteAddress, path9) {
26838
26977
  const conn = {
26839
26978
  id: `ws_${Date.now()}_${this.connections.length}`,
26840
26979
  connectedAt: (/* @__PURE__ */ new Date()).toISOString(),
26841
26980
  remoteAddress,
26842
- path: path10
26981
+ path: path9
26843
26982
  };
26844
26983
  this.connections.push(conn);
26845
26984
  return conn.id;
@@ -26949,7 +27088,7 @@ var init_devAdmin = __esm({
26949
27088
  const p = (url.searchParams.get("path") || "").toString();
26950
27089
  const scanRoot = metricsScanRoot();
26951
27090
  let target = p ? safeJoin(process.cwd(), p, [scanRoot]) : "";
26952
- if (target === null && scanRoot) target = safeJoin(process.cwd(), join22(scanRoot, p), [scanRoot]);
27091
+ if (target === null && scanRoot) target = safeJoin(process.cwd(), join23(scanRoot, p), [scanRoot]);
26953
27092
  if (target === null) {
26954
27093
  res.status(403).json({ error: "Path outside project" });
26955
27094
  return;
@@ -27187,6 +27326,7 @@ var init_devAdmin = __esm({
27187
27326
  const mem = process.memoryUsage();
27188
27327
  const heapUsedMb = Math.round(mem.heapUsed / 1048576);
27189
27328
  const rssMb = Math.round(mem.rss / 1048576);
27329
+ const peakRssMb = Math.round(process.resourceUsage().maxRSS / 1024);
27190
27330
  let dbTableCount;
27191
27331
  let dbConnected = false;
27192
27332
  try {
@@ -27203,12 +27343,14 @@ var init_devAdmin = __esm({
27203
27343
  architecture: process.arch,
27204
27344
  os: `${process.platform} ${process.arch}`,
27205
27345
  pid: process.pid,
27206
- memory_mb: heapUsedMb,
27346
+ // The dashboard's "Memory": the process's current RSS, as tina4-python
27347
+ // reports it. V8's heapUsed (below) leaves out Buffers and native memory.
27348
+ memory_mb: rssMb,
27207
27349
  db_tables: dbTableCount !== void 0 ? dbTableCount : "N/A",
27208
27350
  db_connected: dbConnected,
27209
27351
  memory: {
27210
- current_mb: heapUsedMb,
27211
- peak_mb: rssMb,
27352
+ current_mb: rssMb,
27353
+ peak_mb: peakRssMb,
27212
27354
  limit: "V8 default",
27213
27355
  rss: `${rssMb} MB`,
27214
27356
  heapUsed: `${heapUsedMb} MB`,
@@ -27267,16 +27409,16 @@ var init_devAdmin = __esm({
27267
27409
  failed: queue.size("failed"),
27268
27410
  reserved: queue.size("reserved")
27269
27411
  };
27270
- const topicDir = join22(queueBasePath2(), topic);
27412
+ const topicDir = join23(queueBasePath2(), topic);
27271
27413
  const jobs = [];
27272
27414
  if (!statusFilter || statusFilter === "pending") {
27273
27415
  jobs.push(...readQueueDir(topicDir, topic, "pending"));
27274
27416
  }
27275
27417
  if (!statusFilter || statusFilter === "reserved") {
27276
- jobs.push(...readQueueDir(join22(topicDir, "reserved"), topic, "reserved"));
27418
+ jobs.push(...readQueueDir(join23(topicDir, "reserved"), topic, "reserved"));
27277
27419
  }
27278
27420
  if (!statusFilter || statusFilter === "failed" || statusFilter === "dead") {
27279
- jobs.push(...readQueueDir(join22(topicDir, "failed"), topic, "dead_letter"));
27421
+ jobs.push(...readQueueDir(join23(topicDir, "failed"), topic, "dead_letter"));
27280
27422
  }
27281
27423
  res.json({ stats, jobs });
27282
27424
  } catch (e) {
@@ -27292,10 +27434,10 @@ var init_devAdmin = __esm({
27292
27434
  const { queueBasePath: queueBasePath2 } = await Promise.resolve().then(() => (init_queue(), queue_exports));
27293
27435
  const queueDir = queueBasePath2();
27294
27436
  let topics = [];
27295
- if (existsSync20(queueDir)) {
27437
+ if (existsSync21(queueDir)) {
27296
27438
  topics = readdirSync13(queueDir).filter((d) => {
27297
27439
  try {
27298
- return statSync15(join22(queueDir, d)).isDirectory();
27440
+ return statSync16(join23(queueDir, d)).isDirectory();
27299
27441
  } catch {
27300
27442
  return false;
27301
27443
  }
@@ -27580,7 +27722,7 @@ var init_devAdmin = __esm({
27580
27722
  const count = parseInt(String(body.count ?? "10"), 10) || 10;
27581
27723
  try {
27582
27724
  const orm = await Promise.resolve().then(() => (init_index(), index_exports));
27583
- const dirs = ["src/orm", "src/models"].map((d) => resolve12(process.cwd(), d)).filter((d) => existsSync20(d));
27725
+ const dirs = ["src/orm", "src/models"].map((d) => resolve12(process.cwd(), d)).filter((d) => existsSync21(d));
27584
27726
  const classes = [];
27585
27727
  for (const dir of dirs) {
27586
27728
  for (const m of await orm.discoverModels(dir)) classes.push(m.modelClass);
@@ -27721,7 +27863,7 @@ var init_devAdmin = __esm({
27721
27863
  return;
27722
27864
  }
27723
27865
  try {
27724
- const envPath = join22(process.cwd(), ".env");
27866
+ const envPath = join23(process.cwd(), ".env");
27725
27867
  const fd = openSync5(envPath, constants4.O_RDWR | constants4.O_APPEND | constants4.O_CREAT | (constants4.O_NOFOLLOW ?? 0) | (constants4.O_NONBLOCK ?? 0), 384);
27726
27868
  try {
27727
27869
  const info = fstatSync3(fd);
@@ -27765,29 +27907,29 @@ var init_devAdmin = __esm({
27765
27907
  res.json({ success: false, error: msg });
27766
27908
  }
27767
27909
  };
27768
- __devAdminFilename = fileURLToPath6(import.meta.url);
27910
+ __devAdminFilename = fileURLToPath7(import.meta.url);
27769
27911
  __devAdminDirname = dirname11(__devAdminFilename);
27770
27912
  handleGalleryList = (_req, res) => {
27771
27913
  const galleryDir = resolve12(__devAdminDirname, "..", "gallery");
27772
27914
  const items = [];
27773
- if (existsSync20(galleryDir)) {
27915
+ if (existsSync21(galleryDir)) {
27774
27916
  const entries = readdirSync13(galleryDir).sort();
27775
27917
  for (const entry of entries) {
27776
- const entryPath = join22(galleryDir, entry);
27777
- const metaFile = join22(entryPath, "meta.json");
27778
- if (statSync15(entryPath).isDirectory() && existsSync20(metaFile)) {
27918
+ const entryPath = join23(galleryDir, entry);
27919
+ const metaFile = join23(entryPath, "meta.json");
27920
+ if (statSync16(entryPath).isDirectory() && existsSync21(metaFile)) {
27779
27921
  try {
27780
27922
  const meta = JSON.parse(readFileSync18(metaFile, "utf-8"));
27781
27923
  meta.id = entry;
27782
- const srcDir = join22(entryPath, "src");
27783
- if (existsSync20(srcDir)) {
27924
+ const srcDir = join23(entryPath, "src");
27925
+ if (existsSync21(srcDir)) {
27784
27926
  const allFiles = walkDirRecursive(srcDir);
27785
- meta.files = allFiles.map((f) => relative9(srcDir, f));
27927
+ meta.files = allFiles.map((f) => relative8(srcDir, f));
27786
27928
  }
27787
27929
  const projectSrc = resolve12(process.cwd(), "src");
27788
- if (existsSync20(srcDir) && meta.files) {
27930
+ if (existsSync21(srcDir) && meta.files) {
27789
27931
  meta.deployed = meta.files.every(
27790
- (f) => existsSync20(join22(projectSrc, f))
27932
+ (f) => existsSync21(join23(projectSrc, f))
27791
27933
  );
27792
27934
  } else {
27793
27935
  meta.deployed = false;
@@ -27864,7 +28006,7 @@ var init_devAdmin = __esm({
27864
28006
  const root = resolve12(process.cwd());
27865
28007
  const target = safeJoin(root, rel);
27866
28008
  const { branch, gitRoot, status: gitStatus } = await devGitInfo(root);
27867
- if (!target || !existsSync20(target) || !statSync15(target).isDirectory()) {
28009
+ if (!target || !existsSync21(target) || !statSync16(target).isDirectory()) {
27868
28010
  res.json({ path: rel, branch, entries: [], error: "not a directory" });
27869
28011
  return;
27870
28012
  }
@@ -27877,12 +28019,12 @@ var init_devAdmin = __esm({
27877
28019
  const entries = [];
27878
28020
  for (const name of readdirSync13(target).sort()) {
27879
28021
  if (devFilesHidden(name)) continue;
27880
- const full = join22(target, name);
27881
- const entryRel = relative9(root, full).replace(/\\/g, "/");
28022
+ const full = join23(target, name);
28023
+ const entryRel = relative8(root, full).replace(/\\/g, "/");
27882
28024
  if (isSecretPath(entryRel)) continue;
27883
28025
  entries.push(buildFileEntry(name, full, entryRel, cwdInGit, gitStatus));
27884
28026
  }
27885
- res.json({ path: relative9(root, target).replace(/\\/g, "/") || ".", branch, entries });
28027
+ res.json({ path: relative8(root, target).replace(/\\/g, "/") || ".", branch, entries });
27886
28028
  };
27887
28029
  DEV_ADMIN_LANG_MAP = {
27888
28030
  ".py": "python",
@@ -27940,8 +28082,8 @@ var init_devAdmin = __esm({
27940
28082
  return;
27941
28083
  }
27942
28084
  const content = data.toString("utf-8");
27943
- const path10 = relative9(root, target);
27944
- res.json({ path: path10, content, language: devAdminLanguage(path10), bytes: Buffer.byteLength(content, "utf-8") });
28085
+ const path9 = relative8(root, target);
28086
+ res.json({ path: path9, content, language: devAdminLanguage(path9), bytes: Buffer.byteLength(content, "utf-8") });
27945
28087
  } catch (e) {
27946
28088
  res.json({ error: e.message }, 500);
27947
28089
  }
@@ -27958,14 +28100,14 @@ var init_devAdmin = __esm({
27958
28100
  }
27959
28101
  try {
27960
28102
  mkdirSync14(dirname11(target), { recursive: true });
27961
- const existed = existsSync20(target);
28103
+ const existed = existsSync21(target);
27962
28104
  writeFileSync13(target, content, "utf-8");
27963
28105
  try {
27964
28106
  const { Plan: Plan2 } = await Promise.resolve().then(() => (init_plan(), plan_exports));
27965
- Plan2.recordAction(existed ? "patched" : "created", relative9(root, target));
28107
+ Plan2.recordAction(existed ? "patched" : "created", relative8(root, target));
27966
28108
  } catch {
27967
28109
  }
27968
- res.json({ ok: true, path: relative9(root, target), bytes: Buffer.byteLength(content, "utf-8") });
28110
+ res.json({ ok: true, path: relative8(root, target), bytes: Buffer.byteLength(content, "utf-8") });
27969
28111
  } catch (e) {
27970
28112
  res.json({ error: e.message }, 500);
27971
28113
  }
@@ -28023,7 +28165,7 @@ var init_devAdmin = __esm({
28023
28165
  res.json({ error: "Invalid path" }, 400);
28024
28166
  return;
28025
28167
  }
28026
- if (!existsSync20(src)) {
28168
+ if (!existsSync21(src)) {
28027
28169
  res.json({ error: `Source not found: ${from}` }, 404);
28028
28170
  return;
28029
28171
  }
@@ -28031,7 +28173,7 @@ var init_devAdmin = __esm({
28031
28173
  const { renameSync: renameSync3 } = await import("node:fs");
28032
28174
  mkdirSync14(dirname11(dst), { recursive: true });
28033
28175
  renameSync3(src, dst);
28034
- res.json({ ok: true, from: relative9(root, src), to: relative9(root, dst) });
28176
+ res.json({ ok: true, from: relative8(root, src), to: relative8(root, dst) });
28035
28177
  } catch (e) {
28036
28178
  res.json({ error: e.message }, 500);
28037
28179
  }
@@ -28045,14 +28187,14 @@ var init_devAdmin = __esm({
28045
28187
  res.json({ error: "Invalid path" }, 400);
28046
28188
  return;
28047
28189
  }
28048
- if (!existsSync20(target)) {
28190
+ if (!existsSync21(target)) {
28049
28191
  res.json({ error: `Not found: ${rel}` }, 404);
28050
28192
  return;
28051
28193
  }
28052
28194
  try {
28053
28195
  const { rmSync: rmSync2 } = await import("node:fs");
28054
28196
  rmSync2(target, { recursive: true, force: true });
28055
- res.json({ ok: true, deleted: relative9(root, target) });
28197
+ res.json({ ok: true, deleted: relative8(root, target) });
28056
28198
  } catch (e) {
28057
28199
  res.json({ error: e.message }, 500);
28058
28200
  }
@@ -28087,13 +28229,11 @@ var init_devAdmin = __esm({
28087
28229
  return;
28088
28230
  }
28089
28231
  try {
28090
- const { execFileSync: execFileSync6 } = await import("node:child_process");
28091
28232
  const args = ["install", dev ? "--save-dev" : "--save", pkg];
28092
- const output = execFileSync6("npm", args, {
28233
+ const output = execFileSyncAllowingBatch("npm", args, {
28093
28234
  cwd: resolve12(process.cwd()),
28094
- timeout: 12e4,
28095
- encoding: "utf-8"
28096
- }).toString();
28235
+ timeout: 12e4
28236
+ });
28097
28237
  res.json({ ok: true, package: pkg, output });
28098
28238
  } catch (e) {
28099
28239
  res.json({ error: e.message }, 500);
@@ -28101,15 +28241,15 @@ var init_devAdmin = __esm({
28101
28241
  };
28102
28242
  handleGitStatus = async (_req, res) => {
28103
28243
  try {
28104
- const { execFileSync: execFileSync6 } = await import("node:child_process");
28244
+ const { execFileSync: execFileSync5 } = await import("node:child_process");
28105
28245
  const cwd = resolve12(process.cwd());
28106
28246
  try {
28107
- execFileSync6("git", ["rev-parse", "--is-inside-work-tree"], { cwd, timeout: 3e3 });
28247
+ execFileSync5("git", ["rev-parse", "--is-inside-work-tree"], { cwd, timeout: 3e3 });
28108
28248
  } catch {
28109
28249
  res.json({ error: "Not a git repository" }, 400);
28110
28250
  return;
28111
28251
  }
28112
- const run = (args) => execFileSync6("git", args, { cwd, timeout: 3e3, encoding: "utf-8" }).toString().trim();
28252
+ const run = (args) => execFileSync5("git", args, { cwd, timeout: 3e3, encoding: "utf-8" }).toString().trim();
28113
28253
  res.json({
28114
28254
  branch: run(["branch", "--show-current"]),
28115
28255
  status: run(["status", "--porcelain"]).split(/\r?\n/).filter((l) => l),
@@ -28239,12 +28379,10 @@ var init_devAdmin = __esm({
28239
28379
  return;
28240
28380
  }
28241
28381
  try {
28242
- const { execFileSync: execFileSync6 } = await import("node:child_process");
28243
- const output = execFileSync6("npx", ["tina4nodejs", "generate", kind, name], {
28382
+ const output = execFileSyncAllowingBatch("npx", ["tina4nodejs", "generate", kind, name], {
28244
28383
  cwd: resolve12(process.cwd()),
28245
- timeout: 3e4,
28246
- encoding: "utf-8"
28247
- }).toString();
28384
+ timeout: 3e4
28385
+ });
28248
28386
  res.json({ ok: true, kind, name, output });
28249
28387
  } catch (e) {
28250
28388
  res.json({ error: e.message }, 500);
@@ -28386,21 +28524,21 @@ var init_devAdmin = __esm({
28386
28524
  });
28387
28525
  };
28388
28526
  handleDevAdminJs = async (_req, res) => {
28389
- const { readFileSync: readFileSync27, existsSync: existsSync29 } = await import("node:fs");
28390
- const { dirname: dirname17, join: join33, resolve: resolve21 } = await import("node:path");
28391
- const { fileURLToPath: fileURLToPath10 } = await import("node:url");
28392
- const dir = dirname17(fileURLToPath10(import.meta.url));
28527
+ const { readFileSync: readFileSync27, existsSync: existsSync30 } = await import("node:fs");
28528
+ const { dirname: dirname17, join: join34, resolve: resolve21 } = await import("node:path");
28529
+ const { fileURLToPath: fileURLToPath11 } = await import("node:url");
28530
+ const dir = dirname17(fileURLToPath11(import.meta.url));
28393
28531
  const candidates = [
28394
- join33(dir, "..", "public", "js", "tina4-dev-admin.min.js"),
28532
+ join34(dir, "..", "public", "js", "tina4-dev-admin.min.js"),
28395
28533
  // src/../public/js/
28396
- join33(dir, "..", "..", "public", "js", "tina4-dev-admin.min.js"),
28534
+ join34(dir, "..", "..", "public", "js", "tina4-dev-admin.min.js"),
28397
28535
  // deeper nesting
28398
28536
  resolve21(process.cwd(), "node_modules", "tina4-nodejs", "packages", "core", "public", "js", "tina4-dev-admin.min.js"),
28399
28537
  resolve21(process.cwd(), "public", "js", "tina4-dev-admin.min.js")
28400
28538
  // project public/
28401
28539
  ];
28402
28540
  for (const jsPath of candidates) {
28403
- if (existsSync29(jsPath)) {
28541
+ if (existsSync30(jsPath)) {
28404
28542
  try {
28405
28543
  const content = readFileSync27(jsPath, "utf-8");
28406
28544
  res.raw.writeHead(200, { "Content-Type": "application/javascript; charset=utf-8", "Cache-Control": "no-cache" });
@@ -28414,20 +28552,20 @@ var init_devAdmin = __esm({
28414
28552
  res.raw.end("tina4-dev-admin.min.js not found");
28415
28553
  };
28416
28554
  handleDevAdminSplit = async (_req, res) => {
28417
- const { readFileSync: readFileSync27, existsSync: existsSync29 } = await import("node:fs");
28418
- const { dirname: dirname17, join: join33, resolve: resolve21 } = await import("node:path");
28419
- const { fileURLToPath: fileURLToPath10 } = await import("node:url");
28420
- const dir = dirname17(fileURLToPath10(import.meta.url));
28555
+ const { readFileSync: readFileSync27, existsSync: existsSync30 } = await import("node:fs");
28556
+ const { dirname: dirname17, join: join34, resolve: resolve21 } = await import("node:path");
28557
+ const { fileURLToPath: fileURLToPath11 } = await import("node:url");
28558
+ const dir = dirname17(fileURLToPath11(import.meta.url));
28421
28559
  const candidates = [
28422
- join33(dir, "..", "public", "js", "tina4-dev-admin-split.html"),
28423
- join33(dir, "..", "..", "public", "js", "tina4-dev-admin-split.html"),
28560
+ join34(dir, "..", "public", "js", "tina4-dev-admin-split.html"),
28561
+ join34(dir, "..", "..", "public", "js", "tina4-dev-admin-split.html"),
28424
28562
  resolve21(process.cwd(), "node_modules", "tina4-nodejs", "packages", "core", "public", "js", "tina4-dev-admin-split.html"),
28425
28563
  resolve21(process.cwd(), "public", "js", "tina4-dev-admin-split.html")
28426
28564
  ];
28427
- for (const path10 of candidates) {
28428
- if (existsSync29(path10)) {
28565
+ for (const path9 of candidates) {
28566
+ if (existsSync30(path9)) {
28429
28567
  try {
28430
- const content = readFileSync27(path10, "utf-8");
28568
+ const content = readFileSync27(path9, "utf-8");
28431
28569
  res.raw.writeHead(200, { "Content-Type": "text/html; charset=utf-8", "Cache-Control": "no-cache" });
28432
28570
  res.raw.end(content);
28433
28571
  return;
@@ -28450,8 +28588,8 @@ var init_devAdmin = __esm({
28450
28588
  });
28451
28589
 
28452
28590
  // ../core/src/i18n.ts
28453
- import { readFileSync as readFileSync19, readdirSync as readdirSync14, existsSync as existsSync21 } from "node:fs";
28454
- import { join as join23, resolve as resolve13 } from "node:path";
28591
+ import { readFileSync as readFileSync19, readdirSync as readdirSync14, existsSync as existsSync22 } from "node:fs";
28592
+ import { join as join24, resolve as resolve13 } from "node:path";
28455
28593
  var I18n;
28456
28594
  var init_i18n = __esm({
28457
28595
  "../core/src/i18n.ts"() {
@@ -28470,9 +28608,9 @@ var init_i18n = __esm({
28470
28608
  * Arg order is (locale, path) to match the Python master `I18n(locale, path)`
28471
28609
  * (BUG-7, BREAKING in 3.13.x — was previously (localeDir, defaultLocale)).
28472
28610
  */
28473
- constructor(locale, path10) {
28611
+ constructor(locale, path9) {
28474
28612
  this._localeDir = resolve13(
28475
- path10 ?? process.env.TINA4_LOCALE_DIR ?? "src/locales"
28613
+ path9 ?? process.env.TINA4_LOCALE_DIR ?? "src/locales"
28476
28614
  );
28477
28615
  this._defaultLocale = locale ?? process.env.TINA4_LOCALE ?? "en";
28478
28616
  this._currentLocale = this._defaultLocale;
@@ -28528,7 +28666,7 @@ var init_i18n = __esm({
28528
28666
  }
28529
28667
  /** List available locale codes based on JSON files in the locale directory. */
28530
28668
  availableLocales() {
28531
- if (!existsSync21(this._localeDir)) {
28669
+ if (!existsSync22(this._localeDir)) {
28532
28670
  return [this._defaultLocale];
28533
28671
  }
28534
28672
  try {
@@ -28544,8 +28682,8 @@ var init_i18n = __esm({
28544
28682
  if (this._translations.has(locale)) {
28545
28683
  return;
28546
28684
  }
28547
- const filePath = join23(this._localeDir, `${locale}.json`);
28548
- if (existsSync21(filePath)) {
28685
+ const filePath = join24(this._localeDir, `${locale}.json`);
28686
+ if (existsSync22(filePath)) {
28549
28687
  try {
28550
28688
  const raw = readFileSync19(filePath, "utf-8");
28551
28689
  const data = JSON.parse(raw);
@@ -28557,8 +28695,8 @@ var init_i18n = __esm({
28557
28695
  }
28558
28696
  }
28559
28697
  for (const ext of [".yml", ".yaml"]) {
28560
- const yamlPath = join23(this._localeDir, `${locale}${ext}`);
28561
- if (existsSync21(yamlPath)) {
28698
+ const yamlPath = join24(this._localeDir, `${locale}${ext}`);
28699
+ if (existsSync22(yamlPath)) {
28562
28700
  try {
28563
28701
  const raw = readFileSync19(yamlPath, "utf-8");
28564
28702
  const data = _I18n._parseSimpleYaml(raw);
@@ -30083,11 +30221,11 @@ __export(docsAutoDiscovery_exports, {
30083
30221
  writeMcpDiscovery: () => writeMcpDiscovery
30084
30222
  });
30085
30223
  import * as fs9 from "node:fs";
30086
- import * as path9 from "node:path";
30224
+ import * as path8 from "node:path";
30087
30225
  function writeMcpDiscovery(projectRoot3, port) {
30088
- const root = path9.resolve(projectRoot3);
30089
- const tinaDir = path9.join(root, TINA4_DIR);
30090
- const mcpPath = path9.join(tinaDir, MCP_FILE);
30226
+ const root = path8.resolve(projectRoot3);
30227
+ const tinaDir = path8.join(root, TINA4_DIR);
30228
+ const mcpPath = path8.join(tinaDir, MCP_FILE);
30091
30229
  const portStr = String(
30092
30230
  port || Number(process.env.TINA4_PORT) || Number(process.env.PORT) || 7148
30093
30231
  );
@@ -30114,9 +30252,9 @@ function writeMcpDiscovery(projectRoot3, port) {
30114
30252
  fs9.writeFileSync(mcpPath, desiredJson, "utf-8");
30115
30253
  wrote = true;
30116
30254
  }
30117
- const gitDir = path9.join(root, ".git");
30255
+ const gitDir = path8.join(root, ".git");
30118
30256
  if (fs9.existsSync(gitDir)) {
30119
- const gitignorePath = path9.join(root, ".gitignore");
30257
+ const gitignorePath = path8.join(root, ".gitignore");
30120
30258
  let contents = "";
30121
30259
  if (fs9.existsSync(gitignorePath)) {
30122
30260
  try {
@@ -30127,8 +30265,8 @@ function writeMcpDiscovery(projectRoot3, port) {
30127
30265
  const lines = contents.split(/\r?\n/);
30128
30266
  const already = lines.some((l) => l.trim() === GITIGNORE_LINE || l.trim() === ".tina4");
30129
30267
  if (!already) {
30130
- const sep9 = contents.endsWith("\n") || contents === "" ? "" : "\n";
30131
- fs9.writeFileSync(gitignorePath, `${contents}${sep9}${GITIGNORE_LINE}
30268
+ const sep10 = contents.endsWith("\n") || contents === "" ? "" : "\n";
30269
+ fs9.writeFileSync(gitignorePath, `${contents}${sep10}${GITIGNORE_LINE}
30132
30270
  `, "utf-8");
30133
30271
  }
30134
30272
  }
@@ -30146,11 +30284,11 @@ var init_docsAutoDiscovery = __esm({
30146
30284
 
30147
30285
  // ../core/src/server.ts
30148
30286
  import { randomBytes as randomBytes7 } from "node:crypto";
30149
- import { resolve as resolve15, dirname as dirname12, join as join25, relative as relative10 } from "node:path";
30150
- import { existsSync as existsSync23, readdirSync as readdirSync15, readFileSync as readFileSync21, statSync as statSync16 } from "node:fs";
30287
+ import { resolve as resolve15, dirname as dirname12, join as join26, relative as relative9 } from "node:path";
30288
+ import { existsSync as existsSync24, readdirSync as readdirSync15, readFileSync as readFileSync21, statSync as statSync17 } from "node:fs";
30151
30289
  import { isatty } from "node:tty";
30152
- import { fileURLToPath as fileURLToPath7 } from "node:url";
30153
- import { execFileSync as execFileSync3, execFile } from "node:child_process";
30290
+ import { fileURLToPath as fileURLToPath8 } from "node:url";
30291
+ import { execFile } from "node:child_process";
30154
30292
  import cluster from "node:cluster";
30155
30293
  import os2 from "node:os";
30156
30294
  function isSwaggerAssetPath(pathname) {
@@ -30184,9 +30322,35 @@ function swaggerAdvertised() {
30184
30322
  }
30185
30323
  return TRUTHY3.includes(raw);
30186
30324
  }
30325
+ function stripUrlCredentials(text) {
30326
+ return text.replace(/:\/\/[^/\s]*@/g, "://");
30327
+ }
30328
+ function isModuleNotFound(err) {
30329
+ const code = err?.code;
30330
+ return code === "ERR_MODULE_NOT_FOUND" || code === "MODULE_NOT_FOUND";
30331
+ }
30332
+ function reportOrmBootFailure(stage, err, dbConfig) {
30333
+ const message = stripUrlCredentials(err instanceof Error ? err.message : String(err));
30334
+ if (stage === "connect") {
30335
+ const url = (process.env.TINA4_DATABASE_URL ?? "").trim();
30336
+ const target = url ? stripUrlCredentials(url) : `${dbConfig.type ?? "sqlite"} ${dbConfig.path ?? "./data/tina4.db"}`;
30337
+ bootDbConnectError = message;
30338
+ console.warn(`
30339
+ Database could not be reached (${target}): ${message}`);
30340
+ } else if (stage === "import" && isModuleNotFound(err)) {
30341
+ console.warn(`
30342
+ ORM not available (install @tina4/orm to enable): ${message}`);
30343
+ } else if (stage === "import") {
30344
+ console.warn(`
30345
+ ORM failed to load:`, err);
30346
+ } else {
30347
+ console.warn(`
30348
+ ORM model setup failed:`, err);
30349
+ }
30350
+ }
30187
30351
  async function autoMigrateOnStartup(migrationDir = "migrations", base = process.cwd()) {
30188
30352
  const dir = resolve15(base, migrationDir);
30189
- if (!existsSync23(dir)) return;
30353
+ if (!existsSync24(dir)) return;
30190
30354
  let hasSql = false;
30191
30355
  try {
30192
30356
  hasSql = readdirSync15(dir).some((f) => f.endsWith(".sql") && !f.endsWith(".down.sql"));
@@ -30202,9 +30366,20 @@ async function autoMigrateOnStartup(migrationDir = "migrations", base = process.
30202
30366
  let orm;
30203
30367
  try {
30204
30368
  orm = await Promise.resolve().then(() => (init_index(), index_exports));
30369
+ } catch (err) {
30370
+ Log.debug(`Startup migrations skipped (ORM not available): ${stripUrlCredentials(err instanceof Error ? err.message : String(err))}`);
30371
+ return;
30372
+ }
30373
+ try {
30205
30374
  orm.getAdapter();
30206
30375
  } catch (err) {
30207
- Log.debug(`Startup migrations skipped (no database configured): ${err instanceof Error ? err.message : String(err)}`);
30376
+ const configuredUrl = (process.env.TINA4_DATABASE_URL ?? "").trim();
30377
+ const cause = stripUrlCredentials(bootDbConnectError ?? (err instanceof Error ? err.message : String(err)));
30378
+ if (configuredUrl) {
30379
+ Log.debug(`Startup migrations skipped (database configured but could not connect to ${stripUrlCredentials(configuredUrl)}): ${cause}`);
30380
+ } else {
30381
+ Log.debug(`Startup migrations skipped (no database configured): ${cause}`);
30382
+ }
30208
30383
  return;
30209
30384
  }
30210
30385
  try {
@@ -30265,17 +30440,8 @@ function killPort(port) {
30265
30440
  }
30266
30441
  }
30267
30442
  function findAvailablePort(start2) {
30268
- try {
30269
- execFileSync3(process.execPath, ["-e", `
30270
- const s = require("net").createServer();
30271
- s.listen(${start2}, "0.0.0.0", () => { s.close(); process.exit(0); });
30272
- s.on("error", () => process.exit(1));
30273
- `], { timeout: 1e3 });
30274
- return start2;
30275
- } catch {
30276
- killPort(start2);
30277
- return start2;
30278
- }
30443
+ if (probeBind("0.0.0.0", start2) === "held") killPort(start2);
30444
+ return start2;
30279
30445
  }
30280
30446
  function shouldOpenBrowser(isDevelopment, noBrowser = false) {
30281
30447
  if (!isDevelopment || isTruthy(process.env.TINA4_PRODUCTION) || cluster.isWorker) return false;
@@ -30337,12 +30503,12 @@ async function renderErrorPage(code, data, templatesDir) {
30337
30503
  }
30338
30504
  return instance;
30339
30505
  };
30340
- const userTemplatePath = join25(templatesDir, templateFile);
30341
- if (existsSync23(userTemplatePath)) {
30506
+ const userTemplatePath = join26(templatesDir, templateFile);
30507
+ if (existsSync24(userTemplatePath)) {
30342
30508
  return getCachedFrond(templatesDir).render(templateFile, data);
30343
30509
  }
30344
- const builtinTemplatePath = join25(BUILTIN_ERROR_TEMPLATES_DIR, templateFile);
30345
- if (existsSync23(builtinTemplatePath)) {
30510
+ const builtinTemplatePath = join26(BUILTIN_ERROR_TEMPLATES_DIR, templateFile);
30511
+ if (existsSync24(builtinTemplatePath)) {
30346
30512
  return getCachedFrond(BUILTIN_ERROR_TEMPLATES_DIR).render(templateFile, data);
30347
30513
  }
30348
30514
  return null;
@@ -30359,10 +30525,10 @@ function injectDevToolbar(html, ctx) {
30359
30525
  }
30360
30526
  function walkGalleryFiles(dir) {
30361
30527
  const results = [];
30362
- if (!existsSync23(dir)) return results;
30528
+ if (!existsSync24(dir)) return results;
30363
30529
  for (const f of readdirSync15(dir)) {
30364
- const full = join25(dir, f);
30365
- if (statSync16(full).isDirectory()) results.push(...walkGalleryFiles(full));
30530
+ const full = join26(dir, f);
30531
+ if (statSync17(full).isDirectory()) results.push(...walkGalleryFiles(full));
30366
30532
  else results.push(full);
30367
30533
  }
30368
30534
  return results;
@@ -30370,18 +30536,18 @@ function walkGalleryFiles(dir) {
30370
30536
  function getGalleryDeployedState() {
30371
30537
  const galleryDir = resolve15(__dirname, "..", "gallery");
30372
30538
  const state = {};
30373
- if (!existsSync23(galleryDir)) return state;
30539
+ if (!existsSync24(galleryDir)) return state;
30374
30540
  try {
30375
30541
  const entries = readdirSync15(galleryDir).sort();
30376
30542
  for (const entry of entries) {
30377
- const entryPath = join25(galleryDir, entry);
30378
- const metaFile = join25(entryPath, "meta.json");
30379
- if (statSync16(entryPath).isDirectory() && existsSync23(metaFile)) {
30380
- const srcDir = join25(entryPath, "src");
30381
- if (existsSync23(srcDir)) {
30543
+ const entryPath = join26(galleryDir, entry);
30544
+ const metaFile = join26(entryPath, "meta.json");
30545
+ if (statSync17(entryPath).isDirectory() && existsSync24(metaFile)) {
30546
+ const srcDir = join26(entryPath, "src");
30547
+ if (existsSync24(srcDir)) {
30382
30548
  const files = walkGalleryFiles(srcDir);
30383
30549
  const projectSrc = resolve15(process.cwd(), "src");
30384
- state[entry] = files.every((f) => existsSync23(join25(projectSrc, relative10(srcDir, f))));
30550
+ state[entry] = files.every((f) => existsSync24(join26(projectSrc, relative9(srcDir, f))));
30385
30551
  } else {
30386
30552
  state[entry] = false;
30387
30553
  }
@@ -30412,7 +30578,7 @@ function resolveTemplate(pathname, templatesDir) {
30412
30578
  if (cleanPath.includes("\\") || cleanPath.split("/").some((seg) => seg === "" || seg === "." || seg === "..")) return null;
30413
30579
  const pagesDir = resolve15(templatesDir, TEMPLATE_PAGES_DIR);
30414
30580
  for (const ext of [".twig", ".html"]) {
30415
- if (existsSync23(resolve15(pagesDir, cleanPath + ext))) {
30581
+ if (existsSync24(resolve15(pagesDir, cleanPath + ext))) {
30416
30582
  return `${TEMPLATE_PAGES_DIR}/${cleanPath}${ext}`;
30417
30583
  }
30418
30584
  }
@@ -30421,7 +30587,7 @@ function resolveTemplate(pathname, templatesDir) {
30421
30587
  if (!templateCache) {
30422
30588
  templateCache = /* @__PURE__ */ new Map();
30423
30589
  const pagesDir = resolve15(templatesDir, TEMPLATE_PAGES_DIR);
30424
- if (existsSync23(pagesDir)) {
30590
+ if (existsSync24(pagesDir)) {
30425
30591
  const scan = (dir, prefix) => {
30426
30592
  for (const entry of readdirSync15(dir, { withFileTypes: true })) {
30427
30593
  if (entry.name.startsWith("_")) continue;
@@ -30889,9 +31055,9 @@ function serveMethodNotAllowed(ctx) {
30889
31055
  }
30890
31056
  function serveStaticAsset(ctx) {
30891
31057
  const custom = process.env.TINA4_PUBLIC_DIR;
30892
- if (custom && existsSync23(custom) && tryServeStatic(custom, ctx.req, ctx.res)) return true;
30893
- if (existsSync23(ctx.staticDir) && tryServeStatic(ctx.staticDir, ctx.req, ctx.res)) return true;
30894
- if (existsSync23(ctx.srcPublicDir) && tryServeStatic(ctx.srcPublicDir, ctx.req, ctx.res)) return true;
31058
+ if (custom && existsSync24(custom) && tryServeStatic(custom, ctx.req, ctx.res)) return true;
31059
+ if (existsSync24(ctx.staticDir) && tryServeStatic(ctx.staticDir, ctx.req, ctx.res)) return true;
31060
+ if (existsSync24(ctx.srcPublicDir) && tryServeStatic(ctx.srcPublicDir, ctx.req, ctx.res)) return true;
30895
31061
  if (ctx.swaggerAssetsEnabled || !isSwaggerAssetPath(ctx.pathname)) {
30896
31062
  if (tryServeStatic(BUILTIN_PUBLIC_DIR, ctx.req, ctx.res)) return true;
30897
31063
  }
@@ -31105,6 +31271,9 @@ function startProductionCluster(port, host) {
31105
31271
  Debug: OFF (Log level: ${logLevel})
31106
31272
  ${reset2}`);
31107
31273
  }
31274
+ if (process.env.NODE_CLUSTER_SCHED_POLICY === void 0) {
31275
+ cluster.schedulingPolicy = cluster.SCHED_RR;
31276
+ }
31108
31277
  for (let i = 0; i < numCPUs; i++) cluster.fork();
31109
31278
  cluster.on("exit", (worker, code) => {
31110
31279
  if (code !== 0) {
@@ -31124,12 +31293,13 @@ ${reset2}`);
31124
31293
  function wireLocaleGlobal(frondEngine, base) {
31125
31294
  if (!frondEngine) return;
31126
31295
  const localeDir = resolve15(base, process.env.TINA4_LOCALE_DIR ?? "src/locales");
31127
- if (!existsSync23(localeDir)) return;
31296
+ if (!existsSync24(localeDir)) return;
31128
31297
  try {
31129
31298
  const localeFiles = readdirSync15(localeDir).filter((file) => file.endsWith(".json"));
31130
- if (localeFiles.length === 0 || frondEngine.globals?.t) return;
31299
+ const FrondClass = frondEngine.constructor;
31300
+ if (localeFiles.length === 0 || FrondClass.hasGlobal("t") || frondEngine.globals?.t) return;
31131
31301
  const i18nInstance = new I18n(process.env.TINA4_LOCALE ?? "en", localeDir);
31132
- frondEngine.addGlobal("t", (key, params) => i18nInstance.t(key, params));
31302
+ FrondClass.addGlobal("t", (key, params) => i18nInstance.t(key, params));
31133
31303
  } catch {
31134
31304
  }
31135
31305
  }
@@ -31196,7 +31366,7 @@ async function startServer(config) {
31196
31366
  middleware.use(requestLogger());
31197
31367
  middleware.use(rateLimiter());
31198
31368
  MiddlewareRunner.use(SecurityHeadersMiddleware);
31199
- if (existsSync23(routesDir)) {
31369
+ if (existsSync24(routesDir)) {
31200
31370
  const routes = await discoverRoutes(routesDir);
31201
31371
  for (const route of routes) {
31202
31372
  router.addRoute(route);
@@ -31459,16 +31629,20 @@ ${reset2}
31459
31629
  });
31460
31630
  }
31461
31631
  async function initializeOrm(config, router, base, ormDir, modelsDir) {
31462
- const hasOrmDir = existsSync23(ormDir);
31463
- const hasModelsDir = existsSync23(modelsDir);
31632
+ const hasOrmDir = existsSync24(ormDir);
31633
+ const hasModelsDir = existsSync24(modelsDir);
31464
31634
  if (hasOrmDir || hasModelsDir) {
31635
+ let ormStage = "import";
31636
+ const dbConfig = config?.database ?? {};
31465
31637
  try {
31466
31638
  const orm = await Promise.resolve().then(() => (init_index(), index_exports));
31467
- const dbConfig = config?.database ?? {};
31639
+ ormStage = "connect";
31640
+ bootDbConnectError = null;
31468
31641
  await orm.initDatabase({
31469
31642
  type: dbConfig.type ?? "sqlite",
31470
31643
  path: dbConfig.path ?? "./data/tina4.db"
31471
31644
  });
31645
+ ormStage = "models";
31472
31646
  let models = hasOrmDir ? await orm.discoverModels(ormDir) : [];
31473
31647
  if (hasModelsDir) {
31474
31648
  const extraModels = await orm.discoverModels(modelsDir);
@@ -31503,8 +31677,7 @@ async function initializeOrm(config, router, base, ormDir, modelsDir) {
31503
31677
  }
31504
31678
  }
31505
31679
  } catch (err) {
31506
- console.warn(`
31507
- ORM not available (install @tina4/orm to enable):`, err);
31680
+ reportOrmBootFailure(ormStage, err, dbConfig);
31508
31681
  }
31509
31682
  await autoMigrateOnStartup("migrations", base);
31510
31683
  }
@@ -31520,7 +31693,7 @@ async function configureSwagger(router, ormDir, modelsDir) {
31520
31693
  let modelDefs = [];
31521
31694
  try {
31522
31695
  const orm = await Promise.resolve().then(() => (init_index(), index_exports));
31523
- const allModelDirs = [ormDir, modelsDir].filter((d) => existsSync23(d));
31696
+ const allModelDirs = [ormDir, modelsDir].filter((d) => existsSync24(d));
31524
31697
  const seenTables = /* @__PURE__ */ new Set();
31525
31698
  for (const dir of allModelDirs) {
31526
31699
  const discovered = await orm.discoverModels(dir);
@@ -31542,7 +31715,7 @@ async function configureSwagger(router, ormDir, modelsDir) {
31542
31715
  }
31543
31716
  return enabled;
31544
31717
  }
31545
- var __filename, __dirname, BUILTIN_ERROR_TEMPLATES_DIR, BUILTIN_PUBLIC_DIR, swaggerAssetsEnabled, DEFAULT_SHUTDOWN_TIMEOUT_SECONDS, frondCache, _LEGACY_ENV_VARS, CI_ENVIRONMENT_VARIABLES, CI_NOT_SET_VALUES, portDeprecationWarned, TEMPLATE_PAGES_DIR, HTTP_REASON_PHRASES, templateCache, _dispatchFn, _liveDispatchContext, _serverHandle, LOOP_WATCHDOG_TICK_MS, FALLBACK_STAGES;
31718
+ var __filename, __dirname, BUILTIN_ERROR_TEMPLATES_DIR, BUILTIN_PUBLIC_DIR, swaggerAssetsEnabled, DEFAULT_SHUTDOWN_TIMEOUT_SECONDS, bootDbConnectError, frondCache, _LEGACY_ENV_VARS, CI_ENVIRONMENT_VARIABLES, CI_NOT_SET_VALUES, portDeprecationWarned, TEMPLATE_PAGES_DIR, HTTP_REASON_PHRASES, templateCache, _dispatchFn, _liveDispatchContext, _serverHandle, LOOP_WATCHDOG_TICK_MS, FALLBACK_STAGES;
31546
31719
  var init_server = __esm({
31547
31720
  "../core/src/server.ts"() {
31548
31721
  "use strict";
@@ -31571,12 +31744,13 @@ var init_server = __esm({
31571
31744
  init_background();
31572
31745
  init_tcp();
31573
31746
  init_version();
31574
- __filename = fileURLToPath7(import.meta.url);
31747
+ __filename = fileURLToPath8(import.meta.url);
31575
31748
  __dirname = dirname12(__filename);
31576
31749
  BUILTIN_ERROR_TEMPLATES_DIR = resolve15(__dirname, "..", "templates");
31577
31750
  BUILTIN_PUBLIC_DIR = resolve15(__dirname, "..", "public");
31578
31751
  swaggerAssetsEnabled = false;
31579
31752
  DEFAULT_SHUTDOWN_TIMEOUT_SECONDS = 30;
31753
+ bootDbConnectError = null;
31580
31754
  frondCache = /* @__PURE__ */ new Map();
31581
31755
  _LEGACY_ENV_VARS = {
31582
31756
  DATABASE_URL: "TINA4_DATABASE_URL",
@@ -31734,8 +31908,9 @@ var init_env = __esm({
31734
31908
 
31735
31909
  // ../core/src/fakeData.ts
31736
31910
  import { randomInt, randomUUID as randomUUID7 } from "node:crypto";
31737
- import { existsSync as existsSync24, readdirSync as readdirSync16 } from "node:fs";
31738
- import { resolve as resolve16, join as join26 } from "node:path";
31911
+ import { existsSync as existsSync25, readdirSync as readdirSync16 } from "node:fs";
31912
+ import { resolve as resolve16, join as join27 } from "node:path";
31913
+ import { pathToFileURL as pathToFileURL2 } from "node:url";
31739
31914
  function mulberry32(seed) {
31740
31915
  let s = seed | 0;
31741
31916
  return () => {
@@ -32233,13 +32408,13 @@ var init_fakeData = __esm({
32233
32408
  */
32234
32409
  async seedDir(seedDir) {
32235
32410
  const dir = resolve16(seedDir ?? "src/seeds");
32236
- if (!existsSync24(dir)) return [];
32411
+ if (!existsSync25(dir)) return [];
32237
32412
  const files = readdirSync16(dir).filter((f) => f.endsWith(".ts") || f.endsWith(".js")).sort();
32238
32413
  const executed = [];
32239
32414
  for (const file of files) {
32240
- const fullPath = join26(dir, file);
32415
+ const fullPath = join27(dir, file);
32241
32416
  try {
32242
- const mod = await import(fullPath);
32417
+ const mod = await import(pathToFileURL2(fullPath).href);
32243
32418
  if (typeof mod.default === "function") {
32244
32419
  await mod.default();
32245
32420
  }
@@ -32343,7 +32518,7 @@ var init_mqttMessage = __esm({
32343
32518
  import net3 from "node:net";
32344
32519
  import tls from "node:tls";
32345
32520
  import { randomBytes as randomBytes8 } from "node:crypto";
32346
- import { existsSync as existsSync25, readFileSync as readFileSync22 } from "node:fs";
32521
+ import { existsSync as existsSync26, readFileSync as readFileSync22 } from "node:fs";
32347
32522
  var MqttError, MqttTimeoutError, CONNECT, CONNACK, PUBLISH, PUBACK, SUBSCRIBE, SUBACK, PINGREQ, PINGRESP, DISCONNECT, PROTOCOL_LEVEL, DEFAULT_PORT, DEFAULT_TLS_PORT, DEFAULT_URL, DEFAULT_KEEPALIVE, SUBSCRIPTION_REFUSED, MAX_REMAINING_LENGTH, QOS2_REFUSED_MESSAGE, CONNACK_RETURN_CODES, Mqtt;
32348
32523
  var init_mqtt = __esm({
32349
32524
  "../core/src/mqtt.ts"() {
@@ -32546,7 +32721,7 @@ var init_mqtt = __esm({
32546
32721
  */
32547
32722
  async connect() {
32548
32723
  this.closeSocket();
32549
- if (this.secure && this.tlsVerify && this.caFile && !existsSync25(this.caFile)) {
32724
+ if (this.secure && this.tlsVerify && this.caFile && !existsSync26(this.caFile)) {
32550
32725
  throw new MqttError(
32551
32726
  `MQTT CA file not found: ${this.caFile} -- TINA4_MQTT_CA_FILE (or caFile) must point at the broker's CA certificate in PEM form`
32552
32727
  );
@@ -33028,9 +33203,9 @@ var init_mqtt = __esm({
33028
33203
  });
33029
33204
 
33030
33205
  // ../core/src/service.ts
33031
- import { readdirSync as readdirSync17, statSync as statSync17, watchFile, unwatchFile } from "node:fs";
33032
- import { join as join27, extname as extname7 } from "node:path";
33033
- import { pathToFileURL } from "node:url";
33206
+ import { readdirSync as readdirSync17, statSync as statSync18, watchFile, unwatchFile } from "node:fs";
33207
+ import { join as join28, extname as extname8 } from "node:path";
33208
+ import { pathToFileURL as pathToFileURL3 } from "node:url";
33034
33209
  function matchCronField(field, value) {
33035
33210
  if (field === "*") return true;
33036
33211
  if (field.includes("/")) {
@@ -33201,13 +33376,13 @@ var init_service = __esm({
33201
33376
  return discovered;
33202
33377
  }
33203
33378
  for (const entry of entries) {
33204
- const ext = extname7(entry);
33379
+ const ext = extname8(entry);
33205
33380
  if (ext !== ".ts" && ext !== ".js") continue;
33206
- const fullPath = join27(dir, entry);
33207
- const stat = statSync17(fullPath);
33381
+ const fullPath = join28(dir, entry);
33382
+ const stat = statSync18(fullPath);
33208
33383
  if (!stat.isFile()) continue;
33209
33384
  try {
33210
- const fileUrl = pathToFileURL(fullPath).href;
33385
+ const fileUrl = pathToFileURL3(fullPath).href;
33211
33386
  const mod = await import(fileUrl);
33212
33387
  const exp = mod.default ?? mod;
33213
33388
  if (exp.name && typeof exp.handler === "function") {
@@ -33328,13 +33503,13 @@ var init_service = __esm({
33328
33503
  return;
33329
33504
  }
33330
33505
  for (const entry of entries) {
33331
- const ext = extname7(entry);
33506
+ const ext = extname8(entry);
33332
33507
  if (ext !== ".ts" && ext !== ".js") continue;
33333
- const fullPath = join27(dir, entry);
33508
+ const fullPath = join28(dir, entry);
33334
33509
  if (watchedFiles.has(fullPath)) continue;
33335
33510
  watchedFiles.add(fullPath);
33336
33511
  watchFile(fullPath, { interval: 1e3 }, async () => {
33337
- const fileUrl = pathToFileURL(fullPath).href;
33512
+ const fileUrl = pathToFileURL3(fullPath).href;
33338
33513
  try {
33339
33514
  const mod = await import(fileUrl + "?t=" + Date.now());
33340
33515
  const exp = mod.default ?? mod;
@@ -33597,23 +33772,23 @@ function guessContentType(filename) {
33597
33772
  }
33598
33773
  function buildMultipartBody(boundary, fieldName, filename, fileContent, contentType, extraFields) {
33599
33774
  const crlf = "\r\n";
33600
- const delimiter2 = `--${boundary}`;
33775
+ const delimiter3 = `--${boundary}`;
33601
33776
  const parts = [];
33602
33777
  if (extraFields) {
33603
33778
  for (const [key, value] of Object.entries(extraFields)) {
33604
- parts.push(Buffer.from(delimiter2 + crlf, "utf-8"));
33779
+ parts.push(Buffer.from(delimiter3 + crlf, "utf-8"));
33605
33780
  parts.push(Buffer.from(`Content-Disposition: form-data; name="${key}"` + crlf + crlf, "utf-8"));
33606
33781
  parts.push(Buffer.from(String(value) + crlf, "utf-8"));
33607
33782
  }
33608
33783
  }
33609
- parts.push(Buffer.from(delimiter2 + crlf, "utf-8"));
33784
+ parts.push(Buffer.from(delimiter3 + crlf, "utf-8"));
33610
33785
  parts.push(
33611
33786
  Buffer.from(`Content-Disposition: form-data; name="${fieldName}"; filename="${filename}"` + crlf, "utf-8")
33612
33787
  );
33613
33788
  parts.push(Buffer.from(`Content-Type: ${contentType}` + crlf + crlf, "utf-8"));
33614
33789
  parts.push(fileContent);
33615
33790
  parts.push(Buffer.from(crlf, "utf-8"));
33616
- parts.push(Buffer.from(delimiter2 + "--" + crlf, "utf-8"));
33791
+ parts.push(Buffer.from(delimiter3 + "--" + crlf, "utf-8"));
33617
33792
  return Buffer.concat(parts);
33618
33793
  }
33619
33794
  async function* parseLineStream(chunks) {
@@ -33860,8 +34035,8 @@ var init_api = __esm({
33860
34035
  /**
33861
34036
  * HTTP GET request.
33862
34037
  */
33863
- async get(path10, params) {
33864
- let url = this.buildUrl(path10);
34038
+ async get(path9, params) {
34039
+ let url = this.buildUrl(path9);
33865
34040
  if (params && Object.keys(params).length > 0) {
33866
34041
  const qs = new URLSearchParams(params).toString();
33867
34042
  url += (url.includes("?") ? "&" : "?") + qs;
@@ -33871,32 +34046,32 @@ var init_api = __esm({
33871
34046
  /**
33872
34047
  * HTTP POST request.
33873
34048
  */
33874
- async post(path10, body, contentType = "application/json") {
33875
- return this.sendRequest("POST", path10, body, contentType);
34049
+ async post(path9, body, contentType = "application/json") {
34050
+ return this.sendRequest("POST", path9, body, contentType);
33876
34051
  }
33877
34052
  /**
33878
34053
  * HTTP PUT request.
33879
34054
  */
33880
- async put(path10, body, contentType = "application/json") {
33881
- return this.sendRequest("PUT", path10, body, contentType);
34055
+ async put(path9, body, contentType = "application/json") {
34056
+ return this.sendRequest("PUT", path9, body, contentType);
33882
34057
  }
33883
34058
  /**
33884
34059
  * HTTP PATCH request.
33885
34060
  */
33886
- async patch(path10, body, contentType = "application/json") {
33887
- return this.sendRequest("PATCH", path10, body, contentType);
34061
+ async patch(path9, body, contentType = "application/json") {
34062
+ return this.sendRequest("PATCH", path9, body, contentType);
33888
34063
  }
33889
34064
  /**
33890
34065
  * HTTP DELETE request.
33891
34066
  */
33892
- async delete(path10, body) {
33893
- return this.sendRequest("DELETE", path10, body);
34067
+ async delete(path9, body) {
34068
+ return this.sendRequest("DELETE", path9, body);
33894
34069
  }
33895
34070
  /**
33896
34071
  * Generic request method — public entry point for any HTTP method.
33897
34072
  */
33898
- async sendRequest(method, path10, body, contentType = "application/json") {
33899
- const url = this.buildUrl(path10);
34073
+ async sendRequest(method, path9, body, contentType = "application/json") {
34074
+ const url = this.buildUrl(path9);
33900
34075
  return this.execute(method.toUpperCase(), url, body, contentType);
33901
34076
  }
33902
34077
  /**
@@ -33920,7 +34095,7 @@ var init_api = __esm({
33920
34095
  * await api.upload("/avatars", { fileBytes: raw, filename: "me.png",
33921
34096
  * extraFields: { user_id: "42" } });
33922
34097
  */
33923
- async upload(path10, opts = {}) {
34098
+ async upload(path9, opts = {}) {
33924
34099
  const { filePath, fieldName = "file", extraFields, headers, fileBytes, filename } = opts;
33925
34100
  let content;
33926
34101
  let uploadName;
@@ -33955,7 +34130,7 @@ var init_api = __esm({
33955
34130
  const boundary = "----Tina4Boundary" + randomBytes9(16).toString("hex");
33956
34131
  const bodyBuffer = buildMultipartBody(boundary, fieldName, uploadName, content, partContentType, extraFields);
33957
34132
  const contentType = `multipart/form-data; boundary=${boundary}`;
33958
- return this.execute("POST", this.buildUrl(path10), bodyBuffer, contentType, headers);
34133
+ return this.execute("POST", this.buildUrl(path9), bodyBuffer, contentType, headers);
33959
34134
  }
33960
34135
  /**
33961
34136
  * Stream a GET response body to `destPath` in chunks.
@@ -33970,11 +34145,11 @@ var init_api = __esm({
33970
34145
  * dest, HTTP error status, or a transport failure); the destination file is
33971
34146
  * not written on error.
33972
34147
  */
33973
- async download(path10, destPath, params) {
34148
+ async download(path9, destPath, params) {
33974
34149
  if (!destPath) {
33975
34150
  return { http_code: null, headers: {}, error: "download requires destPath", path: null };
33976
34151
  }
33977
- let url = this.buildUrl(path10);
34152
+ let url = this.buildUrl(path9);
33978
34153
  if (params && Object.keys(params).length > 0) {
33979
34154
  const qs = new URLSearchParams(params).toString();
33980
34155
  url += (url.includes("?") ? "&" : "?") + qs;
@@ -34058,8 +34233,8 @@ var init_api = __esm({
34058
34233
  * bounds just the connect + headers phase (default
34059
34234
  * `TINA4_API_CONNECT_TIMEOUT` or 10s).
34060
34235
  */
34061
- async *streamBytes(path10, opts = {}) {
34062
- const url = this.buildUrl(path10);
34236
+ async *streamBytes(path9, opts = {}) {
34237
+ const url = this.buildUrl(path9);
34063
34238
  const method = (opts.method ?? "GET").toUpperCase();
34064
34239
  const contentType = opts.contentType ?? "application/json";
34065
34240
  const { headers, data } = this.buildRequest(method, contentType, opts.body, opts.headers, url);
@@ -34094,8 +34269,8 @@ var init_api = __esm({
34094
34269
  * yields a trailing line without a terminator on EOF. Built on
34095
34270
  * {@link streamBytes} plus the shared {@link parseLineStream}.
34096
34271
  */
34097
- async *streamLines(path10, opts = {}) {
34098
- yield* parseLineStream(this.streamBytes(path10, opts));
34272
+ async *streamLines(path9, opts = {}) {
34273
+ yield* parseLineStream(this.streamBytes(path9, opts));
34099
34274
  }
34100
34275
  /**
34101
34276
  * Stream the response as SSE (Server-Sent Events). Yields one
@@ -34104,8 +34279,8 @@ var init_api = __esm({
34104
34279
  * with `data === "[DONE]"` and the iterator ends on the next EOF.
34105
34280
  * Built on {@link streamLines} plus the shared {@link parseSseStream}.
34106
34281
  */
34107
- async *streamSse(path10, opts = {}) {
34108
- yield* parseSseStream(this.streamLines(path10, opts));
34282
+ async *streamSse(path9, opts = {}) {
34283
+ yield* parseSseStream(this.streamLines(path9, opts));
34109
34284
  }
34110
34285
  // ── Internal helpers ──────────────────────────────────────────────
34111
34286
  /**
@@ -34171,14 +34346,14 @@ var init_api = __esm({
34171
34346
  req2.end();
34172
34347
  });
34173
34348
  }
34174
- buildUrl(path10) {
34175
- if (path10.startsWith("http://") || path10.startsWith("https://")) {
34176
- return path10;
34349
+ buildUrl(path9) {
34350
+ if (path9.startsWith("http://") || path9.startsWith("https://")) {
34351
+ return path9;
34177
34352
  }
34178
- if (!path10) {
34353
+ if (!path9) {
34179
34354
  return this.baseUrl;
34180
34355
  }
34181
- return `${this.baseUrl}/${path10.replace(/^\/+/, "")}`;
34356
+ return `${this.baseUrl}/${path9.replace(/^\/+/, "")}`;
34182
34357
  }
34183
34358
  /**
34184
34359
  * The headers configured on the client, as they may go to `targetUrl`.
@@ -36118,15 +36293,15 @@ var init_htmlElement = __esm({
36118
36293
  });
36119
36294
 
36120
36295
  // ../core/src/ai.ts
36121
- import { existsSync as existsSync26, mkdirSync as mkdirSync17, writeFileSync as writeFileSync16, readFileSync as readFileSync24 } from "node:fs";
36296
+ import { existsSync as existsSync27, mkdirSync as mkdirSync17, writeFileSync as writeFileSync16, readFileSync as readFileSync24 } from "node:fs";
36122
36297
  import { homedir } from "node:os";
36123
- import { join as join28, resolve as resolve17, relative as relative11, dirname as dirname13 } from "node:path";
36124
- import { fileURLToPath as fileURLToPath8 } from "node:url";
36125
- import { execSync, execFileSync as execFileSync4 } from "node:child_process";
36298
+ import { join as join29, resolve as resolve17, relative as relative10, dirname as dirname13 } from "node:path";
36299
+ import { fileURLToPath as fileURLToPath9 } from "node:url";
36300
+ import { execSync, execFileSync as execFileSync3 } from "node:child_process";
36126
36301
  import { createInterface } from "node:readline";
36127
36302
  function readVersion() {
36128
36303
  try {
36129
- const thisDir = dirname13(fileURLToPath8(import.meta.url));
36304
+ const thisDir = dirname13(fileURLToPath9(import.meta.url));
36130
36305
  const rootPkg = resolve17(thisDir, "..", "..", "..", "package.json");
36131
36306
  const pkg = JSON.parse(readFileSync24(rootPkg, "utf-8"));
36132
36307
  return pkg.version ?? "0.0.0";
@@ -36178,7 +36353,7 @@ function downloadSkillsSync(jobs) {
36178
36353
  })();
36179
36354
  `;
36180
36355
  try {
36181
- const out = execFileSync4(process.execPath, ["-e", child, JSON.stringify(jobs)], {
36356
+ const out = execFileSync3(process.execPath, ["-e", child, JSON.stringify(jobs)], {
36182
36357
  encoding: "utf-8",
36183
36358
  timeout: 5e4,
36184
36359
  maxBuffer: 8 * 1024 * 1024
@@ -36191,8 +36366,8 @@ function downloadSkillsSync(jobs) {
36191
36366
  function installSkills(root = ".", targets) {
36192
36367
  const ref = skillsRef();
36193
36368
  const dests = targets ?? [
36194
- join28(resolve17(root), ".claude", "skills"),
36195
- join28(homedir(), ".claude", "skills")
36369
+ join29(resolve17(root), ".claude", "skills"),
36370
+ join29(homedir(), ".claude", "skills")
36196
36371
  ];
36197
36372
  const jobs = [];
36198
36373
  const index = /* @__PURE__ */ new Map();
@@ -36210,9 +36385,9 @@ function installSkills(root = ".", targets) {
36210
36385
  const base = `https://raw.githubusercontent.com/tina4stack/${spec.repo}/${ref}/.claude/skills/${skill}`;
36211
36386
  skillMdUrl[skill] = `${base}/SKILL.md`;
36212
36387
  for (const dest of dests) {
36213
- add(`${base}/SKILL.md`, join28(dest, skill, "SKILL.md"));
36388
+ add(`${base}/SKILL.md`, join29(dest, skill, "SKILL.md"));
36214
36389
  for (const r of spec.references) {
36215
- add(`${base}/references/${r}`, join28(dest, skill, "references", r));
36390
+ add(`${base}/references/${r}`, join29(dest, skill, "references", r));
36216
36391
  }
36217
36392
  }
36218
36393
  }
@@ -36224,7 +36399,7 @@ function installSkills(root = ".", targets) {
36224
36399
  return installed;
36225
36400
  }
36226
36401
  function isInstalled(root, tool) {
36227
- return existsSync26(join28(resolve17(root), tool.contextFile));
36402
+ return existsSync27(join29(resolve17(root), tool.contextFile));
36228
36403
  }
36229
36404
  function showMenu(root = ".") {
36230
36405
  const r = resolve17(root);
@@ -36347,7 +36522,7 @@ function looksLikeOldFrameworkInstall(existing) {
36347
36522
  function writeOrMerge(contextPath, contextFile, frameworkGuide) {
36348
36523
  const block = skillBlock(contextFile);
36349
36524
  const [start2, end] = markersFor(contextFile);
36350
- if (!existsSync26(contextPath)) {
36525
+ if (!existsSync27(contextPath)) {
36351
36526
  writeFileSync16(contextPath, frameworkGuide.replace(/\s+$/, "") + "\n\n" + block + "\n", "utf-8");
36352
36527
  return "Installed";
36353
36528
  }
@@ -36368,14 +36543,14 @@ function writeOrMerge(contextPath, contextFile, frameworkGuide) {
36368
36543
  }
36369
36544
  function installForTool(root, tool, context) {
36370
36545
  const created = [];
36371
- const contextPath = join28(root, tool.contextFile);
36546
+ const contextPath = join29(root, tool.contextFile);
36372
36547
  if (tool.configDir) {
36373
- mkdirSync17(join28(root, tool.configDir), { recursive: true });
36548
+ mkdirSync17(join29(root, tool.configDir), { recursive: true });
36374
36549
  }
36375
36550
  const parentDir = dirname13(contextPath);
36376
36551
  mkdirSync17(parentDir, { recursive: true });
36377
36552
  const action = writeOrMerge(contextPath, tool.contextFile, context);
36378
- const rel = relative11(root, contextPath);
36553
+ const rel = relative10(root, contextPath);
36379
36554
  created.push(rel);
36380
36555
  console.log(` ${GREEN2}\u2713${RESET2} ${action} ${rel}`);
36381
36556
  if (tool.name === "claude-code") {
@@ -36408,7 +36583,7 @@ function installTina4Ai() {
36408
36583
  function installClaudeSkills(root) {
36409
36584
  const created = [];
36410
36585
  for (const skill of installSkills(root)) {
36411
- created.push(join28(".claude", "skills", skill));
36586
+ created.push(join29(".claude", "skills", skill));
36412
36587
  console.log(` ${GREEN2}\u2713${RESET2} Installed .claude/skills/${skill} (project + global)`);
36413
36588
  }
36414
36589
  return created;
@@ -36749,10 +36924,10 @@ import { tests, assertEqual, runAll } from "tina4-nodejs";
36749
36924
  }
36750
36925
  function generateClaudeCodeContext() {
36751
36926
  try {
36752
- const thisDir = dirname13(fileURLToPath8(import.meta.url));
36927
+ const thisDir = dirname13(fileURLToPath9(import.meta.url));
36753
36928
  const repoRoot = resolve17(thisDir, "..", "..", "..");
36754
- const claudeMdPath = join28(repoRoot, "CLAUDE.md");
36755
- if (existsSync26(claudeMdPath)) {
36929
+ const claudeMdPath = join29(repoRoot, "CLAUDE.md");
36930
+ if (existsSync27(claudeMdPath)) {
36756
36931
  return readFileSync24(claudeMdPath, "utf-8");
36757
36932
  }
36758
36933
  } catch {
@@ -37413,10 +37588,10 @@ var init_aiClient = __esm({
37413
37588
  throw new AiConfigError("AI URL must be an http or https URL");
37414
37589
  }
37415
37590
  if (url.protocol !== "http:" && url.protocol !== "https:") throw new AiConfigError("AI URL must be an http or https URL");
37416
- const path10 = rtrimSlashes(url.pathname);
37417
- if (path10 === "" || path10 === "/v1" || path10 === "/api" || path10 === "/v1beta/openai") {
37591
+ const path9 = rtrimSlashes(url.pathname);
37592
+ if (path9 === "" || path9 === "/v1" || path9 === "/api" || path9 === "/v1beta/openai") {
37418
37593
  const suffix = provider === "anthropic" ? "/messages" : capability === "embed" ? "/embeddings" : "/chat/completions";
37419
- url.pathname = (path10 || "/v1") + suffix;
37594
+ url.pathname = (path9 || "/v1") + suffix;
37420
37595
  }
37421
37596
  return url.toString();
37422
37597
  }
@@ -37932,7 +38107,7 @@ var init_aiClient = __esm({
37932
38107
  });
37933
38108
 
37934
38109
  // ../core/src/queueBackends/rabbitmqBackend.ts
37935
- import { execFileSync as execFileSync5 } from "node:child_process";
38110
+ import { execFileSync as execFileSync4 } from "node:child_process";
37936
38111
  import { randomUUID as randomUUID9 } from "node:crypto";
37937
38112
  function parseAmqpUrl(url) {
37938
38113
  const config = {};
@@ -38353,7 +38528,7 @@ var init_rabbitmqBackend = __esm({
38353
38528
  setTimeout(() => { sock.destroy(); process.exit(1); }, 10000).unref();
38354
38529
  `;
38355
38530
  try {
38356
- const result = execFileSync5(process.execPath, ["-e", script], {
38531
+ const result = execFileSync4(process.execPath, ["-e", script], {
38357
38532
  encoding: "utf-8",
38358
38533
  timeout: 15e3,
38359
38534
  stdio: ["pipe", "pipe", "pipe"]
@@ -38729,27 +38904,27 @@ var init_testClient = __esm({
38729
38904
  return this.ctxPromise;
38730
38905
  }
38731
38906
  /** Send a GET request. */
38732
- async get(path10, options) {
38733
- return this._request("GET", path10, options);
38907
+ async get(path9, options) {
38908
+ return this._request("GET", path9, options);
38734
38909
  }
38735
38910
  /** Send a POST request. */
38736
- async post(path10, options) {
38737
- return this._request("POST", path10, options);
38911
+ async post(path9, options) {
38912
+ return this._request("POST", path9, options);
38738
38913
  }
38739
38914
  /** Send a PUT request. */
38740
- async put(path10, options) {
38741
- return this._request("PUT", path10, options);
38915
+ async put(path9, options) {
38916
+ return this._request("PUT", path9, options);
38742
38917
  }
38743
38918
  /** Send a PATCH request. */
38744
- async patch(path10, options) {
38745
- return this._request("PATCH", path10, options);
38919
+ async patch(path9, options) {
38920
+ return this._request("PATCH", path9, options);
38746
38921
  }
38747
38922
  /** Send a DELETE request. */
38748
- async delete(path10, options) {
38749
- return this._request("DELETE", path10, options);
38923
+ async delete(path9, options) {
38924
+ return this._request("DELETE", path9, options);
38750
38925
  }
38751
38926
  /** Build a mock request/response pair and dispatch it through the REAL pipeline (runDispatch). */
38752
- async _request(method, path10, options) {
38927
+ async _request(method, path9, options) {
38753
38928
  const { json, body, headers } = options ?? {};
38754
38929
  let rawBody = "";
38755
38930
  let contentType = "";
@@ -38775,7 +38950,7 @@ var init_testClient = __esm({
38775
38950
  Object.defineProperty(socket, "remoteAddress", { value: "127.0.0.1" });
38776
38951
  const rawReq = new IncomingMessage2(socket);
38777
38952
  rawReq.method = method.toUpperCase();
38778
- rawReq.url = path10;
38953
+ rawReq.url = path9;
38779
38954
  rawReq.headers = { ...reqHeaders, host: "localhost:7148" };
38780
38955
  if (rawBody) {
38781
38956
  rawReq.push(Buffer.from(rawBody));
@@ -38846,20 +39021,20 @@ var init_test = __esm({
38846
39021
  if (this._client === null) this._client = new TestClient();
38847
39022
  return this._client;
38848
39023
  }
38849
- async get(path10, options) {
38850
- return this.client.get(path10, options);
39024
+ async get(path9, options) {
39025
+ return this.client.get(path9, options);
38851
39026
  }
38852
- async post(path10, options) {
38853
- return this.client.post(path10, options);
39027
+ async post(path9, options) {
39028
+ return this.client.post(path9, options);
38854
39029
  }
38855
- async put(path10, options) {
38856
- return this.client.put(path10, options);
39030
+ async put(path9, options) {
39031
+ return this.client.put(path9, options);
38857
39032
  }
38858
- async patch(path10, options) {
38859
- return this.client.patch(path10, options);
39033
+ async patch(path9, options) {
39034
+ return this.client.patch(path9, options);
38860
39035
  }
38861
- async delete(path10, options) {
38862
- return this.client.delete(path10, options);
39036
+ async delete(path9, options) {
39037
+ return this.client.delete(path9, options);
38863
39038
  }
38864
39039
  // ── Positional assertions — (actual, expected, message) shape ────────
38865
39040
  assertEqual(actual, expected, message) {
@@ -40182,7 +40357,7 @@ __export(sqlite_exports, {
40182
40357
  });
40183
40358
  import { DatabaseSync as DatabaseSync3 } from "node:sqlite";
40184
40359
  import { mkdirSync as mkdirSync18 } from "node:fs";
40185
- import { dirname as dirname14, isAbsolute as isAbsolute5, join as join29, resolve as resolve18, sep as sep7 } from "node:path";
40360
+ import { dirname as dirname14, isAbsolute as isAbsolute5, join as join30, resolve as resolve18, sep as sep8 } from "node:path";
40186
40361
  function isIdentifier(str) {
40187
40362
  return /^[A-Za-z_][A-Za-z0-9_]*$/.test(str);
40188
40363
  }
@@ -40218,16 +40393,16 @@ function resolveSqlitePath(dbPath) {
40218
40393
  return dbPath;
40219
40394
  }
40220
40395
  const cwd = resolve18(process.cwd());
40221
- const path10 = join29(cwd, dbPath);
40222
- const parent = dirname14(path10);
40396
+ const path9 = join30(cwd, dbPath);
40397
+ const parent = dirname14(path9);
40223
40398
  const absParent = resolve18(parent);
40224
- if (absParent !== cwd && !absParent.startsWith(cwd + sep7)) {
40399
+ if (absParent !== cwd && !absParent.startsWith(cwd + sep8)) {
40225
40400
  throw new Error(
40226
40401
  `SQLite path "${dbPath}" resolves outside the project directory: "${absParent}" is not within "${cwd}". Tina4 refuses to create directories outside the project (ADR-0086). Use an absolute path for a database that lives outside the project.`
40227
40402
  );
40228
40403
  }
40229
40404
  mkdirSync18(parent, { recursive: true, mode: 509 });
40230
- return path10;
40405
+ return path9;
40231
40406
  }
40232
40407
  function fieldTypeToSQLite(def) {
40233
40408
  switch (def.type) {
@@ -44106,9 +44281,9 @@ async function initDatabase(config) {
44106
44281
  const rawType = config?.type ?? "sqlite";
44107
44282
  const type2 = rawType === "sqlserver" ? "mssql" : rawType;
44108
44283
  if (config === void 0 && !process.env.TINA4_DATABASE_URL) {
44109
- const path10 = "./data/tina4.db";
44284
+ const path9 = "./data/tina4.db";
44110
44285
  console.warn(
44111
- `[tina4] No TINA4_DATABASE_URL set \u2014 falling back to SQLite at ${path10}. If you meant to use Postgres/MySQL/etc., set TINA4_DATABASE_URL in your .env and re-run. (Was the .env loaded? CLI commands must call loadEnv() first.)`
44286
+ `[tina4] No TINA4_DATABASE_URL set \u2014 falling back to SQLite at ${path9}. If you meant to use Postgres/MySQL/etc., set TINA4_DATABASE_URL in your .env and re-run. (Was the .env loaded? CLI commands must call loadEnv() first.)`
44112
44287
  );
44113
44288
  }
44114
44289
  const finished = (adapter) => {
@@ -45321,8 +45496,9 @@ var init_database = __esm({
45321
45496
  });
45322
45497
 
45323
45498
  // src/model.ts
45324
- import { readdirSync as readdirSync18, statSync as statSync18 } from "node:fs";
45325
- import { join as join30, extname as extname8 } from "node:path";
45499
+ import { readdirSync as readdirSync18, statSync as statSync19 } from "node:fs";
45500
+ import { join as join31, extname as extname9 } from "node:path";
45501
+ import { pathToFileURL as pathToFileURL4 } from "node:url";
45326
45502
  async function discoverModels(modelsDir) {
45327
45503
  const models = [];
45328
45504
  let files;
@@ -45332,13 +45508,13 @@ async function discoverModels(modelsDir) {
45332
45508
  return models;
45333
45509
  }
45334
45510
  for (const file of files) {
45335
- const filePath = join30(modelsDir, file);
45336
- const stat = statSync18(filePath);
45511
+ const filePath = join31(modelsDir, file);
45512
+ const stat = statSync19(filePath);
45337
45513
  if (!stat.isFile()) continue;
45338
- const ext = extname8(file);
45514
+ const ext = extname9(file);
45339
45515
  if (ext !== ".ts" && ext !== ".js") continue;
45340
45516
  try {
45341
- const moduleUrl = `file://${filePath}?t=${Date.now()}`;
45517
+ const moduleUrl = `${pathToFileURL4(filePath).href}?t=${Date.now()}`;
45342
45518
  const mod = await import(moduleUrl);
45343
45519
  const ModelClass = mod.default ?? mod;
45344
45520
  if (!ModelClass.tableName || !ModelClass.fields) {
@@ -45374,8 +45550,8 @@ var init_model = __esm({
45374
45550
  });
45375
45551
 
45376
45552
  // src/migration.ts
45377
- import { existsSync as existsSync27, readdirSync as readdirSync19, readFileSync as readFileSync25, mkdirSync as mkdirSync19, writeFileSync as writeFileSync17, rmSync } from "node:fs";
45378
- import { join as join31, resolve as resolve19 } from "node:path";
45553
+ import { existsSync as existsSync28, readdirSync as readdirSync19, readFileSync as readFileSync25, mkdirSync as mkdirSync19, writeFileSync as writeFileSync17, rmSync } from "node:fs";
45554
+ import { join as join32, resolve as resolve19 } from "node:path";
45379
45555
  import { tmpdir } from "node:os";
45380
45556
  import { createHash as createHash10 } from "node:crypto";
45381
45557
  function unwrapAdapter(db) {
@@ -45679,7 +45855,7 @@ async function removeMigrationRecord(name) {
45679
45855
  [name]
45680
45856
  );
45681
45857
  }
45682
- async function rollback(migrationsDir, delimiter2) {
45858
+ async function rollback(migrationsDir, delimiter3) {
45683
45859
  if (migrationsDir instanceof Map) {
45684
45860
  const downFunctions = migrationsDir;
45685
45861
  const migrations2 = await getLastBatchMigrations();
@@ -45698,14 +45874,14 @@ async function rollback(migrationsDir, delimiter2) {
45698
45874
  return rolledBack2;
45699
45875
  }
45700
45876
  const dir = resolve19(migrationsDir ?? "migrations");
45701
- const delim = delimiter2 ?? ";";
45877
+ const delim = delimiter3 ?? ";";
45702
45878
  const db = getAdapter();
45703
45879
  const migrations = await getLastBatchMigrations();
45704
45880
  const rolledBack = [];
45705
45881
  for (const migration of migrations) {
45706
45882
  const downFile = `${migration.migration_name}.down.sql`;
45707
- const downPath = join31(dir, downFile);
45708
- if (!existsSync27(downPath)) {
45883
+ const downPath = join32(dir, downFile);
45884
+ if (!existsSync28(downPath)) {
45709
45885
  throw new Error(
45710
45886
  `Cannot rollback ${migration.migration_name}: no .down.sql file found`
45711
45887
  );
@@ -45821,13 +45997,13 @@ function hasExecutableSql(sql) {
45821
45997
  function isUnappliedScaffold(sql) {
45822
45998
  return TINA4_EDIT_MARKER_RE.test(sql) && !hasExecutableSql(sql);
45823
45999
  }
45824
- function splitStatements(sql, delimiter2 = ";") {
46000
+ function splitStatements(sql, delimiter3 = ";") {
45825
46001
  const state = {
45826
46002
  sql: normalizeQuotes(sql),
45827
46003
  statements: [],
45828
46004
  current: "",
45829
- delimiter: delimiter2,
45830
- dlen: delimiter2.length,
46005
+ delimiter: delimiter3,
46006
+ dlen: delimiter3.length,
45831
46007
  i: 0,
45832
46008
  inDollarBlock: false,
45833
46009
  inSlashBlock: false
@@ -45892,7 +46068,7 @@ async function acquireMigrationLock(db, dir) {
45892
46068
  return acquireFileLock(dir);
45893
46069
  }
45894
46070
  async function acquireFileLock(dir) {
45895
- const lockFile = join31(tmpdir(), `tina4-migration-${createHash10("sha256").update(resolve19(dir)).digest("hex")}.lock`);
46071
+ const lockFile = join32(tmpdir(), `tina4-migration-${createHash10("sha256").update(resolve19(dir)).digest("hex")}.lock`);
45896
46072
  const deadline = Date.now() + 6e4;
45897
46073
  for (; ; ) {
45898
46074
  try {
@@ -45954,18 +46130,18 @@ async function releaseMigrationLock(db, lock) {
45954
46130
  async function migrate(adapter, options) {
45955
46131
  const db = adapter ?? getAdapter();
45956
46132
  const dir = resolve19(options?.migrationsDir ?? "migrations");
45957
- const delimiter2 = options?.delimiter ?? ";";
45958
- if (!existsSync27(dir)) {
46133
+ const delimiter3 = options?.delimiter ?? ";";
46134
+ if (!existsSync28(dir)) {
45959
46135
  return { applied: [], skipped: [], failed: [] };
45960
46136
  }
45961
46137
  const lock = await acquireMigrationLock(db, dir);
45962
46138
  try {
45963
- return await runPendingMigrations(db, dir, delimiter2);
46139
+ return await runPendingMigrations(db, dir, delimiter3);
45964
46140
  } finally {
45965
46141
  await releaseMigrationLock(db, lock);
45966
46142
  }
45967
46143
  }
45968
- async function runPendingMigrations(db, dir, delimiter2) {
46144
+ async function runPendingMigrations(db, dir, delimiter3) {
45969
46145
  const result = { applied: [], skipped: [], failed: [] };
45970
46146
  await ensureMigrationTableOn(db);
45971
46147
  const files = sortMigrationFiles(
@@ -46000,7 +46176,7 @@ async function runPendingMigrations(db, dir, delimiter2) {
46000
46176
  result.skipped.push(file);
46001
46177
  continue;
46002
46178
  }
46003
- const sqlContent = readFileSync25(join31(dir, file), "utf-8").trim();
46179
+ const sqlContent = readFileSync25(join32(dir, file), "utf-8").trim();
46004
46180
  if (!sqlContent) {
46005
46181
  result.skipped.push(file);
46006
46182
  continue;
@@ -46011,7 +46187,7 @@ async function runPendingMigrations(db, dir, delimiter2) {
46011
46187
  );
46012
46188
  continue;
46013
46189
  }
46014
- const statements = splitStatements(sqlContent, delimiter2);
46190
+ const statements = splitStatements(sqlContent, delimiter3);
46015
46191
  try {
46016
46192
  await adapterStartTransaction(db);
46017
46193
  for (const stmt of statements) {
@@ -46043,7 +46219,7 @@ async function status(adapter, options) {
46043
46219
  const db = adapter ?? getAdapter();
46044
46220
  const dir = resolve19(options?.migrationsDir ?? "migrations");
46045
46221
  const result = { completed: [], pending: [] };
46046
- if (!existsSync27(dir)) {
46222
+ if (!existsSync28(dir)) {
46047
46223
  return result;
46048
46224
  }
46049
46225
  if (!await adapterTableExists(db, MIGRATION_TABLE)) {
@@ -46090,7 +46266,7 @@ async function createMigration(description, options) {
46090
46266
  return createClassMigration(description, options);
46091
46267
  }
46092
46268
  const dir = resolve19(options?.migrationsDir ?? "migrations");
46093
- if (!existsSync27(dir)) {
46269
+ if (!existsSync28(dir)) {
46094
46270
  mkdirSync19(dir, { recursive: true });
46095
46271
  }
46096
46272
  const safeName = description.toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_|_$/g, "");
@@ -46105,8 +46281,8 @@ async function createMigration(description, options) {
46105
46281
  ].join("");
46106
46282
  const upFileName = `${timestamp2}_${safeName}.sql`;
46107
46283
  const downFileName = `${timestamp2}_${safeName}.down.sql`;
46108
- const upPath = join31(dir, upFileName);
46109
- const downPath = join31(dir, downFileName);
46284
+ const upPath = join32(dir, upFileName);
46285
+ const downPath = join32(dir, downFileName);
46110
46286
  const upTemplate = `-- Migration: ${description}
46111
46287
  -- Created: ${now.toISOString()}
46112
46288
 
@@ -46121,7 +46297,7 @@ async function createMigration(description, options) {
46121
46297
  }
46122
46298
  async function createClassMigration(description, options) {
46123
46299
  const dir = resolve19(options?.migrationsDir ?? "migrations");
46124
- if (!existsSync27(dir)) {
46300
+ if (!existsSync28(dir)) {
46125
46301
  mkdirSync19(dir, { recursive: true });
46126
46302
  }
46127
46303
  const safeName = description.toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_|_$/g, "");
@@ -46136,7 +46312,7 @@ async function createClassMigration(description, options) {
46136
46312
  String(now.getSeconds()).padStart(2, "0")
46137
46313
  ].join("");
46138
46314
  const fileName = `${timestamp2}_${safeName}.ts`;
46139
- const filePath = join31(dir, fileName);
46315
+ const filePath = join32(dir, fileName);
46140
46316
  const content = `// Migration: ${description}
46141
46317
  // Created: ${now.toISOString()}
46142
46318
 
@@ -46241,7 +46417,7 @@ var init_migration = __esm({
46241
46417
  /** Return sorted list of all migration files on disk (excludes .down.sql). */
46242
46418
  getFiles() {
46243
46419
  const dir = resolve19(this.dir);
46244
- if (!existsSync27(dir)) return [];
46420
+ if (!existsSync28(dir)) return [];
46245
46421
  return sortMigrationFiles(
46246
46422
  readdirSync19(dir).filter((f) => f.endsWith(".sql") && !f.endsWith(".down.sql"))
46247
46423
  );
@@ -47022,9 +47198,9 @@ var init_crudTable = __esm({
47022
47198
  });
47023
47199
 
47024
47200
  // src/crudRender.ts
47025
- import { existsSync as existsSync28 } from "node:fs";
47201
+ import { existsSync as existsSync29 } from "node:fs";
47026
47202
  import { resolve as pathResolve, join as pathJoin, dirname as dirname15 } from "node:path";
47027
- import { fileURLToPath as fileURLToPath9 } from "node:url";
47203
+ import { fileURLToPath as fileURLToPath10 } from "node:url";
47028
47204
  function frondFor(dir) {
47029
47205
  let engine = frondCache2.get(dir);
47030
47206
  if (!engine) {
@@ -47037,7 +47213,7 @@ function frondFor(dir) {
47037
47213
  function renderCrudTemplate(name, data) {
47038
47214
  const templateFile = `crud/${name}.twig`;
47039
47215
  const userDir = pathResolve(process.cwd(), "src", "templates");
47040
- if (existsSync28(pathJoin(userDir, templateFile))) {
47216
+ if (existsSync29(pathJoin(userDir, templateFile))) {
47041
47217
  return frondFor(userDir).render(templateFile, data);
47042
47218
  }
47043
47219
  return frondFor(FRAMEWORK_TEMPLATES_DIR).render(templateFile, data);
@@ -47165,7 +47341,7 @@ var init_crudRender = __esm({
47165
47341
  init_crudHelpers();
47166
47342
  init_crudTable();
47167
47343
  FRAMEWORK_TEMPLATES_DIR = pathResolve(
47168
- dirname15(fileURLToPath9(import.meta.url)),
47344
+ dirname15(fileURLToPath10(import.meta.url)),
47169
47345
  "..",
47170
47346
  "..",
47171
47347
  "core",
@@ -49749,7 +49925,7 @@ var init_seeder = __esm({
49749
49925
  import { DatabaseSync as DatabaseSync4 } from "node:sqlite";
49750
49926
  import { randomBytes as randomBytes11 } from "node:crypto";
49751
49927
  import { mkdirSync as mkdirSync20 } from "node:fs";
49752
- import { dirname as dirname16, isAbsolute as isAbsolute6, join as join32 } from "node:path";
49928
+ import { dirname as dirname16, isAbsolute as isAbsolute6, join as join33 } from "node:path";
49753
49929
  function iso(d) {
49754
49930
  return d.toISOString();
49755
49931
  }
@@ -50024,12 +50200,12 @@ function regexpFn(pattern, value) {
50024
50200
  }
50025
50201
  function resolveStorePath(dbPath) {
50026
50202
  if (dbPath === ":memory:") return dbPath;
50027
- let path10 = dbPath;
50028
- if (!isAbsolute6(path10)) {
50029
- path10 = join32(process.cwd(), path10);
50030
- mkdirSync20(dirname16(path10), { recursive: true });
50203
+ let path9 = dbPath;
50204
+ if (!isAbsolute6(path9)) {
50205
+ path9 = join33(process.cwd(), path9);
50206
+ mkdirSync20(dirname16(path9), { recursive: true });
50031
50207
  }
50032
- return path10;
50208
+ return path9;
50033
50209
  }
50034
50210
  function mongoUriSource() {
50035
50211
  return MONGO_URI_VARS.find((name) => (process.env[name] ?? "").trim() !== "") ?? "";
@@ -50408,8 +50584,8 @@ var init_docstore = __esm({
50408
50584
  path;
50409
50585
  conn;
50410
50586
  collections = /* @__PURE__ */ new Map();
50411
- constructor(path10) {
50412
- this.path = path10 || process.env.TINA4_DOC_STORE_PATH || "data/tina4_docstore.db";
50587
+ constructor(path9) {
50588
+ this.path = path9 || process.env.TINA4_DOC_STORE_PATH || "data/tina4_docstore.db";
50413
50589
  const resolved = resolveStorePath(this.path);
50414
50590
  this.conn = new DatabaseSync4(resolved);
50415
50591
  this.conn.function("regexp", regexpFn);
@@ -50498,8 +50674,8 @@ var init_graphUrl = __esm({
50498
50674
  this.engine = engine;
50499
50675
  this.host = parsed.hostname || "localhost";
50500
50676
  this.port = parsed.port ? parseInt(parsed.port, 10) : ENGINE_DEFAULT_PORT[engine];
50501
- const path10 = (parsed.pathname || "").replace(/^\//, "");
50502
- this.graph = path10 === "" ? null : path10;
50677
+ const path9 = (parsed.pathname || "").replace(/^\//, "");
50678
+ this.graph = path9 === "" ? null : path9;
50503
50679
  this.username = parsed.username ? decodeURIComponent(parsed.username) : null;
50504
50680
  this.password = parsed.password ? decodeURIComponent(parsed.password) : null;
50505
50681
  this.params = {};
@@ -51510,8 +51686,8 @@ var init_s3Client = __esm({
51510
51686
 
51511
51687
  // src/realtime/storage.ts
51512
51688
  import { randomBytes as randomBytes12 } from "node:crypto";
51513
- import { mkdirSync as mkdirSync21, readFileSync as readFileSync26, writeFileSync as writeFileSync18, unlinkSync as unlinkSync9, statSync as statSync19 } from "node:fs";
51514
- import { resolve as resolve20, sep as sep8 } from "node:path";
51689
+ import { mkdirSync as mkdirSync21, readFileSync as readFileSync26, writeFileSync as writeFileSync18, unlinkSync as unlinkSync9, statSync as statSync20 } from "node:fs";
51690
+ import { resolve as resolve20, sep as sep9 } from "node:path";
51515
51691
  function storageKey(filename = "") {
51516
51692
  let ext = "";
51517
51693
  if (filename && filename.includes(".")) {
@@ -51552,7 +51728,7 @@ var init_storage = __esm({
51552
51728
  // Resolve inside the root and reject any traversal attempt.
51553
51729
  pathFor(key) {
51554
51730
  const target = resolve20(this.directory, key);
51555
- if (target !== this.directory && !target.startsWith(this.directory + sep8)) {
51731
+ if (target !== this.directory && !target.startsWith(this.directory + sep9)) {
51556
51732
  throw new Error(`unsafe storage key: ${JSON.stringify(key)}`);
51557
51733
  }
51558
51734
  return target;
@@ -51579,7 +51755,7 @@ var init_storage = __esm({
51579
51755
  }
51580
51756
  exists(key) {
51581
51757
  try {
51582
- return statSync19(this.pathFor(key)).isFile();
51758
+ return statSync20(this.pathFor(key)).isFile();
51583
51759
  } catch {
51584
51760
  return false;
51585
51761
  }