tina4-nodejs 3.13.164 → 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.
@@ -8,6 +8,7 @@ file, You can obtain one at https://mozilla.org/MPL/2.0/.
8
8
 
9
9
  import { readdirSync, statSync } from "node:fs";
10
10
  import { join, extname } from "node:path";
11
+ import { pathToFileURL } from "node:url";
11
12
  import type { ModelDefinition, FieldDefinition, RelationshipDefinition } from "./types.js";
12
13
 
13
14
  export interface DiscoveredModel {
@@ -35,7 +36,7 @@ export async function discoverModels(modelsDir: string): Promise<DiscoveredModel
35
36
  if (ext !== ".ts" && ext !== ".js") continue;
36
37
 
37
38
  try {
38
- const moduleUrl = `file://${filePath}?t=${Date.now()}`;
39
+ const moduleUrl = `${pathToFileURL(filePath).href}?t=${Date.now()}`;
39
40
  const mod = await import(moduleUrl);
40
41
  const ModelClass = mod.default ?? mod;
41
42
 
@@ -0,0 +1,28 @@
1
+ import type { SpawnSyncOptions, SpawnSyncReturns } from "node:child_process";
2
+ /** True when `file` is a batch file that Node will not spawn without a shell. */
3
+ export declare function isBatchFile(file: string, platform?: NodeJS.Platform): boolean;
4
+ /** One argument, quoted and escaped for a batch file run through `cmd /d /s /c`. */
5
+ export declare function escapeBatchArgument(arg: string): string;
6
+ /**
7
+ * Resolve a bare program name such as `npm` to the file Windows would run.
8
+ *
9
+ * Without a shell, Windows' CreateProcess only adds `.exe`, so `npm` (which is
10
+ * `npm.cmd`) is never found and the spawn fails with ENOENT. This walks PATH
11
+ * with PATHEXT the way cmd.exe does. A name that already has a directory or an
12
+ * extension, every other platform, and a name that is not found are returned
13
+ * unchanged, so the spawn reports its own error exactly as before.
14
+ */
15
+ export declare function findExecutable(name: string, platform?: NodeJS.Platform): string;
16
+ /**
17
+ * `spawnSync`, except that a batch file on Windows runs through cmd.exe with
18
+ * every argument escaped. Returns what spawnSync returns either way.
19
+ */
20
+ export declare function spawnSyncAllowingBatch(file: string, args: readonly string[], options?: SpawnSyncOptions): SpawnSyncReturns<Buffer | string>;
21
+ /**
22
+ * `execFileSync` for a bare program name (`npm`, `npx`) that may be a batch
23
+ * file: resolves it with {@link findExecutable}, runs it with
24
+ * {@link spawnSyncAllowingBatch}, and like execFileSync returns stdout and
25
+ * throws on a spawn error or a non-zero exit (the error carries `status`,
26
+ * `stdout` and `stderr`).
27
+ */
28
+ export declare function execFileSyncAllowingBatch(name: string, args: readonly string[], options?: SpawnSyncOptions): string;
@@ -41,6 +41,21 @@ export declare function writePidfile(port: number, baseDir?: string, pid?: numbe
41
41
  export declare function readPidfile(port: number, baseDir?: string): number | null;
42
42
  /** Drop the PID file for `port` (clean shutdown, or after reclaiming it). */
43
43
  export declare function removePidfile(port: number, baseDir?: string): void;
44
+ /** What a bind probe learned about a port. */
45
+ export type BindProbe = "free" | "held" | "unknown";
46
+ /**
47
+ * Try a plain TCP listener on `host`:`port` (the same net.listen the server
48
+ * uses) and report what happened.
49
+ *
50
+ * Only a bind that fails with EADDRINUSE is "held". A probe that times out,
51
+ * cannot start, or hits any other bind error (EACCES, EADDRNOTAVAIL) is
52
+ * "unknown": it says nothing about whether something holds the port, so the
53
+ * caller must not report the port as in use. The real bind then decides, and
54
+ * it fails loudly with the true error. A probe is a child `node`, so on a slow
55
+ * host (arm64 under emulation, a small board, a CPU-throttled container) the
56
+ * child alone can take longer than the timeout to start.
57
+ */
58
+ export declare function probeBind(host: string, port: number, timeout?: number): BindProbe;
44
59
  /**
45
60
  * Reclaim `port` ONLY from an identity-confirmed Tina4 dev server. The single
46
61
  * guarded path for both the CLI (`tina4 serve`) and the runtime bind-failure
@@ -4,6 +4,11 @@ export interface IndexData {
4
4
  files: Record<string, FileEntry>;
5
5
  generated_at: number;
6
6
  }
7
+ /**
8
+ * The index key for a file: its path relative to `root`, always `/`-separated
9
+ * so the same file has the same key on every OS (PHP's rule).
10
+ */
11
+ export declare function indexKey(root: string, fullPath: string): string;
7
12
  export declare function projectRoot(): string;
8
13
  export declare function indexPath(): string;
9
14
  export declare function summarise(entry: FileEntry): string;
@@ -47,6 +47,11 @@ export interface SessionHandler {
47
47
  destroy(sessionId: string): void;
48
48
  /** Garbage-collect expired sessions. Optional — Redis/Valkey/Mongo handle TTL natively. */
49
49
  gc?(maxLifetime: number): void;
50
+ /**
51
+ * Release a connection the handler opened itself. Optional; idempotent; the
52
+ * next read or write reopens it.
53
+ */
54
+ close?(): void;
50
55
  }
51
56
  export declare class FileSessionHandler implements SessionHandler {
52
57
  private storagePath;
@@ -54,6 +54,14 @@ export declare class DatabaseSessionHandler implements SessionHandler {
54
54
  constructor(config?: DatabaseSessionConfig);
55
55
  /** Open the SQLite database on FIRST USE, not at construction. */
56
56
  private get sqlite();
57
+ /**
58
+ * Release the SQLite connection this handler opened, so its file (and the
59
+ * WAL's -wal / -shm side files) is no longer held open: on Windows an open
60
+ * file cannot be deleted or replaced. Idempotent, and the next read or write
61
+ * reopens the connection. A server engine needs nothing here - each call goes
62
+ * through the sync bridge, which holds no connection between calls.
63
+ */
64
+ close(): void;
57
65
  private get engine();
58
66
  /**
59
67
  * Decide, from TINA4_DATABASE_URL, which engine this handler talks to.