@timber-js/app 0.2.0-alpha.151 → 0.2.0-alpha.153
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/dist/_chunks/actions-8lJZYYGq.js +298 -0
- package/dist/_chunks/actions-8lJZYYGq.js.map +1 -0
- package/dist/_chunks/{cache-api-Co-yI-gP.js → cache-api-e1E4i3Vy.js} +3 -26
- package/dist/_chunks/cache-api-e1E4i3Vy.js.map +1 -0
- package/dist/_chunks/{cli-schema-sync-DJDdyEae.js → cli-schema-sync-ChsRzw8o.js} +2 -2
- package/dist/_chunks/{cli-schema-sync-DJDdyEae.js.map → cli-schema-sync-ChsRzw8o.js.map} +1 -1
- package/dist/_chunks/{cli-schema-sync-D_IhHEUW.js → cli-schema-sync-D4urWkeV.js} +1 -1
- package/dist/_chunks/{actions-a0RczDnB.js → logger-DvmCWhN9.js} +665 -274
- package/dist/_chunks/logger-DvmCWhN9.js.map +1 -0
- package/dist/_chunks/plugin-context-GfDWsdd2.js.map +1 -1
- package/dist/_chunks/{walkers-DvWDj453.js → walkers-DZuFKqFX.js} +2 -2
- package/dist/_chunks/{walkers-DvWDj453.js.map → walkers-DZuFKqFX.js.map} +1 -1
- package/dist/cache/index.js +1 -1
- package/dist/cli.js +1 -1
- package/dist/client/browser-dev.d.ts +3 -0
- package/dist/client/browser-dev.d.ts.map +1 -1
- package/dist/config-types.d.ts +8 -0
- package/dist/config-types.d.ts.map +1 -1
- package/dist/config-validation.d.ts.map +1 -1
- package/dist/index.js +193 -48
- package/dist/index.js.map +1 -1
- package/dist/plugin-context.d.ts +9 -0
- package/dist/plugin-context.d.ts.map +1 -1
- package/dist/plugins/build-report.d.ts +13 -0
- package/dist/plugins/build-report.d.ts.map +1 -1
- package/dist/plugins/chunks.d.ts +11 -4
- package/dist/plugins/chunks.d.ts.map +1 -1
- package/dist/plugins/client-chunks.d.ts +23 -22
- package/dist/plugins/client-chunks.d.ts.map +1 -1
- package/dist/routing/index.js +2 -2
- package/dist/server/index.js +2 -2
- package/dist/server/internal.js +65 -2
- package/dist/server/internal.js.map +1 -1
- package/dist/server/logger.d.ts.map +1 -1
- package/dist/server/pipeline.d.ts.map +1 -1
- package/dist/server/primitives.d.ts +8 -0
- package/dist/server/primitives.d.ts.map +1 -1
- package/dist/server/route-element-builder.d.ts.map +1 -1
- package/dist/server/stream-utils.d.ts +11 -0
- package/dist/server/stream-utils.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/client/browser-dev.ts +3 -0
- package/src/config-types.ts +8 -0
- package/src/config-validation.ts +16 -0
- package/src/index.ts +2 -2
- package/src/plugin-context.ts +9 -0
- package/src/plugins/build-report.ts +105 -10
- package/src/plugins/chunks.ts +74 -5
- package/src/plugins/client-chunks.ts +73 -42
- package/src/server/logger.ts +5 -0
- package/src/server/pipeline.ts +13 -0
- package/src/server/primitives.ts +29 -0
- package/src/server/route-element-builder.ts +4 -1
- package/src/server/stream-utils.ts +73 -0
- package/dist/_chunks/actions-a0RczDnB.js.map +0 -1
- package/dist/_chunks/cache-api-Co-yI-gP.js.map +0 -1
- package/dist/_chunks/logger-CM0clugc.js +0 -645
- package/dist/_chunks/logger-CM0clugc.js.map +0 -1
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
import { $ as revalidationAls, Y as withSpan, _ as RedirectSignal, g as DenySignal } from "./logger-DvmCWhN9.js";
|
|
2
|
+
import { t as cache } from "./cache-api-e1E4i3Vy.js";
|
|
3
|
+
//#region src/server/form-data.ts
|
|
4
|
+
/**
|
|
5
|
+
* FormData preprocessing — schema-agnostic conversion of FormData to typed objects.
|
|
6
|
+
*
|
|
7
|
+
* FormData is all strings. Schema validation expects typed values. This module
|
|
8
|
+
* bridges the gap with intelligent coercion that runs *before* schema validation.
|
|
9
|
+
*
|
|
10
|
+
* Inspired by zod-form-data, but schema-agnostic — works with any Standard Schema
|
|
11
|
+
* library (Zod, Valibot, ArkType).
|
|
12
|
+
*
|
|
13
|
+
* See design/08-forms-and-actions.md §"parseFormData() and coerce helpers"
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Convert FormData into a plain object with intelligent coercion.
|
|
17
|
+
*
|
|
18
|
+
* Handles:
|
|
19
|
+
* - **Duplicate keys → arrays**: `tags=js&tags=ts` → `{ tags: ["js", "ts"] }`
|
|
20
|
+
* - **Nested dot-paths**: `user.name=Alice` → `{ user: { name: "Alice" } }`
|
|
21
|
+
* - **Empty strings → undefined**: Enables `.optional()` semantics in schemas
|
|
22
|
+
* - **Empty Files → undefined**: File inputs with no selection become `undefined`
|
|
23
|
+
* - **Strips `$ACTION_*` fields**: React's internal hidden fields are excluded
|
|
24
|
+
*/
|
|
25
|
+
function parseFormData(formData) {
|
|
26
|
+
const flat = {};
|
|
27
|
+
for (const key of new Set(formData.keys())) {
|
|
28
|
+
if (key.startsWith("$ACTION_")) continue;
|
|
29
|
+
if (DANGEROUS_KEYS.has(key)) continue;
|
|
30
|
+
const processed = formData.getAll(key).map(normalizeValue);
|
|
31
|
+
if (processed.length === 1) flat[key] = processed[0];
|
|
32
|
+
else flat[key] = processed.filter((v) => v !== void 0);
|
|
33
|
+
}
|
|
34
|
+
return expandDotPaths(flat);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Normalize a single FormData entry value.
|
|
38
|
+
* - Empty strings → undefined (enables .optional() semantics)
|
|
39
|
+
* - Empty File objects (no selection) → undefined
|
|
40
|
+
* - Everything else passes through as-is
|
|
41
|
+
*/
|
|
42
|
+
function normalizeValue(value) {
|
|
43
|
+
if (typeof value === "string") return value === "" ? void 0 : value;
|
|
44
|
+
if (value instanceof File && value.size === 0 && value.name === "") return;
|
|
45
|
+
return value;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Expand dot-notation keys into nested objects.
|
|
49
|
+
* `{ "user.name": "Alice", "user.age": "30" }` → `{ user: { name: "Alice", age: "30" } }`
|
|
50
|
+
*
|
|
51
|
+
* Keys without dots are left as-is. Bracket notation (e.g. `items[0]`) is NOT
|
|
52
|
+
* supported — use dot notation (`items.0`) instead.
|
|
53
|
+
*/
|
|
54
|
+
function expandDotPaths(flat) {
|
|
55
|
+
const result = {};
|
|
56
|
+
let hasDotPaths = false;
|
|
57
|
+
for (const key of Object.keys(flat)) if (key.includes(".")) {
|
|
58
|
+
hasDotPaths = true;
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
if (!hasDotPaths) return flat;
|
|
62
|
+
for (const [key, value] of Object.entries(flat)) {
|
|
63
|
+
const parts = key.split(".");
|
|
64
|
+
if (parts.some((p) => DANGEROUS_KEYS.has(p))) continue;
|
|
65
|
+
if (parts.length === 1) {
|
|
66
|
+
result[parts[0]] = value;
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
let current = result;
|
|
70
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
71
|
+
const part = parts[i];
|
|
72
|
+
if (current[part] === void 0 || current[part] === null) current[part] = {};
|
|
73
|
+
if (typeof current[part] !== "object" || current[part] instanceof File) current[part] = {};
|
|
74
|
+
current = current[part];
|
|
75
|
+
}
|
|
76
|
+
current[parts[parts.length - 1]] = value;
|
|
77
|
+
}
|
|
78
|
+
return result;
|
|
79
|
+
}
|
|
80
|
+
var DANGEROUS_KEYS = new Set(["__proto__"]);
|
|
81
|
+
/**
|
|
82
|
+
* Schema-agnostic coercion primitives for common FormData patterns.
|
|
83
|
+
*
|
|
84
|
+
* These are plain transform functions — they compose with any schema library's
|
|
85
|
+
* `transform`/`preprocess` pipeline:
|
|
86
|
+
*
|
|
87
|
+
* ```ts
|
|
88
|
+
* // Zod
|
|
89
|
+
* z.preprocess(coerce.number, z.number())
|
|
90
|
+
* // Valibot
|
|
91
|
+
* v.pipe(v.unknown(), v.transform(coerce.number), v.number())
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
var coerce = {
|
|
95
|
+
/**
|
|
96
|
+
* Coerce a string to a number.
|
|
97
|
+
* - `"42"` → `42`
|
|
98
|
+
* - `"3.14"` → `3.14`
|
|
99
|
+
* - `""` / `undefined` / `null` → `undefined`
|
|
100
|
+
* - Non-numeric strings → `undefined` (schema validation will catch this)
|
|
101
|
+
*/
|
|
102
|
+
number(value) {
|
|
103
|
+
if (value === void 0 || value === null || value === "") return void 0;
|
|
104
|
+
if (typeof value === "number") return value;
|
|
105
|
+
if (typeof value !== "string") return void 0;
|
|
106
|
+
const num = Number(value);
|
|
107
|
+
if (Number.isNaN(num)) return void 0;
|
|
108
|
+
return num;
|
|
109
|
+
},
|
|
110
|
+
/**
|
|
111
|
+
* Coerce a checkbox value to a boolean.
|
|
112
|
+
* HTML checkboxes submit "on" when checked and are absent when unchecked.
|
|
113
|
+
* - `"on"` / any truthy string → `true`
|
|
114
|
+
* - `undefined` / `null` / `""` → `false`
|
|
115
|
+
*/
|
|
116
|
+
checkbox(value) {
|
|
117
|
+
if (value === void 0 || value === null || value === "") return false;
|
|
118
|
+
if (typeof value === "boolean") return value;
|
|
119
|
+
return typeof value === "string" && value.length > 0;
|
|
120
|
+
},
|
|
121
|
+
/**
|
|
122
|
+
* Parse a JSON string into an object.
|
|
123
|
+
* - Valid JSON string → parsed object
|
|
124
|
+
* - `""` / `undefined` / `null` → `undefined`
|
|
125
|
+
* - Invalid JSON → `undefined` (schema validation will catch this)
|
|
126
|
+
*/
|
|
127
|
+
json(value) {
|
|
128
|
+
if (value === void 0 || value === null || value === "") return void 0;
|
|
129
|
+
if (typeof value !== "string") return value;
|
|
130
|
+
try {
|
|
131
|
+
return JSON.parse(value);
|
|
132
|
+
} catch {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
/**
|
|
137
|
+
* Coerce a date string to a Date object.
|
|
138
|
+
* Handles `<input type="date">` (`"2024-01-15"`), `<input type="datetime-local">`
|
|
139
|
+
* (`"2024-01-15T10:30"`), and full ISO 8601 strings.
|
|
140
|
+
* - Valid date string → `Date`
|
|
141
|
+
* - `""` / `undefined` / `null` → `undefined`
|
|
142
|
+
* - Invalid date strings → `undefined` (schema validation will catch this)
|
|
143
|
+
* - Impossible dates that `new Date()` silently normalizes (e.g. Feb 31) → `undefined`
|
|
144
|
+
*/
|
|
145
|
+
date(value) {
|
|
146
|
+
if (value === void 0 || value === null || value === "") return void 0;
|
|
147
|
+
if (value instanceof Date) return value;
|
|
148
|
+
if (typeof value !== "string") return void 0;
|
|
149
|
+
const date = new Date(value);
|
|
150
|
+
if (Number.isNaN(date.getTime())) return void 0;
|
|
151
|
+
const ymdMatch = value.match(/^(\d{4})-(\d{2})-(\d{2})/);
|
|
152
|
+
if (ymdMatch) {
|
|
153
|
+
const inputYear = Number(ymdMatch[1]);
|
|
154
|
+
const inputMonth = Number(ymdMatch[2]);
|
|
155
|
+
const inputDay = Number(ymdMatch[3]);
|
|
156
|
+
const isUTC = value.length === 10 || value.endsWith("Z");
|
|
157
|
+
const parsedYear = isUTC ? date.getUTCFullYear() : date.getFullYear();
|
|
158
|
+
const parsedMonth = isUTC ? date.getUTCMonth() + 1 : date.getMonth() + 1;
|
|
159
|
+
const parsedDay = isUTC ? date.getUTCDate() : date.getDate();
|
|
160
|
+
if (inputYear !== parsedYear || inputMonth !== parsedMonth || inputDay !== parsedDay) return;
|
|
161
|
+
}
|
|
162
|
+
return date;
|
|
163
|
+
},
|
|
164
|
+
/**
|
|
165
|
+
* Create a File coercion function with optional size and mime type validation.
|
|
166
|
+
* Returns the File if valid, `undefined` otherwise.
|
|
167
|
+
*
|
|
168
|
+
* ```ts
|
|
169
|
+
* // Basic — just checks it's a real File
|
|
170
|
+
* z.preprocess(coerce.file(), z.instanceof(File))
|
|
171
|
+
*
|
|
172
|
+
* // With constraints
|
|
173
|
+
* z.preprocess(
|
|
174
|
+
* coerce.file({ maxSize: 5 * 1024 * 1024, accept: ['image/png', 'image/jpeg'] }),
|
|
175
|
+
* z.instanceof(File)
|
|
176
|
+
* )
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
file(options) {
|
|
180
|
+
return (value) => {
|
|
181
|
+
if (value === void 0 || value === null || value === "") return void 0;
|
|
182
|
+
if (!(value instanceof File)) return void 0;
|
|
183
|
+
if (value.size === 0 && value.name === "") return void 0;
|
|
184
|
+
if (options?.maxSize !== void 0 && value.size > options.maxSize) return;
|
|
185
|
+
if (options?.accept !== void 0 && !options.accept.includes(value.type)) return;
|
|
186
|
+
return value;
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
//#endregion
|
|
191
|
+
//#region src/server/actions.ts
|
|
192
|
+
/**
|
|
193
|
+
* Server action primitives: revalidatePath, revalidateTag, and the action handler.
|
|
194
|
+
*
|
|
195
|
+
* - revalidatePath(path) re-renders the route at that path and returns the RSC
|
|
196
|
+
* flight payload for inline reconciliation.
|
|
197
|
+
* - revalidateTag(tag) invalidates timber.cache entries by tag.
|
|
198
|
+
*
|
|
199
|
+
* Both are callable from anywhere on the server — actions, API routes, handlers.
|
|
200
|
+
*
|
|
201
|
+
* The action handler processes incoming action requests, validates CSRF,
|
|
202
|
+
* enforces body limits, executes the action, and returns the response
|
|
203
|
+
* (with piggybacked RSC payload if revalidatePath was called).
|
|
204
|
+
*
|
|
205
|
+
* See design/08-forms-and-actions.md
|
|
206
|
+
*/
|
|
207
|
+
/**
|
|
208
|
+
* Get the current revalidation state. Throws if called outside an action context.
|
|
209
|
+
* @internal
|
|
210
|
+
*/
|
|
211
|
+
function getRevalidationState() {
|
|
212
|
+
const state = revalidationAls.getStore();
|
|
213
|
+
if (!state) throw new Error("revalidatePath/revalidateTag called outside of a server action context. These functions can only be called during action execution.");
|
|
214
|
+
return state;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Re-render the route at `path` and include the RSC flight payload in the
|
|
218
|
+
* action response. The client reconciles inline — no separate fetch needed.
|
|
219
|
+
*
|
|
220
|
+
* Can be called from server actions, API routes, or any server-side context.
|
|
221
|
+
*
|
|
222
|
+
* @param path - The path to re-render (e.g. '/dashboard', '/todos').
|
|
223
|
+
*/
|
|
224
|
+
function revalidatePath(path) {
|
|
225
|
+
const state = getRevalidationState();
|
|
226
|
+
if (!state.paths.includes(path)) state.paths.push(path);
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Invalidate all timber.cache entries tagged with `tag`.
|
|
230
|
+
* Does not return a payload — the next request for an invalidated entry re-executes.
|
|
231
|
+
*
|
|
232
|
+
* @param tag - The cache tag to invalidate (e.g. 'products', 'user:123').
|
|
233
|
+
*/
|
|
234
|
+
function revalidateTag(tag) {
|
|
235
|
+
const state = getRevalidationState();
|
|
236
|
+
if (!state.tags.includes(tag)) state.tags.push(tag);
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Execute a server action and process revalidation.
|
|
240
|
+
*
|
|
241
|
+
* 1. Sets up revalidation state
|
|
242
|
+
* 2. Calls the action function
|
|
243
|
+
* 3. Processes revalidateTag calls (invalidates cache entries)
|
|
244
|
+
* 4. Processes revalidatePath calls (re-renders and captures RSC payload)
|
|
245
|
+
* 5. Returns the action result + optional RSC payload
|
|
246
|
+
*
|
|
247
|
+
* @param actionFn - The server action function to execute.
|
|
248
|
+
* @param args - Arguments to pass to the action.
|
|
249
|
+
* @param config - Handler configuration (cache handler, renderer).
|
|
250
|
+
*/
|
|
251
|
+
async function executeAction(actionFn, args, config = {}, spanMeta) {
|
|
252
|
+
const state = {
|
|
253
|
+
paths: [],
|
|
254
|
+
tags: []
|
|
255
|
+
};
|
|
256
|
+
let actionResult;
|
|
257
|
+
let redirectTo;
|
|
258
|
+
let redirectStatus;
|
|
259
|
+
await revalidationAls.run(state, async () => {
|
|
260
|
+
try {
|
|
261
|
+
actionResult = await withSpan("timber.action", {
|
|
262
|
+
...spanMeta?.actionFile ? { "timber.action_file": spanMeta.actionFile } : {},
|
|
263
|
+
...spanMeta?.actionName ? { "timber.action_name": spanMeta.actionName } : {}
|
|
264
|
+
}, () => actionFn(...args));
|
|
265
|
+
} catch (error) {
|
|
266
|
+
if (error instanceof RedirectSignal) {
|
|
267
|
+
redirectTo = error.location;
|
|
268
|
+
redirectStatus = error.status;
|
|
269
|
+
} else throw error;
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
if (state.tags.length > 0) await Promise.all(state.tags.map((tag) => cache.invalidate({ tag })));
|
|
273
|
+
let revalidation;
|
|
274
|
+
if (state.paths.length > 0 && config.renderer) {
|
|
275
|
+
const path = state.paths[0];
|
|
276
|
+
try {
|
|
277
|
+
revalidation = await config.renderer(path);
|
|
278
|
+
} catch (renderError) {
|
|
279
|
+
if (renderError instanceof RedirectSignal) {
|
|
280
|
+
redirectTo = renderError.location;
|
|
281
|
+
redirectStatus = renderError.status;
|
|
282
|
+
} else if (renderError instanceof DenySignal) console.error(`[timber] revalidatePath dropped — target middleware denied (status ${renderError.status})`);
|
|
283
|
+
else console.error("[timber] revalidatePath render failed:", renderError);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
return {
|
|
287
|
+
actionResult,
|
|
288
|
+
revalidation,
|
|
289
|
+
...redirectTo ? {
|
|
290
|
+
redirectTo,
|
|
291
|
+
redirectStatus
|
|
292
|
+
} : {}
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
//#endregion
|
|
296
|
+
export { parseFormData as a, coerce as i, revalidatePath as n, revalidateTag as r, executeAction as t };
|
|
297
|
+
|
|
298
|
+
//# sourceMappingURL=actions-8lJZYYGq.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actions-8lJZYYGq.js","names":[],"sources":["../../src/server/form-data.ts","../../src/server/actions.ts"],"sourcesContent":["/**\n * FormData preprocessing — schema-agnostic conversion of FormData to typed objects.\n *\n * FormData is all strings. Schema validation expects typed values. This module\n * bridges the gap with intelligent coercion that runs *before* schema validation.\n *\n * Inspired by zod-form-data, but schema-agnostic — works with any Standard Schema\n * library (Zod, Valibot, ArkType).\n *\n * See design/08-forms-and-actions.md §\"parseFormData() and coerce helpers\"\n */\n\n// ─── parseFormData ───────────────────────────────────────────────────────\n\n/**\n * Convert FormData into a plain object with intelligent coercion.\n *\n * Handles:\n * - **Duplicate keys → arrays**: `tags=js&tags=ts` → `{ tags: [\"js\", \"ts\"] }`\n * - **Nested dot-paths**: `user.name=Alice` → `{ user: { name: \"Alice\" } }`\n * - **Empty strings → undefined**: Enables `.optional()` semantics in schemas\n * - **Empty Files → undefined**: File inputs with no selection become `undefined`\n * - **Strips `$ACTION_*` fields**: React's internal hidden fields are excluded\n */\nexport function parseFormData(formData: FormData): Record<string, unknown> {\n const flat: Record<string, unknown> = {};\n\n for (const key of new Set(formData.keys())) {\n // Skip React internal fields\n if (key.startsWith('$ACTION_')) continue;\n\n // Skip prototype-pollution keys at the top level — assigning to\n // `flat['__proto__']` invokes the prototype setter and can splice\n // attacker-controlled data into `flat`'s prototype chain.\n // The dot-path case is filtered separately in `expandDotPaths`.\n if (DANGEROUS_KEYS.has(key)) continue;\n\n const values = formData.getAll(key);\n const processed = values.map(normalizeValue);\n\n if (processed.length === 1) {\n flat[key] = processed[0];\n } else {\n // Filter out undefined entries from multi-value fields\n flat[key] = processed.filter((v) => v !== undefined);\n }\n }\n\n // Expand dot-notation paths into nested objects\n return expandDotPaths(flat);\n}\n\n/**\n * Normalize a single FormData entry value.\n * - Empty strings → undefined (enables .optional() semantics)\n * - Empty File objects (no selection) → undefined\n * - Everything else passes through as-is\n */\nfunction normalizeValue(value: FormDataEntryValue): unknown {\n if (typeof value === 'string') {\n return value === '' ? undefined : value;\n }\n\n // File input with no selection: browsers submit a File with name=\"\" and size=0\n if (value instanceof File && value.size === 0 && value.name === '') {\n return undefined;\n }\n\n return value;\n}\n\n/**\n * Expand dot-notation keys into nested objects.\n * `{ \"user.name\": \"Alice\", \"user.age\": \"30\" }` → `{ user: { name: \"Alice\", age: \"30\" } }`\n *\n * Keys without dots are left as-is. Bracket notation (e.g. `items[0]`) is NOT\n * supported — use dot notation (`items.0`) instead.\n */\nfunction expandDotPaths(flat: Record<string, unknown>): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n let hasDotPaths = false;\n\n // First pass: check if any keys have dots\n for (const key of Object.keys(flat)) {\n if (key.includes('.')) {\n hasDotPaths = true;\n break;\n }\n }\n\n // Fast path: no dot-notation keys, return as-is.\n // Top-level dangerous keys are already filtered in `parseFormData` above.\n if (!hasDotPaths) return flat;\n\n for (const [key, value] of Object.entries(flat)) {\n // Reject any path that contains __proto__ / constructor / prototype.\n // Without this, `__proto__.x=1` writes to Object.prototype because\n // `result['__proto__']` resolves to the prototype object itself.\n const parts = key.split('.');\n if (parts.some((p) => DANGEROUS_KEYS.has(p))) continue;\n\n if (parts.length === 1) {\n result[parts[0]] = value;\n continue;\n }\n\n let current: Record<string, unknown> = result;\n for (let i = 0; i < parts.length - 1; i++) {\n const part = parts[i];\n if (current[part] === undefined || current[part] === null) {\n current[part] = {};\n }\n // If current[part] is not an object (e.g., a string from a non-dotted key),\n // the dot-path takes precedence\n if (typeof current[part] !== 'object' || current[part] instanceof File) {\n current[part] = {};\n }\n current = current[part] as Record<string, unknown>;\n }\n\n current[parts[parts.length - 1]] = value;\n }\n\n return result;\n}\n\n// `__proto__` is the only key in this parser that escapes the dot-path\n// walk's `typeof !== 'object'` reset: accessing `obj['__proto__']` returns\n// `Object.prototype` (itself an object), so the walk steps into the global\n// prototype and the leaf write mutates it. `constructor` resolves to a\n// function (reset fires) and `prototype` is undefined on fresh objects\n// (reset fires), so neither escapes the walk — they parse as legit nested\n// keys and do not mutate anything global.\nconst DANGEROUS_KEYS = new Set(['__proto__']);\n\n// ─── Coercion Helpers ────────────────────────────────────────────────────\n\n/**\n * Schema-agnostic coercion primitives for common FormData patterns.\n *\n * These are plain transform functions — they compose with any schema library's\n * `transform`/`preprocess` pipeline:\n *\n * ```ts\n * // Zod\n * z.preprocess(coerce.number, z.number())\n * // Valibot\n * v.pipe(v.unknown(), v.transform(coerce.number), v.number())\n * ```\n */\nexport const coerce = {\n /**\n * Coerce a string to a number.\n * - `\"42\"` → `42`\n * - `\"3.14\"` → `3.14`\n * - `\"\"` / `undefined` / `null` → `undefined`\n * - Non-numeric strings → `undefined` (schema validation will catch this)\n */\n number(value: unknown): number | undefined {\n if (value === undefined || value === null || value === '') return undefined;\n if (typeof value === 'number') return value;\n if (typeof value !== 'string') return undefined;\n const num = Number(value);\n if (Number.isNaN(num)) return undefined;\n return num;\n },\n\n /**\n * Coerce a checkbox value to a boolean.\n * HTML checkboxes submit \"on\" when checked and are absent when unchecked.\n * - `\"on\"` / any truthy string → `true`\n * - `undefined` / `null` / `\"\"` → `false`\n */\n checkbox(value: unknown): boolean {\n if (value === undefined || value === null || value === '') return false;\n if (typeof value === 'boolean') return value;\n // Any non-empty string (typically \"on\") is true\n return typeof value === 'string' && value.length > 0;\n },\n\n /**\n * Parse a JSON string into an object.\n * - Valid JSON string → parsed object\n * - `\"\"` / `undefined` / `null` → `undefined`\n * - Invalid JSON → `undefined` (schema validation will catch this)\n */\n json(value: unknown): unknown {\n if (value === undefined || value === null || value === '') return undefined;\n if (typeof value !== 'string') return value;\n try {\n return JSON.parse(value);\n } catch {\n return undefined;\n }\n },\n\n /**\n * Coerce a date string to a Date object.\n * Handles `<input type=\"date\">` (`\"2024-01-15\"`), `<input type=\"datetime-local\">`\n * (`\"2024-01-15T10:30\"`), and full ISO 8601 strings.\n * - Valid date string → `Date`\n * - `\"\"` / `undefined` / `null` → `undefined`\n * - Invalid date strings → `undefined` (schema validation will catch this)\n * - Impossible dates that `new Date()` silently normalizes (e.g. Feb 31) → `undefined`\n */\n date(value: unknown): Date | undefined {\n if (value === undefined || value === null || value === '') return undefined;\n if (value instanceof Date) return value;\n if (typeof value !== 'string') return undefined;\n const date = new Date(value);\n if (Number.isNaN(date.getTime())) return undefined;\n\n // Overflow detection: extract Y/M/D from the input string and verify\n // they match the parsed Date components. new Date('2024-02-31') silently\n // normalizes to March 2nd — we reject such inputs.\n const ymdMatch = value.match(/^(\\d{4})-(\\d{2})-(\\d{2})/);\n if (ymdMatch) {\n const inputYear = Number(ymdMatch[1]);\n const inputMonth = Number(ymdMatch[2]);\n const inputDay = Number(ymdMatch[3]);\n\n // Use UTC methods for date-only and Z-suffixed strings to avoid\n // timezone offset shifting the day. For datetime-local (no Z suffix),\n // the Date constructor parses in local time, so use local methods.\n const isUTC = value.length === 10 || value.endsWith('Z');\n const parsedYear = isUTC ? date.getUTCFullYear() : date.getFullYear();\n const parsedMonth = isUTC ? date.getUTCMonth() + 1 : date.getMonth() + 1;\n const parsedDay = isUTC ? date.getUTCDate() : date.getDate();\n\n if (inputYear !== parsedYear || inputMonth !== parsedMonth || inputDay !== parsedDay) {\n return undefined;\n }\n }\n\n return date;\n },\n\n /**\n * Create a File coercion function with optional size and mime type validation.\n * Returns the File if valid, `undefined` otherwise.\n *\n * ```ts\n * // Basic — just checks it's a real File\n * z.preprocess(coerce.file(), z.instanceof(File))\n *\n * // With constraints\n * z.preprocess(\n * coerce.file({ maxSize: 5 * 1024 * 1024, accept: ['image/png', 'image/jpeg'] }),\n * z.instanceof(File)\n * )\n * ```\n */\n file(options?: { maxSize?: number; accept?: string[] }): (value: unknown) => File | undefined {\n return (value: unknown): File | undefined => {\n if (value === undefined || value === null || value === '') return undefined;\n if (!(value instanceof File)) return undefined;\n\n // Empty file input (no selection): browsers submit File with name=\"\" and size=0\n if (value.size === 0 && value.name === '') return undefined;\n\n if (options?.maxSize !== undefined && value.size > options.maxSize) {\n return undefined;\n }\n\n if (options?.accept !== undefined && !options.accept.includes(value.type)) {\n return undefined;\n }\n\n return value;\n };\n },\n};\n","/**\n * Server action primitives: revalidatePath, revalidateTag, and the action handler.\n *\n * - revalidatePath(path) re-renders the route at that path and returns the RSC\n * flight payload for inline reconciliation.\n * - revalidateTag(tag) invalidates timber.cache entries by tag.\n *\n * Both are callable from anywhere on the server — actions, API routes, handlers.\n *\n * The action handler processes incoming action requests, validates CSRF,\n * enforces body limits, executes the action, and returns the response\n * (with piggybacked RSC payload if revalidatePath was called).\n *\n * See design/08-forms-and-actions.md\n */\n\nimport { cache } from '../cache/cache-api';\nimport { DenySignal, RedirectSignal } from './primitives';\nimport { withSpan } from './tracing';\nimport { revalidationAls, type RevalidationState } from './als-registry.js';\nimport type { HeadElementPayload } from '../shared/head-header.js';\n\n// ─── Types ───────────────────────────────────────────────────────────────\n\n/** Result of rendering a revalidation — element tree before RSC serialization. */\nexport interface RevalidationResult {\n /** React element tree (pre-serialization — passed to renderToReadableStream). */\n element: unknown;\n /** Resolved head elements for metadata (forwarded via X-Timber-Head). */\n headElements: HeadElementPayload[];\n}\n\n/** Renderer function that builds a React element tree for a given path. */\nexport type RevalidateRenderer = (path: string) => Promise<RevalidationResult>;\n\n// Re-export the type from the registry for public API consumers.\nexport type { RevalidationState } from './als-registry.js';\n\n/** Options for creating the action handler. */\nexport interface ActionHandlerConfig {\n /** Renderer for producing RSC payloads during revalidation. */\n renderer?: RevalidateRenderer;\n}\n\n/** Result of handling a server action request. */\nexport interface ActionHandlerResult {\n /** The action's return value (serialized). */\n actionResult: unknown;\n /** Revalidation result if revalidatePath was called (element tree, not yet serialized). */\n revalidation?: RevalidationResult;\n /** Redirect location if a RedirectSignal was thrown during revalidation. */\n redirectTo?: string;\n /** Redirect status code. */\n redirectStatus?: number;\n}\n\n// ─── Revalidation State ──────────────────────────────────────────────────\n\n// Per-request revalidation state stored in AsyncLocalStorage (from als-registry.ts).\n// This ensures concurrent requests never share or overwrite each other's state\n// (the previous module-level global was vulnerable to cross-request pollution).\n\n/**\n * Run `fn` inside a revalidation ALS scope.\n * @internal — for tests that call revalidatePath/Tag directly without executeAction().\n */\nexport function _runWithRevalidationState<T>(state: RevalidationState, fn: () => T): T {\n return revalidationAls.run(state, fn);\n}\n\n/**\n * Get the current revalidation state. Throws if called outside an action context.\n * @internal\n */\nfunction getRevalidationState(): RevalidationState {\n const state = revalidationAls.getStore();\n if (!state) {\n throw new Error(\n 'revalidatePath/revalidateTag called outside of a server action context. ' +\n 'These functions can only be called during action execution.'\n );\n }\n return state;\n}\n\n// ─── Public API ──────────────────────────────────────────────────────────\n\n/**\n * Re-render the route at `path` and include the RSC flight payload in the\n * action response. The client reconciles inline — no separate fetch needed.\n *\n * Can be called from server actions, API routes, or any server-side context.\n *\n * @param path - The path to re-render (e.g. '/dashboard', '/todos').\n */\nexport function revalidatePath(path: string): void {\n const state = getRevalidationState();\n if (!state.paths.includes(path)) {\n state.paths.push(path);\n }\n}\n\n/**\n * Invalidate all timber.cache entries tagged with `tag`.\n * Does not return a payload — the next request for an invalidated entry re-executes.\n *\n * @param tag - The cache tag to invalidate (e.g. 'products', 'user:123').\n */\nexport function revalidateTag(tag: string): void {\n const state = getRevalidationState();\n if (!state.tags.includes(tag)) {\n state.tags.push(tag);\n }\n}\n\n// ─── Action Handler ──────────────────────────────────────────────────────\n\n/**\n * Execute a server action and process revalidation.\n *\n * 1. Sets up revalidation state\n * 2. Calls the action function\n * 3. Processes revalidateTag calls (invalidates cache entries)\n * 4. Processes revalidatePath calls (re-renders and captures RSC payload)\n * 5. Returns the action result + optional RSC payload\n *\n * @param actionFn - The server action function to execute.\n * @param args - Arguments to pass to the action.\n * @param config - Handler configuration (cache handler, renderer).\n */\nexport async function executeAction(\n actionFn: (...args: unknown[]) => Promise<unknown>,\n args: unknown[],\n config: ActionHandlerConfig = {},\n spanMeta?: { actionFile?: string; actionName?: string }\n): Promise<ActionHandlerResult> {\n const state: RevalidationState = { paths: [], tags: [] };\n let actionResult: unknown;\n let redirectTo: string | undefined;\n let redirectStatus: number | undefined;\n\n // Run the action inside ALS scope so revalidatePath/Tag resolve to this\n // request's state object — concurrent requests each get their own scope.\n await revalidationAls.run(state, async () => {\n try {\n actionResult = await withSpan(\n 'timber.action',\n {\n ...(spanMeta?.actionFile ? { 'timber.action_file': spanMeta.actionFile } : {}),\n ...(spanMeta?.actionName ? { 'timber.action_name': spanMeta.actionName } : {}),\n },\n () => actionFn(...args)\n );\n } catch (error) {\n if (error instanceof RedirectSignal) {\n redirectTo = error.location;\n redirectStatus = error.status;\n } else {\n throw error;\n }\n }\n });\n\n // Process tag invalidation through cache.invalidate so it records the\n // invalidation epoch — an in-flight cached fn must not re-store data this\n // mutation just invalidated (TIM-1028). cache.invalidate resolves the\n // module-level handler singleton: setCacheHandler() is called at boot from\n // rsc-entry when timber.config.ts provides a cacheHandler; otherwise falls\n // back to in-memory LRU (TIM-599).\n if (state.tags.length > 0) {\n await Promise.all(state.tags.map((tag) => cache.invalidate({ tag })));\n }\n\n // Process path revalidation — build element tree (not yet serialized)\n let revalidation: RevalidationResult | undefined;\n if (state.paths.length > 0 && config.renderer) {\n // For now, render the first revalidated path.\n // Multiple paths could be supported via multipart streaming in the future.\n const path = state.paths[0];\n try {\n revalidation = await config.renderer(path);\n } catch (renderError) {\n if (renderError instanceof RedirectSignal) {\n // Revalidation triggered a redirect (e.g., session expired,\n // middleware on the target path called `redirect()`).\n redirectTo = renderError.location;\n redirectStatus = renderError.status;\n } else if (renderError instanceof DenySignal) {\n // Target path's middleware/access denied this user.\n //\n // Dropping the revalidation here is the security boundary added\n // in TIM-996: without this branch, a DenySignal would fall into\n // the `console.error` path AND the element tree would have\n // already been built and serialized — leaking a privileged RSC\n // payload to the action submitter. By the time the signal\n // surfaces, the renderer has thrown BEFORE building the tree,\n // so we simply drop `revalidation` and ship the action result\n // alone. The action itself still succeeded.\n console.error(\n `[timber] revalidatePath dropped — target middleware denied (status ${renderError.status})`\n );\n } else {\n // Log but don't fail the action — revalidation is best-effort.\n // Includes input-validation rejections from the renderer\n // (e.g., revalidatePath('//evil.com/admin')).\n console.error('[timber] revalidatePath render failed:', renderError);\n }\n }\n }\n\n return {\n actionResult,\n revalidation,\n ...(redirectTo ? { redirectTo, redirectStatus } : {}),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAwBA,SAAgB,cAAc,UAA6C;CACzE,MAAM,OAAgC,CAAC;CAEvC,KAAK,MAAM,OAAO,IAAI,IAAI,SAAS,KAAK,CAAC,GAAG;EAE1C,IAAI,IAAI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AIJ,MAAM,gBAAgB,IAAI,OAAO,YAAY;EAC3C,IAAI;GACF,eAAe,MAAM,SACnB,iBACA;IACE,GAAI,UAAU,aAAa,EAAE,sBAAsB,SAAS,WAAW,IAAI,CAAC;IAC5E,GAAI,UAAU,aAAa,EAAE,sBAAsB,SAAS,WAAW,IAAI,CAAC;GAC9E,SACM,SAAS,GAAG,IAAI,CACxB;EACF,SAAS,OAAO;GACd,IAAI,iBAAiB,gBAAgB;IACnC,aAAa,MAAM;IACnB,iBAAiB,MAAM;GACzB,OACE,MAAM;EAEV;CACF,CAAC;CAQD,IAAI,MAAM,KAAK,SAAS,GACtB,MAAM,QAAQ,IAAI,MAAM,KAAK,KAAK,QAAQ,MAAM,WAAW,EAAE,IAAI,CAAC,CAAC,CAAC;CAItE,IAAI;CACJ,IAAI,MAAM,MAAM,SAAS,KAAK,OAAO,UAAU;EAG7C,MAAM,OAAO,MAAM,MAAM;EACzB,IAAI;GACF,eAAe,MAAM,OAAO,SAAS,IAAI;EAC3C,SAAS,aAAa;GACpB,IAAI,uBAAuB,gBAAgB;IAGzC,aAAa,YAAY;IACzB,iBAAiB,YAAY;GAC/B,OAAO,IAAI,uBAAuB,YAWhC,QAAQ,MACN,sEAAsE,YAAY,OAAO,EAC3F;QAKA,QAAQ,MAAM,0CAA0C,WAAW;EAEvE;CACF;CAEA,OAAO;EACL;EACA;EACA,GAAI,aAAa;GAAE;GAAY;EAAe,IAAI,CAAC;CACrD;AACF"}
|
|
@@ -1,28 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { L as getWaitUntil, V as addSpanEventSync, d as logSwrRefetchFailed } from "./logger-DvmCWhN9.js";
|
|
2
2
|
import { t as fnv1aHash } from "./fast-hash-D6hIVt1Y.js";
|
|
3
|
-
//#region src/server/waituntil-bridge.ts
|
|
4
|
-
/**
|
|
5
|
-
* Per-request waitUntil bridge — ALS bridge for platform adapters.
|
|
6
|
-
*
|
|
7
|
-
* The generated entry point (Nitro, Cloudflare) wraps the handler with
|
|
8
|
-
* `runWithWaitUntil`, binding the platform's lifecycle extension function
|
|
9
|
-
* (e.g., h3's `event.waitUntil()` or CF's `ctx.waitUntil()`) for the
|
|
10
|
-
* request duration. The `waitUntil()` primitive reads from this ALS to
|
|
11
|
-
* dispatch background work to the correct platform API.
|
|
12
|
-
*
|
|
13
|
-
* Design doc: design/11-platform.md §"waitUntil()"
|
|
14
|
-
*/
|
|
15
|
-
/**
|
|
16
|
-
* Get the current request's waitUntil function, if available.
|
|
17
|
-
*
|
|
18
|
-
* Returns undefined when no platform adapter has installed a waitUntil
|
|
19
|
-
* handler for the current request (e.g., on platforms that don't support
|
|
20
|
-
* lifecycle extension, or outside a request context).
|
|
21
|
-
*/
|
|
22
|
-
function getWaitUntil() {
|
|
23
|
-
return waitUntilAls.getStore();
|
|
24
|
-
}
|
|
25
|
-
//#endregion
|
|
26
3
|
//#region src/cache/stable-stringify.ts
|
|
27
4
|
/**
|
|
28
5
|
* Deterministic JSON serialization with sorted object keys.
|
|
@@ -419,6 +396,6 @@ cache.invalidate = async function invalidate(opts) {
|
|
|
419
396
|
await getCacheHandler().invalidate(opts);
|
|
420
397
|
};
|
|
421
398
|
//#endregion
|
|
422
|
-
export {
|
|
399
|
+
export { setDefaultSingleflightTimeout as i, getCacheHandler as n, setCacheHandler as r, cache as t };
|
|
423
400
|
|
|
424
|
-
//# sourceMappingURL=cache-api-
|
|
401
|
+
//# sourceMappingURL=cache-api-e1E4i3Vy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache-api-e1E4i3Vy.js","names":[],"sources":["../../src/cache/stable-stringify.ts","../../src/cache/singleflight.ts","../../src/cache/invalidation-epoch.ts","../../src/cache/timber-cache.ts","../../src/cache/handler-store.ts","../../src/cache/cache-api.ts"],"sourcesContent":["/**\n * Deterministic JSON serialization with sorted object keys.\n * Used for cache key generation — ensures { a: 1, b: 2 } and { b: 2, a: 1 }\n * produce the same string.\n *\n * Matches JSON.stringify semantics for toJSON: Date serializes to its ISO\n * string, URL to its href, and class instances with a custom toJSON use it.\n * Map and Set serialize their entries explicitly (insertion-order\n * independent). Values that would serialize lossily — functions, symbols,\n * and non-plain objects with no enumerable own state (RegExp, class\n * instances holding data behind getters or internal slots) — throw instead:\n * every such value would collapse to the same cache key, silently returning\n * one argument's cached data for another (TIM-1020).\n */\nexport function stableStringify(value: unknown): string {\n if (value === null || value === undefined) return String(value);\n\n const type = typeof value;\n if (type === 'function' || type === 'symbol') {\n throw new TypeError(\n `stableStringify: cannot serialize a ${type} into a stable cache key — ` +\n 'all such values would collide. Provide an explicit `key` option to cache().'\n );\n }\n if (type !== 'object') return JSON.stringify(value);\n\n if (Array.isArray(value)) {\n return '[' + value.map((item) => stableStringify(item)).join(',') + ']';\n }\n\n // Honor toJSON like JSON.stringify does (Date → ISO string, URL → href,\n // custom class serialization). JSON.stringify does not re-invoke toJSON\n // on the value it returns, so a toJSON that returns `this` falls through\n // to plain own-property serialization instead of recursing forever.\n const withToJSON = value as { toJSON?: () => unknown };\n if (typeof withToJSON.toJSON === 'function') {\n const json = withToJSON.toJSON();\n if (json !== value) return stableStringify(json);\n }\n\n // Map/Set have no enumerable own properties — serialize entries explicitly.\n // Entries are sorted after serialization so insertion order doesn't change\n // the key. The Map(/Set( prefixes can't collide with object ('{'), array\n // ('['), or string ('\"') output.\n if (value instanceof Map) {\n const entries = [...value.entries()].map(\n ([k, v]) => stableStringify(k) + '=>' + stableStringify(v)\n );\n return 'Map(' + entries.sort().join(',') + ')';\n }\n if (value instanceof Set) {\n const members = [...value].map((member) => stableStringify(member));\n return 'Set(' + members.sort().join(',') + ')';\n }\n\n const obj = value as Record<string, unknown>;\n const keys = Object.keys(obj).sort();\n const pairs: string[] = [];\n for (const key of keys) {\n if (obj[key] === undefined) continue;\n // A callable own toJSON only reaches this loop via the returns-`this`\n // fall-through above. It's the serialization protocol, not data —\n // JSON.stringify omits it too.\n if (key === 'toJSON' && typeof obj[key] === 'function') continue;\n pairs.push(JSON.stringify(key) + ':' + stableStringify(obj[key]));\n }\n\n // A non-plain object that serializes to '{}' carries its state behind\n // getters or internal slots (RegExp, sessions, ORM entities). Serializing\n // it would give every instance the same cache key.\n if (pairs.length === 0) {\n const proto = Object.getPrototypeOf(value);\n if (proto !== Object.prototype && proto !== null) {\n const name = (value as object).constructor?.name || 'Object';\n throw new TypeError(\n `stableStringify: ${name} instance has no serializable own state — ` +\n 'all instances would share one cache key. Provide an explicit `key` ' +\n 'option to cache(), or add a toJSON() method.'\n );\n }\n }\n\n return '{' + pairs.join(',') + '}';\n}\n","/**\n * Singleflight coalesces concurrent calls with the same key into a single\n * execution. All callers receive the same result (or error).\n *\n * Per-process, in-memory. Each process coalesces independently.\n *\n * An optional `timeoutMs` prevents hung `fn()` calls from permanently\n * blocking all future callers for that key. When set, `fn()` is raced\n * against a timeout — if the timeout fires first, the promise rejects\n * with `SingleflightTimeoutError`, `finally` cleans up the key, and\n * subsequent callers can retry. See TIM-518.\n */\n\nexport interface SingleflightOptions {\n /** Maximum time (ms) a coalesced call may run before being rejected. */\n timeoutMs?: number;\n}\n\nexport interface Singleflight {\n do<T>(key: string, fn: () => Promise<T>): Promise<T>;\n}\n\n/**\n * Error thrown when a singleflight call exceeds `timeoutMs`.\n * Exported so callers can distinguish timeout from other errors.\n */\nexport class SingleflightTimeoutError extends Error {\n constructor(key: string, timeoutMs: number) {\n super(`Singleflight timeout: key \"${key}\" exceeded ${timeoutMs}ms`);\n this.name = 'SingleflightTimeoutError';\n }\n}\n\nexport function createSingleflight(opts?: SingleflightOptions): Singleflight {\n const inflight = new Map<string, Promise<unknown>>();\n const timeoutMs = opts?.timeoutMs;\n\n return {\n do<T>(key: string, fn: () => Promise<T>): Promise<T> {\n const existing = inflight.get(key);\n if (existing) return existing as Promise<T>;\n\n let promise: Promise<T>;\n\n if (timeoutMs != null && timeoutMs > 0) {\n // Race fn() against a timeout to prevent hung calls from\n // permanently blocking the key. See TIM-518.\n promise = new Promise<T>((resolve, reject) => {\n const timer = setTimeout(\n () => reject(new SingleflightTimeoutError(key, timeoutMs)),\n timeoutMs\n );\n // Wrap in try/catch so a synchronous throw from fn()\n // (e.g. argument validation) still clears the timer.\n // Without this, the timer leaks until expiry.\n try {\n fn().then(\n (value) => {\n clearTimeout(timer);\n resolve(value);\n },\n (err) => {\n clearTimeout(timer);\n reject(err);\n }\n );\n } catch (err) {\n clearTimeout(timer);\n reject(err);\n }\n });\n } else {\n promise = fn();\n }\n\n const tracked = promise.finally(() => {\n inflight.delete(key);\n });\n\n inflight.set(key, tracked);\n return tracked as Promise<T>;\n },\n };\n}\n","/**\n * Per-process invalidation epoch tracking for timber.cache (TIM-1028).\n *\n * handler.set for a cache miss runs after `fn()` resolves. An explicit\n * `cache.invalidate({ tag })` / `revalidateTag` that lands while fn is in\n * flight would otherwise be silently undone — the just-invalidated value\n * re-stored as fresh for the full TTL, resurrecting pre-mutation data.\n *\n * Every invalidation bumps a monotonic epoch and records it against the\n * invalidated key/tag. Before storing a result, the cache wrapper checks\n * whether its key or any of its tags were invalidated after fn started and\n * skips the write if so. Skipping is always safe: the only cost is one\n * extra cache miss on the next call.\n *\n * Scope: per-process, like the singleflight map. An invalidation issued by\n * another instance against a shared handler (Redis/KV) during fn flight is\n * not observable here — closing that window fully would require store-level\n * versioning, which no CacheHandler backend offers.\n */\n\nlet epoch = 0;\n\n/**\n * Last-invalidated epoch per `key:<k>` / `tag:<t>` entry. Insertion order is\n * epoch order (entries are re-inserted on update), so the oldest entry is\n * always first — pruning evicts lowest epochs.\n */\nconst lastInvalidated = new Map<string, number>();\n\n/**\n * Bound on tracked entries so high-cardinality tag invalidation (e.g.\n * per-user tags) cannot grow this map without limit.\n */\nconst MAX_TRACKED_ENTRIES = 10_000;\n\n/**\n * Highest epoch evicted from the map. Any execution that started at or\n * before this epoch conservatively counts as invalidated — history was\n * truncated, so we can no longer prove it wasn't.\n */\nlet evictedEpochFloor = 0;\n\n/** The current epoch. Capture before running fn(), pass to wasInvalidatedSince. */\nexport function currentInvalidationEpoch(): number {\n return epoch;\n}\n\n/**\n * Record an invalidation. Call BEFORE handler.invalidate() so an execution\n * whose set-check races the invalidation errs toward skipping the write.\n */\nexport function recordInvalidation(opts: { key?: string; tag?: string }): void {\n epoch++;\n if (opts.key) track(`key:${opts.key}`);\n if (opts.tag) track(`tag:${opts.tag}`);\n}\n\nfunction track(entry: string): void {\n lastInvalidated.delete(entry);\n lastInvalidated.set(entry, epoch);\n while (lastInvalidated.size > MAX_TRACKED_ENTRIES) {\n const oldest = lastInvalidated.entries().next().value;\n if (oldest === undefined) break;\n evictedEpochFloor = Math.max(evictedEpochFloor, oldest[1]);\n lastInvalidated.delete(oldest[0]);\n }\n}\n\n/**\n * Whether the key or any tag was invalidated after `startEpoch` (the epoch\n * captured when fn started executing).\n */\nexport function wasInvalidatedSince(startEpoch: number, key: string, tags: string[]): boolean {\n return lastInvalidationEpochFor(key, tags) > startEpoch;\n}\n\n/**\n * The highest epoch at which the key or any of the tags was invalidated\n * (0 if never). Used to scope the singleflight key: callers arriving after\n * an invalidation must not coalesce onto a flight that started before it —\n * they would receive the pre-invalidation result the invalidation was\n * issued to discard.\n */\nexport function lastInvalidationEpochFor(key: string, tags: string[]): number {\n let last = evictedEpochFloor;\n const keyEpoch = lastInvalidated.get(`key:${key}`);\n if (keyEpoch !== undefined && keyEpoch > last) last = keyEpoch;\n for (const tag of tags) {\n const tagEpoch = lastInvalidated.get(`tag:${tag}`);\n if (tagEpoch !== undefined && tagEpoch > last) last = tagEpoch;\n }\n return last;\n}\n","import type { CacheHandler, CacheOptions } from './index';\nimport { stableStringify } from './stable-stringify';\nimport { createSingleflight } from './singleflight';\nimport {\n currentInvalidationEpoch,\n lastInvalidationEpochFor,\n wasInvalidatedSince,\n} from './invalidation-epoch';\nimport { addSpanEventSync } from '../server/tracing.js';\nimport { logSwrRefetchFailed } from '../server/logger.js';\nimport { getWaitUntil } from '../server/waituntil-bridge.js';\nimport { fnv1aHash } from './fast-hash.js';\n\nlet defaultSingleflight = createSingleflight();\n\n/**\n * Set the timeout for the module-level default singleflight.\n * Called at framework boot with renderTimeoutMs from timber.config.ts so that\n * cache calls without a per-call timeoutMs still get deadlock protection.\n * See design/06-caching.md §\"Singleflight Timeout — Deadlock Risk\".\n */\nexport function setDefaultSingleflightTimeout(timeoutMs: number): void {\n defaultSingleflight = createSingleflight({ timeoutMs });\n}\n\n/**\n * Generate a cache key from function identity and serialized args.\n *\n * Uses FNV-1a (fast non-crypto hash) instead of SHA-256. Cache keys don't\n * need collision resistance — they need speed. The fnId prefix provides\n * namespace isolation; the hash covers the args.\n *\n * See TIM-370 for perf motivation.\n */\nfunction defaultKeyGenerator(fnId: string, args: unknown[]): string {\n const raw = fnId + ':' + stableStringify(args);\n return fnId + ':' + fnv1aHash(raw);\n}\n\n/**\n * Resolve tags from the options — supports static array or function form.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction resolveTags<Fn extends (...args: any[]) => any>(\n opts: CacheOptions<Fn>,\n args: Parameters<Fn>\n): string[] {\n if (!opts.tags) return [];\n if (Array.isArray(opts.tags)) return opts.tags;\n return opts.tags(...args);\n}\n\n/** Per-process count of byte-identical fn sources seen by deriveFallbackFnId. */\nconst fallbackIdOccurrences = new Map<string, number>();\nlet hasWarnedFallbackId = false;\n\n/**\n * Derive a fallback fnId for callsites the timber-cache-transform Vite plugin\n * could not statically detect (aliased bindings, user re-export wrappers).\n *\n * The base is fnv1a(fn.toString()) — deterministic across instances and cold\n * starts of the same build, so two *different* functions can never swap fnIds\n * by module-evaluation order (the TIM-997 poisoning scenario that the old\n * process-local counter allowed; see TIM-1054). A per-process occurrence\n * suffix disambiguates byte-identical duplicate sources. That residue is the\n * one remaining hazard: closures produced by the same factory share source\n * text but capture different values, and their occurrence order may differ\n * across instances — such callsites need an explicit `key` option.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction deriveFallbackFnId(fn: (...args: any[]) => any): string {\n const sourceHash = fnv1aHash(fn.toString());\n const occurrence = fallbackIdOccurrences.get(sourceHash) ?? 0;\n fallbackIdOccurrences.set(sourceHash, occurrence + 1);\n\n if (!hasWarnedFallbackId && typeof process !== 'undefined' && process.env?.NODE_ENV !== 'test') {\n hasWarnedFallbackId = true;\n console.warn(\n '[timber] cache() callsite has no build-time stable ID and no explicit `key` option — ' +\n 'the call is not statically visible to the timber Vite plugin (e.g. an aliased ' +\n 'binding like `const c = cache` or a re-export wrapper module). Falling back to a ' +\n 'function-source hash for the cache key. With a shared CacheHandler (Redis/KV) this ' +\n 'is safe for distinct functions, but byte-identical closures from a factory can swap ' +\n 'cache entries across instances. Provide an explicit `key` option to make the cache ' +\n 'key contract stable and auditable.'\n );\n }\n\n return `timber-cache:fn:${sourceHash}:${occurrence}`;\n}\n\n/**\n * Creates a cached wrapper around an async function.\n *\n * - FNV-1a default keys with normalized JSON args\n * - Singleflight: concurrent misses → single execution AND single\n * handler.set — the write happens inside the coalesced callback (TIM-1028)\n * - Writes are skipped when the key/tags were invalidated while fn was in\n * flight, so explicit invalidation is never silently undone (TIM-1028)\n * - SWR: serve stale immediately, background refetch\n * - Tags as string[] or function of args\n * - The handler is resolved per invocation via `getHandler`, never captured\n * at wrapper-creation time — module-scope cache() wrappers created before\n * the framework's boot wiring calls setCacheHandler() still use the\n * configured handler once it arrives (TIM-1029)\n * - No ALS dependency for correctness — cache() works outside a request\n * context. The waitUntil ALS bridge is read optionally so the SWR\n * background refetch survives handler return on Workers/Lambda.\n *\n * Cache hits/misses are recorded as OTEL span events on the enclosing\n * span (not child spans). The DevSpanProcessor reads these for dev log output.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function createCache<Fn extends (...args: any[]) => Promise<any>>(\n fn: Fn,\n opts: CacheOptions<Fn>,\n getHandler: () => CacheHandler,\n stableId?: string\n): Fn {\n // With an explicit `key` option the fnId never reaches key generation, so\n // no fallback derivation (or warning) is needed in that case.\n const fnId = stableId ?? (opts.key ? undefined : deriveFallbackFnId(fn));\n\n // Per-call timeoutMs gets a dedicated singleflight instance. Otherwise\n // resolve defaultSingleflight per invocation (not captured at creation\n // time) so wrappers created before boot pick up the timeout once\n // setDefaultSingleflightTimeout is called (TIM-1032, same rationale as\n // getCacheHandler for TIM-1029).\n const perCallSf =\n opts.timeoutMs !== undefined ? createSingleflight({ timeoutMs: opts.timeoutMs }) : undefined;\n\n // Cast to Fn to preserve the original function's generic call signature.\n // Without this, generic type parameters (e.g. <T> in apiFetch<T>) are\n // erased and callers lose type safety on the return type.\n return (async (...args: Parameters<Fn>): Promise<Awaited<ReturnType<Fn>>> => {\n const sf = perCallSf ?? defaultSingleflight;\n const key = opts.key ? opts.key(...args) : defaultKeyGenerator(fnId as string, args);\n\n const cacheStart = performance.now();\n const cached = await getHandler().get(key);\n\n if (cached && !cached.stale) {\n // Record as OTEL span event on enclosing span (not a child span).\n // Fire-and-forget — no microtask overhead on the cache hot path.\n addSpanEventSync('timber.cache.hit', {\n key,\n duration_ms: Math.round(performance.now() - cacheStart),\n });\n return cached.value as Awaited<ReturnType<Fn>>;\n }\n\n // From here fn() will execute (SWR refetch or miss). Scope the\n // singleflight key by the last invalidation epoch affecting this\n // key/tags: a caller arriving after an invalidation must not coalesce\n // onto a flight that started before it — it would receive the\n // pre-invalidation result the invalidation was issued to discard.\n // NUL separator: cannot collide with user-provided key strings.\n const tags = resolveTags(opts, args);\n const flightKey = `${key}\\u0000${lastInvalidationEpochFor(key, tags)}`;\n\n /**\n * Run fn and store the result — exactly once per coalesced execution,\n * inside the singleflight callback. The write is skipped when the key or\n * any resolved tag was invalidated after fn started: storing would\n * resurrect just-invalidated data as fresh for the full TTL.\n */\n const executeAndStore = async (): Promise<Awaited<ReturnType<Fn>>> => {\n const startEpoch = currentInvalidationEpoch();\n const result = await fn(...args);\n if (!wasInvalidatedSince(startEpoch, key, tags)) {\n await getHandler().set(key, result, { ttl: opts.ttl, tags });\n }\n return result;\n };\n\n if (cached && cached.stale && opts.staleWhileRevalidate) {\n // Record stale cache hit as OTEL span event (fire-and-forget).\n addSpanEventSync('timber.cache.hit', {\n key,\n duration_ms: Math.round(performance.now() - cacheStart),\n stale: true,\n });\n // Serve stale immediately, trigger background refetch\n const refetch = sf\n .do(`swr:${flightKey}`, async () => {\n try {\n await executeAndStore();\n } catch (err) {\n // Failed refetch — stale entry continues to be served.\n logSwrRefetchFailed({ cacheKey: key, error: err });\n }\n })\n .catch(() => {\n // Singleflight promise rejection handled — stale continues.\n });\n // Platforms that cancel work when the handler returns (Cloudflare\n // Workers, Lambda) would otherwise kill the refetch mid-flight —\n // stale data re-served forever. Register the (never-rejecting)\n // refetch with the request's waitUntil; undefined outside a request\n // context or on platforms without lifecycle extension (Node servers\n // keep floating promises alive, so behavior there is unchanged).\n getWaitUntil()?.(refetch);\n return cached.value as Awaited<ReturnType<Fn>>;\n }\n\n // Cache miss (or stale without SWR) — execute with singleflight.\n // The handler.set lives inside the coalesced callback, so N concurrent\n // misses produce exactly one write (TIM-1028).\n const result = await sf.do(flightKey, executeAndStore);\n\n // Record cache miss as OTEL span event (fire-and-forget).\n addSpanEventSync('timber.cache.miss', {\n key,\n duration_ms: Math.round(performance.now() - cacheStart),\n });\n\n return result;\n }) as unknown as Fn;\n}\n","/**\n * Module-level cache handler singleton.\n *\n * Lazily initialized to MemoryCacheHandler on first access. The framework\n * replaces this at boot from timber.config.ts via setCacheHandler().\n *\n * This module avoids importing from ./index to prevent circular dependencies.\n */\n\n// Inline the interface to avoid circular import with index.ts\ninterface CacheHandlerLike {\n get(key: string): Promise<{ value: unknown; stale: boolean } | null>;\n set(key: string, value: unknown, opts: { ttl: number; tags: string[] }): Promise<void>;\n invalidate(opts: { key?: string; tag?: string }): Promise<void>;\n}\n\nlet handler: CacheHandlerLike | null = null;\n\n/** Replace the active cache handler. Called by the framework at boot. */\nexport function setCacheHandler(h: CacheHandlerLike): void {\n handler = h;\n}\n\n/**\n * Get the active cache handler. Creates a default MemoryCacheHandler on\n * first access if none has been set via setCacheHandler().\n */\nexport function getCacheHandler(): CacheHandlerLike {\n if (!handler) {\n // Inline a minimal LRU cache to avoid circular dep with index.ts.\n // In production, the framework always calls setCacheHandler() at boot.\n handler = createDefaultHandler();\n }\n return handler;\n}\n\nfunction createDefaultHandler(): CacheHandlerLike {\n const store = new Map<string, { value: unknown; expiresAt: number; tags: string[] }>();\n const maxEntries = 1000;\n\n return {\n async get(key) {\n const entry = store.get(key);\n if (!entry) return null;\n store.delete(key);\n store.set(key, entry);\n const stale = Date.now() > entry.expiresAt;\n return { value: entry.value, stale };\n },\n async set(key, value, opts) {\n if (store.has(key)) store.delete(key);\n while (store.size >= maxEntries) {\n const oldest = store.keys().next().value;\n if (oldest !== undefined) store.delete(oldest);\n else break;\n }\n store.set(key, { value, expiresAt: Date.now() + opts.ttl * 1000, tags: opts.tags });\n },\n async invalidate(opts) {\n if (opts.key) store.delete(opts.key);\n if (opts.tag) {\n for (const [key, entry] of store) {\n if (entry.tags.includes(opts.tag)) store.delete(key);\n }\n }\n },\n };\n}\n","import type { CacheOptions } from './index';\nimport { createCache } from './timber-cache';\nimport { getCacheHandler } from './handler-store';\nimport { recordInvalidation } from './invalidation-epoch';\n\n/**\n * Public caching API: `cache(fn, opts)`.\n *\n * Wraps an async function with cross-request caching. Uses the configured\n * cache handler (defaults to MemoryCacheHandler, overridable via timber.config.ts).\n *\n * ```ts\n * import { cache } from '@timber-js/app/cache';\n *\n * const getUser = cache(\n * async (id: string) => db.users.findUnique({ where: { id } }),\n * { ttl: 60, tags: (id) => [`user:${id}`] }\n * );\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function cache<Fn extends (...args: any[]) => Promise<any>>(\n fn: Fn,\n opts: CacheOptions<Fn>,\n stableId?: string\n): Fn {\n // Pass the getter, not a resolved handler: the wrapper re-resolves it on\n // every call, so module-scope wrappers created before the framework's boot\n // wiring calls setCacheHandler() still pick up the configured handler\n // instead of permanently binding the in-memory fallback (TIM-1029).\n return createCache(fn, opts, getCacheHandler, stableId);\n}\n\n/**\n * Invalidate cache entries by tag or key.\n *\n * ```ts\n * cache.invalidate({ tag: 'products' });\n * cache.invalidate({ key: 'user:abc' });\n * ```\n */\ncache.invalidate = async function invalidate(opts: { key?: string; tag?: string }): Promise<void> {\n // Record before the handler delete so a cached fn in flight skips its\n // post-resolve set instead of resurrecting the invalidated value (TIM-1028).\n recordInvalidation(opts);\n await getCacheHandler().invalidate(opts);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;AAcA,SAAgB,gBAAgB,OAAwB;CACtD,IAAI,UAAU,QAAQ,UAAU,KAAA,GAAW,OAAO,OAAO,KAAK;CAE9D,MAAM,OAAO,OAAO;CACpB,IAAI,SAAS,cAAc,SAAS,UAClC,MAAM,IAAI,UACR,uCAAuC,KAAK,yGAE9C;CAEF,IAAI,SAAS,UAAU,OAAO,KAAK,UAAU,KAAK;CAElD,IAAI,MAAM,QAAQ,KAAK,GACrB,OAAO,MAAM,MAAM,KAAK,SAAS,gBAAgB,IAAI,CAAC,EAAE,KAAK,GAAG,IAAI;CAOtE,MAAM,aAAa;CACnB,IAAI,OAAO,WAAW,WAAW,YAAY;EAC3C,MAAM,OAAO,WAAW,OAAO;EAC/B,IAAI,SAAS,OAAO,OAAO,gBAAgB,IAAI;CACjD;CAMA,IAAI,iBAAiB,KAInB,OAAO,SAHS,CAAC,GAAG,MAAM,QAAQ,CAAC,EAAE,KAClC,CAAC,GAAG,OAAO,gBAAgB,CAAC,IAAI,OAAO,gBAAgB,CAAC,CAE3C,EAAQ,KAAK,EAAE,KAAK,GAAG,IAAI;CAE7C,IAAI,iBAAiB,KAEnB,OAAO,SADS,CAAC,GAAG,KAAK,EAAE,KAAK,WAAW,gBAAgB,MAAM,CACjD,EAAQ,KAAK,EAAE,KAAK,GAAG,IAAI;CAG7C,MAAM,MAAM;CACZ,MAAM,OAAO,OAAO,KAAK,GAAG,EAAE,KAAK;CACnC,MAAM,QAAkB,CAAC;CACzB,KAAK,MAAM,OAAO,MAAM;EACtB,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AAQ,KAAK,IAAI,IAAI,MAAM;GACjC,OAAO;IAAE,OAAO,MAAM;IAAO;GAAM;EACrC;EACA,MAAM,IAAI,KAAK,OAAO,MAAM;GAC1B,IAAI,MAAM,IAAI,GAAG,GAAG,MAAM,OAAO,GAAG;GACpC,OAAO,MAAM,QAAQ,YAAY;IAC/B,MAAM,SAAS,MAAM,KAAK,EAAE,KAAK,EAAE;IACnC,IAAI,WAAW,KAAA,GAAW,MAAM,OAAO,MAAM;SACxC;GACP;GACA,MAAM,IAAI,KAAK;IAAE;IAAO,WAAW,KAAK,IAAI,IAAI,KAAK,MAAM;IAAM,MAAM,KAAK;GAAK,CAAC;EACpF;EACA,MAAM,WAAW,MAAM;GACrB,IAAI,KAAK,KAAK,MAAM,OAAO,KAAK,GAAG;GACnC,IAAI,KAAK;SACF,MAAM,CAAC,KAAK,UAAU,OACzB,IAAI,MAAM,KAAK,SAAS,KAAK,GAAG,GAAG,MAAM,OAAO,GAAG;GAAA;EAGzD;CACF;AACF;;;;;;;;;;;;;;;;;;AC9CA,SAAgB,MACd,IACA,MACA,UACI;CAKJ,OAAO,YAAY,IAAI,MAAM,iBAAiB,QAAQ;AACxD;;;;;;;;;AAUA,MAAM,aAAa,eAAe,WAAW,MAAqD;CAGhG,mBAAmB,IAAI;CACvB,MAAM,gBAAgB,EAAE,WAAW,IAAI;AACzC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { a as classifyMetadataRoute, c as isDynamicMetadataExtension, n as NULL_BYTE_RE, t as ENCODED_SEPARATOR_RE } from "./canonicalize-P41GR6tY.js";
|
|
2
2
|
import { r as DEFAULT_PAGE_EXTENSIONS, t as classifySegment } from "./segment-classify-CDDRVKs7.js";
|
|
3
|
-
import { h as swallow } from "./logger-
|
|
3
|
+
import { h as swallow } from "./logger-DvmCWhN9.js";
|
|
4
4
|
import { o as resolveAppDir } from "./plugin-context-GfDWsdd2.js";
|
|
5
5
|
import { basename, extname, join } from "node:path";
|
|
6
6
|
import { existsSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
|
|
@@ -626,4 +626,4 @@ function runSchemaSync(projectRoot) {
|
|
|
626
626
|
//#endregion
|
|
627
627
|
export { parseExistingSchemaKeys as a, findSegmentParamsBlock as i, defaultCodecForSegment as n, runSchemaSync as o, findSchemaFile as r, scanRoutes as s, collectDynamicSegments as t };
|
|
628
628
|
|
|
629
|
-
//# sourceMappingURL=cli-schema-sync-
|
|
629
|
+
//# sourceMappingURL=cli-schema-sync-ChsRzw8o.js.map
|