@timber-js/app 0.2.0-alpha.166 → 0.2.0-alpha.167
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-CDPfMp_I.js → actions-TSxpXLHJ.js} +2 -2
- package/dist/_chunks/{actions-CDPfMp_I.js.map → actions-TSxpXLHJ.js.map} +1 -1
- package/dist/_chunks/{cache-api-DygSeKCB.js → cache-api-DzpQQOEx.js} +52 -48
- package/dist/_chunks/{cache-api-DygSeKCB.js.map → cache-api-DzpQQOEx.js.map} +1 -1
- package/dist/_chunks/{cli-schema-sync-EXGYPhI2.js → cli-schema-sync-wX-i90Og.js} +4 -2
- package/dist/_chunks/cli-schema-sync-wX-i90Og.js.map +1 -0
- package/dist/_chunks/cloudflare-AHoWYTYr.js +1188 -0
- package/dist/_chunks/cloudflare-AHoWYTYr.js.map +1 -0
- package/dist/_chunks/logger-t3uxAmbX.js.map +1 -1
- package/dist/_chunks/{walkers-DBVzXuWc.js → walkers-Cfwvl-UC.js} +2 -2
- package/dist/_chunks/{walkers-DBVzXuWc.js.map → walkers-Cfwvl-UC.js.map} +1 -1
- package/dist/adapters/cloudflare-dev.js +1 -1
- package/dist/adapters/cloudflare-kv-cache.js +1 -1
- package/dist/adapters/cloudflare.d.ts +12 -1
- package/dist/adapters/cloudflare.d.ts.map +1 -1
- package/dist/adapters/cloudflare.js +2 -461
- package/dist/adapters/types.d.ts +2 -0
- package/dist/adapters/types.d.ts.map +1 -1
- package/dist/cache/cache-api.d.ts +33 -11
- package/dist/cache/cache-api.d.ts.map +1 -1
- package/dist/cache/index.js +1 -1
- package/dist/cli.js +1 -1
- package/dist/client/browser-entry/post-hydration.d.ts.map +1 -1
- package/dist/client/history.d.ts +10 -0
- package/dist/client/history.d.ts.map +1 -1
- package/dist/client/internal.js +138 -114
- package/dist/client/internal.js.map +1 -1
- package/dist/client/router.d.ts.map +1 -1
- package/dist/index.js +36 -27
- package/dist/index.js.map +1 -1
- package/dist/plugins/adapter-build.d.ts.map +1 -1
- package/dist/plugins/cache.d.ts +8 -8
- package/dist/plugins/cache.d.ts.map +1 -1
- package/dist/routing/index.js +2 -2
- package/dist/server/als-registry.d.ts +7 -0
- package/dist/server/als-registry.d.ts.map +1 -1
- package/dist/server/deny-boundary.d.ts +3 -1
- package/dist/server/deny-boundary.d.ts.map +1 -1
- package/dist/server/index.js +1 -1
- package/dist/server/internal.js +6 -3
- package/dist/server/internal.js.map +1 -1
- package/dist/server/route-element-builder.d.ts +9 -0
- package/dist/server/route-element-builder.d.ts.map +1 -1
- package/dist/server/rsc-entry/render-route.d.ts.map +1 -1
- package/dist/server/rsc-entry/rsc-payload.d.ts.map +1 -1
- package/dist/server/rsc-entry/rsc-stream.d.ts +8 -0
- package/dist/server/rsc-entry/rsc-stream.d.ts.map +1 -1
- package/docs/api/32-api-cache.mdx +4 -4
- package/docs/learn/09-caching.mdx +5 -5
- package/docs/more/03-coming-from-nextjs.mdx +2 -2
- package/docs/more/50-ai-agent-instructions.mdx +5 -5
- package/package.json +3 -2
- package/src/adapters/cloudflare.ts +63 -25
- package/src/adapters/types.ts +2 -0
- package/src/cache/cache-api.ts +84 -84
- package/src/client/browser-entry/post-hydration.ts +16 -9
- package/src/client/history.ts +11 -0
- package/src/client/router.ts +212 -206
- package/src/plugins/adapter-build.ts +1 -0
- package/src/plugins/cache.ts +45 -30
- package/src/routing/scanner.ts +7 -0
- package/src/server/als-registry.ts +7 -0
- package/src/server/deny-boundary.ts +6 -3
- package/src/server/route-element-builder.ts +49 -8
- package/src/server/rsc-entry/render-route.ts +3 -1
- package/src/server/rsc-entry/rsc-payload.ts +21 -4
- package/src/server/rsc-entry/rsc-stream.ts +8 -0
- package/dist/_chunks/cli-schema-sync-EXGYPhI2.js.map +0 -1
- package/dist/adapters/cloudflare.js.map +0 -1
|
@@ -1,461 +1,2 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
|
|
3
|
-
import { readFile, readdir, rm, writeFile } from "node:fs/promises";
|
|
4
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
5
|
-
import { execFile } from "node:child_process";
|
|
6
|
-
//#region src/adapters/cloudflare.ts
|
|
7
|
-
var BINDINGS_ALS_KEY = Symbol.for("timber:cf-bindings-als");
|
|
8
|
-
function getBindingsAls() {
|
|
9
|
-
let als = globalThis[BINDINGS_ALS_KEY];
|
|
10
|
-
if (!als) {
|
|
11
|
-
als = new AsyncLocalStorage();
|
|
12
|
-
globalThis[BINDINGS_ALS_KEY] = als;
|
|
13
|
-
}
|
|
14
|
-
return als;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Get Cloudflare Worker bindings for the current request.
|
|
18
|
-
*
|
|
19
|
-
* Returns the `env` object passed to the Worker's `fetch` handler,
|
|
20
|
-
* giving direct access to KV, D1, Durable Objects, R2, Queues, and
|
|
21
|
-
* any other bindings configured in `wrangler.jsonc`.
|
|
22
|
-
*
|
|
23
|
-
* Must be called within a request context (server component, middleware,
|
|
24
|
-
* server action). Throws outside a request.
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```ts
|
|
28
|
-
* import { getCloudflareBindings } from '@timber-js/app/adapters/cloudflare'
|
|
29
|
-
*
|
|
30
|
-
* export default async function Page() {
|
|
31
|
-
* const { MY_KV, MY_DB } = getCloudflareBindings()
|
|
32
|
-
* const data = await MY_KV.get('key')
|
|
33
|
-
* return <div>{data}</div>
|
|
34
|
-
* }
|
|
35
|
-
* ```
|
|
36
|
-
*/
|
|
37
|
-
function getCloudflareBindings() {
|
|
38
|
-
const env = getBindingsAls().getStore();
|
|
39
|
-
if (!env) throw new Error("getCloudflareBindings() called outside a Cloudflare Workers request context. It can only be called from server components, middleware, or server actions when running on the Cloudflare adapter.");
|
|
40
|
-
return env;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Run a function with Cloudflare bindings available via getCloudflareBindings().
|
|
44
|
-
* @internal Used by cloudflareDevBindings() to wrap dev-server requests.
|
|
45
|
-
*/
|
|
46
|
-
function runWithBindings(env, fn) {
|
|
47
|
-
return getBindingsAls().run(env, fn);
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Create a Cloudflare Workers adapter.
|
|
51
|
-
*
|
|
52
|
-
* @example
|
|
53
|
-
* ```ts
|
|
54
|
-
* import { cloudflare } from '@timber-js/app/adapters/cloudflare'
|
|
55
|
-
*
|
|
56
|
-
* export default {
|
|
57
|
-
* output: 'server',
|
|
58
|
-
* adapter: cloudflare(),
|
|
59
|
-
* }
|
|
60
|
-
* ```
|
|
61
|
-
*/
|
|
62
|
-
function cloudflare(options = {}) {
|
|
63
|
-
return {
|
|
64
|
-
name: "cloudflare",
|
|
65
|
-
async buildOutput(config, buildDir) {
|
|
66
|
-
const outDir = join(buildDir, "cloudflare");
|
|
67
|
-
await rm(join(outDir, "prebuilt"), {
|
|
68
|
-
recursive: true,
|
|
69
|
-
force: true
|
|
70
|
-
}).catch(() => {});
|
|
71
|
-
await rm(join(outDir, "static", "prebuilt"), {
|
|
72
|
-
recursive: true,
|
|
73
|
-
force: true
|
|
74
|
-
}).catch(() => {});
|
|
75
|
-
await runSharedBuildSteps({
|
|
76
|
-
config,
|
|
77
|
-
buildDir,
|
|
78
|
-
outDir,
|
|
79
|
-
publicDirName: "static"
|
|
80
|
-
});
|
|
81
|
-
let hasWorkerHandlers = false;
|
|
82
|
-
if (options.workerHandlers) {
|
|
83
|
-
const handlersEntry = join(process.cwd(), options.workerHandlers);
|
|
84
|
-
const { build: viteBuild } = await import("vite");
|
|
85
|
-
await viteBuild({
|
|
86
|
-
configFile: false,
|
|
87
|
-
logLevel: "info",
|
|
88
|
-
build: {
|
|
89
|
-
lib: {
|
|
90
|
-
entry: handlersEntry,
|
|
91
|
-
formats: ["es"],
|
|
92
|
-
fileName: () => "_worker-handlers.js"
|
|
93
|
-
},
|
|
94
|
-
outDir,
|
|
95
|
-
emptyOutDir: false,
|
|
96
|
-
minify: false,
|
|
97
|
-
rollupOptions: { external: [/^node:/, /^cloudflare:/] }
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
hasWorkerHandlers = true;
|
|
101
|
-
}
|
|
102
|
-
const prebuiltData = await readPrebuiltData(buildDir);
|
|
103
|
-
await writeFile(join(outDir, "_timber-prebuilt-source.js"), generatePrebuiltSourceModule(prebuiltData));
|
|
104
|
-
await rm(join(outDir, "prebuilt"), {
|
|
105
|
-
recursive: true,
|
|
106
|
-
force: true
|
|
107
|
-
}).catch(() => {});
|
|
108
|
-
await writeFile(join(outDir, "_timber-runtime-init.js"), generateRuntimeInitModule());
|
|
109
|
-
const workerEntry = generateWorkerEntry(outDir, outDir, !!config.manifestInit, hasWorkerHandlers);
|
|
110
|
-
await writeFile(join(outDir, "_worker.js"), workerEntry);
|
|
111
|
-
const wranglerConfig = generateWranglerConfig(config, options);
|
|
112
|
-
await writeFile(join(outDir, "wrangler.jsonc"), JSON.stringify(wranglerConfig, null, 2));
|
|
113
|
-
},
|
|
114
|
-
async preview(_config, buildDir) {
|
|
115
|
-
const cmd = generatePreviewCommand(buildDir);
|
|
116
|
-
await spawnPreviewProcess(cmd.command, cmd.args, cmd.cwd);
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
/** @internal Exported for testing. */
|
|
121
|
-
function generateWorkerEntry(buildDir, outDir, hasManifestInit = false, hasWorkerHandlers = false) {
|
|
122
|
-
let rscEntryRelative = relative(outDir, join(buildDir, "rsc", "index.js"));
|
|
123
|
-
if (!rscEntryRelative.startsWith(".")) rscEntryRelative = "./" + rscEntryRelative;
|
|
124
|
-
return `// Generated by @timber-js/app/adapters/cloudflare
|
|
125
|
-
// Do not edit — this file is regenerated on each build.
|
|
126
|
-
|
|
127
|
-
import { AsyncLocalStorage } from 'node:async_hooks'
|
|
128
|
-
// Side-effect imports: evaluated IN ORDER before the _worker.js body runs.
|
|
129
|
-
// _timber-runtime-init.js sets TIMBER_RUNTIME before createRequestHandler()
|
|
130
|
-
// runs (during the RSC entry's top-level await) so the auto-wire for
|
|
131
|
-
// WorkersCachePurge can detect the Cloudflare runtime (TIM-1170).
|
|
132
|
-
// _timber-prebuilt-source.js sets globalThis.__TIMBER_PREBUILT_SOURCE__
|
|
133
|
-
// for cache.component payloads.
|
|
134
|
-
import './_timber-runtime-init.js'
|
|
135
|
-
import './_timber-prebuilt-source.js'
|
|
136
|
-
${hasManifestInit ? "import './_timber-manifest-init.js'\n" : ""}import handler, { runWithWaitUntil, runWithWorkersCachePurge } from '${rscEntryRelative}'
|
|
137
|
-
${hasWorkerHandlers ? "import * as workerHandlers from './_worker-handlers.js'\n" : ""}
|
|
138
|
-
|
|
139
|
-
// Bind Cloudflare env to ALS so getCloudflareBindings() works at runtime.
|
|
140
|
-
// Uses the same Symbol.for key as getCloudflareBindings() reads from.
|
|
141
|
-
const ALS_KEY = Symbol.for('timber:cf-bindings-als')
|
|
142
|
-
let bindingsAls = globalThis[ALS_KEY]
|
|
143
|
-
if (!bindingsAls) {
|
|
144
|
-
bindingsAls = new AsyncLocalStorage()
|
|
145
|
-
globalThis[ALS_KEY] = bindingsAls
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// Register timber's platform tracer so pipeline phase spans (timber.proxy,
|
|
149
|
-
// timber.middleware, timber.render, timber.access, timber.action, …) appear
|
|
150
|
-
// as native Cloudflare spans in the Observability dashboard, nested under
|
|
151
|
-
// the auto-instrumented fetch/KV/D1 spans. Requires observability.traces
|
|
152
|
-
// enabled in wrangler.jsonc (generated by default).
|
|
153
|
-
//
|
|
154
|
-
// Lazily imported and guarded: runtimes without the custom spans API
|
|
155
|
-
// (older compatibility dates, older local workerd) fall back to OTEL-only
|
|
156
|
-
// emission. withSpan() in the framework composes both channels.
|
|
157
|
-
const TRACER_KEY = Symbol.for('timber:platform-tracer')
|
|
158
|
-
let tracerInit
|
|
159
|
-
function initPlatformTracer() {
|
|
160
|
-
tracerInit ??= import('cloudflare:workers')
|
|
161
|
-
.then(({ tracing }) => {
|
|
162
|
-
if (tracing && typeof tracing.enterSpan === 'function') {
|
|
163
|
-
globalThis[TRACER_KEY] ??= {
|
|
164
|
-
enterSpan: (name, fn) => tracing.enterSpan(name, fn),
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
})
|
|
168
|
-
.catch(() => {})
|
|
169
|
-
return tracerInit
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
export default {
|
|
173
|
-
${hasWorkerHandlers ? " ...workerHandlers,\n" : ""} async fetch(request, env, ctx) {
|
|
174
|
-
// One-time on first request; resolved-promise await thereafter.
|
|
175
|
-
await initPlatformTracer()
|
|
176
|
-
|
|
177
|
-
// Edge-cache GET/HEAD responses via the Cache API. RSC navigation
|
|
178
|
-
// requests (Accept: text/x-component) are excluded — they vary by
|
|
179
|
-
// X-Timber-State-Tree which the cache key doesn't capture.
|
|
180
|
-
const isRsc = request.headers.get('Accept')?.includes('text/x-component')
|
|
181
|
-
const reqCc = request.headers.get('Cache-Control') || ''
|
|
182
|
-
const bypassCache = reqCc.includes('no-cache') || reqCc.includes('max-age=0')
|
|
183
|
-
|| request.headers.has('Pragma')
|
|
184
|
-
const cacheable = !isRsc && !bypassCache
|
|
185
|
-
&& (request.method === 'GET' || request.method === 'HEAD')
|
|
186
|
-
const cache = cacheable && typeof caches !== 'undefined' ? caches.default : null
|
|
187
|
-
if (cache) {
|
|
188
|
-
const cached = await cache.match(request)
|
|
189
|
-
if (cached) return cached
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
// Bridge ctx.cache into the per-request ALS so WorkersCachePurge can
|
|
193
|
-
// call ctx.cache.purge({ tags }) during cache.invalidate/revalidateTag.
|
|
194
|
-
// Workers Cache is available on all Cloudflare plans — no API token needed.
|
|
195
|
-
const workersCacheCtx = ctx.cache && typeof ctx.cache.purge === 'function' ? ctx.cache : null
|
|
196
|
-
const runHandler = () =>
|
|
197
|
-
runWithWaitUntil((promise) => ctx.waitUntil(promise), () => handler(request))
|
|
198
|
-
const response = await bindingsAls.run(env, () =>
|
|
199
|
-
workersCacheCtx
|
|
200
|
-
? runWithWorkersCachePurge(workersCacheCtx, runHandler)
|
|
201
|
-
: runHandler()
|
|
202
|
-
)
|
|
203
|
-
|
|
204
|
-
// Cache public responses at the edge. A response is edge-cacheable if
|
|
205
|
-
// it has 'public' or 's-maxage' (a shared-cache TTL directive) and no
|
|
206
|
-
// 'no-store' or 'private'. Cloudflare's cache.put() only accepts GET
|
|
207
|
-
// requests and rejects 206, so only store GET 200s. HEAD requests
|
|
208
|
-
// benefit from cache.match() which handles HEAD→GET matching automatically.
|
|
209
|
-
// See design/25-production-deployments.md §"CDN / Edge Cache".
|
|
210
|
-
if (cache && request.method === 'GET' && response.status === 200) {
|
|
211
|
-
const cc = response.headers.get('Cache-Control')
|
|
212
|
-
const vary = response.headers.get('Vary')
|
|
213
|
-
if (cc && !cc.includes('no-store') && !cc.includes('private')
|
|
214
|
-
&& (cc.includes('public') || cc.includes('s-maxage'))
|
|
215
|
-
&& vary !== '*' && !response.headers.has('Set-Cookie')) {
|
|
216
|
-
ctx.waitUntil(cache.put(request, response.clone()))
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
return response
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
`;
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* Discover and read prebuilt flight payload files from the build directory.
|
|
227
|
-
* Returns null when no prebuilt artifacts exist (no cache.component usage).
|
|
228
|
-
*
|
|
229
|
-
* @internal Exported for testing.
|
|
230
|
-
*/
|
|
231
|
-
async function readPrebuiltData(buildDir) {
|
|
232
|
-
const prebuiltDir = join(buildDir, "prebuilt");
|
|
233
|
-
let manifestJson;
|
|
234
|
-
try {
|
|
235
|
-
manifestJson = await readFile(join(prebuiltDir, "manifest.json"), "utf-8");
|
|
236
|
-
} catch {
|
|
237
|
-
return null;
|
|
238
|
-
}
|
|
239
|
-
const payloads = [];
|
|
240
|
-
try {
|
|
241
|
-
const componentDirs = await readdir(prebuiltDir, { withFileTypes: true });
|
|
242
|
-
for (const dir of componentDirs) {
|
|
243
|
-
if (!dir.isDirectory()) continue;
|
|
244
|
-
const files = await readdir(join(prebuiltDir, dir.name));
|
|
245
|
-
for (const file of files) if (file.endsWith(".flight")) {
|
|
246
|
-
const filePath = `${dir.name}/${file}`;
|
|
247
|
-
const bytes = await readFile(join(prebuiltDir, filePath));
|
|
248
|
-
payloads.push({
|
|
249
|
-
file: filePath,
|
|
250
|
-
bytes
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
} catch {}
|
|
255
|
-
return {
|
|
256
|
-
manifestJson,
|
|
257
|
-
payloads
|
|
258
|
-
};
|
|
259
|
-
}
|
|
260
|
-
/**
|
|
261
|
-
* Generate the prebuilt payload source module for Cloudflare Workers.
|
|
262
|
-
*
|
|
263
|
-
* Inlines manifest JSON and flight payload bytes directly into the module
|
|
264
|
-
* so they're part of the worker's JS bundle — no external Text/Data module
|
|
265
|
-
* imports needed. This avoids depending on wrangler's find_additional_modules
|
|
266
|
-
* to discover non-JS files, which doesn't reliably resolve Text/Data imports.
|
|
267
|
-
*
|
|
268
|
-
* @internal Exported for testing.
|
|
269
|
-
*/
|
|
270
|
-
function generatePrebuiltSourceModule(data) {
|
|
271
|
-
if (!data) return `// Generated by @timber-js/app/adapters/cloudflare
|
|
272
|
-
// No prebuilt artifacts — all cache.component wrappers render dynamically.
|
|
273
|
-
globalThis.__TIMBER_PREBUILT_SOURCE__ = {
|
|
274
|
-
async loadManifest() { return null },
|
|
275
|
-
async readPayload() { return null },
|
|
276
|
-
}
|
|
277
|
-
`;
|
|
278
|
-
const entries = [];
|
|
279
|
-
for (const { file, bytes } of data.payloads) {
|
|
280
|
-
const b64 = bytes.toString("base64");
|
|
281
|
-
entries.push(` ${JSON.stringify(file)}: ${JSON.stringify(b64)}`);
|
|
282
|
-
}
|
|
283
|
-
return `// Generated by @timber-js/app/adapters/cloudflare
|
|
284
|
-
// Prebuilt payload source — inlines cache.component flight payloads
|
|
285
|
-
// directly into the worker bundle (TIM-1162).
|
|
286
|
-
const _manifest = ${data.manifestJson.trim()}
|
|
287
|
-
|
|
288
|
-
function _decode(b64) {
|
|
289
|
-
const bin = atob(b64)
|
|
290
|
-
const buf = new Uint8Array(bin.length)
|
|
291
|
-
for (let i = 0; i < bin.length; i++) buf[i] = bin.charCodeAt(i)
|
|
292
|
-
return buf
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
const _payloads = {
|
|
296
|
-
${entries.join(",\n")}
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
globalThis.__TIMBER_PREBUILT_SOURCE__ = {
|
|
300
|
-
async loadManifest() { return _manifest },
|
|
301
|
-
async readPayload(file) {
|
|
302
|
-
const b64 = _payloads[file]
|
|
303
|
-
return b64 ? _decode(b64) : null
|
|
304
|
-
},
|
|
305
|
-
}
|
|
306
|
-
`;
|
|
307
|
-
}
|
|
308
|
-
/**
|
|
309
|
-
* Generate the runtime init module that sets TIMBER_RUNTIME before the
|
|
310
|
-
* RSC entry evaluates. Imported as a side-effect module in _worker.js.
|
|
311
|
-
*
|
|
312
|
-
* @internal Exported for testing.
|
|
313
|
-
*/
|
|
314
|
-
function generateRuntimeInitModule() {
|
|
315
|
-
return `// Generated by @timber-js/app/adapters/cloudflare
|
|
316
|
-
// Sets TIMBER_RUNTIME before the RSC handler evaluates (TIM-1170).
|
|
317
|
-
// Must be a separate module imported before rsc/index.js so that ESM
|
|
318
|
-
// evaluation order guarantees the env var is set when
|
|
319
|
-
// createRequestHandler() runs its auto-wire logic.
|
|
320
|
-
globalThis.process ??= { env: {} }
|
|
321
|
-
process.env.TIMBER_RUNTIME = 'cloudflare'
|
|
322
|
-
`;
|
|
323
|
-
}
|
|
324
|
-
/**
|
|
325
|
-
* Convert declarative `CloudflareBindings` into wrangler.jsonc binding sections.
|
|
326
|
-
*
|
|
327
|
-
* Maps:
|
|
328
|
-
* - `kv` → `kv_namespaces`
|
|
329
|
-
* - `d1` → `d1_databases`
|
|
330
|
-
* - `r2` → `r2_buckets`
|
|
331
|
-
* - `queues` → `queues` (producers + consumers)
|
|
332
|
-
* - `durableObjects` → `durable_objects`
|
|
333
|
-
*
|
|
334
|
-
* Empty arrays are omitted from the output.
|
|
335
|
-
*
|
|
336
|
-
* @internal Exported for testing.
|
|
337
|
-
*/
|
|
338
|
-
function generateBindingsConfig(bindings) {
|
|
339
|
-
if (!bindings) return {};
|
|
340
|
-
const result = {};
|
|
341
|
-
if (bindings.kv && bindings.kv.length > 0) result.kv_namespaces = bindings.kv.map((kv) => ({
|
|
342
|
-
binding: kv.name,
|
|
343
|
-
id: kv.id ?? ""
|
|
344
|
-
}));
|
|
345
|
-
if (bindings.d1 && bindings.d1.length > 0) result.d1_databases = bindings.d1.map((d1) => ({
|
|
346
|
-
binding: d1.name,
|
|
347
|
-
database_id: d1.database_id
|
|
348
|
-
}));
|
|
349
|
-
if (bindings.r2 && bindings.r2.length > 0) result.r2_buckets = bindings.r2.map((r2) => ({
|
|
350
|
-
binding: r2.name,
|
|
351
|
-
bucket_name: r2.bucket_name
|
|
352
|
-
}));
|
|
353
|
-
if (bindings.queues) {
|
|
354
|
-
const queues = {};
|
|
355
|
-
if (bindings.queues.producers && bindings.queues.producers.length > 0) queues.producers = bindings.queues.producers.map((p) => ({
|
|
356
|
-
binding: p.name,
|
|
357
|
-
queue: p.queue
|
|
358
|
-
}));
|
|
359
|
-
if (bindings.queues.consumers && bindings.queues.consumers.length > 0) queues.consumers = bindings.queues.consumers.map((c) => {
|
|
360
|
-
const consumer = { queue: c.queue };
|
|
361
|
-
if (c.max_batch_size !== void 0) consumer.max_batch_size = c.max_batch_size;
|
|
362
|
-
if (c.max_retries !== void 0) consumer.max_retries = c.max_retries;
|
|
363
|
-
if (c.dead_letter_queue !== void 0) consumer.dead_letter_queue = c.dead_letter_queue;
|
|
364
|
-
return consumer;
|
|
365
|
-
});
|
|
366
|
-
if (Object.keys(queues).length > 0) result.queues = queues;
|
|
367
|
-
}
|
|
368
|
-
if (bindings.durableObjects && bindings.durableObjects.length > 0) result.durable_objects = { bindings: bindings.durableObjects.map((dobj) => {
|
|
369
|
-
const entry = {
|
|
370
|
-
name: dobj.name,
|
|
371
|
-
class_name: dobj.class_name
|
|
372
|
-
};
|
|
373
|
-
if (dobj.script_name) entry.script_name = dobj.script_name;
|
|
374
|
-
return entry;
|
|
375
|
-
}) };
|
|
376
|
-
return result;
|
|
377
|
-
}
|
|
378
|
-
/**
|
|
379
|
-
* One-level deep merge: for each key in `override`, if both the base and
|
|
380
|
-
* override values are plain objects (not arrays, not null), merge their
|
|
381
|
-
* keys with override winning on conflicts. Everything else (primitives,
|
|
382
|
-
* arrays, null) is replaced outright — matching the intuitive behavior
|
|
383
|
-
* where `kv_namespaces: [...]` replaces fully but
|
|
384
|
-
* `durable_objects: { migrations }` merges with generated `bindings`.
|
|
385
|
-
*/
|
|
386
|
-
function shallowDeepMerge(base, override) {
|
|
387
|
-
const result = { ...base };
|
|
388
|
-
for (const key of Object.keys(override)) {
|
|
389
|
-
const baseVal = result[key];
|
|
390
|
-
const overVal = override[key];
|
|
391
|
-
if (isPlainObject(baseVal) && isPlainObject(overVal)) result[key] = {
|
|
392
|
-
...baseVal,
|
|
393
|
-
...overVal
|
|
394
|
-
};
|
|
395
|
-
else result[key] = overVal;
|
|
396
|
-
}
|
|
397
|
-
return result;
|
|
398
|
-
}
|
|
399
|
-
/** True for `{}` literals — false for arrays, null, Date, etc. */
|
|
400
|
-
function isPlainObject(val) {
|
|
401
|
-
return val !== null && typeof val === "object" && !Array.isArray(val);
|
|
402
|
-
}
|
|
403
|
-
/** @internal Exported for testing. */
|
|
404
|
-
function generateWranglerConfig(config, options) {
|
|
405
|
-
const base = {
|
|
406
|
-
name: "timber-app",
|
|
407
|
-
main: "_worker.js",
|
|
408
|
-
compatibility_date: options.compatibilityDate ?? (/* @__PURE__ */ new Date()).toISOString().slice(0, 10),
|
|
409
|
-
compatibility_flags: options.compatibilityFlags ?? ["nodejs_compat"],
|
|
410
|
-
no_bundle: true,
|
|
411
|
-
find_additional_modules: true,
|
|
412
|
-
rules: [{
|
|
413
|
-
type: "ESModule",
|
|
414
|
-
globs: ["**/*.js"]
|
|
415
|
-
}],
|
|
416
|
-
assets: {
|
|
417
|
-
directory: "./static",
|
|
418
|
-
binding: "ASSETS"
|
|
419
|
-
},
|
|
420
|
-
observability: { traces: { enabled: true } }
|
|
421
|
-
};
|
|
422
|
-
const bindingsConfig = generateBindingsConfig(options.bindings);
|
|
423
|
-
const merged = {
|
|
424
|
-
...base,
|
|
425
|
-
...bindingsConfig
|
|
426
|
-
};
|
|
427
|
-
if (options.wrangler) return shallowDeepMerge(merged, options.wrangler);
|
|
428
|
-
return merged;
|
|
429
|
-
}
|
|
430
|
-
/** @internal Exported for testing. */
|
|
431
|
-
function generatePreviewCommand(buildDir) {
|
|
432
|
-
const cfDir = join(buildDir, "cloudflare");
|
|
433
|
-
return {
|
|
434
|
-
command: "wrangler",
|
|
435
|
-
args: [
|
|
436
|
-
"dev",
|
|
437
|
-
"--local",
|
|
438
|
-
"--config",
|
|
439
|
-
join(cfDir, "wrangler.jsonc")
|
|
440
|
-
],
|
|
441
|
-
cwd: cfDir
|
|
442
|
-
};
|
|
443
|
-
}
|
|
444
|
-
/**
|
|
445
|
-
* Spawn a long-running preview process and pipe stdio to the parent.
|
|
446
|
-
* Resolves when the process exits.
|
|
447
|
-
*/
|
|
448
|
-
function spawnPreviewProcess(command, args, cwd) {
|
|
449
|
-
return new Promise((resolve, reject) => {
|
|
450
|
-
const child = execFile(command, args, { cwd }, (err) => {
|
|
451
|
-
if (err) reject(err);
|
|
452
|
-
else resolve();
|
|
453
|
-
});
|
|
454
|
-
child.stdout?.pipe(process.stdout);
|
|
455
|
-
child.stderr?.pipe(process.stderr);
|
|
456
|
-
});
|
|
457
|
-
}
|
|
458
|
-
//#endregion
|
|
459
|
-
export { cloudflare, generateBindingsConfig, generatePrebuiltSourceModule, generatePreviewCommand, generateRuntimeInitModule, generateWorkerEntry, generateWranglerConfig, getCloudflareBindings, readPrebuiltData, runWithBindings };
|
|
460
|
-
|
|
461
|
-
//# sourceMappingURL=cloudflare.js.map
|
|
1
|
+
import { a as generateRuntimeInitModule, c as getCloudflareBindings, d as runWithBindings, i as generatePreviewCommand, l as readPrebuiltData, n as generateBindingsConfig, o as generateWorkerEntry, r as generatePrebuiltSourceModule, s as generateWranglerConfig, t as cloudflare, u as readUserWranglerConfig } from "../_chunks/cloudflare-AHoWYTYr.js";
|
|
2
|
+
export { cloudflare, generateBindingsConfig, generatePrebuiltSourceModule, generatePreviewCommand, generateRuntimeInitModule, generateWorkerEntry, generateWranglerConfig, getCloudflareBindings, readPrebuiltData, readUserWranglerConfig, runWithBindings };
|
package/dist/adapters/types.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/adapters/types.ts"],"names":[],"mappings":"AAMA;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC5B,wBAAwB,CAAC,EAAE,OAAO,CAAC;IACnC;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,qBAAqB;IACpC,8DAA8D;IAC9D,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,WAAW,CAAC,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEnE;;;OAGG;IACH,OAAO,CAAC,CAAC,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEhE;;;;;;;;;OASG;IACH,cAAc,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;CACxC"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/adapters/types.ts"],"names":[],"mappings":"AAMA;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,qDAAqD;IACrD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC5B,wBAAwB,CAAC,EAAE,OAAO,CAAC;IACnC;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,qBAAqB;IACpC,8DAA8D;IAC9D,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,WAAW,CAAC,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEnE;;;OAGG;IACH,OAAO,CAAC,CAAC,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEhE;;;;;;;;;OASG;IACH,cAAc,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;CACxC"}
|
|
@@ -1,26 +1,48 @@
|
|
|
1
1
|
import type { CacheOptions } from './index';
|
|
2
2
|
import type { PrebuiltComponentOptions } from '../server/prebuilt-runtime';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* Wraps an async function with cross-request caching. Uses the configured
|
|
7
|
-
* cache handler (defaults to MemoryCacheHandler, overridable via timber.config.ts).
|
|
4
|
+
* Cache namespace — `cache.data`, `cache.component`, `cache.invalidate`.
|
|
8
5
|
*
|
|
9
6
|
* ```ts
|
|
10
7
|
* import { cache } from '@timber-js/app/cache';
|
|
11
8
|
*
|
|
12
|
-
* const getUser = cache(
|
|
9
|
+
* const getUser = cache.data(
|
|
13
10
|
* async (id: string) => db.users.findUnique({ where: { id } }),
|
|
14
11
|
* { ttl: 60, tags: (id) => [`user:${id}`] }
|
|
15
12
|
* );
|
|
16
13
|
* ```
|
|
17
14
|
*/
|
|
18
|
-
export declare
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
export declare const cache: {
|
|
16
|
+
/**
|
|
17
|
+
* Wrap an async function with cross-request caching.
|
|
18
|
+
*
|
|
19
|
+
* The configured cache handler (defaults to MemoryCacheHandler, overridable
|
|
20
|
+
* via timber.config.ts) is re-resolved on every call, so module-scope
|
|
21
|
+
* wrappers created before `setCacheHandler()` still pick up the configured
|
|
22
|
+
* handler (TIM-1029).
|
|
23
|
+
*/
|
|
24
|
+
data<Fn extends (...args: any[]) => Promise<any>>(fn: Fn, opts: CacheOptions<Fn>, stableId?: string): Fn;
|
|
25
|
+
/**
|
|
26
|
+
* Invalidate cache entries by tag or key.
|
|
27
|
+
*
|
|
28
|
+
* ```ts
|
|
29
|
+
* cache.invalidate({ tag: 'products' });
|
|
30
|
+
* cache.invalidate({ key: 'user:abc' });
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
invalidate(opts: {
|
|
21
34
|
key?: string;
|
|
22
35
|
tag?: string;
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
|
|
36
|
+
}): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Runtime fallback for `cache.component(...)` callsites the timber-prebuilt
|
|
39
|
+
* transform does not rewrite — nested/computed/argument-position forms (see
|
|
40
|
+
* plugins/prebuilt.ts). Only module-scope `const X = cache.component(...)`
|
|
41
|
+
* declarations are transformed and eligible for prebuilding; everything else
|
|
42
|
+
* lands here, warns once per component, and renders dynamically. Same
|
|
43
|
+
* safety-net pattern as the data cache's runtime fnId fallback (TIM-1054):
|
|
44
|
+
* an untraceable callsite degrades in performance, never in correctness.
|
|
45
|
+
*/
|
|
46
|
+
component<C extends (props: any) => unknown>(componentFn: C, _options?: PrebuiltComponentOptions): C;
|
|
47
|
+
};
|
|
26
48
|
//# sourceMappingURL=cache-api.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache-api.d.ts","sourceRoot":"","sources":["../../src/cache/cache-api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"cache-api.d.ts","sourceRoot":"","sources":["../../src/cache/cache-api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAS3E;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,KAAK;IAChB;;;;;;;OAOG;SAEE,EAAE,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,MAC1C,EAAE,QACA,YAAY,CAAC,EAAE,CAAC,aACX,MAAM,GAChB,EAAE;IAIL;;;;;;;OAOG;qBACoB;QAAE,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAiCrE;;;;;;;;OAQG;cAEO,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,KAAK,OAAO,eAC5B,CAAC,aACH,wBAAwB,GAClC,CAAC;CAYL,CAAC"}
|
package/dist/cache/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { _ as setDefaultSingleflightTimeout, f as MemoryCacheHandler, g as setCacheHandler, h as getCacheHandler, m as RedisCacheHandler, p as TagAwareCacheHandler, t as cache } from "../_chunks/cache-api-
|
|
1
|
+
import { _ as setDefaultSingleflightTimeout, f as MemoryCacheHandler, g as setCacheHandler, h as getCacheHandler, m as RedisCacheHandler, p as TagAwareCacheHandler, t as cache } from "../_chunks/cache-api-DzpQQOEx.js";
|
|
2
2
|
import { t as estimateByteSize } from "../_chunks/sizeof-lXffQ1Vr.js";
|
|
3
3
|
export { MemoryCacheHandler, RedisCacheHandler, TagAwareCacheHandler, cache, estimateByteSize, getCacheHandler, setCacheHandler, setDefaultSingleflightTimeout };
|
package/dist/cli.js
CHANGED
|
@@ -115,7 +115,7 @@ async function runCheck(options) {
|
|
|
115
115
|
async function runSchema(args) {
|
|
116
116
|
const subcommand = args[0];
|
|
117
117
|
if (subcommand !== "sync") throw new Error(`Unknown schema subcommand: ${subcommand ?? "(none)"}. Usage: timber schema sync`);
|
|
118
|
-
const { runSchemaSync, defaultCodecForSegment } = await import("./_chunks/cli-schema-sync-
|
|
118
|
+
const { runSchemaSync, defaultCodecForSegment } = await import("./_chunks/cli-schema-sync-wX-i90Og.js").then((n) => n.t);
|
|
119
119
|
const result = runSchemaSync(process.cwd());
|
|
120
120
|
if (result.filesystemSegments.length === 0) {
|
|
121
121
|
console.log("[timber] No dynamic segments found in app/.");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"post-hydration.d.ts","sourceRoot":"","sources":["../../../src/client/browser-entry/post-hydration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAGpE,UAAU,oBAAoB;IAC5B,MAAM,EAAE,cAAc,CAAC;IACvB,gBAAgB,EAAE,uBAAuB,GAAG,IAAI,CAAC;IACjD,oEAAoE;IACpE,cAAc,EAAE,OAAO,CAAC;CACzB;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,EACjC,MAAM,EACN,gBAAgB,EAChB,cAAc,GACf,EAAE,oBAAoB,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"post-hydration.d.ts","sourceRoot":"","sources":["../../../src/client/browser-entry/post-hydration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAGpE,UAAU,oBAAoB;IAC5B,MAAM,EAAE,cAAc,CAAC;IACvB,gBAAgB,EAAE,uBAAuB,GAAG,IAAI,CAAC;IACjD,oEAAoE;IACpE,cAAc,EAAE,OAAO,CAAC;CACzB;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,EACjC,MAAM,EACN,gBAAgB,EAChB,cAAc,GACf,EAAE,oBAAoB,GAAG,IAAI,CA6E7B"}
|
package/dist/client/history.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { SegmentInfo } from './segment-cache';
|
|
1
2
|
export interface HistoryEntry {
|
|
2
3
|
/** The complete segment tree payload at the time of navigation */
|
|
3
4
|
payload: unknown;
|
|
@@ -8,6 +9,15 @@ export interface HistoryEntry {
|
|
|
8
9
|
* and revalidation overwrites preserve the current state (TIM-1037).
|
|
9
10
|
*/
|
|
10
11
|
params?: Record<string, string | string[]> | null;
|
|
12
|
+
/**
|
|
13
|
+
* Segment metadata for this page's route. Restored into the segment cache
|
|
14
|
+
* on popstate cached replay so the next forward navigation computes a
|
|
15
|
+
* correct state tree. Without this, the segment cache retains the
|
|
16
|
+
* *previous* page's segments after back-button, causing the server to
|
|
17
|
+
* skip segments that aren't mounted — and the partial payload targets
|
|
18
|
+
* a non-existent outlet.
|
|
19
|
+
*/
|
|
20
|
+
segmentInfo?: SegmentInfo[] | null;
|
|
11
21
|
}
|
|
12
22
|
/**
|
|
13
23
|
* Session-lived history stack keyed by URL. Enables instant back/forward
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"history.d.ts","sourceRoot":"","sources":["../../src/client/history.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"history.d.ts","sourceRoot":"","sources":["../../src/client/history.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAInD,MAAM,WAAW,YAAY;IAC3B,kEAAkE;IAClE,OAAO,EAAE,OAAO,CAAC;IACjB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC;IAClD;;;;;;;OAOG;IACH,WAAW,CAAC,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC;CACpC;AAID;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,OAAO,CAAmC;IAElD,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,GAAG,IAAI;IAI5C,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;IAI1C,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;CAG1B"}
|