@farm.js/plugin 0.1.34 → 0.1.36

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/index.d.ts CHANGED
@@ -39,5 +39,5 @@
39
39
  * })
40
40
  * ```
41
41
  */
42
- export declare const version = "0.1.34";
42
+ export declare const version = "0.1.36";
43
43
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -39,7 +39,7 @@
39
39
  * })
40
40
  * ```
41
41
  */
42
- export const version = "0.1.34";
42
+ export const version = "0.1.36";
43
43
  // Note: Import plugins from their respective subpaths:
44
44
  // - @farm.js/plugin/rsc
45
45
  // - @farm.js/plugin/middleware
@@ -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,CAovC1D"}
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,CAuwC1D"}
@@ -386,8 +386,11 @@ if (farmNativeMCPPlugin) {
386
386
  methods: [...route.methods],
387
387
  endpoints: { ...route.handlers },
388
388
  }));
389
- // Rejects a plugin route that would replace an app endpoint.
390
- for (const route of mergePluginAPIRoutes(mountedRoutes, [farmNativeMCPPlugin])) {
389
+ // Rejects a plugin route that would replace an app endpoint. An MCP tool calls its
390
+ // endpoint through handler(), so the middleware guarding that path runs for it.
391
+ for (const route of mergePluginAPIRoutes(mountedRoutes, [farmNativeMCPPlugin], undefined, {
392
+ dispatch: (request) => handler(request),
393
+ })) {
391
394
  for (const method of route.pluginMethods ?? []) {
392
395
  let target = apiRouteMap.get(route.path);
393
396
  if (!target) {
@@ -476,25 +479,36 @@ debug('Discovered API routes:', Array.from(apiRouteMap.keys()));
476
479
  * Convert an app-relative middleware file path to the route it guards, with the
477
480
  * same rules as core's middleware discovery: a route group such as
478
481
  * '(protected)' or a parallel route slot such as '@team' adds no URL segment,
479
- * and a '_private' or dot-prefixed folder holds no routes, so its middleware
480
- * never runs (null).
482
+ * an intercepting folder guards the URL it intercepts, a '_private' folder
483
+ * routes its pages so its middleware guards them, and a dot-prefixed folder
484
+ * holds no routes, so its middleware never runs (null).
481
485
  * e.g., '/middleware.ts' -> '/'
482
486
  * e.g., '/(protected)/dashboard/middleware.ts' -> '/dashboard'
483
487
  * e.g., '/dashboard/@team/middleware.ts' -> '/dashboard'
488
+ * e.g., '/feed/@modal/(.)photo/middleware.ts' -> '/feed/photo'
484
489
  */
485
490
  function middlewarePathToRoute(filePath) {
486
491
  const segments = filePath
487
492
  .replace(/\\/middleware\\.[tj]sx?$/, '')
488
493
  .split('/')
489
494
  .filter(Boolean);
490
- if (segments.some((segment) => segment.startsWith('_') || segment.startsWith('.'))) {
495
+ if (segments.some((segment) => segment.startsWith('.'))) {
491
496
  return null;
492
497
  }
493
- const routeSegments = segments.filter(
494
- (segment) =>
495
- !(segment.startsWith('(') && segment.endsWith(')')) &&
496
- !/^@[A-Za-z][A-Za-z0-9_-]*$/.test(segment),
497
- );
498
+ const routeSegments = [];
499
+ for (const segment of segments) {
500
+ const marker = /^((?:\\(\\.\\.\\))+|\\(\\.\\.\\.\\)|\\(\\.\\))(.*)$/.exec(segment);
501
+ if (marker) {
502
+ if (marker[1] === '(...)') routeSegments.length = 0;
503
+ else if (marker[1] !== '(.)') routeSegments.splice(-(marker[1].length / 4));
504
+ if (marker[2]) routeSegments.push(marker[2]);
505
+ continue;
506
+ }
507
+ if ((segment.startsWith('(') && segment.endsWith(')')) || /^@[A-Za-z][A-Za-z0-9_-]*$/.test(segment)) {
508
+ continue;
509
+ }
510
+ routeSegments.push(segment);
511
+ }
498
512
  return routeSegments.length === 0 ? '/' : '/' + routeSegments.join('/');
499
513
  }
500
514
 
@@ -553,7 +567,12 @@ const RouteErrorBoundary = React.Component
553
567
 
554
568
  // Parse and rank once per entry initialization, not on every request. Use the
555
569
  // same validation, decoding and specificity rules as Farm's ordinary router.
556
- const pageRoutes = Object.entries(pages).map(([filePath, module]) => ({
570
+ // RSC renders no parallel route slots, so a page inside '@modal/...' would otherwise
571
+ // answer at its literal folder path ('/feed/@modal/(.)photo/1'), past the middleware
572
+ // that guards the URL it intercepts.
573
+ const pageRoutes = Object.entries(pages)
574
+ .filter(([filePath]) => !filePath.split('/').some((segment) => /^@[A-Za-z][A-Za-z0-9_-]*$/.test(segment)))
575
+ .map(([filePath, module]) => ({
557
576
  filePath,
558
577
  module,
559
578
  segments: parseRoutePath(filePath).segments,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farm.js/plugin",
3
- "version": "0.1.34",
3
+ "version": "0.1.36",
4
4
  "description": "Official plugins for Farm.js framework",
5
5
  "license": "MIT",
6
6
  "author": "Farm.js Team",
@@ -62,7 +62,7 @@
62
62
  "nitro": "3.0.260903-beta",
63
63
  "picocolors": "^1.0.0",
64
64
  "rsc-html-stream": "^0.0.4",
65
- "@farm.js/core": "0.1.34"
65
+ "@farm.js/core": "0.1.36"
66
66
  },
67
67
  "devDependencies": {
68
68
  "@types/node": "^22.20.5",
@@ -83,7 +83,7 @@
83
83
  "react-dom": "19.2.8",
84
84
  "react-server-dom-webpack": "19.2.8",
85
85
  "vite": ">=6.0.0",
86
- "@farm.js/core": "0.1.34"
86
+ "@farm.js/core": "0.1.36"
87
87
  },
88
88
  "peerDependenciesMeta": {
89
89
  "@vitejs/plugin-rsc": {