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.
- package/CLAUDE.md +12 -8
- package/package.json +1 -1
- package/packages/cli/dist/bin.js +899 -693
- package/packages/cli/src/bin.ts +13 -5
- package/packages/cli/src/commands/lint.ts +3 -1
- package/packages/core/dist/index.js +789 -613
- package/packages/core/src/batchSpawn.ts +129 -0
- package/packages/core/src/devAdmin.ts +15 -11
- package/packages/core/src/fakeData.ts +4 -1
- package/packages/core/src/mcp.ts +4 -1
- package/packages/core/src/portTakeover.ts +62 -10
- package/packages/core/src/projectIndex.ts +3 -4
- package/packages/core/src/projectIndexStorage.ts +9 -1
- package/packages/core/src/response.ts +4 -1
- package/packages/core/src/routeDiscovery.ts +8 -2
- package/packages/core/src/server.ts +97 -20
- package/packages/core/src/session.ts +5 -0
- package/packages/core/src/sessionHandlers/databaseHandler.ts +16 -0
- package/packages/frond/dist/index.js +66 -19
- package/packages/frond/src/engine.ts +74 -23
- package/packages/orm/dist/index.js +823 -647
- package/packages/orm/src/model.ts +2 -1
- package/types/core/src/batchSpawn.d.ts +28 -0
- package/types/core/src/portTakeover.d.ts +18 -1
- package/types/core/src/projectIndexStorage.d.ts +5 -0
- package/types/core/src/session.d.ts +5 -0
- package/types/core/src/sessionHandlers/databaseHandler.d.ts +8 -0
- package/types/frond/src/engine.d.ts +31 -2
|
@@ -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 =
|
|
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,10 +41,27 @@ 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
|
|
47
62
|
* fallback. `dev`/`noTakeover` are passed in so this stays pure and directly
|
|
48
63
|
* testable; callers resolve them from isDev() / noTakeoverOptedOut().
|
|
64
|
+
* Before a bind, the caller passes the `host` it will bind, so a free port is
|
|
65
|
+
* reported as nothing rather than refused as "in use".
|
|
49
66
|
*/
|
|
50
|
-
export declare function takeOverPort(port: number, dev: boolean, noTakeover: boolean, baseDir?: string, grace?: number): TakeoverResult;
|
|
67
|
+
export declare function takeOverPort(port: number, dev: boolean, noTakeover: boolean, baseDir?: string, grace?: number, host?: string): TakeoverResult;
|
|
@@ -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.
|
|
@@ -90,23 +90,28 @@ export declare class Frond {
|
|
|
90
90
|
private static classFilters;
|
|
91
91
|
private static classGlobals;
|
|
92
92
|
private static classTests;
|
|
93
|
+
private static classRegistryVersion;
|
|
93
94
|
private static liveFragments;
|
|
94
95
|
private static liveSources;
|
|
95
96
|
private static liveWsPaths;
|
|
96
97
|
private static liveBroadcaster;
|
|
97
98
|
/**
|
|
98
99
|
* Register a custom filter at the class level — available to every
|
|
99
|
-
*
|
|
100
|
+
* instance, existing ones included: an engine merges the class filters
|
|
101
|
+
* again at its next render (ADR-0107). Callable as ``Frond.addFilter()``
|
|
100
102
|
* (static) or ``frond.addFilter()`` (instance). See instance method
|
|
101
103
|
* below for the dual-call semantics.
|
|
102
104
|
*/
|
|
103
105
|
static addFilter(name: string, fn: FilterFn): void;
|
|
104
106
|
/**
|
|
105
107
|
* Register a global variable available in all templates of every
|
|
106
|
-
*
|
|
108
|
+
* instance, existing ones included: class globals are read at render time
|
|
109
|
+
* (ADR-0106). Callable as ``Frond.addGlobal()`` (static) or
|
|
107
110
|
* ``frond.addGlobal()`` (instance).
|
|
108
111
|
*/
|
|
109
112
|
static addGlobal(name: string, value: unknown): void;
|
|
113
|
+
/** True when a class-level global with this name is registered. */
|
|
114
|
+
static hasGlobal(name: string): boolean;
|
|
110
115
|
/**
|
|
111
116
|
* Register a custom test (``{% if x is positive %}``) at the class
|
|
112
117
|
* level. Callable as ``Frond.addTest()`` (static) or
|
|
@@ -121,8 +126,17 @@ export declare class Frond {
|
|
|
121
126
|
*/
|
|
122
127
|
static clearRegistry(): void;
|
|
123
128
|
private templateDir;
|
|
129
|
+
/** Effective filters: built-in < class < instance (see syncRegistries). */
|
|
124
130
|
private filters;
|
|
131
|
+
/** Filters / tests registered on THIS instance only (ADR-0052). */
|
|
132
|
+
private localFilters;
|
|
133
|
+
private localTests;
|
|
134
|
+
/** The class-registry version `filters` / `tests` were last merged at. */
|
|
135
|
+
private registryVersion;
|
|
136
|
+
/** Globals registered on THIS instance only (ADR-0052). */
|
|
125
137
|
private globals;
|
|
138
|
+
/** Built-in globals (formToken, range, dump, csp_nonce, ...). */
|
|
139
|
+
private builtinGlobals;
|
|
126
140
|
private tests;
|
|
127
141
|
private _sandbox;
|
|
128
142
|
private _allowedFilters;
|
|
@@ -149,6 +163,13 @@ export declare class Frond {
|
|
|
149
163
|
private readonly _applyFiltersBound;
|
|
150
164
|
getTemplateDir(): string;
|
|
151
165
|
constructor(templateDir?: string);
|
|
166
|
+
/**
|
|
167
|
+
* Rebuild the merged filter/test maps when the class registry changed.
|
|
168
|
+
* Same layering as globals -- built-ins < class < this instance. Filter
|
|
169
|
+
* lookup is on the hot path, so the merge is a plain object rebuilt only
|
|
170
|
+
* when the class-registry version moves, never a per-lookup chain.
|
|
171
|
+
*/
|
|
172
|
+
private syncRegistries;
|
|
152
173
|
sandbox(filters?: string[], tags?: string[], vars?: string[]): Frond;
|
|
153
174
|
unsandbox(): Frond;
|
|
154
175
|
/**
|
|
@@ -172,6 +193,14 @@ export declare class Frond {
|
|
|
172
193
|
* isn't a reliable freshness signal.
|
|
173
194
|
*/
|
|
174
195
|
private cacheTtlSeconds;
|
|
196
|
+
/**
|
|
197
|
+
* Layer the globals under the render data: built-ins < class globals (read
|
|
198
|
+
* live, so registration order never matters) < this instance's own globals
|
|
199
|
+
* < the data passed to render(). Every render starts here, so this is also
|
|
200
|
+
* where the filter/test maps catch up with any class registration made
|
|
201
|
+
* since the last render.
|
|
202
|
+
*/
|
|
203
|
+
private withGlobals;
|
|
175
204
|
render(template: string, data?: Record<string, unknown>): string;
|
|
176
205
|
renderString(source: string, data?: Record<string, unknown>): string;
|
|
177
206
|
/** Clear all compiled template caches. */
|