@valbuild/next 0.88.0 → 0.89.0

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 (2) hide show
  1. package/README.md +90 -1
  2. package/package.json +6 -6
package/README.md CHANGED
@@ -55,10 +55,12 @@ Join us on [discord](https://discord.gg/cZzqPvaX8k) to get help or give us feedb
55
55
  - [Nullable](#nullable)
56
56
  - [Array](#array)
57
57
  - [Record](#record)
58
+ - [Router](#router)
58
59
  - [Object](#object)
59
60
  - [Rich text](#richtext)
60
61
  - [Image](#image)
61
62
  - [keyOf](#keyof)
63
+ - [Route](#route)
62
64
 
63
65
  ## Installation
64
66
 
@@ -355,6 +357,42 @@ It is similar to an array, in that editors can add and remove items in it, howev
355
357
  s.record(t.number()); // <- Schema<Record<string, number>>
356
358
  ```
357
359
 
360
+ ## Router
361
+
362
+ The `router` schema is a convenient shorthand for creating a record with router configuration. It combines `s.record()` and `.router()` into a single call.
363
+
364
+ ```ts
365
+ import { s, c, nextAppRouter } from "../val.config";
366
+
367
+ const pageSchema = s.object({ title: s.string() });
368
+
369
+ // Using s.router() - shorthand
370
+ const pagesSchema = s.router(nextAppRouter, pageSchema);
371
+
372
+ // Equivalent to:
373
+ const pagesSchema = s.record(pageSchema).router(nextAppRouter);
374
+ ```
375
+
376
+ ### Example:
377
+
378
+ ```ts
379
+ import { s, c, nextAppRouter } from "../val.config";
380
+
381
+ const pageSchema = s.object({ title: s.string() });
382
+
383
+ // NOTE: to use router(nextAppRouter) - the module must be a sibling of the page.tsx
384
+ export default c.define(
385
+ "/app/[slug]/page.val.ts",
386
+ s.router(nextAppRouter, pageSchema),
387
+ {
388
+ "/test-page": {
389
+ // This is the full pathname of the page - it must match the pattern of the Next JS route
390
+ title: "Test page",
391
+ },
392
+ },
393
+ );
394
+ ```
395
+
358
396
  ## Object
359
397
 
360
398
  ```ts
@@ -363,7 +401,7 @@ s.object({
363
401
  });
364
402
  ```
365
403
 
366
- #### Page router
404
+ #### Page router (using .router() method)
367
405
 
368
406
  You can configure Val to track your page structure and display content as navigable web pages in the editor interface.
369
407
 
@@ -774,6 +812,57 @@ const authors = useVal(otherVal); // s.record(s.object({ name: s.string() }))
774
812
  const nameOfAuthor = authors[articleVal.author].name;
775
813
  ```
776
814
 
815
+ ## Route
816
+
817
+ The `route` schema represents a string that references a route path in your application. It can be used with `include` and `exclude` patterns to constrain which routes are valid.
818
+
819
+ ### Route Schema
820
+
821
+ ```ts
822
+ s.route(); // <- Schema<string>
823
+ ```
824
+
825
+ ### Route with patterns
826
+
827
+ You can use `include` and `exclude` to constrain valid routes using regular expressions:
828
+
829
+ ```ts
830
+ // Only allow API routes
831
+ s.route().include(/^\/api\//);
832
+
833
+ // Exclude admin routes
834
+ s.route().exclude(/^\/admin\//);
835
+
836
+ // Combine both: API routes except internal ones
837
+ s.route()
838
+ .include(/^\/api\//)
839
+ .exclude(/^\/api\/internal\//);
840
+ ```
841
+
842
+ **Pattern semantics:**
843
+
844
+ - If only `include` is set: route must match the include pattern
845
+ - If only `exclude` is set: route must NOT match the exclude pattern
846
+ - If both are set: route must match include AND must NOT match exclude
847
+
848
+ ### Using routes
849
+
850
+ Routes are validated against router modules (records with `.router()` or `s.router()`). The route value must exist as a key in one of your router modules.
851
+
852
+ ```ts
853
+ import { s, c } from "../val.config";
854
+
855
+ const linkSchema = s.object({
856
+ label: s.string(),
857
+ href: s.route().include(/^\//), // Only allow routes starting with /
858
+ });
859
+
860
+ export default c.define("/components/link.val.ts", linkSchema, {
861
+ label: "Home",
862
+ href: "/", // This must exist in a router module
863
+ });
864
+ ```
865
+
777
866
  # Custom validation
778
867
 
779
868
  All schema can use the `validate` method to show custom validation errors to editors.
package/package.json CHANGED
@@ -12,7 +12,7 @@
12
12
  "next",
13
13
  "react"
14
14
  ],
15
- "version": "0.88.0",
15
+ "version": "0.89.0",
16
16
  "scripts": {
17
17
  "typecheck": "tsc --noEmit",
18
18
  "test": "jest"
@@ -49,11 +49,11 @@
49
49
  "exports": true
50
50
  },
51
51
  "dependencies": {
52
- "@valbuild/core": "~0.88.0",
53
- "@valbuild/react": "~0.88.0",
54
- "@valbuild/server": "~0.88.0",
55
- "@valbuild/shared": "~0.88.0",
56
- "@valbuild/ui": "~0.88.0",
52
+ "@valbuild/core": "~0.89.0",
53
+ "@valbuild/react": "~0.89.0",
54
+ "@valbuild/server": "~0.89.0",
55
+ "@valbuild/shared": "~0.89.0",
56
+ "@valbuild/ui": "~0.89.0",
57
57
  "client-only": "^0.0.1",
58
58
  "server-only": "^0.0.1"
59
59
  },