tina4-nodejs 3.13.133 → 3.13.134

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.
Files changed (50) hide show
  1. package/CLAUDE.md +3 -3
  2. package/README.md +2 -2
  3. package/package.json +1 -1
  4. package/packages/cli/dist/bin.js +3181 -3051
  5. package/packages/cli/src/commands/generate.ts +33 -22
  6. package/packages/cli/src/commands/lint.ts +77 -111
  7. package/packages/core/dist/index.js +3090 -2952
  8. package/packages/core/src/.tina4-metrics.json +15004 -0
  9. package/packages/core/src/aiClient.ts +199 -161
  10. package/packages/core/src/dispatchPipeline.ts +65 -67
  11. package/packages/core/src/docs.ts +52 -544
  12. package/packages/core/src/docsParser.ts +270 -0
  13. package/packages/core/src/docsScanner.ts +121 -0
  14. package/packages/core/src/docsSignatures.ts +165 -0
  15. package/packages/core/src/index.ts +2 -0
  16. package/packages/core/src/logger.ts +68 -82
  17. package/packages/core/src/mcp.ts +32 -60
  18. package/packages/core/src/messenger.ts +136 -157
  19. package/packages/core/src/middleware.ts +56 -60
  20. package/packages/core/src/plan.ts +78 -70
  21. package/packages/core/src/projectIndex.ts +15 -288
  22. package/packages/core/src/projectIndexExtractors.ts +126 -0
  23. package/packages/core/src/projectIndexStorage.ts +122 -0
  24. package/packages/core/src/push.ts +281 -0
  25. package/packages/core/src/server.ts +182 -183
  26. package/packages/frond/dist/index.js +607 -770
  27. package/packages/frond/src/engine.ts +670 -818
  28. package/packages/orm/dist/index.js +3100 -2965
  29. package/packages/orm/src/adapters/mongodb.ts +99 -144
  30. package/packages/orm/src/baseModel.ts +429 -515
  31. package/packages/orm/src/fakeData.ts +73 -61
  32. package/packages/orm/src/migration.ts +96 -126
  33. package/packages/orm/src/seeder.ts +6 -238
  34. package/packages/orm/src/seederTable.ts +101 -0
  35. package/packages/orm/src/seederTypes.ts +14 -0
  36. package/packages/orm/src/validation.ts +97 -80
  37. package/types/core/src/aiClient.d.ts +5 -0
  38. package/types/core/src/docsParser.d.ts +28 -0
  39. package/types/core/src/docsScanner.d.ts +1 -0
  40. package/types/core/src/docsSignatures.d.ts +11 -0
  41. package/types/core/src/index.d.ts +2 -0
  42. package/types/core/src/messenger.d.ts +8 -0
  43. package/types/core/src/projectIndexExtractors.d.ts +3 -0
  44. package/types/core/src/projectIndexStorage.d.ts +13 -0
  45. package/types/core/src/push.d.ts +45 -0
  46. package/types/frond/src/engine.d.ts +25 -0
  47. package/types/orm/src/fakeData.d.ts +3 -0
  48. package/types/orm/src/seeder.d.ts +3 -89
  49. package/types/orm/src/seederTable.d.ts +9 -0
  50. package/types/orm/src/seederTypes.d.ts +16 -0
@@ -0,0 +1,101 @@
1
+ import { FakeData } from "./fakeData.js";
2
+ import { adapterExecute, adapterColumns, adapterInsert } from "./database.js";
3
+ import { Log } from "../../core/src/index.js";
4
+ import type { DatabaseAdapter, FieldDefinition, FieldType } from "./types.js";
5
+ import type { SeedOptions, SeedSummary } from "./seederTypes.js";
6
+
7
+ function normaliseOptions(overrides?: Record<string, unknown>, opts?: SeedOptions):
8
+ Required<Pick<SeedOptions, "clear" | "strict">> & { overrides?: Record<string, unknown> } {
9
+ const merged = { ...(opts ?? {}) };
10
+ return {
11
+ overrides: merged.overrides ?? overrides,
12
+ clear: merged.clear ?? false,
13
+ strict: merged.strict ?? false,
14
+ };
15
+ }
16
+
17
+ /** Delete every row, logging but not hiding a clear failure. */
18
+ export async function clearTable(db: DatabaseAdapter, tableName: string): Promise<void> {
19
+ try {
20
+ await adapterExecute(db, `DELETE FROM "${tableName}"`);
21
+ } catch (e) {
22
+ Log.warning(`Seeder: could not clear '${tableName}': ${(e as Error).message}`);
23
+ }
24
+ }
25
+
26
+ function sqlTypeToFieldType(sqlType: string): FieldType {
27
+ const type = (sqlType || "").toUpperCase();
28
+ if (type.includes("INT")) return "integer";
29
+ if (type.includes("BOOL")) return "boolean";
30
+ if (["REAL", "FLOA", "DOUB", "NUM", "DEC"].some((part) => type.includes(part))) return "number";
31
+ if (type.includes("DATE") || type.includes("TIME")) return "datetime";
32
+ if (type.includes("TEXT") || type.includes("CLOB")) return "text";
33
+ return "string";
34
+ }
35
+
36
+ /** Build generators from live table metadata for the explicit seedTable path. */
37
+ export async function autoFieldMap(
38
+ db: DatabaseAdapter,
39
+ table: string,
40
+ fake: FakeData = new FakeData(),
41
+ ): Promise<Record<string, () => unknown>> {
42
+ const columns = await adapterColumns(db, table);
43
+ const fieldMap: Record<string, () => unknown> = {};
44
+ for (const column of columns) {
45
+ const name = column.name;
46
+ const sqlType = String(column.type ?? "").toUpperCase();
47
+ const generatedPk = column.primaryKey === true &&
48
+ (sqlType.includes("AUTO") || sqlType.includes("SERIAL") || sqlType.includes("IDENTITY") || name.toLowerCase() === "id");
49
+ if (generatedPk) continue;
50
+ fieldMap[name] = () => fake.forField({ type: sqlTypeToFieldType(sqlType) }, name, table);
51
+ }
52
+ return fieldMap;
53
+ }
54
+
55
+ /** Seed a table through the adapter insert path, counting or re-raising row failures. */
56
+ export async function seedTable(
57
+ db: DatabaseAdapter,
58
+ tableName: string,
59
+ count = 10,
60
+ fieldMap?: Record<string, (() => unknown) | unknown>,
61
+ overrides?: Record<string, unknown>,
62
+ opts?: SeedOptions,
63
+ ): Promise<SeedSummary> {
64
+ if (opts?.seed !== undefined) {
65
+ throw new Error(
66
+ "seedTable() no longer accepts opts.seed: it has no generators of its own to seed " +
67
+ "(fieldMap callables are opaque). Build a seeded FakeData yourself and close over it " +
68
+ "in fieldMap, e.g. const fake = new FakeData(42); seedTable(db, table, count, " +
69
+ "{ name: () => fake.name() }).",
70
+ );
71
+ }
72
+ const { overrides: effectiveOverrides, clear, strict } = normaliseOptions(overrides, opts);
73
+ if (!fieldMap || Object.keys(fieldMap).length === 0) return { seeded: 0, failed: 0, errors: [] };
74
+ if (clear) await clearTable(db, tableName);
75
+
76
+ let seeded = 0;
77
+ let failed = 0;
78
+ const errors: Array<{ row: number; message: string }> = [];
79
+ for (let i = 0; i < count; i++) {
80
+ try {
81
+ const row: Record<string, unknown> = {};
82
+ for (const [column, generator] of Object.entries(fieldMap)) {
83
+ row[column] = typeof generator === "function" ? (generator as () => unknown)() : generator;
84
+ }
85
+ for (const [column, value] of Object.entries(effectiveOverrides ?? {})) row[column] = value;
86
+ await adapterInsert(db, tableName, row);
87
+ seeded++;
88
+ } catch (e) {
89
+ const message = (e as Error).message ?? String(e);
90
+ if (strict) {
91
+ Log.error(`Seeder: row ${i} failed seeding '${tableName}' (strict): ${message}`);
92
+ throw e;
93
+ }
94
+ failed++;
95
+ errors.push({ row: i, message });
96
+ Log.warning(`Seeder: row ${i} failed seeding '${tableName}', skipped: ${message}`);
97
+ }
98
+ }
99
+ Log.info(`Seeder: '${tableName}' — seeded ${seeded}, ${failed} failed`);
100
+ return { seeded, failed, errors };
101
+ }
@@ -0,0 +1,14 @@
1
+ /** Result of a seed run. */
2
+ export interface SeedSummary {
3
+ seeded: number;
4
+ failed: number;
5
+ errors: Array<{ row: number; message: string }>;
6
+ }
7
+
8
+ /** Options shared by the table and ORM seed paths. */
9
+ export interface SeedOptions {
10
+ overrides?: Record<string, unknown>;
11
+ clear?: boolean;
12
+ seed?: number;
13
+ strict?: boolean;
14
+ }
@@ -5,6 +5,101 @@ export interface ValidationError {
5
5
  message: string;
6
6
  }
7
7
 
8
+ function error(field: string, message: string): ValidationError {
9
+ return { field, message };
10
+ }
11
+
12
+ function validateString(
13
+ name: string,
14
+ value: string,
15
+ def: FieldDefinition,
16
+ pattern: RegExp | undefined,
17
+ ): ValidationError[] {
18
+ const errors: ValidationError[] = [];
19
+ if (def.minLength !== undefined && value.length < def.minLength) {
20
+ errors.push(error(name, `must be at least ${def.minLength} characters`));
21
+ }
22
+ if (def.maxLength !== undefined && value.length > def.maxLength) {
23
+ errors.push(error(name, `must be at most ${def.maxLength} characters`));
24
+ }
25
+ if (pattern && !pattern.test(value)) {
26
+ errors.push(error(name, "does not match the required format"));
27
+ }
28
+ return errors;
29
+ }
30
+
31
+ function validateNumber(name: string, value: unknown, def: FieldDefinition): ValidationError[] {
32
+ const num = typeof value === "string" ? Number(value) : value;
33
+ if (typeof num !== "number" || isNaN(num)) return [error(name, "must be a number")];
34
+
35
+ const errors: ValidationError[] = [];
36
+ if (def.type === "integer" && !Number.isInteger(num)) {
37
+ errors.push(error(name, "must be an integer"));
38
+ }
39
+ if (def.min !== undefined && num < def.min) {
40
+ errors.push(error(name, `must be at least ${def.min}`));
41
+ }
42
+ if (def.max !== undefined && num > def.max) {
43
+ errors.push(error(name, `must be at most ${def.max}`));
44
+ }
45
+ return errors;
46
+ }
47
+
48
+ function validateBoolean(name: string, value: unknown): ValidationError[] {
49
+ return typeof value === "boolean" || value === 0 || value === 1 || value === "true" || value === "false"
50
+ ? []
51
+ : [error(name, "must be a boolean")];
52
+ }
53
+
54
+ function validateDatetime(name: string, value: unknown): ValidationError[] {
55
+ return typeof value === "string" && isNaN(Date.parse(value))
56
+ ? [error(name, "must be a valid date/time")]
57
+ : [];
58
+ }
59
+
60
+ function validateJson(name: string, value: unknown): ValidationError[] {
61
+ return value !== null && typeof value !== "object" && typeof value !== "string"
62
+ ? [error(name, "must be a JSON object or array")]
63
+ : [];
64
+ }
65
+
66
+ function validateForeignKey(name: string, value: unknown): ValidationError[] {
67
+ const fkNum = typeof value === "string" ? Number(value) : value;
68
+ return typeof fkNum !== "number" || isNaN(fkNum) || !Number.isInteger(fkNum)
69
+ ? [error(name, "must be a valid foreign key (integer)")]
70
+ : [];
71
+ }
72
+
73
+ function validateField(
74
+ name: string,
75
+ value: unknown,
76
+ def: FieldDefinition,
77
+ pattern: RegExp | undefined,
78
+ ): ValidationError[] {
79
+ if (def.type === "string" || def.type === "text") {
80
+ return typeof value === "string"
81
+ ? validateString(name, value, def, pattern)
82
+ : [error(name, "must be a string")];
83
+ }
84
+
85
+ if (def.type === "integer" || def.type === "number" || def.type === "numeric") {
86
+ return validateNumber(name, value, def);
87
+ }
88
+
89
+ switch (def.type) {
90
+ case "boolean":
91
+ return validateBoolean(name, value);
92
+ case "datetime":
93
+ return validateDatetime(name, value);
94
+ case "json":
95
+ return validateJson(name, value);
96
+ case "foreignKey":
97
+ return validateForeignKey(name, value);
98
+ default:
99
+ return [];
100
+ }
101
+ }
102
+
8
103
  export function validate(
9
104
  data: Record<string, unknown>,
10
105
  fields: Record<string, FieldDefinition>,
@@ -28,92 +123,14 @@ export function validate(
28
123
 
29
124
  // Required check (skip on update if field not provided)
30
125
  if (def.required && !isUpdate && (value === undefined || value === null || value === "")) {
31
- errors.push({ field: name, message: "is required" });
126
+ errors.push(error(name, "is required"));
32
127
  continue;
33
128
  }
34
129
 
35
130
  // Skip further validation if value not provided
36
131
  if (value === undefined || value === null) continue;
37
132
 
38
- // Type checks
39
- switch (def.type) {
40
- case "string":
41
- case "text":
42
- if (typeof value !== "string") {
43
- errors.push({ field: name, message: "must be a string" });
44
- } else {
45
- if (def.minLength !== undefined && value.length < def.minLength) {
46
- errors.push({ field: name, message: `must be at least ${def.minLength} characters` });
47
- }
48
- if (def.maxLength !== undefined && value.length > def.maxLength) {
49
- errors.push({ field: name, message: `must be at most ${def.maxLength} characters` });
50
- }
51
- const regex = compiledPatterns.get(name);
52
- if (regex && !regex.test(value)) {
53
- // Feature 19 (VALID-TWO-MESSAGES): one canonical wording per rule
54
- // across BOTH validators. The request Validator says "does not match
55
- // the required format"; the ORM validator must say the same so a
56
- // client keying on the message matches either surface.
57
- errors.push({ field: name, message: `does not match the required format` });
58
- }
59
- }
60
- break;
61
-
62
- case "integer":
63
- case "number":
64
- case "numeric": {
65
- const num = typeof value === "string" ? Number(value) : value;
66
- if (typeof num !== "number" || isNaN(num)) {
67
- errors.push({ field: name, message: "must be a number" });
68
- } else {
69
- if (def.type === "integer" && !Number.isInteger(num)) {
70
- errors.push({ field: name, message: "must be an integer" });
71
- }
72
- if (def.min !== undefined && num < def.min) {
73
- errors.push({ field: name, message: `must be at least ${def.min}` });
74
- }
75
- if (def.max !== undefined && num > def.max) {
76
- errors.push({ field: name, message: `must be at most ${def.max}` });
77
- }
78
- }
79
- break;
80
- }
81
-
82
- case "boolean":
83
- if (typeof value !== "boolean" && value !== 0 && value !== 1 && value !== "true" && value !== "false") {
84
- errors.push({ field: name, message: "must be a boolean" });
85
- }
86
- break;
87
-
88
- case "datetime":
89
- if (typeof value === "string" && isNaN(Date.parse(value))) {
90
- errors.push({ field: name, message: "must be a valid date/time" });
91
- }
92
- break;
93
-
94
- case "json":
95
- // A JSON column holds an object/array (or a pre-serialised JSON
96
- // string); reject a bare scalar. A value that can't be JSON-encoded
97
- // (a circular reference, a BigInt) fails loud at save time.
98
- if (value !== null && typeof value !== "object" && typeof value !== "string") {
99
- errors.push({ field: name, message: "must be a JSON object or array" });
100
- }
101
- break;
102
-
103
- case "foreignKey": {
104
- // Outlier D: previously there was no foreignKey case, so ANY value
105
- // passed validation silently. A foreign key references another model's
106
- // primary key — by default an auto-increment integer — so validate it
107
- // as an integer (a numeric string like "12" is coerced and accepted).
108
- // This catches the common bug of assigning a whole object / array /
109
- // non-numeric string to an *_id column before it reaches the driver.
110
- const fkNum = typeof value === "string" ? Number(value) : value;
111
- if (typeof fkNum !== "number" || isNaN(fkNum) || !Number.isInteger(fkNum)) {
112
- errors.push({ field: name, message: "must be a valid foreign key (integer)" });
113
- }
114
- break;
115
- }
116
- }
133
+ errors.push(...validateField(name, value, def, compiledPatterns.get(name)));
117
134
  }
118
135
 
119
136
  return errors;
@@ -146,6 +146,10 @@ export declare class Ai {
146
146
  */
147
147
  private static validateMessages;
148
148
  private static validateContent;
149
+ private static validateContentPart;
150
+ private static validateTextPart;
151
+ private static validateImagePart;
152
+ private static validateToolResultPart;
149
153
  /**
150
154
  * Validate the outbound tool declarations (ADR-0061). Each tool needs a
151
155
  * non-empty `name`, a string `description`, and a JSON-Schema-shaped
@@ -215,5 +219,6 @@ export declare class Ai {
215
219
  */
216
220
  private static streamRequest;
217
221
  private static responseChunks;
222
+ private static readStream;
218
223
  private static streamError;
219
224
  }
@@ -0,0 +1,28 @@
1
+ export interface ParsedClass {
2
+ name: string;
3
+ line: number;
4
+ doc: string;
5
+ exported: boolean;
6
+ methods: ParsedMethod[];
7
+ }
8
+ export interface ParsedMethod {
9
+ name: string;
10
+ line: number;
11
+ doc: string;
12
+ signature: string;
13
+ visibility: "public" | "protected" | "private";
14
+ static: boolean;
15
+ }
16
+ export interface ParsedFile {
17
+ classes: ParsedClass[];
18
+ functions: ParsedMethod[];
19
+ }
20
+ /**
21
+ * Parse a TS source string. Lightweight — finds top-level classes and their
22
+ * public methods, plus top-level exported functions. Captures preceding JSDoc.
23
+ *
24
+ * Strategy: scan token-by-token. We don't need a full AST — we only care
25
+ * about identifying class declarations, brace depth (to find class members),
26
+ * method/function declarations, and JSDoc comments immediately above.
27
+ */
28
+ export declare function parseTypeScript(source: string, _debugTag?: string): ParsedFile;
@@ -0,0 +1 @@
1
+ export declare function stripStrings(source: string): string;
@@ -0,0 +1,11 @@
1
+ interface MethodMatch {
2
+ name: string;
3
+ signature: string;
4
+ endIndex: number;
5
+ nameStart: number;
6
+ visibility: "public" | "protected" | "private";
7
+ static: boolean;
8
+ }
9
+ export declare function matchMethodSignature(stripped: string, source: string, i: number): MethodMatch | null;
10
+ export declare function matchTopLevelFunction(stripped: string, source: string, i: number): MethodMatch | null;
11
+ export {};
@@ -57,6 +57,8 @@ export { AI_TOOLS, isInstalled, showMenu, installSelected, installAll, generateC
57
57
  export type { AiTool } from "./ai.js";
58
58
  export { Sso, SSO, SsoError } from "./sso.js";
59
59
  export type { SsoOptions } from "./sso.js";
60
+ export { Push, PushError, generateVapidKeys } from "./push.js";
61
+ export type { PushOptions, PushSubscription, PushResult, PushPayload } from "./push.js";
60
62
  export { Ai, AiError, AiConfigError, AiHTTPError, AiTimeoutError, AiParseError } from "./aiClient.js";
61
63
  export type { ChatResponse, AiMessage, AiChatOptions, AiEmbedOptions, AiEvent, ContentPart, AiMessageContent, AiToolDeclaration, AiToolChoice } from "./aiClient.js";
62
64
  export type { ImapMessage, ImapFullMessage, ImapAttachment } from "./messenger.js";
@@ -139,6 +139,14 @@ export declare class Messenger {
139
139
  private shouldCapture;
140
140
  /** The local mailbox, created on first capture and reused after. */
141
141
  private getDevMailbox;
142
+ private prepareRecipients;
143
+ private connectSmtpSocket;
144
+ private requireSmtpResponse;
145
+ private openSmtpSession;
146
+ private authenticateSmtp;
147
+ private sendSmtpEnvelope;
148
+ private sendSmtpMessage;
149
+ private sendSmtp;
142
150
  send(to: string | string[], subject: string, body: string, html?: boolean, text?: string, cc?: string | string[], bcc?: string | string[], replyTo?: string, attachments?: string[], headers?: Record<string, string>): Promise<SendResult>;
143
151
  /**
144
152
  * Render a Frond template STRING and send it as an HTML email (G7, parity with
@@ -0,0 +1,3 @@
1
+ import type { FileEntry } from "./projectIndex.js";
2
+ export declare function extractForPath(filePath: string, text: string): FileEntry;
3
+ export declare function languageFor(filePath: string): string;
@@ -0,0 +1,13 @@
1
+ import type { FileEntry } from "./projectIndex.js";
2
+ export interface IndexData {
3
+ version: number;
4
+ files: Record<string, FileEntry>;
5
+ generated_at: number;
6
+ }
7
+ export declare function projectRoot(): string;
8
+ export declare function indexPath(): string;
9
+ export declare function summarise(entry: FileEntry): string;
10
+ export declare function extract(fullPath: string): FileEntry;
11
+ export declare function walk(dir: string, out: string[]): void;
12
+ export declare function loadRaw(): IndexData;
13
+ export declare function saveRaw(data: IndexData): void;
@@ -0,0 +1,45 @@
1
+ export interface PushSubscription {
2
+ endpoint: string;
3
+ keys: {
4
+ p256dh: string;
5
+ auth: string;
6
+ };
7
+ }
8
+ export interface PushOptions {
9
+ subject?: string;
10
+ publicKey?: string;
11
+ privateKey?: string;
12
+ ttl?: number;
13
+ urgency?: "very-low" | "low" | "normal" | "high";
14
+ }
15
+ export interface PushResult {
16
+ ok: boolean;
17
+ status: number;
18
+ dead: boolean;
19
+ retryable: boolean;
20
+ endpoint: string;
21
+ response: string;
22
+ }
23
+ export type PushPayload = string | Uint8Array | Record<string, unknown> | unknown[] | number | boolean | null;
24
+ export declare class PushError extends Error {
25
+ constructor(message: string);
26
+ }
27
+ export declare function generateVapidKeys(): {
28
+ publicKey: string;
29
+ privateKey: string;
30
+ };
31
+ /** Provider-neutral Web Push sender. A subscription is accepted as returned by PushManager. */
32
+ export declare class Push {
33
+ private readonly options;
34
+ constructor(options?: PushOptions);
35
+ static fromEnv(options?: PushOptions): Push;
36
+ static generateKeys(): {
37
+ publicKey: string;
38
+ privateKey: string;
39
+ };
40
+ private requireConfiguration;
41
+ private endpointFor;
42
+ private vapidKeys;
43
+ private deliver;
44
+ send(subscription: PushSubscription, payload: PushPayload): Promise<PushResult>;
45
+ }
@@ -97,6 +97,7 @@ export declare class Frond {
97
97
  private _allowedVars;
98
98
  private fragmentCache;
99
99
  private _autoEscape;
100
+ private readonly blockHandlers;
100
101
  /**
101
102
  * Token pre-compilation cache for file templates.
102
103
  *
@@ -188,6 +189,10 @@ export declare class Frond {
188
189
  */
189
190
  private substituteBlocks;
190
191
  private renderWithBlocks;
192
+ private dispatchBlock;
193
+ private renderTextToken;
194
+ private renderVarToken;
195
+ private renderBlockToken;
191
196
  private renderTokens;
192
197
  /**
193
198
  * May this filter RUN under the current sandbox?
@@ -206,6 +211,7 @@ export declare class Frond {
206
211
  * instead of the four names that happened to be checked individually.
207
212
  */
208
213
  private tagPermitted;
214
+ private applyFilterValue;
209
215
  /**
210
216
  * Consume a denied tag WITHOUT running it, returning the index past its body.
211
217
  *
@@ -228,8 +234,22 @@ export declare class Frond {
228
234
  private applyFilters;
229
235
  private evalVar;
230
236
  private evalVarRaw;
237
+ /**
238
+ * Apply the no-argument filters that are common enough to avoid generic
239
+ * dispatch. Keeping this table separate from evalVarInner makes the
240
+ * expression pipeline easier to audit without changing filter order.
241
+ */
242
+ private applyFastFilter;
243
+ private applyRenderedFilter;
244
+ private variablePermitted;
245
+ private resolveConcatenation;
246
+ private applyRenderedFilters;
231
247
  private evalVarInner;
248
+ private pushIfBranch;
249
+ private collectIfBranches;
232
250
  private handleIf;
251
+ private collectForTokens;
252
+ private forItems;
233
253
  private handleFor;
234
254
  private handleSet;
235
255
  private handleInclude;
@@ -257,6 +277,8 @@ export declare class Frond {
257
277
  */
258
278
  private handleImportAs;
259
279
  private handleFromImport;
280
+ private collectMacroDefinitions;
281
+ private createMacro;
260
282
  /**
261
283
  * Collect the body tokens of a {% <openTag> %}...{% end<openTag> %} block,
262
284
  * starting from the token after the opening tag (start + 1). Nested same-tag
@@ -279,6 +301,9 @@ export declare class Frond {
279
301
  * Python master's _handle_live and PHP/Ruby handleLive.
280
302
  */
281
303
  private handleLive;
304
+ private parseLiveOptions;
305
+ private collectLiveBody;
306
+ private liveAttributes;
282
307
  /**
283
308
  * Re-render a registered {% live %} fragment by name with fresh data.
284
309
  * Returns the rendered HTML, or null if no fragment is registered under that
@@ -19,6 +19,9 @@ export declare class FakeData extends CoreFakeData {
19
19
  * Matches the Python API's datetime() method.
20
20
  */
21
21
  datetime(startYear?: number, endYear?: number): Date;
22
+ private heuristicValue;
23
+ private stringValue;
24
+ private typedValue;
22
25
  /**
23
26
  * Generate a fake value appropriate for an ORM field definition.
24
27
  * Respects min/max, minLength/maxLength, and type constraints.
@@ -1,92 +1,7 @@
1
- import { FakeData } from "./fakeData.js";
2
1
  import type { DatabaseAdapter, FieldDefinition } from "./types.js";
3
- /**
4
- * Result of a seed run — `{ seeded, failed, errors }`.
5
- *
6
- * `errors` is a list of `{ row, message }` describing every skipped row
7
- * (`row` is the 0-based index). Mirrors the Python `SeedSummary`; Node tests
8
- * compare `.seeded` / `.failed` rather than the bare integer.
9
- */
10
- export interface SeedSummary {
11
- seeded: number;
12
- failed: number;
13
- errors: Array<{
14
- row: number;
15
- message: string;
16
- }>;
17
- }
18
- /** Options shared by seedTable / seedOrm / seedModels. */
19
- export interface SeedOptions {
20
- /** Static values applied to every row (overrides generated values). */
21
- overrides?: Record<string, unknown>;
22
- /** Delete every existing row in the target before seeding (P2). */
23
- clear?: boolean;
24
- /**
25
- * PRNG seed for reproducible FakeData output (P3). Honoured by seedOrm and
26
- * seedModels, which build and seed their own FakeData internally.
27
- *
28
- * NOT honoured by seedTable (SEED-TABLE-SEED-INERT, SEED-DEC-01, ratified
29
- * 2026-08-11 — same principle as the no-op ForeignKeyField on_delete):
30
- * seedTable has no generators of its own to seed — fieldMap callables are
31
- * opaque — so this used to be a silent no-op there. Passing it to seedTable
32
- * now THROWS instead. Build your own `new FakeData(seed)` and close over it
33
- * in fieldMap: `const fake = new FakeData(42); seedTable(db, table, count,
34
- * { name: () => fake.name() })`.
35
- */
36
- seed?: number;
37
- /** Re-raise on the first failed row instead of skipping it (P1). */
38
- strict?: boolean;
39
- }
40
- /**
41
- * Introspect `table`'s columns and build a column->generator field map for
42
- * {@link seedTable}, skipping the auto-increment / `id` primary key (the engine
43
- * assigns it). Mirrors the Python master's `auto_field_map`
44
- * (tina4_python/seeder/__init__.py): the shared "seed a table I did not
45
- * hand-write generators for" helper that both the dev-admin seed endpoint and
46
- * the MCP `seed_table` dev tool use — `seedTable` itself stays explicit
47
- * (no map = no rows), and this is how a caller opts into automatic generation.
48
- *
49
- * Reuses `FakeData.forField()` (column-name + type heuristics) so the generated
50
- * data matches every other Tina4 seeding path. Returns an empty map when the
51
- * table has no seedable columns, so `seedTable` then seeds nothing rather than
52
- * crashing.
53
- *
54
- * @param db - A DatabaseAdapter instance (pass `getAdapter()`, NOT the Database
55
- * wrapper — the wrapper has no `columns()`).
56
- * @param table - The table to introspect.
57
- * @param fake - Optional shared FakeData (pass one seeded via `new FakeData(n)`
58
- * for reproducible output).
59
- * @returns `{ column -> () => value }`, ready to hand to `seedTable`.
60
- */
61
- export declare function autoFieldMap(db: DatabaseAdapter, table: string, fake?: FakeData): Promise<Record<string, () => unknown>>;
62
- /**
63
- * Seed a database table with fake data using raw SQL inserts.
64
- *
65
- * Visible-but-resilient (P1): each row is wrapped. On a row failure the cause
66
- * is logged (with the row index) and the row is skipped — unless `strict: true`,
67
- * in which case the first failure RE-RAISES. At the end a one-line summary is
68
- * logged ("seeded N, M failed").
69
- *
70
- * @param db - A DatabaseAdapter instance
71
- * @param tableName - The table to insert into
72
- * @param count - Number of rows to insert (default 10)
73
- * @param fieldMap - Dict of column_name -> callable that generates a value
74
- * (or a static value). If not provided, no rows are inserted.
75
- * @param overrides - (legacy positional) Static values applied to every row.
76
- * Prefer `opts.overrides`.
77
- * @param opts - Seed options: `{ overrides, clear, strict }`. `opts.seed` is
78
- * NOT honoured here (see {@link SeedOptions.seed}) and throws if supplied.
79
- * @returns A SeedSummary `{ seeded, failed, errors }`.
80
- * @throws {Error} If `opts.seed` is defined (SEED-TABLE-SEED-INERT removal).
81
- *
82
- * @example
83
- * const fake = new FakeData();
84
- * await seedTable(db, "users", 50, {
85
- * name: () => fake.name(),
86
- * email: () => fake.email(),
87
- * }, undefined, { clear: true });
88
- */
89
- export declare function seedTable(db: DatabaseAdapter, tableName: string, count?: number, fieldMap?: Record<string, (() => unknown) | unknown>, overrides?: Record<string, unknown>, opts?: SeedOptions): Promise<SeedSummary>;
2
+ import type { SeedOptions, SeedSummary } from "./seederTypes.js";
3
+ export { autoFieldMap, seedTable } from "./seederTable.js";
4
+ export type { SeedOptions, SeedSummary } from "./seederTypes.js";
90
5
  /** A model-like shape the seeder can drive (real BaseModel subclass or mock). */
91
6
  interface SeedableModel {
92
7
  tableName: string;
@@ -128,4 +43,3 @@ export declare function seedOrm(ormClass: SeedableModel, count?: number, overrid
128
43
  export declare function seedModels(ormClasses: SeedableModel[], count?: number, opts?: SeedOptions & {
129
44
  overrides?: Record<string, unknown> | Map<SeedableModel, Record<string, unknown>>;
130
45
  }): Promise<Record<string, SeedSummary>>;
131
- export {};
@@ -0,0 +1,9 @@
1
+ import { FakeData } from "./fakeData.js";
2
+ import type { DatabaseAdapter } from "./types.js";
3
+ import type { SeedOptions, SeedSummary } from "./seederTypes.js";
4
+ /** Delete every row, logging but not hiding a clear failure. */
5
+ export declare function clearTable(db: DatabaseAdapter, tableName: string): Promise<void>;
6
+ /** Build generators from live table metadata for the explicit seedTable path. */
7
+ export declare function autoFieldMap(db: DatabaseAdapter, table: string, fake?: FakeData): Promise<Record<string, () => unknown>>;
8
+ /** Seed a table through the adapter insert path, counting or re-raising row failures. */
9
+ export declare function seedTable(db: DatabaseAdapter, tableName: string, count?: number, fieldMap?: Record<string, (() => unknown) | unknown>, overrides?: Record<string, unknown>, opts?: SeedOptions): Promise<SeedSummary>;
@@ -0,0 +1,16 @@
1
+ /** Result of a seed run. */
2
+ export interface SeedSummary {
3
+ seeded: number;
4
+ failed: number;
5
+ errors: Array<{
6
+ row: number;
7
+ message: string;
8
+ }>;
9
+ }
10
+ /** Options shared by the table and ORM seed paths. */
11
+ export interface SeedOptions {
12
+ overrides?: Record<string, unknown>;
13
+ clear?: boolean;
14
+ seed?: number;
15
+ strict?: boolean;
16
+ }