@farm.js/plugin 0.1.51-beta.3 → 0.1.61

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +1 -1
  4. package/dist/middleware/index.d.ts +1 -8
  5. package/dist/middleware/index.d.ts.map +1 -1
  6. package/dist/middleware/index.js +10 -16
  7. package/dist/middleware/matching.d.ts +2 -4
  8. package/dist/middleware/matching.d.ts.map +1 -1
  9. package/dist/middleware/matching.js +47 -7
  10. package/dist/rsc/entries/client.d.ts.map +1 -1
  11. package/dist/rsc/entries/client.js +9 -22
  12. package/dist/rsc/entries/rsc.d.ts.map +1 -1
  13. package/dist/rsc/entries/rsc.js +40 -533
  14. package/dist/rsc/entries/ssr.d.ts.map +1 -1
  15. package/dist/rsc/entries/ssr.js +6 -7
  16. package/dist/rsc/index.d.ts +2 -35
  17. package/dist/rsc/index.d.ts.map +1 -1
  18. package/dist/rsc/index.js +290 -238
  19. package/dist/rsc/middleware-config-module.d.ts +0 -3
  20. package/dist/rsc/middleware-config-module.d.ts.map +1 -1
  21. package/dist/rsc/middleware-config-module.js +28 -41
  22. package/dist/rsc/nitro-build.d.ts.map +1 -1
  23. package/dist/rsc/nitro-build.js +81 -259
  24. package/dist/rsc/server-fn-transform.d.ts +5 -1
  25. package/dist/rsc/server-fn-transform.d.ts.map +1 -1
  26. package/dist/rsc/server-fn-transform.js +338 -3
  27. package/dist/rsc/types.d.ts +0 -28
  28. package/dist/rsc/types.d.ts.map +1 -1
  29. package/dist/rsc/vite-plugin-nitro.d.ts +0 -2
  30. package/dist/rsc/vite-plugin-nitro.d.ts.map +1 -1
  31. package/dist/rsc/vite-plugin-nitro.js +2 -12
  32. package/package.json +3 -3
  33. package/dist/rsc/client-sourcemaps.d.ts +0 -13
  34. package/dist/rsc/client-sourcemaps.d.ts.map +0 -1
  35. package/dist/rsc/client-sourcemaps.js +0 -52
  36. package/dist/rsc/document-layouts.d.ts +0 -16
  37. package/dist/rsc/document-layouts.d.ts.map +0 -1
  38. package/dist/rsc/document-layouts.js +0 -82
package/dist/index.d.ts CHANGED
@@ -39,5 +39,5 @@
39
39
  * })
40
40
  * ```
41
41
  */
42
- export declare const version = "0.1.51-beta.3";
42
+ export declare const version = "0.1.21";
43
43
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,eAAO,MAAM,OAAO,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,eAAO,MAAM,OAAO,WAAW,CAAC"}
package/dist/index.js CHANGED
@@ -39,7 +39,7 @@
39
39
  * })
40
40
  * ```
41
41
  */
42
- export const version = "0.1.51-beta.3";
42
+ export const version = "0.1.21";
43
43
  // Note: Import plugins from their respective subpaths:
44
44
  // - @farm.js/plugin/rsc
45
45
  // - @farm.js/plugin/middleware
@@ -40,7 +40,7 @@ export interface CookieOptions {
40
40
  export interface CookieJar {
41
41
  get(name: string): string | undefined;
42
42
  set(name: string, value: string, options?: CookieOptions): void;
43
- delete(name: string, options?: CookieOptions): void;
43
+ delete(name: string): void;
44
44
  getAll(): Record<string, string>;
45
45
  }
46
46
  /**
@@ -50,14 +50,7 @@ export interface MiddlewareContext {
50
50
  request: IncomingMessage;
51
51
  response: ServerResponse;
52
52
  url: URL;
53
- /** Request pathname as received: still percent-encoded. */
54
53
  pathname: string;
55
- /**
56
- * The pathname the router matches: each segment decoded once, as core's
57
- * `ctx.routePathname`. `.when()` conditions and function matchers also see it,
58
- * so `/%61dmin` cannot skip a check written for `/admin`. Updated by `rewrite()`.
59
- */
60
- readonly routePathname: string;
61
54
  searchParams: URLSearchParams;
62
55
  method: string;
63
56
  params: Record<string, string>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/middleware/index.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAU5D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AA8BjE,MAAM,WAAW,qBAAqB;IACpC,oEAAoE;IACpE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,2BAA2B;IAC3B,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,IAAI,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,QAAQ,GAAG,KAAK,GAAG,MAAM,CAAC;CACtC;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IACtC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,IAAI,CAAC;IAChE,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,IAAI,CAAC;IACpD,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED;;GAEG;AACH,MAAM,WAAW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
4
  import { devServableFileExists } from "../dev-static.js";
5
5
  import { resolveDevRequestURL, resolveViteHtmlFallbackUrl } from "../dev-request.js";
6
- import { canonicalizeRequestPathname, matchesMiddlewareConfig, serializeMiddlewareCookieDeletion, } from "@farm.js/core/middleware";
6
+ import { matchesMiddlewareConfig } from "@farm.js/core/middleware";
7
7
  import { middlewareMatchesPath, parseCookies, serializeCookie } from "./matching.js";
8
8
  // Create require for ESM compatibility
9
9
  const require_ = createRequire(import.meta.url);
@@ -37,27 +37,24 @@ const getColors = () => {
37
37
  */
38
38
  function createCookieJar(req, res) {
39
39
  const cookies = parseCookies(req.headers.cookie);
40
- // Keep any Set-Cookie an earlier handler already wrote.
41
- const existing = res.getHeader("Set-Cookie");
42
- const setCookies = Array.isArray(existing)
43
- ? existing.map(String)
44
- : existing === undefined
45
- ? []
46
- : [String(existing)];
40
+ const setCookies = [];
47
41
  return {
48
42
  get(name) {
49
43
  return cookies[name];
50
44
  },
51
45
  set(name, value, options = {}) {
52
46
  cookies[name] = value;
53
- setCookies.push(serializeCookie(name, value, options));
47
+ const cookieString = serializeCookie(name, value, options);
48
+ setCookies.push(cookieString);
54
49
  res.setHeader("Set-Cookie", setCookies);
55
50
  },
56
- delete(name, options = {}) {
51
+ delete(name) {
57
52
  delete cookies[name];
58
- // Path and Domain must match the cookie that was set, or the tombstone
59
- // addresses a different cookie and the original survives.
60
- setCookies.push(serializeMiddlewareCookieDeletion(name, options));
53
+ const cookieString = serializeCookie(name, "", {
54
+ maxAge: 0,
55
+ expires: new Date(0),
56
+ });
57
+ setCookies.push(cookieString);
61
58
  res.setHeader("Set-Cookie", setCookies);
62
59
  },
63
60
  getAll() {
@@ -94,8 +91,6 @@ function createContext(req, res, viteServer) {
94
91
  response: res,
95
92
  url,
96
93
  pathname: url.pathname,
97
- // Vite has already removed its base from the URL, so this is the app's path.
98
- routePathname: canonicalizeRequestPathname(url.pathname),
99
94
  searchParams: url.searchParams,
100
95
  method: req.method || "GET",
101
96
  params: {},
@@ -130,7 +125,6 @@ function createContext(req, res, viteServer) {
130
125
  const newUrl = new URL(rewriteUrl, `http://${req.headers.host || "localhost"}`);
131
126
  ctx.url = newUrl;
132
127
  ctx.pathname = newUrl.pathname;
133
- ctx.routePathname = canonicalizeRequestPathname(newUrl.pathname);
134
128
  ctx.searchParams = newUrl.searchParams;
135
129
  // Update the original request URL
136
130
  req.url = rewriteUrl;
@@ -6,8 +6,7 @@ import type { CookieOptions } from "./index.js";
6
6
  * (a latin-1 value from an old link, a crawler, or a bare `%`) must not take
7
7
  * the whole map down: an unguarded `decodeURIComponent` throws `URIError`,
8
8
  * which fails the request before any middleware runs. Decoding falls back to
9
- * the raw value per entry instead. This is core's parser, so dev and production
10
- * agree on which duplicate wins.
9
+ * the raw value per entry instead.
11
10
  */
12
11
  export declare function parseCookies(cookieHeader?: string): Record<string, string>;
13
12
  /**
@@ -29,8 +28,7 @@ export declare function middlewareMatchesPath(pathname: string, middlewarePath:
29
28
  *
30
29
  * `Max-Age=0` is the canonical immediate-expiry directive, so the attribute is
31
30
  * emitted whenever `maxAge` is provided — a `0` must not be dropped the way a
32
- * plain truthiness check would drop it. This is core's serializer, so a dev
33
- * Set-Cookie carries the attributes a browser requires, as production does.
31
+ * plain truthiness check would drop it.
34
32
  */
35
33
  export declare function serializeCookie(name: string, value: string, options?: CookieOptions): string;
36
34
  //# sourceMappingURL=matching.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"matching.d.ts","sourceRoot":"","sources":["../../src/middleware/matching.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAE1E;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,OAAO,CAMvF;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,MAAM,CAEhG"}
1
+ {"version":3,"file":"matching.d.ts","sourceRoot":"","sources":["../../src/middleware/matching.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAc1E;AAUD;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,OAAO,CAMvF;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,MAAM,CAkChG"}
@@ -1,4 +1,4 @@
1
- import { canonicalizeRequestPathSegments, parseMiddlewareCookieHeader, serializeMiddlewareCookie, } from "@farm.js/core/middleware";
1
+ import { canonicalizeRequestPathSegments } from "@farm.js/core/middleware";
2
2
  /**
3
3
  * Parse cookies from a Cookie header.
4
4
  *
@@ -6,11 +6,27 @@ import { canonicalizeRequestPathSegments, parseMiddlewareCookieHeader, serialize
6
6
  * (a latin-1 value from an old link, a crawler, or a bare `%`) must not take
7
7
  * the whole map down: an unguarded `decodeURIComponent` throws `URIError`,
8
8
  * which fails the request before any middleware runs. Decoding falls back to
9
- * the raw value per entry instead. This is core's parser, so dev and production
10
- * agree on which duplicate wins.
9
+ * the raw value per entry instead.
11
10
  */
12
11
  export function parseCookies(cookieHeader) {
13
- return parseMiddlewareCookieHeader(cookieHeader);
12
+ if (!cookieHeader)
13
+ return {};
14
+ return cookieHeader.split(";").reduce((cookies, cookie) => {
15
+ const [name, ...rest] = cookie.split("=");
16
+ const value = rest.join("=").trim();
17
+ if (name && value) {
18
+ cookies[name.trim()] = decodeCookieValue(value);
19
+ }
20
+ return cookies;
21
+ }, {});
22
+ }
23
+ function decodeCookieValue(value) {
24
+ try {
25
+ return decodeURIComponent(value);
26
+ }
27
+ catch {
28
+ return value;
29
+ }
14
30
  }
15
31
  /**
16
32
  * Whether a middleware registered at `middlewarePath` applies to `pathname`.
@@ -39,9 +55,33 @@ export function middlewareMatchesPath(pathname, middlewarePath) {
39
55
  *
40
56
  * `Max-Age=0` is the canonical immediate-expiry directive, so the attribute is
41
57
  * emitted whenever `maxAge` is provided — a `0` must not be dropped the way a
42
- * plain truthiness check would drop it. This is core's serializer, so a dev
43
- * Set-Cookie carries the attributes a browser requires, as production does.
58
+ * plain truthiness check would drop it.
44
59
  */
45
60
  export function serializeCookie(name, value, options = {}) {
46
- return serializeMiddlewareCookie(name, value, options);
61
+ let cookie = `${encodeURIComponent(name)}=${encodeURIComponent(value)}`;
62
+ if (options.maxAge != null) {
63
+ cookie += `; Max-Age=${options.maxAge}`;
64
+ }
65
+ if (options.expires) {
66
+ cookie += `; Expires=${options.expires.toUTCString()}`;
67
+ }
68
+ if (options.path) {
69
+ cookie += `; Path=${options.path}`;
70
+ }
71
+ else {
72
+ cookie += "; Path=/";
73
+ }
74
+ if (options.domain) {
75
+ cookie += `; Domain=${options.domain}`;
76
+ }
77
+ if (options.secure) {
78
+ cookie += "; Secure";
79
+ }
80
+ if (options.httpOnly) {
81
+ cookie += "; HttpOnly";
82
+ }
83
+ if (options.sameSite) {
84
+ cookie += `; SameSite=${options.sameSite.charAt(0).toUpperCase() + options.sameSite.slice(1)}`;
85
+ }
86
+ return cookie;
47
87
  }
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/rsc/entries/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,eAAO,MAAM,mCAAmC,62BA6B9C,CAAC;AAEH;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CAsU7D"}
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/rsc/entries/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,eAAO,MAAM,mCAAmC,62BA6B9C,CAAC;AAEH;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CAyT7D"}
@@ -63,7 +63,7 @@ import {
63
63
  `;
64
64
  if (ctx.actionsEnabled) {
65
65
  imports += `import { setServerCallback, encodeReply, createTemporaryReferenceSet } from '@vitejs/plugin-rsc/browser';
66
- import { applyFarmCacheInvalidations } from '@farm.js/core/internal/client-runtime';
66
+ import { applyFarmCacheInvalidations } from '@farm.js/core/cache';
67
67
  import {
68
68
  beginFarmServerQueryAction,
69
69
  completeFarmServerQueryAction,
@@ -177,10 +177,9 @@ async function main() {
177
177
 
178
178
  debug('Starting client hydration');
179
179
 
180
- // Clean duplicate DOM as early as possible (server may have sent two blocks). Only Farm's own
181
- // wrapper: an app that owns the document can have an element with id="root" in its content.
180
+ // Clean duplicate DOM as early as possible (server may have sent two blocks)
182
181
  const rootEl = document.getElementById('root');
183
- if (rootEl && rootEl.firstElementChild?.hasAttribute('data-farm-root')) {
182
+ if (rootEl) {
184
183
  while (rootEl.children.length > 1) rootEl.lastElementChild.remove();
185
184
  while (rootEl.nextElementSibling) rootEl.nextElementSibling.remove();
186
185
  }
@@ -281,13 +280,8 @@ async function main() {
281
280
  debug('Fetching RSC for:', url);
282
281
 
283
282
  try {
284
- // Request the page's RSC payload, '<page>.rsc', which a prerendered page serves as a
285
- // static file. The page URL itself may be static HTML.
286
- const payloadUrl = new URL(url, location.href);
287
- payloadUrl.pathname = payloadUrl.pathname.endsWith('/')
288
- ? payloadUrl.pathname + 'index.rsc'
289
- : payloadUrl.pathname + '.rsc';
290
- const res = await fetch(payloadUrl, {
283
+ // Request RSC format instead of HTML
284
+ const res = await fetch(url, {
291
285
  headers: createFarmDeploymentRequestHeaders(farmDeploymentId, {
292
286
  Accept: 'text/x-component',
293
287
  }),
@@ -311,10 +305,6 @@ async function main() {
311
305
  // reflect the page actually rendered (auth gates redirect this way).
312
306
  if (res.redirected && res.url) {
313
307
  const dest = new URL(res.url);
314
- if (dest.pathname.endsWith('.rsc')) {
315
- const page = dest.pathname.slice(0, -'.rsc'.length);
316
- dest.pathname = page.endsWith('/index') ? page.slice(0, -'index'.length) : page;
317
- }
318
308
  if (dest.origin === location.origin) {
319
309
  const target = dest.pathname + dest.search + dest.hash;
320
310
  if (target !== location.pathname + location.search + location.hash) {
@@ -331,17 +321,14 @@ async function main() {
331
321
  location.href = url;
332
322
  }
333
323
  }
334
- // A root layout that renders <html> owns the document: hydrate it whole, as Next.js does.
335
- const rootElForHydrate = initial.ownsDocument ? document : document.getElementById('root');
324
+ const rootElForHydrate = document.getElementById('root');
336
325
  if (!rootElForHydrate) {
337
326
  console.error('[Farm.js] #root element not found');
338
327
  return;
339
328
  }
340
- if (!initial.ownsDocument) {
341
- // Final cleanup pass before hydrate (in case DOM changed during async)
342
- while (rootElForHydrate.children.length > 1) rootElForHydrate.lastElementChild.remove();
343
- while (rootElForHydrate.nextElementSibling) rootElForHydrate.nextElementSibling.remove();
344
- }
329
+ // Final cleanup pass before hydrate (in case DOM changed during async)
330
+ while (rootElForHydrate.children.length > 1) rootElForHydrate.lastElementChild.remove();
331
+ while (rootElForHydrate.nextElementSibling) rootElForHydrate.nextElementSibling.remove();
345
332
  debug('Hydrating application');
346
333
  globalThis.__FARM_RSC_HYDRATED = true;
347
334
  hydrateRoot(rootElForHydrate, React.createElement(BrowserRoot), {
@@ -1 +1 @@
1
- {"version":3,"file":"rsc.d.ts","sourceRoot":"","sources":["../../../src/rsc/entries/rsc.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAYhD;;;GAGG;AACH,wBAAgB,mCAAmC,IAAI,MAAM,CAe5D;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CAu+C1D"}
1
+ {"version":3,"file":"rsc.d.ts","sourceRoot":"","sources":["../../../src/rsc/entries/rsc.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD;;;GAGG;AACH,wBAAgB,mCAAmC,IAAI,MAAM,CAe5D;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CAy+B1D"}