@rsc-kit/mcp 0.30.49 → 0.30.51

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/recipes.js CHANGED
@@ -1789,6 +1789,13 @@ Guard a route in Laravel's vocabulary, no route declared in PHP:
1789
1789
  // resources/js/app/admin/middleware.ts
1790
1790
  export const middleware = ['auth', 'verified', 'can:update,post']
1791
1791
 
1792
+ They run against the page's request, not the host call's: signed checks the
1793
+ link the visitor followed, throttle counts per visitor and once per page load,
1794
+ and can:update,post gets the {post} the route bound - bind it with
1795
+ Route::bind or Route::model, since a page has no controller signature for
1796
+ implicit binding. In Go, a guard reads rsckit.PageFrom(ctx) (URL, and Params:
1797
+ only the route's own, never the query) and rsckit.ClientIP(ctx).
1798
+
1792
1799
  Make one: php artisan make:rsc-action Orders --method=cancel --auth
1793
1800
  --can=update,Order --middleware=throttle:60,1 --revalidate=orders (--rpc for
1794
1801
  an rpc() class under app/Rsc; no --method = invokable; a slash nests,
@@ -2780,12 +2787,38 @@ const source: DataSource<Customer, Values> = {
2780
2787
  delete: (id, { tenant }) => ...,
2781
2788
  }
2782
2789
  \`\`\`
2790
+ PAGES BY COUNT OR BY CURSOR - list answers either, per resource:
2791
+ { rows, total } counted: numbered pages, "12 orders"
2792
+ { rows, next, prev } by cursor: Previous/Next links carrying ?cursor=,
2793
+ no count; null is no page that way
2794
+ The source is told the cursor it handed out as query.cursor (absent on the
2795
+ first page) and reads it instead of page. Laravel's cursorPaginate maps as
2796
+ { rows: p.data as Order[], next: p.next_cursor, prev: p.prev_cursor }, and
2797
+ paginate as { rows: p.data as Order[], total: p.total } - a paginator result is
2798
+ typed as it encodes, its rows unknown. cursorPaginate is called with
2799
+ cursorPaginate($query['perPage'], cursor: $query['cursor'] ?? null). Do NOT
2800
+ count a table just to page it.
2783
2801
  The last argument of every call is the context { tenant } (null without
2784
2802
  tenancy). On a Laravel/Go backend the functions call rpc() and the backend
2785
2803
  validates again - the panel's check is the renderer's, the backend's counts.
2786
2804
  A BACKEND 422 (unique:products,sku, a stock check) shows under the same fields
2787
2805
  as the schema's, values kept: do NOT catch it in create/update - let the rpc()
2788
2806
  call throw, and the panel's save answers it as field errors.
2807
+ THE BACKEND'S ACTIONS AS THE FORM: when a FormRequest or a Go struct already
2808
+ says what a record takes, write NO schema. Give the generated actions instead
2809
+ of form, and the source only list/find/delete:
2810
+ source: { list, find, delete },
2811
+ actions: { create: productsStore, update: productsUpdate },
2812
+ fields: { category_id: { relation: 'categories' } }, // the backend's names, typechecked
2813
+ form and actions are one or the other, never both. The create form is drawn
2814
+ from create's input, the edit form from update's. create(values); update(values,
2815
+ key) - the KEY COMES SECOND:
2816
+ Laravel: update(UpdateProductRequest $request, string $product) - the key is
2817
+ the FormRequest's route parameter by that name, so
2818
+ Rule::unique('products')->ignore($this->route('product')) works, and
2819
+ Route::model() binds it.
2820
+ Go: func(ctx context.Context, in ProductInput, id string)
2821
+ An update taking only the values, or a create taking a key, throws at startup.
2789
2822
  memorySource(rows, key, make) is for tests and demos; perTenant((tenantId) =>
2790
2823
  source) keeps one source per tenant.
2791
2824
 
@@ -2931,9 +2964,11 @@ handle: (values) => contactSend(values).
2931
2964
  THE BOT TRAP: every form carries a hidden field named homepage. Filled in, the
2932
2965
  submission is answered as a success and dropped - handle() never runs. So a
2933
2966
  form cannot have a field named homepage. It is not a CAPTCHA; rate-limit a form
2934
- worth attacking, at the CDN or proxy: a backend sees the renderer's address on
2935
- an rpc(), so Laravel's throttle on a method puts every logged-out visitor in one
2936
- bucket. To limit in the backend, key on the submitted email.
2967
+ worth attacking. Every host call carries the visitor's address
2968
+ (X-Rsc-Client-Ip), so Laravel's throttle:5,1 on the action counts each
2969
+ visitor ($request->ip()), as Go's rsckit.ClientIP(ctx) does. Behind a load
2970
+ balancer or Cloudflare set RSC_TRUST_FORWARDED=1 on the renderer, or every
2971
+ visitor arrives as the balancer.
2937
2972
 
2938
2973
  A THEME draws it with one component, PublicForm (type FormsTheme from
2939
2974
  @rsc-kit/press/forms); replace it with theme: { ...shadcn, PublicForm: Mine }.