@rsc-kit/mcp 0.30.50 → 0.30.52

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
@@ -2721,7 +2721,7 @@ its own: where the data lives, who may see it, whose it is. Full guides:
2721
2721
  admin, admin-plugins. There is no @rsc-kit/admin any more - do not import it.
2722
2722
  @rsc-kit/press defineResource, memorySource, perTenant, definePlugin, types
2723
2723
  @rsc-kit/press/admin definePanel, resourceParams, recordParams, listSearch, pluginsSearch, AdminTheme
2724
- @rsc-kit/press/forms defineForm - a public form from a schema (how_to public-forms)
2724
+ @rsc-kit/press/forms defineBlueprint - a form defined once, drawn in pages and panels (how_to blueprints)
2725
2725
  @rsc-kit/press/pages definePages - pages an editor builds from blocks (how_to pages)
2726
2726
  @rsc-kit/press/shadcn shadcn (the theme; it draws panels and public forms)
2727
2727
 
@@ -2787,12 +2787,38 @@ const source: DataSource<Customer, Values> = {
2787
2787
  delete: (id, { tenant }) => ...,
2788
2788
  }
2789
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.
2790
2801
  The last argument of every call is the context { tenant } (null without
2791
2802
  tenancy). On a Laravel/Go backend the functions call rpc() and the backend
2792
2803
  validates again - the panel's check is the renderer's, the backend's counts.
2793
2804
  A BACKEND 422 (unique:products,sku, a stock check) shows under the same fields
2794
2805
  as the schema's, values kept: do NOT catch it in create/update - let the rpc()
2795
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.
2796
2822
  memorySource(rows, key, make) is for tests and demos; perTenant((tenantId) =>
2797
2823
  source) keeps one source per tenant.
2798
2824
 
@@ -2880,18 +2906,20 @@ the save. Export a function of options returning the plugin. Publish with
2880
2906
  rsc-kit-admin-plugin.`,
2881
2907
  },
2882
2908
  {
2883
- topic: 'public-forms',
2884
- summary: 'A public form (contact, sign-up, survey) from a Standard Schema with @rsc-kit/press/forms: browser and server checks, a bot trap, any backend',
2885
- body: `defineForm turns a Standard Schema into a form anyone may fill in - the
2886
- admin panel's form without the panel, drawn by the same theme. Full guide:
2887
- public-forms.
2909
+ topic: 'blueprints',
2910
+ summary: 'A form defined once with defineBlueprint from @rsc-kit/press/forms - a contact form, a sign-up, an edit page, an admin resource\'s form - from a Standard Schema or the backend\'s actions: browser and server checks, a bot trap',
2911
+ body: `defineBlueprint turns a Standard Schema, or the backend's actions, into a
2912
+ form defined once - fields, checks, saves - drawn in any page with
2913
+ <contact.Form />, as an edit page with <profile.Form id={...} values={...} />,
2914
+ and as an admin resource's create and edit pages with
2915
+ defineResource({ form: profile }). Full guide: blueprints.
2888
2916
 
2889
2917
  \`\`\`ts title="src/forms/contact.ts"
2890
2918
  import * as z from 'zod'
2891
- import { defineForm } from '@rsc-kit/press/forms'
2919
+ import { defineBlueprint } from '@rsc-kit/press/forms'
2892
2920
  import { shadcn } from '@rsc-kit/press/shadcn'
2893
2921
 
2894
- export const contact = defineForm({
2922
+ export const contact = defineBlueprint({
2895
2923
  name: 'contact', // unique; lowercase letters, digits, dashes
2896
2924
  form: z.object({ name: z.string().min(2), email: z.email(), message: z.string().min(10) }),
2897
2925
  fields: { message: { type: 'textarea' } }, // what the schema cannot say
@@ -2899,7 +2927,8 @@ export const contact = defineForm({
2899
2927
  submit: 'Send message',
2900
2928
  done: 'Thanks - we will be in touch.', // shown in place of the form
2901
2929
  // redirect: '/thanks', // OR this; never both
2902
- handle: async (values) => { await db.insert(messages).values(values) },
2930
+ handle: async (values) => { await db.insert(messages).values(values) }, // creates
2931
+ // update: async (values, key) => { ... }, // edits, when drawn with an id
2903
2932
  })
2904
2933
  \`\`\`
2905
2934
 
@@ -2920,10 +2949,28 @@ passed. A refusal handle() decides goes under its field:
2920
2949
  import { fieldErrors } from '@rsc-kit/core/action'
2921
2950
  if (await subscribed(email)) fieldErrors({ email: 'Already on the list.' })
2922
2951
 
2923
- A BACKEND, WITH NO SCHEMA: defineForm({ name, action: contactSend, theme }),
2952
+ EDITING A RECORD: give it update(values, key), and draw
2953
+ <profile.Form id={user.id} values={user} />. Only the blueprint's own fields
2954
+ of values reach the browser. THE KEY COMES BACK FROM THE BROWSER and anyone
2955
+ can post another: update must check the visitor may change that record (a
2956
+ FormRequest's authorize(), a comparison with the session's user). Drawn with
2957
+ an id and no update, or without one and no handle/create, it throws.
2958
+ honeypot: false drops the bot trap for a form only signed-in people reach.
2959
+
2960
+ IN A PANEL: defineResource<Row>()({ ..., form: blueprint }) - the panel's
2961
+ create and edit pages are the blueprint's form. A blueprint that saves (both
2962
+ create and update) saves the panel's records too, so source is only
2963
+ { list, find, delete }; one that does not needs a whole source. Say fields and
2964
+ actions on the blueprint, never again on the resource (that throws).
2965
+
2966
+ A BACKEND, WITH NO SCHEMA: defineBlueprint({ name, actions: { create: contactSend }, theme }),
2924
2967
  with contactSend imported from the generated server-actions module - the
2925
2968
  action itself, never its name as a string (a string throws). No form, no
2926
- handle, no zod. bunx rsc-kit make:form contactSend writes forms/contact.ts.
2969
+ handle, no zod. actions is { create, update }, either or both: create's input
2970
+ draws the create form, update's the edit form, and update is called
2971
+ (values, key) - update(UpdateProfile $request, string $user) in Laravel,
2972
+ reading the key with $this->route('user'); func(ctx, in ProfileInput,
2973
+ id string) in Go. bunx rsc-kit make:form contactSend writes forms/contact.ts.
2927
2974
  The action is a Laravel class in app/Rsc/Actions (Contact::send is
2928
2975
  contactSend; a class in app/Rsc is rpc only and has no action) or Go's
2929
2976
  reg.HandleAction("contactSend", "Contact.send", fn). Fields and browser checks
@@ -2944,8 +2991,19 @@ visitor ($request->ip()), as Go's rsckit.ClientIP(ctx) does. Behind a load
2944
2991
  balancer or Cloudflare set RSC_TRUST_FORWARDED=1 on the renderer, or every
2945
2992
  visitor arrives as the balancer.
2946
2993
 
2947
- A THEME draws it with one component, PublicForm (type FormsTheme from
2948
- @rsc-kit/press/forms); replace it with theme: { ...shadcn, PublicForm: Mine }.
2994
+ A THEME draws it with one component, BlueprintForm (type FormsTheme from
2995
+ @rsc-kit/press/forms), given action, fields, values, submit, done and
2996
+ honeypot; replace it with theme: { ...shadcn, BlueprintForm: Mine }.
2997
+ VISIBLE: fields: { company: { visible: { when: 'topic', is: 'sales' } } }
2998
+ shows a field only while another has one of the values in is (one or a
2999
+ list); not turns it round; neither means once the other is filled in or
3000
+ switched on. A hidden field is not sent or browser-checked, and the server
3001
+ drops one sent anyway, so the schema makes it optional. Laravel's
3002
+ required_if:topic,sales and Go's validate:"required_if=Topic sales" are read
3003
+ as visible, required when shown.
3004
+ FROM: fields: { slug: { from: { field: 'title' } } } fills the slug as the
3005
+ title is typed, until it is edited by hand; left empty, the server fills it.
3006
+ when and field name another field of the form, or startup fails.
2949
3007
  SETUP is the panel's: bun add @rsc-kit/press, and
2950
3008
  @import "@rsc-kit/press/shadcn.css" in the stylesheet.`,
2951
3009
  },